GuC submission support
Subsystems (2)
cover GuC submission support
As discussed in [1], [2] we are enabling GuC submission support in the i915. This is a subset of the patches in step 5 described in [1], basically it is absolute to enable CI with GuC submission on gen11+ platforms.
This series itself will likely be broken down into smaller patch sets to merge. Likely into CTBs changes, basic submission, virtual engines, and resets.
A following series will address the missing patches remaining from [1].
Locally tested on TGL machine and basic tests seem to be passing.
[1] https://patchwork.freedesktop.org/series/89844/
[2] https://patchwork.freedesktop.org/series/91417/
Daniele Ceraolo Spurio (1):
drm/i915/guc: Unblock GuC submission on Gen11+
John Harrison (10):
drm/i915/guc: Module load failure test for CT buffer creation drm/i915: Track 'serial' counts for virtual engines drm/i915/guc: Provide mmio list to be saved/restored on engine reset drm/i915/guc: Don't complain about reset races drm/i915/guc: Enable GuC engine reset
drm/i915/guc: Fix for error capture after full GPU reset with GuC drm/i915/guc: Hook GuC scheduling policies up drm/i915/guc: Connect reset modparam updates to GuC policy flags drm/i915/guc: Include scheduling policies in the debugfs state dump drm/i915/guc: Add golden context to GuC ADS
Matthew Brost (36):
drm/i915/guc: Relax CTB response timeout
drm/i915/guc: Improve error message for unsolicited CT response drm/i915/guc: Increase size of CTB buffers
drm/i915/guc: Add non blocking CTB send function drm/i915/guc: Add stall timer to non blocking CTB send function drm/i915/guc: Optimize CTB writes and reads
drm/i915/guc: Add new GuC interface defines and structures drm/i915/guc: Remove GuC stage descriptor, add lrc descriptor drm/i915/guc: Add lrc descriptor context lookup array drm/i915/guc: Implement GuC submission tasklet drm/i915/guc: Add bypass tasklet submission path to GuC drm/i915/guc: Implement GuC context operations for new inteface drm/i915/guc: Insert fence on context when deregistering drm/i915/guc: Defer context unpin until scheduling is disabled drm/i915/guc: Disable engine barriers with GuC during unpin drm/i915/guc: Extend deregistration fence to schedule disable drm/i915: Disable preempt busywait when using GuC scheduling drm/i915/guc: Ensure request ordering via completion fences drm/i915/guc: Disable semaphores when using GuC scheduling drm/i915/guc: Ensure G2H response has space in buffer drm/i915/guc: Update intel_gt_wait_for_idle to work with GuC drm/i915/guc: Update GuC debugfs to support new GuC drm/i915/guc: Add several request trace points
drm/i915: Add intel_context tracing
drm/i915/guc: GuC virtual engines
drm/i915: Hold reference to intel_context over life of i915_request drm/i915/guc: Disable bonding extension with GuC submission drm/i915/guc: Direct all breadcrumbs for a class to single breadcrumbs drm/i915/guc: Reset implementation for new GuC interface drm/i915: Reset GPU immediately if submission is disabled drm/i915/guc: Add disable interrupts to guc sanitize drm/i915/guc: Suspend/resume implementation for new interface drm/i915/guc: Handle context reset notification drm/i915/guc: Handle engine reset failure notification drm/i915/guc: Enable the timer expired interrupt for GuC drm/i915/guc: Capture error state on context reset
drivers/gpu/drm/i915/gem/i915_gem_context.c | 30 +- drivers/gpu/drm/i915/gem/i915_gem_context.h | 1 + drivers/gpu/drm/i915/gem/i915_gem_mman.c | 3 +- drivers/gpu/drm/i915/gt/gen8_engine_cs.c | 6 +- drivers/gpu/drm/i915/gt/intel_breadcrumbs.c | 41 +- drivers/gpu/drm/i915/gt/intel_breadcrumbs.h | 14 +- .../gpu/drm/i915/gt/intel_breadcrumbs_types.h | 7 + drivers/gpu/drm/i915/gt/intel_context.c | 41 +- drivers/gpu/drm/i915/gt/intel_context.h | 31 +- drivers/gpu/drm/i915/gt/intel_context_types.h | 49 + drivers/gpu/drm/i915/gt/intel_engine.h | 72 +- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 182 +- .../gpu/drm/i915/gt/intel_engine_heartbeat.c | 71 +- .../gpu/drm/i915/gt/intel_engine_heartbeat.h | 4 + drivers/gpu/drm/i915/gt/intel_engine_types.h | 12 +- .../drm/i915/gt/intel_execlists_submission.c | 234 +- .../drm/i915/gt/intel_execlists_submission.h | 11 - drivers/gpu/drm/i915/gt/intel_gt.c | 21 + drivers/gpu/drm/i915/gt/intel_gt.h | 2 + drivers/gpu/drm/i915/gt/intel_gt_pm.c | 6 +- drivers/gpu/drm/i915/gt/intel_gt_requests.c | 22 +- drivers/gpu/drm/i915/gt/intel_gt_requests.h | 9 +- drivers/gpu/drm/i915/gt/intel_lrc_reg.h | 1 - drivers/gpu/drm/i915/gt/intel_reset.c | 20 +- .../gpu/drm/i915/gt/intel_ring_submission.c | 28 + drivers/gpu/drm/i915/gt/intel_rps.c | 4 + drivers/gpu/drm/i915/gt/intel_workarounds.c | 46 +- .../gpu/drm/i915/gt/intel_workarounds_types.h | 1 + drivers/gpu/drm/i915/gt/mock_engine.c | 41 +- drivers/gpu/drm/i915/gt/selftest_context.c | 10 + drivers/gpu/drm/i915/gt/selftest_execlists.c | 20 +- .../gpu/drm/i915/gt/uc/abi/guc_actions_abi.h | 15 + drivers/gpu/drm/i915/gt/uc/intel_guc.c | 82 +- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 106 +- drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c | 460 +++- drivers/gpu/drm/i915/gt/uc/intel_guc_ads.h | 3 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 318 ++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 22 +- .../gpu/drm/i915/gt/uc/intel_guc_debugfs.c | 25 +- drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h | 88 +- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 2197 +++++++++++++++-- .../gpu/drm/i915/gt/uc/intel_guc_submission.h | 17 +- drivers/gpu/drm/i915/gt/uc/intel_uc.c | 102 +- drivers/gpu/drm/i915/gt/uc/intel_uc.h | 11 + drivers/gpu/drm/i915/i915_debugfs.c | 2 + drivers/gpu/drm/i915/i915_debugfs_params.c | 31 + drivers/gpu/drm/i915/i915_gem_evict.c | 1 + drivers/gpu/drm/i915/i915_gpu_error.c | 25 +- drivers/gpu/drm/i915/i915_reg.h | 2 + drivers/gpu/drm/i915/i915_request.c | 159 +- drivers/gpu/drm/i915/i915_request.h | 21 + drivers/gpu/drm/i915/i915_scheduler.c | 6 + drivers/gpu/drm/i915/i915_scheduler.h | 6 + drivers/gpu/drm/i915/i915_scheduler_types.h | 5 + drivers/gpu/drm/i915/i915_trace.h | 197 +- .../gpu/drm/i915/selftests/igt_live_test.c | 2 +- .../gpu/drm/i915/selftests/mock_gem_device.c | 3 +- 57 files changed, 4159 insertions(+), 787 deletions(-)
Signature · 1 line
2.28.0
PATCH 1/47 drm/i915/guc: Relax CTB response timeout
In upcoming patch we will allow more CTB requests to be sent in parallel to the GuC for processing, so we shouldn't assume any more that GuC will always reply without 10ms.
Use bigger value hardcoded value of 1s instead.
v2: Add CONFIG_DRM_I915_GUC_CTB_TIMEOUT config option v3:
(Daniel Vetter)
- Use hardcoded value of 1s rather than config option
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4 -2
@@ -474,14 +474,16 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)/* * Fast commands should complete in less than 10us, so sample quickly * up to that length of time, then switch to a slower sleep-wait loop. -* No GuC command should ever take longer than 10ms. +* No GuC command should ever take longer than 10ms but many GuC +* commands can be inflight at time, so use a 1s timeout on the slower +* sleep-wait loop. */ #define done \ (FIELD_GET(GUC_HXG_MSG_0_ORIGIN, READ_ONCE(req->status)) == \ GUC_HXG_ORIGIN_GUC) err =wait_for_us (done,10 );if (err) - err =wait_for (done,10 ); + err =wait_for (done,1000 );#undef doneif (unlikely (err))
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 01/47] drm/i915/guc: Relax CTB response timeout
Quoted 27 lines · Matthew Brost
In upcoming patch we will allow more CTB requests to be sent in parallel to the GuC for processing, so we shouldn't assume any more that GuC will always reply without 10ms.
Use bigger value hardcoded value of 1s instead.
v2: Add
CONFIG_DRM_I915_GUC_CTB_TIMEOUTconfig option v3:
(Daniel Vetter)
- Use hardcoded value of 1s rather than config optionSigned-off-by Matthew Brost <[email protected]>Cc Michal Wajdeczko <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1@@ -474,14 +474,16 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)/* * Fast commands should complete in less than 10us, so sample quickly * up to that length of time, then switch to a slower sleep-wait loop. -* No GuC command should ever take longer than 10ms. +* No GuC command should ever take longer than 10ms but many GuC
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 486
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-1+* commands can be inflight at time, so use a 1s timeout on the slower +* sleep-wait loop. */ #define done \ (FIELD_GET(GUC_HXG_MSG_0_ORIGIN, READ_ONCE(req->status)) == \ GUC_HXG_ORIGIN_GUC) err =wait_for_us (done,10 );if (err) - err =wait_for (done,10 ); + err =wait_for (done,1000 );
can we add #defines for these 10/1000 values? with that
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 489
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0#undef doneif (unlikely (err))
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 2/47 drm/i915/guc: Improve error message for unsolicited CT response
In reply to Matthew BrostImprove the error message when a unsolicited CT response is received by printing fence that couldn't be found, the last fence, and all requests with a response outstanding.
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7 -3
@@ -730,12 +730,16 @@ static int ct_handle_response(struct intel_guc_ct *ct, struct ct_incoming_msg *r found = true;break ; } -spin_unlock_irqrestore (&ct->requests.lock, flags); -if (!found) {CT_ERROR (ct,"Unsolicited response (fence %u)\n" , fence); -return -ENOKEY ; +CT_ERROR (ct,"Could not find fence=%u, last_fence=%u\n" , fence, + ct->requests.last_fence); +list_for_each_entry (req, &ct->requests.pending, link) +CT_ERROR (ct,"request %u awaits response\n" , + req->fence); + err = -ENOKEY ; } +spin_unlock_irqrestore (&ct->requests.lock, flags);if (unlikely (err))return err;
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 02/47] drm/i915/guc: Improve error message for unsolicited CT response
Quoted 17 lines · Matthew Brost
Improve the error message when a unsolicited CT response is received by printing fence that couldn't be found, the last fence, and all requests with a response outstanding.
Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0@@ -730,12 +730,16 @@ static int ct_handle_response(struct intel_guc_ct *ct, struct ct_incoming_msg *r found = true;break ; }
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_handle_response(struct intel_guc_ct *ct, struct ct_incoming_msg *r · line 739
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-3-spin_unlock_irqrestore (&ct->requests.lock, flags); -if (!found) {CT_ERROR (ct,"Unsolicited response (fence %u)\n" , fence); -return -ENOKEY ; +CT_ERROR (ct,"Could not find fence=%u, last_fence=%u\n" , fence, + ct->requests.last_fence); +list_for_each_entry (req, &ct->requests.pending, link) +CT_ERROR (ct,"request %u awaits response\n" , + req->fence);
not quite sure how listing of awaiting requests could help here (if we suspect that this is a duplicated reply, then we should rather track short list of already processed messages to look there) but since it does not hurt too much, this is:
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_handle_response(struct intel_guc_ct *ct, struct ct_incoming_msg *r · line 745
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +2
-0+ err = -ENOKEY ; } +spin_unlock_irqrestore (&ct->requests.lock, flags);if (unlikely (err))return err;
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 3/47 drm/i915/guc: Increase size of CTB buffers
In reply to Matthew BrostWith the introduction of non-blocking CTBs more than one CTB can be in flight at a time. Increasing the size of the CTBs should reduce how often software hits the case where no space is available in the CTB buffer.
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +8 -3
@@ -58,11 +58,16 @@ static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct)* +--------+-----------------------------------------------+------+ * * Size of each `CT Buffer`_ must be multiple of 4K. -* As we don't expect too many messages, for now use minimum sizes. +* We don't expect too many messages in flight at any time, unless we are +* using the GuC submission. In that case each request requires a minimum +* 2 dwords which gives us a maximum 256 queue'd requests. Hopefully this +* enough space to avoid backpressure on the driver. We increase the size +* of the receive buffer (relative to the send) to ensure a G2H response +* CTB has a landing spot. */ #define CTB_DESC_SIZE ALIGN(sizeof(struct guc_ct_buffer_desc), SZ_2K)#define CTB_H2G_BUFFER_SIZE (SZ_4K) -#define CTB_G2H_BUFFER_SIZE (SZ_4K) +#define CTB_G2H_BUFFER_SIZE (4 * CTB_H2G_BUFFER_SIZE)struct ct_request {struct list_head link;
@@ -641,7 +646,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)/* beware of buffer wrap case */ if (unlikely (available <0 )) available += size; -CT_DEBUG (ct,"available %d (%u:%u)\n" , available, head, tail); +CT_DEBUG (ct,"available %d (%u:%u:%u)\n" , available, head, tail, size);GEM_BUG_ON (available <0 ); header = cmds[head];
Signature · 1 line
2.28.0
Re: [PATCH 03/47] drm/i915/guc: Increase size of CTB buffers
Quoted 35 lines · Matthew Brost
With the introduction of non-blocking CTBs more than one CTB can be in flight at a time. Increasing the size of the CTBs should reduce how often software hits the case where no space is available in the CTB buffer.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-2@@ -58,11 +58,16 @@ static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct)* +--------+-----------------------------------------------+------+ * * Size of each `CT Buffer`_ must be multiple of 4K. -* As we don't expect too many messages, for now use minimum sizes. +* We don't expect too many messages in flight at any time, unless we are +* using the GuC submission. In that case each request requires a minimum +* 2 dwords which gives us a maximum 256 queue'd requests. Hopefully this +* enough space to avoid backpressure on the driver. We increase the size +* of the receive buffer (relative to the send) to ensure a G2H response +* CTB has a landing spot. */ #define CTB_DESC_SIZE ALIGN(sizeof(struct guc_ct_buffer_desc), SZ_2K)#define CTB_H2G_BUFFER_SIZE (SZ_4K) -#define CTB_G2H_BUFFER_SIZE (SZ_4K) +#define CTB_G2H_BUFFER_SIZE (4 * CTB_H2G_BUFFER_SIZE)struct ct_request {struct list_head link;
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) · line 649
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1@@ -641,7 +646,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)/* beware of buffer wrap case */ if (unlikely (available <0 )) available += size; -CT_DEBUG (ct,"available %d (%u:%u)\n" , available, head, tail); +CT_DEBUG (ct,"available %d (%u:%u:%u)\n" , available, head, tail, size);
CTB size is already printed in intel_guc_ct_init() and is fixed so not sure if repeating it on every ct_read has any benefit
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) · line 652
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0GEM_BUG_ON (available <0 ); header = cmds[head];
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 03/47] drm/i915/guc: Increase size of CTB buffers
Quoted 35 lines · Michal Wajdeczko
Quoted 32 lines · Matthew Brost
With the introduction of non-blocking CTBs more than one CTB can be in flight at a time. Increasing the size of the CTBs should reduce how often software hits the case where no space is available in the CTB buffer.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-2@@ -58,11 +58,16 @@ static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct)* +--------+-----------------------------------------------+------+ * * Size of each `CT Buffer`_ must be multiple of 4K. -* As we don't expect too many messages, for now use minimum sizes. +* We don't expect too many messages in flight at any time, unless we are +* using the GuC submission. In that case each request requires a minimum +* 2 dwords which gives us a maximum 256 queue'd requests. Hopefully this +* enough space to avoid backpressure on the driver. We increase the size +* of the receive buffer (relative to the send) to ensure a G2H response +* CTB has a landing spot. */ #define CTB_DESC_SIZE ALIGN(sizeof(struct guc_ct_buffer_desc), SZ_2K)#define CTB_H2G_BUFFER_SIZE (SZ_4K) -#define CTB_G2H_BUFFER_SIZE (SZ_4K) +#define CTB_G2H_BUFFER_SIZE (4 * CTB_H2G_BUFFER_SIZE)
Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) · line 649
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1struct ct_request {struct list_head link;@@ -641,7 +646,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)/* beware of buffer wrap case */ if (unlikely (available <0 )) available += size; -CT_DEBUG (ct,"available %d (%u:%u)\n" , available, head, tail); +CT_DEBUG (ct,"available %d (%u:%u:%u)\n" , available, head, tail, size);CTB size is already printed in
intel_guc_ct_init()and is fixed so not sure if repeating it on everyct_readhas any benefit
I'd say more debug the better and if CT_DEBUG is enabled the logs are very verbose so an extra value doesn't really hurt.
Matt
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0GEM_BUG_ON (available <0 ); header = cmds[head];
Michal Wajdeczko
Reviewed-byRe: [PATCH 03/47] drm/i915/guc: Increase size of CTB buffers
Quoted 49 lines · Matthew Brost
Quoted 35 lines · Michal Wajdeczko
Quoted 32 lines · Matthew Brost
With the introduction of non-blocking CTBs more than one CTB can be in flight at a time. Increasing the size of the CTBs should reduce how often software hits the case where no space is available in the CTB buffer.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-2@@ -58,11 +58,16 @@ static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct)* +--------+-----------------------------------------------+------+ * * Size of each `CT Buffer`_ must be multiple of 4K. -* As we don't expect too many messages, for now use minimum sizes. +* We don't expect too many messages in flight at any time, unless we are +* using the GuC submission. In that case each request requires a minimum +* 2 dwords which gives us a maximum 256 queue'd requests. Hopefully this +* enough space to avoid backpressure on the driver. We increase the size +* of the receive buffer (relative to the send) to ensure a G2H response +* CTB has a landing spot. */ #define CTB_DESC_SIZE ALIGN(sizeof(struct guc_ct_buffer_desc), SZ_2K)#define CTB_H2G_BUFFER_SIZE (SZ_4K) -#define CTB_G2H_BUFFER_SIZE (SZ_4K) +#define CTB_G2H_BUFFER_SIZE (4 * CTB_H2G_BUFFER_SIZE)Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) · line 649
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1struct ct_request {struct list_head link;@@ -641,7 +646,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)/* beware of buffer wrap case */ if (unlikely (available <0 )) available += size; -CT_DEBUG (ct,"available %d (%u:%u)\n" , available, head, tail); +CT_DEBUG (ct,"available %d (%u:%u:%u)\n" , available, head, tail, size);CTB size is already printed in
intel_guc_ct_init()and is fixed so not sure if repeating it on everyct_readhas any benefit
Quoted 2 lines
I'd say more debug the better and if
CT_DEBUGis enabled the logs are very verbose so an extra value doesn't really hurt.
fair, but this doesn't mean we should add little/no value item, anyway since DEBUG_GUC is if off by default, this is:
Quoted 7 lines
Matt
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0GEM_BUG_ON (available <0 ); header = cmds[head];
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 4/47 drm/i915/guc: Add non blocking CTB send function
In reply to Matthew BrostAdd non blocking CTB send function, intel_guc_send_nb. GuC submission will send CTBs in the critical path and does not need to wait for these CTBs to complete before moving on, hence the need for this new function.
The non-blocking CTB now must have a flow control mechanism to ensure the buffer isn't overrun. A lazy spin wait is used as we believe the flow control condition should be rare with a properly sized buffer.
The function, intel_guc_send_nb, is exported in this patch but unused. Several patches later in the series make use of this function.
--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 12 +++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 77 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 3 +- 3 files changed, 82 insertions(+), 10 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +10 -2
@@ -74,7 +74,15 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)static inline int intel_guc_send (struct intel_guc *guc,const u32 *action,u32 len) { -return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ); +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ,0 ); +} + +#define INTEL_GUC_SEND_NB BIT(31) +static +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +{ +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , +INTEL_GUC_SEND_NB ); } static inline int
@@ -82,7 +90,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size) {return intel_guc_ct_send (&guc->ct, action, len, - response_buf, response_buf_size); + response_buf, response_buf_size,0 ); }static inline void intel_guc_to_host_event_handler (struct intel_guc *guc)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +71 -6
133 lines not on this page · raw message
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1 -2
@@ -42,7 +42,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking
@@ -88,7 +87,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 04/47] drm/i915/guc: Add non blocking CTB send function
Quoted 24 lines · Matthew Brost
Add non blocking CTB send function,
intel_guc_send_nb. GuC submission will send CTBs in the critical path and does not need to wait for these CTBs to complete before moving on, hence the need for this new function.The non-blocking CTB now must have a flow control mechanism to ensure the buffer isn't overrun. A lazy spin wait is used as we believe the flow control condition should be rare with a properly sized buffer.
The function,
intel_guc_send_nb, is exported in this patch but unused. Several patches later in the series make use of this function.Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 12 +++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 77 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 3 +- 3 files changed, 82 insertions(+), 10 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc.h +0
-0
drivers/gpu/drm/i915/gt/uc/intel_guc.h static inline struct intel_guc *log_to_guc(struct intel_guc_log *log) · line 80
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-1@@ -74,7 +74,15 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)static inline int intel_guc_send (struct intel_guc *guc,const u32 *action,u32 len) { -return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ); +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ,0 ); +} + +#define INTEL_GUC_SEND_NB BIT(31)
hmm, this flag really belongs to intel_guc_ct_send() so it should be defined as CTB flag near that function declaration
Quoted 46 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +6
-1+static +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +{ +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , +INTEL_GUC_SEND_NB ); } static inline int@@ -82,7 +90,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size) {return intel_guc_ct_send (&guc->ct, action, len, - response_buf, response_buf_size); + response_buf, response_buf_size,0 ); }static inline void intel_guc_to_host_event_handler (struct intel_guc *guc)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-1@@ -3,6 +3,11 @@* Copyright © 2016-2019 Intel Corporation */ +#include <linux/circ_buf.h> +#include <linux/ktime.h> +#include <linux/time64.h> +#include <linux/timekeeping.h> +#include "i915_drv.h" #include "intel_guc_ct.h" #include "gt/intel_gt.h" @@ -373,7 +378,7 @@ static void write_barrier(struct intel_guc_ct *ct)static int ct_write (struct intel_guc_ct *ct,const u32 *action,u32 len/* in dwords */ , -u32 fence) +u32 fence,u32 flags) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc;@@ -421,9 +426,13 @@ static int ct_write(struct intel_guc_ct *ct,FIELD_PREP (GUC_CTB_MSG_0_NUM_DWORDS , len) |FIELD_PREP (GUC_CTB_MSG_0_FENCE , fence);
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 435
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-3- hxg =FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | -FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | -GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]); + hxg = (flags &INTEL_GUC_SEND_NB ) ? + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_EVENT ) | +FIELD_PREP (GUC_HXG_EVENT_MSG_0_ACTION | +GUC_HXG_EVENT_MSG_0_DATA0 , action[0 ])) : + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | +FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | +GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]));
or as we already switched to accept and return whole HXG messages in guc_send_mmio() maybe we should do the same for CTB variant too and instead of using extra flag just let caller to prepare proper HXG header with HXG_EVENT type and then in CTB code just look at this type to make decision which code path to use
note that existing callers should not be impacted, as full HXG header for the REQUEST message looks exactly the same as "action" code alone.
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0CT_DEBUG (ct,"writing (tail %u) %*ph %*ph %*ph\n" , tail,4 , &header,4 , &hxg,4 * (len -1 ), &action[1 ]);@@ -498,6 +507,46 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; }
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 518
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +{ +struct guc_ct_buffer_desc *desc = ctb->desc; +u32 head =READ_ONCE (desc->head); +u32 space; + + space =CIRC_SPACE (desc->tail, head, ctb->size); + +return space >= len_dw;
here you are returning true(1) as has room
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-0+} + +static int ct_send_nb(struct intel_guc_ct *ct, + const u32 *action, + u32 len,
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 533
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-0+ u32 flags) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +unsigned long spin_flags; +u32 fence; +int ret; + +spin_lock_irqsave (&ctb->lock, spin_flags); + + ret =h2g_has_room (ctb, len +1 );
but here you treat "1" it as en error
and this "1" is GUC_HXG_MSG_MIN_LEN, right ?
Quoted 28 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +17
-0+if (unlikely (ret)) + goto out; + + fence =ct_get_next_fence (ct); + ret =ct_write (ct, action, len, fence, flags); +if (unlikely (ret)) + goto out; + +intel_guc_notify (ct_to_guc (ct)); + +out: +spin_unlock_irqrestore (&ctb->lock, spin_flags); + +return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -505,6 +554,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;u32 fence;
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 572
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-0@@ -514,8 +564,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep (); +/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare.
shouldn't we at least try to log such cases with RATE_LIMITED to find out how "rare" it is, or if really unlikely just return -EBUSY as in case of non-blocking send ?
Quoted 53 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +12
-2+*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!h2g_has_room (ctb, len +1 ))) { +spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + } fence =ct_get_next_fence (ct); request.fence = fence;@@ -527,7 +589,7 @@ static int ct_send(struct intel_guc_ct *ct,list_add_tail (&request.link, &ct->requests.pending);spin_unlock (&ct->requests.lock); - err =ct_write (ct, action, len, fence); + err =ct_write (ct, action, len, fence,0 );spin_unlock_irqrestore (&ct->ctbs.send.lock, flags);@@ -569,7 +631,7 @@ static int ct_send(struct intel_guc_ct *ct,* Command Transport (CT) buffer based GuC send function. */ int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size) +u32 *response_buf,u32 response_buf_size,u32 flags) {u32 status = ~0 ;/* undefined */ int ret;@@ -579,6 +641,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,return -ENODEV ; } +if (flags &INTEL_GUC_SEND_NB ) +return ct_send_nb (ct, action, len, flags); + ret =ct_send (ct, action, len, response_buf, response_buf_size, &status);if (unlikely (ret <0 )) { CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n",drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +0
-1@@ -42,7 +42,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) · line 93
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-1@@ -88,7 +87,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 04/47] drm/i915/guc: Add non blocking CTB send function
Quoted 22 lines · Michal Wajdeczko
Quoted 19 lines · Matthew Brost
Add non blocking CTB send function,
intel_guc_send_nb. GuC submission will send CTBs in the critical path and does not need to wait for these CTBs to complete before moving on, hence the need for this new function.The non-blocking CTB now must have a flow control mechanism to ensure the buffer isn't overrun. A lazy spin wait is used as we believe the flow control condition should be rare with a properly sized buffer.
The function,
intel_guc_send_nb, is exported in this patch but unused. Several patches later in the series make use of this function.Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 12 +++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 77 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 3 +- 3 files changed, 82 insertions(+), 10 deletions(-)
Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h static inline struct intel_guc *log_to_guc(struct intel_guc_log *log) · line 80
Quoted 13 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-1@@ -74,7 +74,15 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)static inline int intel_guc_send (struct intel_guc *guc,const u32 *action,u32 len) { -return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ); +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ,0 ); +} + +#define INTEL_GUC_SEND_NB BIT(31)hmm, this flag really belongs to
intel_guc_ct_send()so it should be defined as CTB flag near that function declaration
I can move this up a few lines.
Quoted 46 lines
Quoted 46 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +6
-1+static +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +{ +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , +INTEL_GUC_SEND_NB ); } static inline int@@ -82,7 +90,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size) {return intel_guc_ct_send (&guc->ct, action, len, - response_buf, response_buf_size); + response_buf, response_buf_size,0 ); }static inline void intel_guc_to_host_event_handler (struct intel_guc *guc)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-1@@ -3,6 +3,11 @@* Copyright © 2016-2019 Intel Corporation */ +#include <linux/circ_buf.h> +#include <linux/ktime.h> +#include <linux/time64.h> +#include <linux/timekeeping.h> +#include "i915_drv.h" #include "intel_guc_ct.h" #include "gt/intel_gt.h" @@ -373,7 +378,7 @@ static void write_barrier(struct intel_guc_ct *ct)static int ct_write (struct intel_guc_ct *ct,const u32 *action,u32 len/* in dwords */ , -u32 fence) +u32 fence,u32 flags) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc;@@ -421,9 +426,13 @@ static int ct_write(struct intel_guc_ct *ct,FIELD_PREP (GUC_CTB_MSG_0_NUM_DWORDS , len) |FIELD_PREP (GUC_CTB_MSG_0_FENCE , fence);
Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 435
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-3- hxg =FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | -FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | -GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]); + hxg = (flags &INTEL_GUC_SEND_NB ) ? + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_EVENT ) | +FIELD_PREP (GUC_HXG_EVENT_MSG_0_ACTION | +GUC_HXG_EVENT_MSG_0_DATA0 , action[0 ])) : + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | +FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | +GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]));or as we already switched to accept and return whole HXG messages in
guc_send_mmio()maybe we should do the same for CTB variant too and instead of using extra flag just let caller to prepare proper HXG header withHXG_EVENTtype and then in CTB code just look at this type to make decision which code path to use
Not sure I follow. Anyways could this be done in a follow up by you if want this change.
Quoted 10 lines
note that existing callers should not be impacted, as full HXG header for the REQUEST message looks exactly the same as "action" code alone.
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0CT_DEBUG (ct,"writing (tail %u) %*ph %*ph %*ph\n" , tail,4 , &header,4 , &hxg,4 * (len -1 ), &action[1 ]);@@ -498,6 +507,46 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; }
Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 518
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +{ +struct guc_ct_buffer_desc *desc = ctb->desc; +u32 head =READ_ONCE (desc->head); +u32 space; + + space =CIRC_SPACE (desc->tail, head, ctb->size); + +return space >= len_dw;here you are returning true(1) as has room
See below.
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+} + +static int ct_send_nb (struct intel_guc_ct *ct, +const u32 *action, +u32 len, +u32 flags) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +unsigned long spin_flags;
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 533
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-0+u32 fence; +int ret; + +spin_lock_irqsave (&ctb->lock, spin_flags); + + ret =h2g_has_room (ctb, len +1 );but here you treat "1" it as en error
Yes, this patch is broken but fixed in a follow up one. Regardless I'll fix this patch in place.
Quoted 2 lines
and this "1" is
GUC_HXG_MSG_MIN_LEN, right ?
Not exactly. This is following how ct_send() uses the action + len field. Action[0] field goes in the HXG header and extra + 1 is for the CT header.
Quoted 33 lines
Quoted 33 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +18
-0+if (unlikely (ret)) + goto out; + + fence =ct_get_next_fence (ct); + ret =ct_write (ct, action, len, fence, flags); +if (unlikely (ret)) + goto out; + +intel_guc_notify (ct_to_guc (ct)); + +out: +spin_unlock_irqrestore (&ctb->lock, spin_flags); + +return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -505,6 +554,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;u32 fence;@@ -514,8 +564,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep ();
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 572
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-0+/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare. shouldn't we at least try to log such cases with
RATE_LIMITEDto find out how "rare" it is, or if really unlikely just return-EBUSYas in case of non-blocking send ?
Definitely not return -EBUSY as this a blocking call. Perhaps we can log this, but IGTs likely can hit rather easily. It really is only interesting if real workloads hit this. Regardless that can be a follow up.
Matt
Quoted 61 lines
Quoted 61 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +12
-2+*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!h2g_has_room (ctb, len +1 ))) { +spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + } fence =ct_get_next_fence (ct); request.fence = fence;@@ -527,7 +589,7 @@ static int ct_send(struct intel_guc_ct *ct,list_add_tail (&request.link, &ct->requests.pending);spin_unlock (&ct->requests.lock); - err =ct_write (ct, action, len, fence); + err =ct_write (ct, action, len, fence,0 );spin_unlock_irqrestore (&ct->ctbs.send.lock, flags);@@ -569,7 +631,7 @@ static int ct_send(struct intel_guc_ct *ct,* Command Transport (CT) buffer based GuC send function. */ int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size) +u32 *response_buf,u32 response_buf_size,u32 flags) {u32 status = ~0 ;/* undefined */ int ret;@@ -579,6 +641,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,return -ENODEV ; } +if (flags &INTEL_GUC_SEND_NB ) +return ct_send_nb (ct, action, len, flags); + ret =ct_send (ct, action, len, response_buf, response_buf_size, &status);if (unlikely (ret <0 )) { CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n",drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-2@@ -42,7 +42,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking @@ -88,7 +87,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */
Re: [Intel-gfx] [PATCH 04/47] drm/i915/guc: Add non blocking CTB send function
Quoted 157 lines · Matthew Brost
Quoted 22 lines · Michal Wajdeczko
Quoted 19 lines · Matthew Brost
Add non blocking CTB send function,
intel_guc_send_nb. GuC submission will send CTBs in the critical path and does not need to wait for these CTBs to complete before moving on, hence the need for this new function.The non-blocking CTB now must have a flow control mechanism to ensure the buffer isn't overrun. A lazy spin wait is used as we believe the flow control condition should be rare with a properly sized buffer.
The function,
intel_guc_send_nb, is exported in this patch but unused. Several patches later in the series make use of this function.Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 12 +++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 77 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 3 +- 3 files changed, 82 insertions(+), 10 deletions(-)Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h static inline struct intel_guc *log_to_guc(struct intel_guc_log *log) · line 80
Quoted 13 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-1@@ -74,7 +74,15 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)static inline int intel_guc_send (struct intel_guc *guc,const u32 *action,u32 len) { -return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ); +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ,0 ); +} + +#define INTEL_GUC_SEND_NB BIT(31)hmm, this flag really belongs to
intel_guc_ct_send()so it should be defined as CTB flag near that function declarationI can move this up a few lines.
Quoted 46 lines
Quoted 46 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +6
-1+static +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +{ +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , +INTEL_GUC_SEND_NB ); } static inline int@@ -82,7 +90,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size) {return intel_guc_ct_send (&guc->ct, action, len, - response_buf, response_buf_size); + response_buf, response_buf_size,0 ); }static inline void intel_guc_to_host_event_handler (struct intel_guc *guc)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-1@@ -3,6 +3,11 @@* Copyright © 2016-2019 Intel Corporation */ +#include <linux/circ_buf.h> +#include <linux/ktime.h> +#include <linux/time64.h> +#include <linux/timekeeping.h> +#include "i915_drv.h" #include "intel_guc_ct.h" #include "gt/intel_gt.h" @@ -373,7 +378,7 @@ static void write_barrier(struct intel_guc_ct *ct)static int ct_write (struct intel_guc_ct *ct,const u32 *action,u32 len/* in dwords */ , -u32 fence) +u32 fence,u32 flags) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc;@@ -421,9 +426,13 @@ static int ct_write(struct intel_guc_ct *ct,FIELD_PREP (GUC_CTB_MSG_0_NUM_DWORDS , len) |FIELD_PREP (GUC_CTB_MSG_0_FENCE , fence);Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 435
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-3- hxg =FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | -FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | -GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]); + hxg = (flags &INTEL_GUC_SEND_NB ) ? + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_EVENT ) | +FIELD_PREP (GUC_HXG_EVENT_MSG_0_ACTION | +GUC_HXG_EVENT_MSG_0_DATA0 , action[0 ])) : + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | +FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | +GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]));or as we already switched to accept and return whole HXG messages in
guc_send_mmio()maybe we should do the same for CTB variant too and instead of using extra flag just let caller to prepare proper HXG header withHXG_EVENTtype and then in CTB code just look at this type to make decision which code path to useNot sure I follow. Anyways could this be done in a follow up by you if want this change.
Quoted 10 lines
note that existing callers should not be impacted, as full HXG header for the REQUEST message looks exactly the same as "action" code alone.
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0CT_DEBUG (ct,"writing (tail %u) %*ph %*ph %*ph\n" , tail,4 , &header,4 , &hxg,4 * (len -1 ), &action[1 ]);@@ -498,6 +507,46 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; }Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 518
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +{ +struct guc_ct_buffer_desc *desc = ctb->desc; +u32 head =READ_ONCE (desc->head); +u32 space; + + space =CIRC_SPACE (desc->tail, head, ctb->size); + +return space >= len_dw;here you are returning true(1) as has room
See below.
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+} + +static int ct_send_nb (struct intel_guc_ct *ct, +const u32 *action, +u32 len, +u32 flags) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +unsigned long spin_flags;Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 533
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-0+u32 fence; +int ret; + +spin_lock_irqsave (&ctb->lock, spin_flags); + + ret =h2g_has_room (ctb, len +1 );but here you treat "1" it as en error
Yes, this patch is broken but fixed in a follow up one. Regardless I'll fix this patch in place.
Quoted 6 lines
Quoted 2 lines
and this "1" is
GUC_HXG_MSG_MIN_LEN, right ?Not exactly. This is following how
ct_send()uses the action + len field. Action[0] field goes in the HXG header and extra + 1 is for the CT header.
well, "len" already counts "action" so by treating input as full HXG message (including HXG header) will make it cleaner
we can try do it later but by doing it right now we would avoid introducing this send_nb() function and deprecating them long term again
Quoted 44 lines
Quoted 34 lines
Quoted 34 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +18
-0+if (unlikely (ret)) + goto out; + + fence =ct_get_next_fence (ct); + ret =ct_write (ct, action, len, fence, flags); +if (unlikely (ret)) + goto out; + +intel_guc_notify (ct_to_guc (ct)); + +out: +spin_unlock_irqrestore (&ctb->lock, spin_flags); + +return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -505,6 +554,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;u32 fence;@@ -514,8 +564,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep ();Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 572
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-0+/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare. shouldn't we at least try to log such cases with
RATE_LIMITEDto find out how "rare" it is, or if really unlikely just return-EBUSYas in case of non-blocking send ?
Quoted 1 line
Definitely not return
-EBUSYas this a blocking call. Perhaps we can log
blocking calls still can fail for various reasons, full CTB is one of them, and if we return error (now broken) for non-blocking variant then we should do the same for blocking variant as well and let the caller decide about next steps
Quoted 3 lines
this, but IGTs likely can hit rather easily. It really is only interesting if real workloads hit this. Regardless that can be a follow up.
if we hide retry in a silent loop then we will not find it out if we hit this condition (IGT or real WL) or not
Quoted 64 lines
Matt
Quoted 61 lines
Quoted 61 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +12
-2+*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!h2g_has_room (ctb, len +1 ))) { +spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + } fence =ct_get_next_fence (ct); request.fence = fence;@@ -527,7 +589,7 @@ static int ct_send(struct intel_guc_ct *ct,list_add_tail (&request.link, &ct->requests.pending);spin_unlock (&ct->requests.lock); - err =ct_write (ct, action, len, fence); + err =ct_write (ct, action, len, fence,0 );spin_unlock_irqrestore (&ct->ctbs.send.lock, flags);@@ -569,7 +631,7 @@ static int ct_send(struct intel_guc_ct *ct,* Command Transport (CT) buffer based GuC send function. */ int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size) +u32 *response_buf,u32 response_buf_size,u32 flags) {u32 status = ~0 ;/* undefined */ int ret;@@ -579,6 +641,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,return -ENODEV ; } +if (flags &INTEL_GUC_SEND_NB ) +return ct_send_nb (ct, action, len, flags); + ret =ct_send (ct, action, len, response_buf, response_buf_size, &status);if (unlikely (ret <0 )) { CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n",drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-2@@ -42,7 +42,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking @@ -88,7 +87,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */
Re: [Intel-gfx] [PATCH 04/47] drm/i915/guc: Add non blocking CTB send function
Quoted 163 lines · Michal Wajdeczko
Quoted 160 lines · Matthew Brost
Quoted 22 lines · Michal Wajdeczko
Quoted 19 lines · Matthew Brost
Add non blocking CTB send function,
intel_guc_send_nb. GuC submission will send CTBs in the critical path and does not need to wait for these CTBs to complete before moving on, hence the need for this new function.The non-blocking CTB now must have a flow control mechanism to ensure the buffer isn't overrun. A lazy spin wait is used as we believe the flow control condition should be rare with a properly sized buffer.
The function,
intel_guc_send_nb, is exported in this patch but unused. Several patches later in the series make use of this function.Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 12 +++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 77 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 3 +- 3 files changed, 82 insertions(+), 10 deletions(-)Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h static inline struct intel_guc *log_to_guc(struct intel_guc_log *log) · line 80
Quoted 13 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-1@@ -74,7 +74,15 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)static inline int intel_guc_send (struct intel_guc *guc,const u32 *action,u32 len) { -return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ); +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ,0 ); +} + +#define INTEL_GUC_SEND_NB BIT(31)hmm, this flag really belongs to
intel_guc_ct_send()so it should be defined as CTB flag near that function declarationI can move this up a few lines.
Quoted 46 lines
Quoted 46 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +6
-1+static +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +{ +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , +INTEL_GUC_SEND_NB ); } static inline int@@ -82,7 +90,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size) {return intel_guc_ct_send (&guc->ct, action, len, - response_buf, response_buf_size); + response_buf, response_buf_size,0 ); }static inline void intel_guc_to_host_event_handler (struct intel_guc *guc)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-1@@ -3,6 +3,11 @@* Copyright © 2016-2019 Intel Corporation */ +#include <linux/circ_buf.h> +#include <linux/ktime.h> +#include <linux/time64.h> +#include <linux/timekeeping.h> +#include "i915_drv.h" #include "intel_guc_ct.h" #include "gt/intel_gt.h" @@ -373,7 +378,7 @@ static void write_barrier(struct intel_guc_ct *ct)static int ct_write (struct intel_guc_ct *ct,const u32 *action,u32 len/* in dwords */ , -u32 fence) +u32 fence,u32 flags) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc;@@ -421,9 +426,13 @@ static int ct_write(struct intel_guc_ct *ct,FIELD_PREP (GUC_CTB_MSG_0_NUM_DWORDS , len) |FIELD_PREP (GUC_CTB_MSG_0_FENCE , fence);Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 435
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-3- hxg =FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | -FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | -GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]); + hxg = (flags &INTEL_GUC_SEND_NB ) ? + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_EVENT ) | +FIELD_PREP (GUC_HXG_EVENT_MSG_0_ACTION | +GUC_HXG_EVENT_MSG_0_DATA0 , action[0 ])) : + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | +FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | +GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]));or as we already switched to accept and return whole HXG messages in
guc_send_mmio()maybe we should do the same for CTB variant too and instead of using extra flag just let caller to prepare proper HXG header withHXG_EVENTtype and then in CTB code just look at this type to make decision which code path to useNot sure I follow. Anyways could this be done in a follow up by you if want this change.
Quoted 10 lines
note that existing callers should not be impacted, as full HXG header for the REQUEST message looks exactly the same as "action" code alone.
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0CT_DEBUG (ct,"writing (tail %u) %*ph %*ph %*ph\n" , tail,4 , &header,4 , &hxg,4 * (len -1 ), &action[1 ]);@@ -498,6 +507,46 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; }Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 518
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +{ +struct guc_ct_buffer_desc *desc = ctb->desc; +u32 head =READ_ONCE (desc->head); +u32 space; + + space =CIRC_SPACE (desc->tail, head, ctb->size); + +return space >= len_dw;here you are returning true(1) as has room
See below.
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+} + +static int ct_send_nb (struct intel_guc_ct *ct, +const u32 *action, +u32 len, +u32 flags) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +unsigned long spin_flags;Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 533
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-0+u32 fence; +int ret; + +spin_lock_irqsave (&ctb->lock, spin_flags); + + ret =h2g_has_room (ctb, len +1 );but here you treat "1" it as en error
Yes, this patch is broken but fixed in a follow up one. Regardless I'll fix this patch in place.
Quoted 2 lines
and this "1" is
GUC_HXG_MSG_MIN_LEN, right ?
Quoted 7 lines
Quoted 3 lines
Not exactly. This is following how
ct_send()uses the action + len field. Action[0] field goes in the HXG header and extra + 1 is for the CT header.well, "len" already counts "action" so by treating input as full HXG message (including HXG header) will make it cleaner
Yes, I know. See above. To me GUC_HXG_MSG_MIN_LEN makes zero sense and it is worse than adding + 1. This + 1 accounts for the CT header not the HXG header. If any we add a new define, GUC_CT_HDR_LEN, and add that.
Matt
Quoted 125 lines
we can try do it later but by doing it right now we would avoid introducing this
send_nb()function and deprecating them long term againQuoted 44 lines
Quoted 34 lines
Quoted 34 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +18
-0+if (unlikely (ret)) + goto out; + + fence =ct_get_next_fence (ct); + ret =ct_write (ct, action, len, fence, flags); +if (unlikely (ret)) + goto out; + +intel_guc_notify (ct_to_guc (ct)); + +out: +spin_unlock_irqrestore (&ctb->lock, spin_flags); + +return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -505,6 +554,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;u32 fence;@@ -514,8 +564,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep ();Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 572
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-0+/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare. shouldn't we at least try to log such cases with
RATE_LIMITEDto find out how "rare" it is, or if really unlikely just return-EBUSYas in case of non-blocking send ?Quoted 1 line
Definitely not return
-EBUSYas this a blocking call. Perhaps we can logblocking calls still can fail for various reasons, full CTB is one of them, and if we return error (now broken) for non-blocking variant then we should do the same for blocking variant as well and let the caller decide about next steps
Quoted 3 lines
this, but IGTs likely can hit rather easily. It really is only interesting if real workloads hit this. Regardless that can be a follow up.
if we hide retry in a silent loop then we will not find it out if we hit this condition (IGT or real WL) or not
Quoted 64 lines
Matt
Quoted 61 lines
Quoted 61 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +12
-2+*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!h2g_has_room (ctb, len +1 ))) { +spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + } fence =ct_get_next_fence (ct); request.fence = fence;@@ -527,7 +589,7 @@ static int ct_send(struct intel_guc_ct *ct,list_add_tail (&request.link, &ct->requests.pending);spin_unlock (&ct->requests.lock); - err =ct_write (ct, action, len, fence); + err =ct_write (ct, action, len, fence,0 );spin_unlock_irqrestore (&ct->ctbs.send.lock, flags);@@ -569,7 +631,7 @@ static int ct_send(struct intel_guc_ct *ct,* Command Transport (CT) buffer based GuC send function. */ int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size) +u32 *response_buf,u32 response_buf_size,u32 flags) {u32 status = ~0 ;/* undefined */ int ret;@@ -579,6 +641,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,return -ENODEV ; } +if (flags &INTEL_GUC_SEND_NB ) +return ct_send_nb (ct, action, len, flags); + ret =ct_send (ct, action, len, response_buf, response_buf_size, &status);if (unlikely (ret <0 )) { CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n",drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-2@@ -42,7 +42,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking @@ -88,7 +87,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */
Re: [Intel-gfx] [PATCH 04/47] drm/i915/guc: Add non blocking CTB send function
Quoted 168 lines · Matthew Brost
Quoted 167 lines · Michal Wajdeczko
Quoted 163 lines · Matthew Brost
Quoted 22 lines · Michal Wajdeczko
Quoted 19 lines · Matthew Brost
Add non blocking CTB send function,
intel_guc_send_nb. GuC submission will send CTBs in the critical path and does not need to wait for these CTBs to complete before moving on, hence the need for this new function.The non-blocking CTB now must have a flow control mechanism to ensure the buffer isn't overrun. A lazy spin wait is used as we believe the flow control condition should be rare with a properly sized buffer.
The function,
intel_guc_send_nb, is exported in this patch but unused. Several patches later in the series make use of this function.Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 12 +++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 77 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 3 +- 3 files changed, 82 insertions(+), 10 deletions(-)Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h static inline struct intel_guc *log_to_guc(struct intel_guc_log *log) · line 80
Quoted 13 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-1@@ -74,7 +74,15 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)static inline int intel_guc_send (struct intel_guc *guc,const u32 *action,u32 len) { -return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ); +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ,0 ); +} + +#define INTEL_GUC_SEND_NB BIT(31)hmm, this flag really belongs to
intel_guc_ct_send()so it should be defined as CTB flag near that function declarationI can move this up a few lines.
Quoted 46 lines
Quoted 46 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +6
-1+static +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +{ +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , +INTEL_GUC_SEND_NB ); } static inline int@@ -82,7 +90,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size) {return intel_guc_ct_send (&guc->ct, action, len, - response_buf, response_buf_size); + response_buf, response_buf_size,0 ); }static inline void intel_guc_to_host_event_handler (struct intel_guc *guc)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-1@@ -3,6 +3,11 @@* Copyright © 2016-2019 Intel Corporation */ +#include <linux/circ_buf.h> +#include <linux/ktime.h> +#include <linux/time64.h> +#include <linux/timekeeping.h> +#include "i915_drv.h" #include "intel_guc_ct.h" #include "gt/intel_gt.h" @@ -373,7 +378,7 @@ static void write_barrier(struct intel_guc_ct *ct)static int ct_write (struct intel_guc_ct *ct,const u32 *action,u32 len/* in dwords */ , -u32 fence) +u32 fence,u32 flags) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc;@@ -421,9 +426,13 @@ static int ct_write(struct intel_guc_ct *ct,FIELD_PREP (GUC_CTB_MSG_0_NUM_DWORDS , len) |FIELD_PREP (GUC_CTB_MSG_0_FENCE , fence);Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 435
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-3- hxg =FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | -FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | -GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]); + hxg = (flags &INTEL_GUC_SEND_NB ) ? + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_EVENT ) | +FIELD_PREP (GUC_HXG_EVENT_MSG_0_ACTION | +GUC_HXG_EVENT_MSG_0_DATA0 , action[0 ])) : + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | +FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | +GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]));or as we already switched to accept and return whole HXG messages in
guc_send_mmio()maybe we should do the same for CTB variant too and instead of using extra flag just let caller to prepare proper HXG header withHXG_EVENTtype and then in CTB code just look at this type to make decision which code path to useNot sure I follow. Anyways could this be done in a follow up by you if want this change.
Quoted 10 lines
note that existing callers should not be impacted, as full HXG header for the REQUEST message looks exactly the same as "action" code alone.
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0CT_DEBUG (ct,"writing (tail %u) %*ph %*ph %*ph\n" , tail,4 , &header,4 , &hxg,4 * (len -1 ), &action[1 ]);@@ -498,6 +507,46 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; }Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 518
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +{ +struct guc_ct_buffer_desc *desc = ctb->desc; +u32 head =READ_ONCE (desc->head); +u32 space; + + space =CIRC_SPACE (desc->tail, head, ctb->size); + +return space >= len_dw;here you are returning true(1) as has room
See below.
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+} + +static int ct_send_nb (struct intel_guc_ct *ct, +const u32 *action, +u32 len, +u32 flags) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +unsigned long spin_flags;Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 533
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-0+u32 fence; +int ret; + +spin_lock_irqsave (&ctb->lock, spin_flags); + + ret =h2g_has_room (ctb, len +1 );but here you treat "1" it as en error
Yes, this patch is broken but fixed in a follow up one. Regardless I'll fix this patch in place.
Quoted 2 lines
and this "1" is
GUC_HXG_MSG_MIN_LEN, right ?Not exactly. This is following how
ct_send()uses the action + len field. Action[0] field goes in the HXG header and extra + 1 is for the CT header.
Quoted 7 lines
Quoted 3 lines
well, "len" already counts "action" so by treating input as full HXG message (including HXG header) will make it cleaner
Yes, I know. See above. To me
GUC_HXG_MSG_MIN_LENmakes zero sense and it is worse than adding + 1. This + 1 accounts for the CT header not the HXG header. If any we add a new define,GUC_CT_HDR_LEN, and add that.
you mean GUC_CTB_MSG_MIN_LEN ? it's already there [1]
Quoted 121 lines
Matt
Quoted 118 lines
we can try do it later but by doing it right now we would avoid introducing this
send_nb()function and deprecating them long term againQuoted 44 lines
Quoted 34 lines
Quoted 34 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +18
-0+if (unlikely (ret)) + goto out; + + fence =ct_get_next_fence (ct); + ret =ct_write (ct, action, len, fence, flags); +if (unlikely (ret)) + goto out; + +intel_guc_notify (ct_to_guc (ct)); + +out: +spin_unlock_irqrestore (&ctb->lock, spin_flags); + +return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -505,6 +554,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;u32 fence;@@ -514,8 +564,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep ();Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 572
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-0+/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare. shouldn't we at least try to log such cases with
RATE_LIMITEDto find out how "rare" it is, or if really unlikely just return-EBUSYas in case of non-blocking send ?Quoted 1 line
Definitely not return
-EBUSYas this a blocking call. Perhaps we can logblocking calls still can fail for various reasons, full CTB is one of them, and if we return error (now broken) for non-blocking variant then we should do the same for blocking variant as well and let the caller decide about next steps
Quoted 3 lines
this, but IGTs likely can hit rather easily. It really is only interesting if real workloads hit this. Regardless that can be a follow up.
if we hide retry in a silent loop then we will not find it out if we hit this condition (IGT or real WL) or not
Quoted 57 lines
Matt
Quoted 54 lines
Quoted 54 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +12
-2+*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!h2g_has_room (ctb, len +1 ))) { +spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + } fence =ct_get_next_fence (ct); request.fence = fence;@@ -527,7 +589,7 @@ static int ct_send(struct intel_guc_ct *ct,list_add_tail (&request.link, &ct->requests.pending);spin_unlock (&ct->requests.lock); - err =ct_write (ct, action, len, fence); + err =ct_write (ct, action, len, fence,0 );spin_unlock_irqrestore (&ct->ctbs.send.lock, flags);@@ -569,7 +631,7 @@ static int ct_send(struct intel_guc_ct *ct,* Command Transport (CT) buffer based GuC send function. */ int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size) +u32 *response_buf,u32 response_buf_size,u32 flags) {u32 status = ~0 ;/* undefined */ int ret;@@ -579,6 +641,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,return -ENODEV ; } +if (flags &INTEL_GUC_SEND_NB ) +return ct_send_nb (ct, action, len, flags); + ret =ct_send (ct, action, len, response_buf, response_buf_size, &status);if (unlikely (ret <0 )) { CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n",drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +0
-1@@ -42,7 +42,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking @@ -88,7 +87,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) · line 93
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-1int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 04/47] drm/i915/guc: Add non blocking CTB send function
Quoted 175 lines · Michal Wajdeczko
Quoted 172 lines · Matthew Brost
Quoted 170 lines · Michal Wajdeczko
Quoted 157 lines · Matthew Brost
Quoted 22 lines · Michal Wajdeczko
Quoted 19 lines · Matthew Brost
Add non blocking CTB send function,
intel_guc_send_nb. GuC submission will send CTBs in the critical path and does not need to wait for these CTBs to complete before moving on, hence the need for this new function.The non-blocking CTB now must have a flow control mechanism to ensure the buffer isn't overrun. A lazy spin wait is used as we believe the flow control condition should be rare with a properly sized buffer.
The function,
intel_guc_send_nb, is exported in this patch but unused. Several patches later in the series make use of this function.Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 12 +++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 77 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 3 +- 3 files changed, 82 insertions(+), 10 deletions(-)Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h static inline struct intel_guc *log_to_guc(struct intel_guc_log *log) · line 80
Quoted 13 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-1@@ -74,7 +74,15 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)static inline int intel_guc_send (struct intel_guc *guc,const u32 *action,u32 len) { -return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ); +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ,0 ); +} + +#define INTEL_GUC_SEND_NB BIT(31)hmm, this flag really belongs to
intel_guc_ct_send()so it should be defined as CTB flag near that function declarationI can move this up a few lines.
Quoted 46 lines
Quoted 46 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +6
-1+static +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +{ +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , +INTEL_GUC_SEND_NB ); } static inline int@@ -82,7 +90,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size) {return intel_guc_ct_send (&guc->ct, action, len, - response_buf, response_buf_size); + response_buf, response_buf_size,0 ); }static inline void intel_guc_to_host_event_handler (struct intel_guc *guc)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-1@@ -3,6 +3,11 @@* Copyright © 2016-2019 Intel Corporation */ +#include <linux/circ_buf.h> +#include <linux/ktime.h> +#include <linux/time64.h> +#include <linux/timekeeping.h> +#include "i915_drv.h" #include "intel_guc_ct.h" #include "gt/intel_gt.h" @@ -373,7 +378,7 @@ static void write_barrier(struct intel_guc_ct *ct)static int ct_write (struct intel_guc_ct *ct,const u32 *action,u32 len/* in dwords */ , -u32 fence) +u32 fence,u32 flags) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc;@@ -421,9 +426,13 @@ static int ct_write(struct intel_guc_ct *ct,FIELD_PREP (GUC_CTB_MSG_0_NUM_DWORDS , len) |FIELD_PREP (GUC_CTB_MSG_0_FENCE , fence);Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 435
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-3- hxg =FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | -FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | -GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]); + hxg = (flags &INTEL_GUC_SEND_NB ) ? + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_EVENT ) | +FIELD_PREP (GUC_HXG_EVENT_MSG_0_ACTION | +GUC_HXG_EVENT_MSG_0_DATA0 , action[0 ])) : + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | +FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | +GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]));or as we already switched to accept and return whole HXG messages in
guc_send_mmio()maybe we should do the same for CTB variant too and instead of using extra flag just let caller to prepare proper HXG header withHXG_EVENTtype and then in CTB code just look at this type to make decision which code path to useNot sure I follow. Anyways could this be done in a follow up by you if want this change.
Quoted 10 lines
note that existing callers should not be impacted, as full HXG header for the REQUEST message looks exactly the same as "action" code alone.
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0CT_DEBUG (ct,"writing (tail %u) %*ph %*ph %*ph\n" , tail,4 , &header,4 , &hxg,4 * (len -1 ), &action[1 ]);@@ -498,6 +507,46 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; }Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 518
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +{ +struct guc_ct_buffer_desc *desc = ctb->desc; +u32 head =READ_ONCE (desc->head); +u32 space; + + space =CIRC_SPACE (desc->tail, head, ctb->size); + +return space >= len_dw;here you are returning true(1) as has room
See below.
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+} + +static int ct_send_nb (struct intel_guc_ct *ct, +const u32 *action, +u32 len, +u32 flags) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +unsigned long spin_flags;Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 533
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-0+u32 fence; +int ret; + +spin_lock_irqsave (&ctb->lock, spin_flags); + + ret =h2g_has_room (ctb, len +1 );but here you treat "1" it as en error
Yes, this patch is broken but fixed in a follow up one. Regardless I'll fix this patch in place.
Quoted 6 lines
Quoted 2 lines
and this "1" is
GUC_HXG_MSG_MIN_LEN, right ?Not exactly. This is following how
ct_send()uses the action + len field. Action[0] field goes in the HXG header and extra + 1 is for the CT header.well, "len" already counts "action" so by treating input as full HXG message (including HXG header) will make it cleaner
Quoted 6 lines
Quoted 3 lines
Yes, I know. See above. To me
GUC_HXG_MSG_MIN_LENmakes zero sense and it is worse than adding + 1. This + 1 accounts for the CT header not the HXG header. If any we add a new define,GUC_CT_HDR_LEN, and add that.you mean
GUC_CTB_MSG_MIN_LEN? it's already there [1]
Kinda? I think we should have a define GUC_CTB_HDR_LEN which is 1 and GUC_CTB_MSG_MIN_LEN is defined as GUC_CTB_HDR_LEN. 'GUC_CTB_HDR_LEN' makes it clear that the + 1 is referring to the header. I've done this branch of these patches already.
Matt
Quoted 131 lines
Quoted 128 lines
Matt
Quoted 125 lines
we can try do it later but by doing it right now we would avoid introducing this
send_nb()function and deprecating them long term againQuoted 44 lines
Quoted 34 lines
Quoted 34 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +18
-0+if (unlikely (ret)) + goto out; + + fence =ct_get_next_fence (ct); + ret =ct_write (ct, action, len, fence, flags); +if (unlikely (ret)) + goto out; + +intel_guc_notify (ct_to_guc (ct)); + +out: +spin_unlock_irqrestore (&ctb->lock, spin_flags); + +return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -505,6 +554,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;u32 fence;@@ -514,8 +564,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep ();Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 572
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-0+/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare. shouldn't we at least try to log such cases with
RATE_LIMITEDto find out how "rare" it is, or if really unlikely just return-EBUSYas in case of non-blocking send ?Quoted 1 line
Definitely not return
-EBUSYas this a blocking call. Perhaps we can logblocking calls still can fail for various reasons, full CTB is one of them, and if we return error (now broken) for non-blocking variant then we should do the same for blocking variant as well and let the caller decide about next steps
Quoted 3 lines
this, but IGTs likely can hit rather easily. It really is only interesting if real workloads hit this. Regardless that can be a follow up.
if we hide retry in a silent loop then we will not find it out if we hit this condition (IGT or real WL) or not
Quoted 64 lines
Matt
Quoted 61 lines
Quoted 61 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +12
-2+*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!h2g_has_room (ctb, len +1 ))) { +spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + } fence =ct_get_next_fence (ct); request.fence = fence;@@ -527,7 +589,7 @@ static int ct_send(struct intel_guc_ct *ct,list_add_tail (&request.link, &ct->requests.pending);spin_unlock (&ct->requests.lock); - err =ct_write (ct, action, len, fence); + err =ct_write (ct, action, len, fence,0 );spin_unlock_irqrestore (&ct->ctbs.send.lock, flags);@@ -569,7 +631,7 @@ static int ct_send(struct intel_guc_ct *ct,* Command Transport (CT) buffer based GuC send function. */ int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size) +u32 *response_buf,u32 response_buf_size,u32 flags) {u32 status = ~0 ;/* undefined */ int ret;@@ -579,6 +641,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,return -ENODEV ; } +if (flags &INTEL_GUC_SEND_NB ) +return ct_send_nb (ct, action, len, flags); + ret =ct_send (ct, action, len, response_buf, response_buf_size, &status);if (unlikely (ret <0 )) { CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n",drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-2@@ -42,7 +42,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking @@ -88,7 +87,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */
Re: [Intel-gfx] [PATCH 04/47] drm/i915/guc: Add non blocking CTB send function
In reply to Michal WajdeczkoQuoted 217 lines · Michal Wajdeczko
Quoted 157 lines · Matthew Brost
Quoted 22 lines · Michal Wajdeczko
Quoted 19 lines · Matthew Brost
Add non blocking CTB send function,
intel_guc_send_nb. GuC submission will send CTBs in the critical path and does not need to wait for these CTBs to complete before moving on, hence the need for this new function.The non-blocking CTB now must have a flow control mechanism to ensure the buffer isn't overrun. A lazy spin wait is used as we believe the flow control condition should be rare with a properly sized buffer.
The function,
intel_guc_send_nb, is exported in this patch but unused. Several patches later in the series make use of this function.Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 12 +++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 77 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 3 +- 3 files changed, 82 insertions(+), 10 deletions(-)Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h static inline struct intel_guc *log_to_guc(struct intel_guc_log *log) · line 80
Quoted 13 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-1@@ -74,7 +74,15 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)static inline int intel_guc_send (struct intel_guc *guc,const u32 *action,u32 len) { -return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ); +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ,0 ); +} + +#define INTEL_GUC_SEND_NB BIT(31)hmm, this flag really belongs to
intel_guc_ct_send()so it should be defined as CTB flag near that function declarationI can move this up a few lines.
Quoted 46 lines
Quoted 46 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +6
-1+static +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +{ +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , +INTEL_GUC_SEND_NB ); } static inline int@@ -82,7 +90,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size) {return intel_guc_ct_send (&guc->ct, action, len, - response_buf, response_buf_size); + response_buf, response_buf_size,0 ); }static inline void intel_guc_to_host_event_handler (struct intel_guc *guc)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-1@@ -3,6 +3,11 @@* Copyright © 2016-2019 Intel Corporation */ +#include <linux/circ_buf.h> +#include <linux/ktime.h> +#include <linux/time64.h> +#include <linux/timekeeping.h> +#include "i915_drv.h" #include "intel_guc_ct.h" #include "gt/intel_gt.h" @@ -373,7 +378,7 @@ static void write_barrier(struct intel_guc_ct *ct)static int ct_write (struct intel_guc_ct *ct,const u32 *action,u32 len/* in dwords */ , -u32 fence) +u32 fence,u32 flags) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc;@@ -421,9 +426,13 @@ static int ct_write(struct intel_guc_ct *ct,FIELD_PREP (GUC_CTB_MSG_0_NUM_DWORDS , len) |FIELD_PREP (GUC_CTB_MSG_0_FENCE , fence);Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 435
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-3- hxg =FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | -FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | -GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]); + hxg = (flags &INTEL_GUC_SEND_NB ) ? + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_EVENT ) | +FIELD_PREP (GUC_HXG_EVENT_MSG_0_ACTION | +GUC_HXG_EVENT_MSG_0_DATA0 , action[0 ])) : + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | +FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | +GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]));or as we already switched to accept and return whole HXG messages in
guc_send_mmio()maybe we should do the same for CTB variant too and instead of using extra flag just let caller to prepare proper HXG header withHXG_EVENTtype and then in CTB code just look at this type to make decision which code path to useNot sure I follow. Anyways could this be done in a follow up by you if want this change.
Quoted 10 lines
note that existing callers should not be impacted, as full HXG header for the REQUEST message looks exactly the same as "action" code alone.
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0CT_DEBUG (ct,"writing (tail %u) %*ph %*ph %*ph\n" , tail,4 , &header,4 , &hxg,4 * (len -1 ), &action[1 ]);@@ -498,6 +507,46 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; }Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 518
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +{ +struct guc_ct_buffer_desc *desc = ctb->desc; +u32 head =READ_ONCE (desc->head); +u32 space; + + space =CIRC_SPACE (desc->tail, head, ctb->size); + +return space >= len_dw;here you are returning true(1) as has room
See below.
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+} + +static int ct_send_nb (struct intel_guc_ct *ct, +const u32 *action, +u32 len, +u32 flags) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +unsigned long spin_flags;Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 533
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-0+u32 fence; +int ret; + +spin_lock_irqsave (&ctb->lock, spin_flags); + + ret =h2g_has_room (ctb, len +1 );but here you treat "1" it as en error
Yes, this patch is broken but fixed in a follow up one. Regardless I'll fix this patch in place.
Quoted 6 lines
Quoted 2 lines
and this "1" is
GUC_HXG_MSG_MIN_LEN, right ?Not exactly. This is following how
ct_send()uses the action + len field. Action[0] field goes in the HXG header and extra + 1 is for the CT header.well, "len" already counts "action" so by treating input as full HXG message (including HXG header) will make it cleaner
we can try do it later but by doing it right now we would avoid introducing this
send_nb()function and deprecating them long term againQuoted 44 lines
Quoted 43 lines
Quoted 29 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +17
-0+if (unlikely (ret)) + goto out; + + fence =ct_get_next_fence (ct); + ret =ct_write (ct, action, len, fence, flags); +if (unlikely (ret)) + goto out; + +intel_guc_notify (ct_to_guc (ct)); + +out: +spin_unlock_irqrestore (&ctb->lock, spin_flags); + +return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -505,6 +554,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;u32 fence;drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 572
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-0@@ -514,8 +564,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep (); +/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare. shouldn't we at least try to log such cases with
RATE_LIMITEDto find out how "rare" it is, or if really unlikely just return-EBUSYas in case of non-blocking send ?
Quoted 7 lines
Quoted 1 line
Definitely not return
-EBUSYas this a blocking call. Perhaps we can logblocking calls still can fail for various reasons, full CTB is one of them, and if we return error (now broken) for non-blocking variant then we should do the same for blocking variant as well and let the caller decide about next steps
And have to rewrite reset of the stack with the new behavior, that seems wrong. This function is allowed to block, so let it.
If you want to do this but all means go ahead but I'll likely NACK it as over engineered.
Quoted 7 lines
Quoted 3 lines
this, but IGTs likely can hit rather easily. It really is only interesting if real workloads hit this. Regardless that can be a follow up.
if we hide retry in a silent loop then we will not find it out if we hit this condition (IGT or real WL) or not
We don't care if this is hit in IGTs as this isn't a real world use case and will spam the dmesg if we hit this. I can make a note of this as an open and we can revisit later.
Matt
Quoted 64 lines
Quoted 64 lines
Matt
Quoted 61 lines
Quoted 61 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +12
-2+*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!h2g_has_room (ctb, len +1 ))) { +spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + } fence =ct_get_next_fence (ct); request.fence = fence;@@ -527,7 +589,7 @@ static int ct_send(struct intel_guc_ct *ct,list_add_tail (&request.link, &ct->requests.pending);spin_unlock (&ct->requests.lock); - err =ct_write (ct, action, len, fence); + err =ct_write (ct, action, len, fence,0 );spin_unlock_irqrestore (&ct->ctbs.send.lock, flags);@@ -569,7 +631,7 @@ static int ct_send(struct intel_guc_ct *ct,* Command Transport (CT) buffer based GuC send function. */ int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size) +u32 *response_buf,u32 response_buf_size,u32 flags) {u32 status = ~0 ;/* undefined */ int ret;@@ -579,6 +641,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,return -ENODEV ; } +if (flags &INTEL_GUC_SEND_NB ) +return ct_send_nb (ct, action, len, flags); + ret =ct_send (ct, action, len, response_buf, response_buf_size, &status);if (unlikely (ret <0 )) { CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n",drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-2@@ -42,7 +42,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking @@ -88,7 +87,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */
PATCH 5/47 drm/i915/guc: Add stall timer to non blocking CTB send function
In reply to Matthew BrostImplement a stall timer which fails H2G CTBs once a period of time with no forward progress is reached to prevent deadlock.
Also update to ct_write to return -EIO rather than -EPIPE on a corrupted descriptor.
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 47 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 4 ++ 2 files changed, 48 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +44 -3
@@ -319,6 +319,7 @@ int intel_guc_ct_enable(struct intel_guc_ct *ct) goto err_deregister; ct->enabled = true; + ct->stall_time =KTIME_MAX ;return 0 ;
@@ -392,7 +393,7 @@ static int ct_write(struct intel_guc_ct *ct,unsigned int i;if (unlikely (ctb->broken)) -return -EPIPE ; +return -EIO ;if (unlikely (desc->status)) goto corrupted;
@@ -464,7 +465,7 @@ static int ct_write(struct intel_guc_ct *ct,CT_ERROR (ct,"Corrupted descriptor head=%u tail=%u status=%#x\n" , desc->head, desc->tail, desc->status); ctb->broken = true; -return -EPIPE ; +return -EIO ; }/**
@@ -507,6 +508,18 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; } +#define GUC_CTB_TIMEOUT_MS 1500 +static inline bool ct_deadlocked (struct intel_guc_ct *ct) +{ +long timeout =GUC_CTB_TIMEOUT_MS ; +bool ret =ktime_ms_delta (ktime_get (), ct->stall_time) > timeout; + +if (unlikely (ret)) +CT_ERROR (ct,"CT deadlocked\n" ); + +return ret; +} +static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) {struct guc_ct_buffer_desc *desc = ctb->desc;
@@ -518,6 +531,26 @@ static inline bool h2g_has_room(struct intel_guc_ct_buffer *ctb, u32 len_dw)return space >= len_dw; } +static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; + +lockdep_assert_held (&ct->ctbs.send.lock); + +if (unlikely (!h2g_has_room (ctb, len_dw))) { +if (ct->stall_time ==KTIME_MAX ) + ct->stall_time =ktime_get (); + +if (unlikely (ct_deadlocked (ct))) +return -EIO ; +else +return -EBUSY ; + } + + ct->stall_time =KTIME_MAX ; +return 0 ; +} + static int ct_send_nb(struct intel_guc_ct *ct, const u32 *action, u32 len,
@@ -530,7 +563,7 @@ static int ct_send_nb(struct intel_guc_ct *ct,spin_lock_irqsave (&ctb->lock, spin_flags); - ret =h2g_has_room (ctb, len +1 ); + ret =has_room_nb (ct, len +1 );if (unlikely (ret)) goto out;
@@ -574,11 +607,19 @@ static int ct_send(struct intel_guc_ct *ct, retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags);if (unlikely (!h2g_has_room (ctb, len +1 ))) { +if (ct->stall_time ==KTIME_MAX ) + ct->stall_time =ktime_get ();spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); + +if (unlikely (ct_deadlocked (ct))) +return -EIO ; +cond_resched (); goto retry; } + ct->stall_time =KTIME_MAX ; + fence =ct_get_next_fence (ct); request.fence = fence; request.status =0 ;
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +4 -0
@@ -9,6 +9,7 @@#include <linux/interrupt.h> #include <linux/spinlock.h> #include <linux/workqueue.h> +#include <linux/ktime.h> #include "intel_guc_fwif.h"
@@ -68,6 +69,9 @@ struct intel_guc_ct {struct list_head incoming;/* incoming requests */ struct work_struct worker;/* handler for incoming requests */ } requests; + +/** @stall_time: time of first time a CTB submission is stalled */ +ktime_t stall_time; };void intel_guc_ct_init_early (struct intel_guc_ct *ct);
Signature · 1 line
2.28.0
Re: [Intel-gfx] [PATCH 05/47] drm/i915/guc: Add stall timer to non blocking CTB send function
Quoted 5 lines · Matthew Brost
Implement a stall timer which fails H2G CTBs once a period of time with no forward progress is reached to prevent deadlock.
Also update to
ct_writeto return-EIOrather than-EPIPEon a corrupted descriptor.
by doing so you will have the same error code for two different problems:
a) corrupted CTB descriptor (definitely unrecoverable)
b) long stall in CTB processing (still recoverable)
while caller is explicitly instructed to retry only on:
c) temporary stall in CTB processing (likely recoverable)
so why do we want to limit our diagnostics?
Quoted 40 lines
Signed-off-by John Harrison <[email protected]>Signed-off-by Daniele Ceraolo Spurio <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 47 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 4 ++ 2 files changed, 48 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-2@@ -319,6 +319,7 @@ int intel_guc_ct_enable(struct intel_guc_ct *ct) goto err_deregister; ct->enabled = true; + ct->stall_time =KTIME_MAX ;return 0 ;@@ -392,7 +393,7 @@ static int ct_write(struct intel_guc_ct *ct,unsigned int i;if (unlikely (ctb->broken)) -return -EPIPE ; +return -EIO ;if (unlikely (desc->status)) goto corrupted;@@ -464,7 +465,7 @@ static int ct_write(struct intel_guc_ct *ct,CT_ERROR (ct,"Corrupted descriptor head=%u tail=%u status=%#x\n" , desc->head, desc->tail, desc->status); ctb->broken = true; -return -EPIPE ; +return -EIO ; }/**
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 511
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0@@ -507,6 +508,18 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; } +#define GUC_CTB_TIMEOUT_MS 1500
it's 150% of core CTB timeout, maybe we should correlate them ?
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 518
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-0+static inline bool ct_deadlocked (struct intel_guc_ct *ct) +{ +long timeout =GUC_CTB_TIMEOUT_MS ; +bool ret =ktime_ms_delta (ktime_get (), ct->stall_time) > timeout; + +if (unlikely (ret)) +CT_ERROR (ct,"CT deadlocked\n" );
nit: in commit message you said all these changes are to "prevent deadlock" so maybe this message should rather be:
int delta = ktime_ms_delta(ktime_get(), ct->stall_time); CT_ERROR(ct, "Communication stalled for %dms\n", delta);
(note that CT_ERROR already adds "CT" prefix)
Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-0+ +return ret; +} +static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) {struct guc_ct_buffer_desc *desc = ctb->desc;@@ -518,6 +531,26 @@ static inline bool h2g_has_room(struct intel_guc_ct_buffer *ctb, u32 len_dw)return space >= len_dw; } +static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline bool h2g_has_room(struct intel_guc_ct_buffer *ctb, u32 len_dw) · line 544
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-0+{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; + +lockdep_assert_held (&ct->ctbs.send.lock); + +if (unlikely (!h2g_has_room (ctb, len_dw))) { +if (ct->stall_time ==KTIME_MAX ) + ct->stall_time =ktime_get (); + +if (unlikely (ct_deadlocked (ct)))
and maybe above message should be printed somewhere around here when we detect "deadlock" for the first time?
Quoted 22 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-1+return -EIO ; + else + return -EBUSY; + } + + ct->stall_time =KTIME_MAX ; +return 0 ; +} + static int ct_send_nb(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -530,7 +563,7 @@ static int ct_send_nb(struct intel_guc_ct *ct,spin_lock_irqsave (&ctb->lock, spin_flags); - ret =h2g_has_room (ctb, len +1 ); + ret =has_room_nb (ct, len +1 );if (unlikely (ret)) goto out;
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 611
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +2
-0@@ -574,11 +607,19 @@ static int ct_send(struct intel_guc_ct *ct, retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags);if (unlikely (!h2g_has_room (ctb, len +1 ))) { +if (ct->stall_time ==KTIME_MAX ) + ct->stall_time =ktime_get ();
as this is a repeated pattern, maybe it should be moved to h2g_has_room or other wrapper ?
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 621
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-0spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); + +if (unlikely (ct_deadlocked (ct))) +return -EIO ; +cond_resched (); goto retry; } + ct->stall_time =KTIME_MAX ;
this one too
Quoted 18 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0+ fence =ct_get_next_fence (ct); request.fence = fence; request.status =0 ;drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-0@@ -9,6 +9,7 @@#include <linux/interrupt.h> #include <linux/spinlock.h> #include <linux/workqueue.h> +#include <linux/ktime.h> #include "intel_guc_fwif.h"
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct { · line 77
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0@@ -68,6 +69,9 @@ struct intel_guc_ct {struct list_head incoming;/* incoming requests */ struct work_struct worker;/* handler for incoming requests */ } requests; + +/** @stall_time: time of first time a CTB submission is stalled */ +ktime_t stall_time; };void intel_guc_ct_init_early (struct intel_guc_ct *ct);
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 05/47] drm/i915/guc: Add stall timer to non blocking CTB send function
Quoted 6 lines · Michal Wajdeczko
Quoted 3 lines · Matthew Brost
Implement a stall timer which fails H2G CTBs once a period of time with no forward progress is reached to prevent deadlock.
Quoted 8 lines
Quoted 2 lines
Also update to
ct_writeto return-EIOrather than-EPIPEon a corrupted descriptor.by doing so you will have the same error code for two different problems:
a) corrupted CTB descriptor (definitely unrecoverable)
b) long stall in CTB processing (still recoverable)
Already discussed both are treated exactly the same by the rest of the stack so we return a single error code.
Quoted 44 lines
while caller is explicitly instructed to retry only on:
c) temporary stall in CTB processing (likely recoverable)
so why do we want to limit our diagnostics?
Quoted 38 lines
Signed-off-by John Harrison <[email protected]>Signed-off-by Daniele Ceraolo Spurio <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 47 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 4 ++ 2 files changed, 48 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-2@@ -319,6 +319,7 @@ int intel_guc_ct_enable(struct intel_guc_ct *ct) goto err_deregister; ct->enabled = true; + ct->stall_time =KTIME_MAX ;return 0 ;@@ -392,7 +393,7 @@ static int ct_write(struct intel_guc_ct *ct,unsigned int i;if (unlikely (ctb->broken)) -return -EPIPE ; +return -EIO ;if (unlikely (desc->status)) goto corrupted;@@ -464,7 +465,7 @@ static int ct_write(struct intel_guc_ct *ct,CT_ERROR (ct,"Corrupted descriptor head=%u tail=%u status=%#x\n" , desc->head, desc->tail, desc->status); ctb->broken = true; -return -EPIPE ; +return -EIO ; }
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 511
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0/** @@ -507,6 +508,18 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; } +#define GUC_CTB_TIMEOUT_MS 1500it's 150% of core CTB timeout, maybe we should correlate them ?
Seems overkill.
Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 518
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-0+static inline bool ct_deadlocked (struct intel_guc_ct *ct) +{ +long timeout =GUC_CTB_TIMEOUT_MS ; +bool ret =ktime_ms_delta (ktime_get (), ct->stall_time) > timeout; + +if (unlikely (ret)) +CT_ERROR (ct,"CT deadlocked\n" );nit: in commit message you said all these changes are to "prevent deadlock" so maybe this message should rather be:
Quoted 4 lines
int delta = ktime_ms_delta(ktime_get(), ct->stall_time); CT_ERROR(ct, "Communication stalled for %dms\n", delta);
Sure.
Quoted 13 lines
(note that
CT_ERRORalready adds "CT" prefix)Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-0+ +return ret; +} +static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) {struct guc_ct_buffer_desc *desc = ctb->desc;@@ -518,6 +531,26 @@ static inline bool h2g_has_room(struct intel_guc_ct_buffer *ctb, u32 len_dw)return space >= len_dw; }
Quoted 15 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline bool h2g_has_room(struct intel_guc_ct_buffer *ctb, u32 len_dw) · line 544
Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +11
-0+static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; + +lockdep_assert_held (&ct->ctbs.send.lock); + +if (unlikely (!h2g_has_room (ctb, len_dw))) { +if (ct->stall_time ==KTIME_MAX ) + ct->stall_time =ktime_get (); + +if (unlikely (ct_deadlocked (ct)))and maybe above message should be printed somewhere around here when we detect "deadlock" for the first time?
Not sure I follow. The error message is in the correct place if ask me. Probably should set the broken flag though when the message is printed though.
Quoted 21 lines
Quoted 21 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-1+return -EIO ; + else + return -EBUSY; + } + + ct->stall_time =KTIME_MAX ; +return 0 ; +} + static int ct_send_nb(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -530,7 +563,7 @@ static int ct_send_nb(struct intel_guc_ct *ct,spin_lock_irqsave (&ctb->lock, spin_flags); - ret =h2g_has_room (ctb, len +1 ); + ret =has_room_nb (ct, len +1 );if (unlikely (ret)) goto out;
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 611
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +2
-0@@ -574,11 +607,19 @@ static int ct_send(struct intel_guc_ct *ct, retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags);if (unlikely (!h2g_has_room (ctb, len +1 ))) { +if (ct->stall_time ==KTIME_MAX ) + ct->stall_time =ktime_get ();as this is a repeated pattern, maybe it should be moved to
h2g_has_roomor other wrapper ?
Once we check G2H credits the pattern changes, hence the reason for this outside of the wrapper. Also IMO sometimes we go a little overboard with wrappers and it makes the code harder to understand.
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-0spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); + +if (unlikely (ct_deadlocked (ct))) +return -EIO ; +cond_resched (); goto retry; }
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 621
Quoted 1 line
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0+ ct->stall_time =KTIME_MAX ;this one too
Same as above.
Matt
Quoted 25 lines
Quoted 25 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0+ fence =ct_get_next_fence (ct); request.fence = fence; request.status =0 ;drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +4
-0@@ -9,6 +9,7 @@#include <linux/interrupt.h> #include <linux/spinlock.h> #include <linux/workqueue.h> +#include <linux/ktime.h> #include "intel_guc_fwif.h" @@ -68,6 +69,9 @@ struct intel_guc_ct {struct list_head incoming;/* incoming requests */ struct work_struct worker;/* handler for incoming requests */ } requests; + +/** @stall_time: time of first time a CTB submission is stalled */ +ktime_t stall_time; };
Quoted 2 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct { · line 77
Quoted 2 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +0
-0void intel_guc_ct_init_early (struct intel_guc_ct *ct);
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 6/47 drm/i915/guc: Optimize CTB writes and reads
In reply to Matthew BrostCTB writes are now in the path of command submission and should be optimized for performance. Rather than reading CTB descriptor values (e.g. head, tail) which could result in accesses across the PCIe bus, store shadow local copies and only read/write the descriptor values when absolutely necessary. Also store the current space in the each channel locally.
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 76 ++++++++++++++--------- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 6 ++ 2 files changed, 51 insertions(+), 31 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +45 -31
@@ -130,6 +130,10 @@ static void guc_ct_buffer_desc_init(struct guc_ct_buffer_desc *desc)static void guc_ct_buffer_reset (struct intel_guc_ct_buffer *ctb) { ctb->broken = false; + ctb->tail =0 ; + ctb->head =0 ; + ctb->space =CIRC_SPACE (ctb->tail, ctb->head, ctb->size); +guc_ct_buffer_desc_init (ctb->desc); }
@@ -383,10 +387,8 @@ static int ct_write(struct intel_guc_ct *ct, {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head = desc->head; -u32 tail = desc->tail; +u32 tail = ctb->tail;u32 size = ctb->size; -u32 used;u32 header;u32 hxg;u32 *cmds = ctb->cmds;
@@ -398,25 +400,14 @@ static int ct_write(struct intel_guc_ct *ct,if (unlikely (desc->status)) goto corrupted; -if (unlikely ((tail | head) >= size)) { +#ifdef CONFIG_DRM_I915_DEBUG_GUC +if (unlikely ((desc->tail | desc->head) >= size)) {CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , - head, tail, size); + desc->head, desc->tail, size); desc->status |=GUC_CTB_STATUS_OVERFLOW ; goto corrupted; } - -/* -* tail == head condition indicates empty. GuC FW does not support -* using up the entire buffer to get tail == head meaning full. -*/ -if (tail < head) - used = (size - head) + tail; -else - used = tail - head; - -/* make sure there is a space including extra dw for the fence */ -if (unlikely (used + len +1 >= size)) -return -ENOSPC ; +#endif /* * dw0: CT header (including fence)
@@ -457,7 +448,9 @@ static int ct_write(struct intel_guc_ct *ct,write_barrier (ct);/* now update descriptor */ + ctb->tail = tail;WRITE_ONCE (desc->tail, tail); + ctb->space -= len +1 ;return 0 ;
@@ -473,7 +466,7 @@ static int ct_write(struct intel_guc_ct *ct,* @req: pointer to pending request * @status: placeholder for status * -* For each sent request, Guc shall send bac CT response message. +* For each sent request, GuC shall send back CT response message. * Our message handler will update status of tracked request once * response message with given fence is received. Wait here and * check for valid response status value.
@@ -520,24 +513,35 @@ static inline bool ct_deadlocked(struct intel_guc_ct *ct)return ret; } -static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +static inline bool h2g_has_room (struct intel_guc_ct *ct,u32 len_dw) { -struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head =READ_ONCE (desc->head); +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +u32 head;u32 space; - space =CIRC_SPACE (desc->tail, head, ctb->size); +if (ctb->space >= len_dw) +return true; + + head =READ_ONCE (ctb->desc->head); +if (unlikely (head > ctb->size)) { +CT_ERROR (ct,"Corrupted descriptor head=%u tail=%u size=%u\n" , + ctb->desc->head, ctb->desc->tail, ctb->size); + ctb->desc->status |=GUC_CTB_STATUS_OVERFLOW ; + ctb->broken = true; +return false; + } + + space =CIRC_SPACE (ctb->tail, head, ctb->size); + ctb->space = space;return space >= len_dw; }static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw) { -struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; -lockdep_assert_held (&ct->ctbs.send.lock); -if (unlikely (!h2g_has_room (ctb, len_dw))) { +if (unlikely (!h2g_has_room (ct, len_dw))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get ();
@@ -606,10 +610,10 @@ static int ct_send(struct intel_guc_ct *ct,*/ retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); -if (unlikely (!h2g_has_room (ctb, len +1 ))) { +if (unlikely (!h2g_has_room (ct, len +1 ))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get (); -spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +spin_unlock_irqrestore (&ctb->lock, flags);if (unlikely (ct_deadlocked (ct)))return -EIO ;
@@ -632,7 +636,7 @@ static int ct_send(struct intel_guc_ct *ct, err =ct_write (ct, action, len, fence,0 ); -spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +spin_unlock_irqrestore (&ctb->lock, flags);if (unlikely (err)) goto unlink;
@@ -720,7 +724,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.recv;struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head = desc->head; +u32 head = ctb->head;u32 tail = desc->tail;u32 size = ctb->size;u32 *cmds = ctb->cmds;
@@ -735,12 +739,21 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)if (unlikely (desc->status)) goto corrupted; -if (unlikely ((tail | head) >= size)) { +#ifdef CONFIG_DRM_I915_DEBUG_GUC +if (unlikely ((desc->tail | desc->head) >= size)) {CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , head, tail, size); desc->status |=GUC_CTB_STATUS_OVERFLOW ; goto corrupted; } +#else +if (unlikely ((tail | ctb->head) >= size)) { +CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , + head, tail, size); + desc->status |=GUC_CTB_STATUS_OVERFLOW ; + goto corrupted; + } +#endif /* tail == head condition indicates empty */ available = tail - head;
@@ -790,6 +803,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) }CT_DEBUG (ct,"received %*ph\n" ,4 * len, (*msg)->msg); + ctb->head = head;/* now update descriptor */ WRITE_ONCE (desc->head, head);
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +6 -0
@@ -33,6 +33,9 @@ struct intel_guc;* @desc: pointer to the buffer descriptor * @cmds: pointer to the commands buffer * @size: size of the commands buffer in dwords +* @head: local shadow copy of head in dwords +* @tail: local shadow copy of tail in dwords +* @space: local shadow copy of space in dwords * @broken: flag to indicate if descriptor data is broken */ struct intel_guc_ct_buffer {
@@ -40,6 +43,9 @@ struct intel_guc_ct_buffer {struct guc_ct_buffer_desc *desc;u32 *cmds;u32 size; +u32 tail; +u32 head; +u32 space;bool broken; };
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 06/47] drm/i915/guc: Optimize CTB writes and reads
Quoted 42 lines · Matthew Brost
CTB writes are now in the path of command submission and should be optimized for performance. Rather than reading CTB descriptor values (e.g. head, tail) which could result in accesses across the PCIe bus, store shadow local copies and only read/write the descriptor values when absolutely necessary. Also store the current space in the each channel locally.
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 76 ++++++++++++++--------- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 6 ++ 2 files changed, 51 insertions(+), 31 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-3@@ -130,6 +130,10 @@ static void guc_ct_buffer_desc_init(struct guc_ct_buffer_desc *desc)static void guc_ct_buffer_reset (struct intel_guc_ct_buffer *ctb) { ctb->broken = false; + ctb->tail =0 ; + ctb->head =0 ; + ctb->space =CIRC_SPACE (ctb->tail, ctb->head, ctb->size); +guc_ct_buffer_desc_init (ctb->desc); }@@ -383,10 +387,8 @@ static int ct_write(struct intel_guc_ct *ct, {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head = desc->head; -u32 tail = desc->tail; +u32 tail = ctb->tail;u32 size = ctb->size; -u32 used;u32 header;u32 hxg;u32 *cmds = ctb->cmds;
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 403
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1@@ -398,25 +400,14 @@ static int ct_write(struct intel_guc_ct *ct,if (unlikely (desc->status)) goto corrupted; -if (unlikely ((tail | head) >= size)) { +#ifdef CONFIG_DRM_I915_DEBUG_GUC
since we are caching tail, we may want to check if it's sill correct:
tail = READ_ONCE(desc->tail);
if (unlikely(tail != ctb->tail)) {
CT_ERROR(ct, "Tail was modified %u != %u\n",
tail, ctb->tail);
desc->status |= GUC_CTB_STATUS_MISMATCH;
goto corrupted;
}and since we own the tail then we can be more strict:
GEM_BUG_ON(tail > size);
and then finally just check GuC head:
head = READ_ONCE(desc->head);
if (unlikely(head >= size)) {
...Quoted 25 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-14+if (unlikely ((desc->tail | desc->head) >= size)) {CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , - head, tail, size); + desc->head, desc->tail, size); desc->status |=GUC_CTB_STATUS_OVERFLOW ; goto corrupted; } - -/* -* tail == head condition indicates empty. GuC FW does not support -* using up the entire buffer to get tail == head meaning full. -*/ -if (tail < head) - used = (size - head) + tail; -else - used = tail - head; - -/* make sure there is a space including extra dw for the fence */ -if (unlikely (used + len +1 >= size)) -return -ENOSPC ; +#endif /* * dw0: CT header (including fence)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 453
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +2
-0@@ -457,7 +448,9 @@ static int ct_write(struct intel_guc_ct *ct,write_barrier (ct);/* now update descriptor */ + ctb->tail = tail;WRITE_ONCE (desc->tail, tail); + ctb->space -= len +1 ;
this magic "1" is likely GUC_CTB_MSG_MIN_LEN, right ?
Quoted 30 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +8
-5return 0 ;@@ -473,7 +466,7 @@ static int ct_write(struct intel_guc_ct *ct,* @req: pointer to pending request * @status: placeholder for status * -* For each sent request, Guc shall send bac CT response message. +* For each sent request, GuC shall send back CT response message. * Our message handler will update status of tracked request once * response message with given fence is received. Wait here and * check for valid response status value. @@ -520,24 +513,35 @@ static inline bool ct_deadlocked(struct intel_guc_ct *ct)return ret; } -static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +static inline bool h2g_has_room (struct intel_guc_ct *ct,u32 len_dw) { -struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head =READ_ONCE (desc->head); +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +u32 head;u32 space; - space =CIRC_SPACE (desc->tail, head, ctb->size); +if (ctb->space >= len_dw) +return true; + + head =READ_ONCE (ctb->desc->head);
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline bool ct_deadlocked(struct intel_guc_ct *ct) · line 535
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-0+if (unlikely (head > ctb->size)) { +CT_ERROR (ct,"Corrupted descriptor head=%u tail=%u size=%u\n" , + ctb->desc->head, ctb->desc->tail, ctb->size); + ctb->desc->status |=GUC_CTB_STATUS_OVERFLOW ; + ctb->broken = true; +return false; + } + + space =CIRC_SPACE (ctb->tail, head, ctb->size); + ctb->space = space;
maybe here we could mark stall_time ?
if (space >= len_dw)
return true; if (ct->stall_time == KTIME_MAX) ct->stall_time = ktime_get(); return false;
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline bool ct_deadlocked(struct intel_guc_ct *ct) · line 537
Quoted 2 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0return space >= len_dw;
btw, maybe to avoid filling CTB to the last dword, this should be
space > len_dw
note the earlier comment:
/*
* tail == head condition indicates empty. GuC FW does not support
* using up the entire buffer to get tail == head meaning full. */
Quoted 45 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-7}static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw) { -struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; -lockdep_assert_held (&ct->ctbs.send.lock); -if (unlikely (!h2g_has_room (ctb, len_dw))) { +if (unlikely (!h2g_has_room (ct, len_dw))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get ();@@ -606,10 +610,10 @@ static int ct_send(struct intel_guc_ct *ct,*/ retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); -if (unlikely (!h2g_has_room (ctb, len +1 ))) { +if (unlikely (!h2g_has_room (ct, len +1 ))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get (); -spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +spin_unlock_irqrestore (&ctb->lock, flags);if (unlikely (ct_deadlocked (ct)))return -EIO ;@@ -632,7 +636,7 @@ static int ct_send(struct intel_guc_ct *ct, err =ct_write (ct, action, len, fence,0 ); -spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +spin_unlock_irqrestore (&ctb->lock, flags);if (unlikely (err)) goto unlink;@@ -720,7 +724,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.recv;struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head = desc->head; +u32 head = ctb->head;u32 tail = desc->tail;u32 size = ctb->size;u32 *cmds = ctb->cmds;
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) · line 742
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1@@ -735,12 +739,21 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)if (unlikely (desc->status)) goto corrupted; -if (unlikely ((tail | head) >= size)) { +#ifdef CONFIG_DRM_I915_DEBUG_GUC
as above we may want to check if our cached head was not modified
Quoted 40 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-0+if (unlikely ((desc->tail | desc->head) >= size)) {CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , head, tail, size); desc->status |=GUC_CTB_STATUS_OVERFLOW ; goto corrupted; } +#else +if (unlikely ((tail | ctb->head) >= size)) { +CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , + head, tail, size); + desc->status |=GUC_CTB_STATUS_OVERFLOW ; + goto corrupted; + } +#endif /* tail == head condition indicates empty */ available = tail - head;@@ -790,6 +803,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) }CT_DEBUG (ct,"received %*ph\n" ,4 * len, (*msg)->msg); + ctb->head = head;/* now update descriptor */ WRITE_ONCE (desc->head, head);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0@@ -33,6 +33,9 @@ struct intel_guc;* @desc: pointer to the buffer descriptor * @cmds: pointer to the commands buffer * @size: size of the commands buffer in dwords +* @head: local shadow copy of head in dwords +* @tail: local shadow copy of tail in dwords +* @space: local shadow copy of space in dwords * @broken: flag to indicate if descriptor data is broken */ struct intel_guc_ct_buffer {
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct_buffer { · line 48
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0@@ -40,6 +43,9 @@ struct intel_guc_ct_buffer {struct guc_ct_buffer_desc *desc;u32 *cmds;u32 size; +u32 tail; +u32 head; +u32 space;
in later patch this is changing to atomic_t
maybe we can start with it ?
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct_buffer { · line 51
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +0
-0bool broken; };
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 06/47] drm/i915/guc: Optimize CTB writes and reads
Quoted 63 lines · Michal Wajdeczko
Quoted 42 lines · Matthew Brost
CTB writes are now in the path of command submission and should be optimized for performance. Rather than reading CTB descriptor values (e.g. head, tail) which could result in accesses across the PCIe bus, store shadow local copies and only read/write the descriptor values when absolutely necessary. Also store the current space in the each channel locally.
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 76 ++++++++++++++--------- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 6 ++ 2 files changed, 51 insertions(+), 31 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-3@@ -130,6 +130,10 @@ static void guc_ct_buffer_desc_init(struct guc_ct_buffer_desc *desc)static void guc_ct_buffer_reset (struct intel_guc_ct_buffer *ctb) { ctb->broken = false; + ctb->tail =0 ; + ctb->head =0 ; + ctb->space =CIRC_SPACE (ctb->tail, ctb->head, ctb->size); +guc_ct_buffer_desc_init (ctb->desc); }@@ -383,10 +387,8 @@ static int ct_write(struct intel_guc_ct *ct, {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head = desc->head; -u32 tail = desc->tail; +u32 tail = ctb->tail;u32 size = ctb->size; -u32 used;u32 header;u32 hxg;u32 *cmds = ctb->cmds;drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 403
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1@@ -398,25 +400,14 @@ static int ct_write(struct intel_guc_ct *ct,if (unlikely (desc->status)) goto corrupted; -if (unlikely ((tail | head) >= size)) { +#ifdef CONFIG_DRM_I915_DEBUG_GUC since we are caching tail, we may want to check if it's sill correct:
tail = READ_ONCE(desc->tail); if (unlikely(tail != ctb->tail)) { CT_ERROR(ct, "Tail was modified %u != %u\n", tail, ctb->tail); desc->status |= GUC_CTB_STATUS_MISMATCH; goto corrupted; }and since we own the tail then we can be more strict:
Quoted 8 lines
GEM_BUG_ON(tail > size);and then finally just check GuC head:
head = READ_ONCE(desc->head); if (unlikely(head >= size)) { ...
Sure, but still hidden behind CONFIG_DRM_I915_DEBUG_GUC, right?
Quoted 27 lines
Quoted 27 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-14+if (unlikely ((desc->tail | desc->head) >= size)) {CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , - head, tail, size); + desc->head, desc->tail, size); desc->status |=GUC_CTB_STATUS_OVERFLOW ; goto corrupted; } - -/* -* tail == head condition indicates empty. GuC FW does not support -* using up the entire buffer to get tail == head meaning full. -*/ -if (tail < head) - used = (size - head) + tail; -else - used = tail - head; - -/* make sure there is a space including extra dw for the fence */ -if (unlikely (used + len +1 >= size)) -return -ENOSPC ; +#endif /* * dw0: CT header (including fence) @@ -457,7 +448,9 @@ static int ct_write(struct intel_guc_ct *ct,write_barrier (ct);
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 453
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +2
-0/* now update descriptor */ + ctb->tail = tail;WRITE_ONCE (desc->tail, tail); + ctb->space -= len +1 ;this magic "1" is likely
GUC_CTB_MSG_MIN_LEN, right ?
Yes.
Quoted 43 lines
Quoted 30 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +8
-5return 0 ;@@ -473,7 +466,7 @@ static int ct_write(struct intel_guc_ct *ct,* @req: pointer to pending request * @status: placeholder for status * -* For each sent request, Guc shall send bac CT response message. +* For each sent request, GuC shall send back CT response message. * Our message handler will update status of tracked request once * response message with given fence is received. Wait here and * check for valid response status value. @@ -520,24 +513,35 @@ static inline bool ct_deadlocked(struct intel_guc_ct *ct)return ret; } -static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +static inline bool h2g_has_room (struct intel_guc_ct *ct,u32 len_dw) { -struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head =READ_ONCE (desc->head); +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +u32 head;u32 space; - space =CIRC_SPACE (desc->tail, head, ctb->size); +if (ctb->space >= len_dw) +return true; + + head =READ_ONCE (ctb->desc->head);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline bool ct_deadlocked(struct intel_guc_ct *ct) · line 535
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-0+if (unlikely (head > ctb->size)) { +CT_ERROR (ct,"Corrupted descriptor head=%u tail=%u size=%u\n" , + ctb->desc->head, ctb->desc->tail, ctb->size); + ctb->desc->status |=GUC_CTB_STATUS_OVERFLOW ; + ctb->broken = true; +return false; + } + + space =CIRC_SPACE (ctb->tail, head, ctb->size); + ctb->space = space;maybe here we could mark
stall_time?
Quoted 7 lines
if (space >=
len_dw)return true; if (ct->stall_time == KTIME_MAX) ct->stall_time = ktime_get(); return false;
No. See my eariler comment [1] about why I'd rather leave this to the caller.
[1] https://patchwork.freedesktop.org/patch/440703/?series=91840&rev=1
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline bool ct_deadlocked(struct intel_guc_ct *ct) · line 537
Quoted 2 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0return space >= len_dw;btw, maybe to avoid filling CTB to the last dword, this should be
space >
len_dw
CIRC_SPACE leaves an extra DW already.
Quoted 7 lines
note the earlier comment:
/*
* tail == head condition indicates empty. GuC FW does not support
* using up the entire buffer to get tail == head meaning full. */
Yes, again CIRC_SPACE uses this same algorithm.
Matt
Quoted 107 lines
Quoted 45 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-7}static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw) { -struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; -lockdep_assert_held (&ct->ctbs.send.lock); -if (unlikely (!h2g_has_room (ctb, len_dw))) { +if (unlikely (!h2g_has_room (ct, len_dw))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get ();@@ -606,10 +610,10 @@ static int ct_send(struct intel_guc_ct *ct,*/ retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); -if (unlikely (!h2g_has_room (ctb, len +1 ))) { +if (unlikely (!h2g_has_room (ct, len +1 ))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get (); -spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +spin_unlock_irqrestore (&ctb->lock, flags);if (unlikely (ct_deadlocked (ct)))return -EIO ;@@ -632,7 +636,7 @@ static int ct_send(struct intel_guc_ct *ct, err =ct_write (ct, action, len, fence,0 ); -spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +spin_unlock_irqrestore (&ctb->lock, flags);if (unlikely (err)) goto unlink;@@ -720,7 +724,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.recv;struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head = desc->head; +u32 head = ctb->head;u32 tail = desc->tail;u32 size = ctb->size;u32 *cmds = ctb->cmds;drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) · line 742
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1@@ -735,12 +739,21 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)if (unlikely (desc->status)) goto corrupted; -if (unlikely ((tail | head) >= size)) { +#ifdef CONFIG_DRM_I915_DEBUG_GUC as above we may want to check if our cached head was not modified
Quoted 40 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-0+if (unlikely ((desc->tail | desc->head) >= size)) {CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , head, tail, size); desc->status |=GUC_CTB_STATUS_OVERFLOW ; goto corrupted; } +#else +if (unlikely ((tail | ctb->head) >= size)) { +CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , + head, tail, size); + desc->status |=GUC_CTB_STATUS_OVERFLOW ; + goto corrupted; + } +#endif /* tail == head condition indicates empty */ available = tail - head;@@ -790,6 +803,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) }CT_DEBUG (ct,"received %*ph\n" ,4 * len, (*msg)->msg); + ctb->head = head;/* now update descriptor */ WRITE_ONCE (desc->head, head);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0@@ -33,6 +33,9 @@ struct intel_guc;* @desc: pointer to the buffer descriptor * @cmds: pointer to the commands buffer * @size: size of the commands buffer in dwords +* @head: local shadow copy of head in dwords +* @tail: local shadow copy of tail in dwords +* @space: local shadow copy of space in dwords * @broken: flag to indicate if descriptor data is broken */ struct intel_guc_ct_buffer {drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct_buffer { · line 48
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0@@ -40,6 +43,9 @@ struct intel_guc_ct_buffer {struct guc_ct_buffer_desc *desc;u32 *cmds;u32 size; +u32 tail; +u32 head; +u32 space;in later patch this is changing to
atomic_t
maybe we can start with it ?Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +0
-0bool broken; };
Re: [Intel-gfx] [PATCH 06/47] drm/i915/guc: Optimize CTB writes and reads
In reply to Michal WajdeczkoQuoted 10 lines · Michal Wajdeczko
Quoted 7 lines · Matthew Brost
CTB writes are now in the path of command submission and should be optimized for performance. Rather than reading CTB descriptor values (e.g. head, tail) which could result in accesses across the PCIe bus, store shadow local copies and only read/write the descriptor values when absolutely necessary. Also store the current space in the each channel locally.
Missed two comments, addressed below.
Quoted 207 lines
Quoted 35 lines
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 76 ++++++++++++++--------- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 6 ++ 2 files changed, 51 insertions(+), 31 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-3@@ -130,6 +130,10 @@ static void guc_ct_buffer_desc_init(struct guc_ct_buffer_desc *desc)static void guc_ct_buffer_reset (struct intel_guc_ct_buffer *ctb) { ctb->broken = false; + ctb->tail =0 ; + ctb->head =0 ; + ctb->space =CIRC_SPACE (ctb->tail, ctb->head, ctb->size); +guc_ct_buffer_desc_init (ctb->desc); }@@ -383,10 +387,8 @@ static int ct_write(struct intel_guc_ct *ct, {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head = desc->head; -u32 tail = desc->tail; +u32 tail = ctb->tail;u32 size = ctb->size; -u32 used;u32 header;u32 hxg;u32 *cmds = ctb->cmds;drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 403
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1@@ -398,25 +400,14 @@ static int ct_write(struct intel_guc_ct *ct,if (unlikely (desc->status)) goto corrupted; -if (unlikely ((tail | head) >= size)) { +#ifdef CONFIG_DRM_I915_DEBUG_GUC since we are caching tail, we may want to check if it's sill correct:
tail = READ_ONCE(desc->tail); if (unlikely(tail != ctb->tail)) { CT_ERROR(ct, "Tail was modified %u != %u\n", tail, ctb->tail); desc->status |= GUC_CTB_STATUS_MISMATCH; goto corrupted; }and since we own the tail then we can be more strict:
GEM_BUG_ON(tail > size);and then finally just check GuC head:
head = READ_ONCE(desc->head); if (unlikely(head >= size)) { ...Quoted 25 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-14+if (unlikely ((desc->tail | desc->head) >= size)) {CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , - head, tail, size); + desc->head, desc->tail, size); desc->status |=GUC_CTB_STATUS_OVERFLOW ; goto corrupted; } - -/* -* tail == head condition indicates empty. GuC FW does not support -* using up the entire buffer to get tail == head meaning full. -*/ -if (tail < head) - used = (size - head) + tail; -else - used = tail - head; - -/* make sure there is a space including extra dw for the fence */ -if (unlikely (used + len +1 >= size)) -return -ENOSPC ; +#endif /* * dw0: CT header (including fence) drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 453
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +2
-0@@ -457,7 +448,9 @@ static int ct_write(struct intel_guc_ct *ct,write_barrier (ct);/* now update descriptor */ + ctb->tail = tail;WRITE_ONCE (desc->tail, tail); + ctb->space -= len +1 ;this magic "1" is likely
GUC_CTB_MSG_MIN_LEN, right ?Quoted 30 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +8
-5return 0 ;@@ -473,7 +466,7 @@ static int ct_write(struct intel_guc_ct *ct,* @req: pointer to pending request * @status: placeholder for status * -* For each sent request, Guc shall send bac CT response message. +* For each sent request, GuC shall send back CT response message. * Our message handler will update status of tracked request once * response message with given fence is received. Wait here and * check for valid response status value. @@ -520,24 +513,35 @@ static inline bool ct_deadlocked(struct intel_guc_ct *ct)return ret; } -static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +static inline bool h2g_has_room (struct intel_guc_ct *ct,u32 len_dw) { -struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head =READ_ONCE (desc->head); +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +u32 head;u32 space; - space =CIRC_SPACE (desc->tail, head, ctb->size); +if (ctb->space >= len_dw) +return true; + + head =READ_ONCE (ctb->desc->head);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline bool ct_deadlocked(struct intel_guc_ct *ct) · line 535
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-0+if (unlikely (head > ctb->size)) { +CT_ERROR (ct,"Corrupted descriptor head=%u tail=%u size=%u\n" , + ctb->desc->head, ctb->desc->tail, ctb->size); + ctb->desc->status |=GUC_CTB_STATUS_OVERFLOW ; + ctb->broken = true; +return false; + } + + space =CIRC_SPACE (ctb->tail, head, ctb->size); + ctb->space = space;maybe here we could mark
stall_time?if (space >=
len_dw)return true; if (ct->stall_time == KTIME_MAX) ct->stall_time = ktime_get(); return false;drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline bool ct_deadlocked(struct intel_guc_ct *ct) · line 537
Quoted 2 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0return space >= len_dw;btw, maybe to avoid filling CTB to the last dword, this should be
space >
len_dwnote the earlier comment:
/*
* tail == head condition indicates empty. GuC FW does not support
* using up the entire buffer to get tail == head meaning full. */Quoted 48 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-7}static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw) { -struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; -lockdep_assert_held (&ct->ctbs.send.lock); -if (unlikely (!h2g_has_room (ctb, len_dw))) { +if (unlikely (!h2g_has_room (ct, len_dw))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get ();@@ -606,10 +610,10 @@ static int ct_send(struct intel_guc_ct *ct,*/ retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); -if (unlikely (!h2g_has_room (ctb, len +1 ))) { +if (unlikely (!h2g_has_room (ct, len +1 ))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get (); -spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +spin_unlock_irqrestore (&ctb->lock, flags);if (unlikely (ct_deadlocked (ct)))return -EIO ;@@ -632,7 +636,7 @@ static int ct_send(struct intel_guc_ct *ct, err =ct_write (ct, action, len, fence,0 ); -spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +spin_unlock_irqrestore (&ctb->lock, flags);if (unlikely (err)) goto unlink;@@ -720,7 +724,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.recv;struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head = desc->head; +u32 head = ctb->head;u32 tail = desc->tail;u32 size = ctb->size;u32 *cmds = ctb->cmds;@@ -735,12 +739,21 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)if (unlikely (desc->status)) goto corrupted;
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) · line 742
Quoted 2 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1-if (unlikely ((tail | head) >= size)) { +#ifdef CONFIG_DRM_I915_DEBUG_GUC as above we may want to check if our cached head was not modified
Sure.
Quoted 41 lines
Quoted 41 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-0+if (unlikely ((desc->tail | desc->head) >= size)) {CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , head, tail, size); desc->status |=GUC_CTB_STATUS_OVERFLOW ; goto corrupted; } +#else +if (unlikely ((tail | ctb->head) >= size)) { +CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , + head, tail, size); + desc->status |=GUC_CTB_STATUS_OVERFLOW ; + goto corrupted; + } +#endif /* tail == head condition indicates empty */ available = tail - head;@@ -790,6 +803,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) }CT_DEBUG (ct,"received %*ph\n" ,4 * len, (*msg)->msg); + ctb->head = head;/* now update descriptor */ WRITE_ONCE (desc->head, head);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0@@ -33,6 +33,9 @@ struct intel_guc;* @desc: pointer to the buffer descriptor * @cmds: pointer to the commands buffer * @size: size of the commands buffer in dwords +* @head: local shadow copy of head in dwords +* @tail: local shadow copy of tail in dwords +* @space: local shadow copy of space in dwords * @broken: flag to indicate if descriptor data is broken */ struct intel_guc_ct_buffer {@@ -40,6 +43,9 @@ struct intel_guc_ct_buffer {struct guc_ct_buffer_desc *desc;
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct_buffer { · line 48
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0u32 *cmds;u32 size; +u32 tail; +u32 head; +u32 space;in later patch this is changing to
atomic_t
maybe we can start with it ?
I'd rather leave this as is. It doesn't make to use an atomic here but G2H credits patch makes it clear why we need an atomic.
Matt
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct_buffer { · line 51
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +0
-0bool broken; };
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 7/47 drm/i915/guc: Module load failure test for CT buffer creation
In reply to Matthew BrostFrom: John Harrison <[email protected]>
Add several module failure load inject points in the CT buffer creation code path.
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +8 -0
@@ -175,6 +175,10 @@ static int ct_register_buffer(struct intel_guc_ct *ct, u32 type, {int err; + err =i915_inject_probe_error (guc_to_gt (ct_to_guc (ct))->i915, -ENXIO ); +if (unlikely (err)) +return err; + err =guc_action_register_ct_buffer (ct_to_guc (ct), type, desc_addr, buff_addr, size);if (unlikely (err))
@@ -226,6 +230,10 @@ int intel_guc_ct_init(struct intel_guc_ct *ct)u32 *cmds;int err; + err =i915_inject_probe_error (guc_to_gt (guc)->i915, -ENXIO ); +if (err) +return err; +GEM_BUG_ON (ct->vma); blob_size =2 *CTB_DESC_SIZE +CTB_H2G_BUFFER_SIZE +CTB_G2H_BUFFER_SIZE ;
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 8/47 drm/i915/guc: Add new GuC interface defines and structures
In reply to Matthew BrostAdd new GuC interface defines and structures while maintaining old ones in parallel.
--- .../gpu/drm/i915/gt/uc/abi/guc_actions_abi.h | 14 +++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h | 41 +++++++++++++++++++ 2 files changed, 55 insertions(+)
drivers/gpu/drm/i915/gt/uc/abi/guc_actions_abi.h +14 -0
@@ -124,10 +124,24 @@ enum intel_guc_action {INTEL_GUC_ACTION_FORCE_LOG_BUFFER_FLUSH =0x302 ,INTEL_GUC_ACTION_ENTER_S_STATE =0x501 ,INTEL_GUC_ACTION_EXIT_S_STATE =0x502 , +INTEL_GUC_ACTION_GLOBAL_SCHED_POLICY_CHANGE =0x506 , +INTEL_GUC_ACTION_SCHED_CONTEXT =0x1000 , +INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_SET =0x1001 , +INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_DONE =0x1002 , +INTEL_GUC_ACTION_SCHED_ENGINE_MODE_SET =0x1003 , +INTEL_GUC_ACTION_SCHED_ENGINE_MODE_DONE =0x1004 , +INTEL_GUC_ACTION_SET_CONTEXT_PRIORITY =0x1005 , +INTEL_GUC_ACTION_SET_CONTEXT_EXECUTION_QUANTUM =0x1006 , +INTEL_GUC_ACTION_SET_CONTEXT_PREEMPTION_TIMEOUT =0x1007 , +INTEL_GUC_ACTION_CONTEXT_RESET_NOTIFICATION =0x1008 , +INTEL_GUC_ACTION_ENGINE_FAILURE_NOTIFICATION =0x1009 ,INTEL_GUC_ACTION_SLPC_REQUEST =0x3003 ,INTEL_GUC_ACTION_AUTHENTICATE_HUC =0x4000 , +INTEL_GUC_ACTION_REGISTER_CONTEXT =0x4502 , +INTEL_GUC_ACTION_DEREGISTER_CONTEXT =0x4503 ,INTEL_GUC_ACTION_REGISTER_COMMAND_TRANSPORT_BUFFER =0x4505 ,INTEL_GUC_ACTION_DEREGISTER_COMMAND_TRANSPORT_BUFFER =0x4506 , +INTEL_GUC_ACTION_DEREGISTER_CONTEXT_DONE =0x4600 ,INTEL_GUC_ACTION_LIMIT };
drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h +41 -0
59 lines not on this page · raw message
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 08/47] drm/i915/guc: Add new GuC interface defines and structures
Quoted 5 lines · Matthew Brost
Add new GuC interface defines and structures while maintaining old ones in parallel.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>
I think there was some difference of opinion over whether these additions should be squashed in to the specific patches that first use them. However, on the grounds that such is basically a patch-only style comment and doesn't change the final product plus, we need to get this stuff merged efficiently and not spend forever rebasing and refactoring...
Quoted 90 lines
--- .../gpu/drm/i915/gt/uc/abi/guc_actions_abi.h | 14 +++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h | 41 +++++++++++++++++++ 2 files changed, 55 insertions(+)drivers/gpu/drm/i915/gt/uc/abi/guc_actions_abi.h +14
-0@@ -124,10 +124,24 @@ enum intel_guc_action {INTEL_GUC_ACTION_FORCE_LOG_BUFFER_FLUSH =0x302 ,INTEL_GUC_ACTION_ENTER_S_STATE =0x501 ,INTEL_GUC_ACTION_EXIT_S_STATE =0x502 , +INTEL_GUC_ACTION_GLOBAL_SCHED_POLICY_CHANGE =0x506 , +INTEL_GUC_ACTION_SCHED_CONTEXT =0x1000 , +INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_SET =0x1001 , +INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_DONE =0x1002 , +INTEL_GUC_ACTION_SCHED_ENGINE_MODE_SET =0x1003 , +INTEL_GUC_ACTION_SCHED_ENGINE_MODE_DONE =0x1004 , +INTEL_GUC_ACTION_SET_CONTEXT_PRIORITY =0x1005 , +INTEL_GUC_ACTION_SET_CONTEXT_EXECUTION_QUANTUM =0x1006 , +INTEL_GUC_ACTION_SET_CONTEXT_PREEMPTION_TIMEOUT =0x1007 , +INTEL_GUC_ACTION_CONTEXT_RESET_NOTIFICATION =0x1008 , +INTEL_GUC_ACTION_ENGINE_FAILURE_NOTIFICATION =0x1009 ,INTEL_GUC_ACTION_SLPC_REQUEST =0x3003 ,INTEL_GUC_ACTION_AUTHENTICATE_HUC =0x4000 , +INTEL_GUC_ACTION_REGISTER_CONTEXT =0x4502 , +INTEL_GUC_ACTION_DEREGISTER_CONTEXT =0x4503 ,INTEL_GUC_ACTION_REGISTER_COMMAND_TRANSPORT_BUFFER =0x4505 ,INTEL_GUC_ACTION_DEREGISTER_COMMAND_TRANSPORT_BUFFER =0x4506 , +INTEL_GUC_ACTION_DEREGISTER_CONTEXT_DONE =0x4600 ,INTEL_GUC_ACTION_LIMIT };drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h +34
-0@@ -17,6 +17,9 @@#include "abi/guc_communication_ctb_abi.h" #include "abi/guc_messages_abi.h" +#define GUC_CONTEXT_DISABLE 0 +#define GUC_CONTEXT_ENABLE 1 +#define GUC_CLIENT_PRIORITY_KMD_HIGH 0#define GUC_CLIENT_PRIORITY_HIGH 1#define GUC_CLIENT_PRIORITY_KMD_NORMAL 2@@ -26,6 +29,9 @@#define GUC_MAX_STAGE_DESCRIPTORS 1024#define GUC_INVALID_STAGE_ID GUC_MAX_STAGE_DESCRIPTORS +#define GUC_MAX_LRC_DESCRIPTORS 65535 +#define GUC_INVALID_LRC_ID GUC_MAX_LRC_DESCRIPTORS +#define GUC_RENDER_ENGINE 0#define GUC_VIDEO_ENGINE 1#define GUC_BLITTER_ENGINE 2@@ -237,6 +243,41 @@ struct guc_stage_desc {u64 desc_private; } __packed; +#define CONTEXT_REGISTRATION_FLAG_KMD BIT(0) + +#define CONTEXT_POLICY_DEFAULT_EXECUTION_QUANTUM_US 1000000 +#define CONTEXT_POLICY_DEFAULT_PREEMPTION_TIME_US 500000 + +/* Preempt to idle on quantum expiry */ +#define CONTEXT_POLICY_FLAG_PREEMPT_TO_IDLE BIT(0) + +/* +* GuC Context registration descriptor. +* FIXME: This is only required to exist during context registration. +* The current 1:1 between guc_lrc_desc and LRCs for the lifetime of the LRC +* is not required. +*/ +struct guc_lrc_desc { +u32 hw_context_desc; +u32 slpm_perf_mode_hint;/* SPLC v1 only */ +u32 slpm_freq_hint; +u32 engine_submit_mask;/* In logical space */ +u8 engine_class; +u8 reserved0[3 ]; +u32 priority; +u32 process_desc; +u32 wq_addr; +u32 wq_size; +u32 context_flags;/* CONTEXT_REGISTRATION_* */ +/* Time for one workload to execute. (in micro seconds) */ +u32 execution_quantum;
drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h struct guc_stage_desc { · line 283
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h +7
-0+/* Time to wait for a preemption request to complete before issuing a +* reset. (in micro seconds). */ +u32 preemption_timeout; +u32 policy_flags;/* CONTEXT_POLICY_* */ +u32 reserved1[19 ]; +} __packed; +#define GUC_POWER_UNSPECIFIED 0#define GUC_POWER_D0 1#define GUC_POWER_D1 2
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 08/47] drm/i915/guc: Add new GuC interface defines and structures
Quoted 4 lines · John Harrison
Quoted 3 lines · Matthew Brost
Add new GuC interface defines and structures while maintaining old ones in parallel.
Quoted 8 lines
Quoted 2 lines
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>I think there was some difference of opinion over whether these additions should be squashed in to the specific patches that first use them. However, on the grounds that such is basically a patch-only style comment and doesn't change the final product plus, we need to get this stuff merged efficiently and not spend forever rebasing and refactoring...
Agree this doesn't need to be squashed as it doesn't break anything and also this all dead code anyways until we enable submission at the end of the series.
Matt
Quoted 100 lines
Reviewed-by John Harrison <[email protected]>Quoted 96 lines
--- .../gpu/drm/i915/gt/uc/abi/guc_actions_abi.h | 14 +++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h | 41 +++++++++++++++++++ 2 files changed, 55 insertions(+)drivers/gpu/drm/i915/gt/uc/abi/guc_actions_abi.h +14
-0@@ -124,10 +124,24 @@ enum intel_guc_action {INTEL_GUC_ACTION_FORCE_LOG_BUFFER_FLUSH =0x302 ,INTEL_GUC_ACTION_ENTER_S_STATE =0x501 ,INTEL_GUC_ACTION_EXIT_S_STATE =0x502 , +INTEL_GUC_ACTION_GLOBAL_SCHED_POLICY_CHANGE =0x506 , +INTEL_GUC_ACTION_SCHED_CONTEXT =0x1000 , +INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_SET =0x1001 , +INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_DONE =0x1002 , +INTEL_GUC_ACTION_SCHED_ENGINE_MODE_SET =0x1003 , +INTEL_GUC_ACTION_SCHED_ENGINE_MODE_DONE =0x1004 , +INTEL_GUC_ACTION_SET_CONTEXT_PRIORITY =0x1005 , +INTEL_GUC_ACTION_SET_CONTEXT_EXECUTION_QUANTUM =0x1006 , +INTEL_GUC_ACTION_SET_CONTEXT_PREEMPTION_TIMEOUT =0x1007 , +INTEL_GUC_ACTION_CONTEXT_RESET_NOTIFICATION =0x1008 , +INTEL_GUC_ACTION_ENGINE_FAILURE_NOTIFICATION =0x1009 ,INTEL_GUC_ACTION_SLPC_REQUEST =0x3003 ,INTEL_GUC_ACTION_AUTHENTICATE_HUC =0x4000 , +INTEL_GUC_ACTION_REGISTER_CONTEXT =0x4502 , +INTEL_GUC_ACTION_DEREGISTER_CONTEXT =0x4503 ,INTEL_GUC_ACTION_REGISTER_COMMAND_TRANSPORT_BUFFER =0x4505 ,INTEL_GUC_ACTION_DEREGISTER_COMMAND_TRANSPORT_BUFFER =0x4506 , +INTEL_GUC_ACTION_DEREGISTER_CONTEXT_DONE =0x4600 ,INTEL_GUC_ACTION_LIMIT };drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h +41
-0@@ -17,6 +17,9 @@#include "abi/guc_communication_ctb_abi.h" #include "abi/guc_messages_abi.h" +#define GUC_CONTEXT_DISABLE 0 +#define GUC_CONTEXT_ENABLE 1 +#define GUC_CLIENT_PRIORITY_KMD_HIGH 0#define GUC_CLIENT_PRIORITY_HIGH 1#define GUC_CLIENT_PRIORITY_KMD_NORMAL 2@@ -26,6 +29,9 @@#define GUC_MAX_STAGE_DESCRIPTORS 1024#define GUC_INVALID_STAGE_ID GUC_MAX_STAGE_DESCRIPTORS +#define GUC_MAX_LRC_DESCRIPTORS 65535 +#define GUC_INVALID_LRC_ID GUC_MAX_LRC_DESCRIPTORS +#define GUC_RENDER_ENGINE 0#define GUC_VIDEO_ENGINE 1#define GUC_BLITTER_ENGINE 2@@ -237,6 +243,41 @@ struct guc_stage_desc {u64 desc_private; } __packed; +#define CONTEXT_REGISTRATION_FLAG_KMD BIT(0) + +#define CONTEXT_POLICY_DEFAULT_EXECUTION_QUANTUM_US 1000000 +#define CONTEXT_POLICY_DEFAULT_PREEMPTION_TIME_US 500000 + +/* Preempt to idle on quantum expiry */ +#define CONTEXT_POLICY_FLAG_PREEMPT_TO_IDLE BIT(0) + +/* +* GuC Context registration descriptor. +* FIXME: This is only required to exist during context registration. +* The current 1:1 between guc_lrc_desc and LRCs for the lifetime of the LRC +* is not required. +*/ +struct guc_lrc_desc { +u32 hw_context_desc; +u32 slpm_perf_mode_hint;/* SPLC v1 only */ +u32 slpm_freq_hint; +u32 engine_submit_mask;/* In logical space */ +u8 engine_class; +u8 reserved0[3 ]; +u32 priority; +u32 process_desc; +u32 wq_addr; +u32 wq_size; +u32 context_flags;/* CONTEXT_REGISTRATION_* */ +/* Time for one workload to execute. (in micro seconds) */ +u32 execution_quantum; +/* Time to wait for a preemption request to complete before issuing a +* reset. (in micro seconds). */ +u32 preemption_timeout; +u32 policy_flags;/* CONTEXT_POLICY_* */ +u32 reserved1[19 ]; +} __packed; +#define GUC_POWER_UNSPECIFIED 0#define GUC_POWER_D0 1#define GUC_POWER_D1 2
PATCH 9/47 drm/i915/guc: Remove GuC stage descriptor, add lrc descriptor
In reply to Matthew BrostRemove old GuC stage descriptor, add lrc descriptor which will be used by the new GuC interface implemented in this patch series.
--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 4 +- drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h | 65 ----------------- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 72 ++++++------------- 3 files changed, 25 insertions(+), 116 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2 -2
@@ -43,8 +43,8 @@ struct intel_guc {struct i915_vma *ads_vma;struct __guc_ads_blob *ads_blob; -struct i915_vma *stage_desc_pool; -void *stage_desc_pool_vaddr; +struct i915_vma *lrc_desc_pool; +void *lrc_desc_pool_vaddr;/* Control params for fw initialization */ u32 params[GUC_CTL_MAX_DWORDS ];
drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h +0 -65
77 lines not on this page · raw message
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +23 -49
121 lines not on this page · raw message
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 09/47] drm/i915/guc: Remove GuC stage descriptor, add lrc descriptor
Quoted 5 lines · Matthew Brost
Remove old GuC stage descriptor, add lrc descriptor which will be used by the new GuC interface implemented in this patch series.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 10/47 drm/i915/guc: Add lrc descriptor context lookup array
In reply to Matthew BrostAdd lrc descriptor context lookup array which can resolve the intel_context from the lrc descriptor index. In addition to lookup, it can determine in the lrc descriptor context is currently registered with the GuC by checking if an entry for a descriptor index is present. Future patches in the series will make use of this array.
--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 5 +++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 32 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +5 -0
@@ -6,6 +6,8 @@#ifndef _INTEL_GUC_H_#define _INTEL_GUC_H_ +#include "linux/xarray.h" +#include "intel_uncore.h" #include "intel_guc_fw.h" #include "intel_guc_fwif.h"
@@ -46,6 +48,9 @@ struct intel_guc {struct i915_vma *lrc_desc_pool;void *lrc_desc_pool_vaddr; +/* guc_id to intel_context lookup */ +struct xarray context_lookup; +/* Control params for fw initialization */ u32 params[GUC_CTL_MAX_DWORDS ];
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +30 -2
@@ -65,8 +65,6 @@ static inline struct i915_priolist *to_priolist(struct rb_node *rb) return rb_entry(rb, struct i915_priolist, node); } -/* Future patches will use this function */ -__attribute__ ((unused))static struct guc_lrc_desc *__get_lrc_desc (struct intel_guc *guc,u32 index) {struct guc_lrc_desc *base = guc->lrc_desc_pool_vaddr;
@@ -76,6 +74,15 @@ static struct guc_lrc_desc *__get_lrc_desc(struct intel_guc *guc, u32 index)return &base[index]; } +static inline struct intel_context *__get_context (struct intel_guc *guc,u32 id) +{ +struct intel_context *ce =xa_load (&guc->context_lookup, id); + +GEM_BUG_ON (id >=GUC_MAX_LRC_DESCRIPTORS ); + +return ce; +} +static int guc_lrc_desc_pool_create (struct intel_guc *guc) {u32 size;
@@ -96,6 +103,25 @@ static void guc_lrc_desc_pool_destroy(struct intel_guc *guc)i915_vma_unpin_and_release (&guc->lrc_desc_pool,I915_VMA_RELEASE_MAP ); } +static inline void reset_lrc_desc (struct intel_guc *guc,u32 id) +{ +struct guc_lrc_desc *desc =__get_lrc_desc (guc, id); + +memset (desc,0 ,sizeof (*desc)); +xa_erase_irq (&guc->context_lookup, id); +} + +static inline bool lrc_desc_registered (struct intel_guc *guc,u32 id) +{ +return __get_context (guc, id); +} + +static inline void set_lrc_desc_registered (struct intel_guc *guc,u32 id, +struct intel_context *ce) +{ +xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); +} +static void guc_add_request (struct intel_guc *guc,struct i915_request *rq) {/* Leaving stub as this function will be used in future patches */
@@ -400,6 +426,8 @@ int intel_guc_submission_init(struct intel_guc *guc)*/ GEM_BUG_ON (!guc->lrc_desc_pool); +xa_init_flags (&guc->context_lookup,XA_FLAGS_LOCK_IRQ ); +return 0 ; }
Signature · 1 line
2.28.0
Re: [PATCH 10/47] drm/i915/guc: Add lrc descriptor context lookup array
Quoted 5 lines · Matthew Brost
Add lrc descriptor context lookup array which can resolve the
intel_contextfrom the lrc descriptor index. In addition to lookup, it can determine in the lrc descriptor context is currently registered with the GuC by checking if an entry for a descriptor index is present. Future patches in the series will make use of this array.
s/lrc/LRC
Quoted 13 lines
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 5 +++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 32 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc.h +0
-0
drivers/gpu/drm/i915/gt/uc/intel_guc.h line 9
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +1
-0@@ -6,6 +6,8 @@#ifndef _INTEL_GUC_H_#define _INTEL_GUC_H_ +#include "linux/xarray.h"
#include <linux/xarray.h>
drivers/gpu/drm/i915/gt/uc/intel_guc.h struct intel_guc { · line 55
Quoted 13 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-0+#include "intel_uncore.h" #include "intel_guc_fw.h" #include "intel_guc_fwif.h" @@ -46,6 +48,9 @@ struct intel_guc {struct i915_vma *lrc_desc_pool;void *lrc_desc_pool_vaddr; +/* guc_id to intel_context lookup */ +struct xarray context_lookup; +/* Control params for fw initialization */ u32 params[GUC_CTL_MAX_DWORDS ];
btw, IIRC there was idea to move most struct definitions to intel_guc_types.h, is this still a plan ?
Quoted 58 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +28
-2@@ -65,8 +65,6 @@ static inline struct i915_priolist *to_priolist(struct rb_node *rb) return rb_entry(rb, struct i915_priolist, node); } -/* Future patches will use this function */ -__attribute__ ((unused))static struct guc_lrc_desc *__get_lrc_desc (struct intel_guc *guc,u32 index) {struct guc_lrc_desc *base = guc->lrc_desc_pool_vaddr;@@ -76,6 +74,15 @@ static struct guc_lrc_desc *__get_lrc_desc(struct intel_guc *guc, u32 index)return &base[index]; } +static inline struct intel_context *__get_context (struct intel_guc *guc,u32 id) +{ +struct intel_context *ce =xa_load (&guc->context_lookup, id); + +GEM_BUG_ON (id >=GUC_MAX_LRC_DESCRIPTORS ); + +return ce; +} +static int guc_lrc_desc_pool_create (struct intel_guc *guc) {u32 size;@@ -96,6 +103,25 @@ static void guc_lrc_desc_pool_destroy(struct intel_guc *guc)i915_vma_unpin_and_release (&guc->lrc_desc_pool,I915_VMA_RELEASE_MAP ); } +static inline void reset_lrc_desc (struct intel_guc *guc,u32 id) +{ +struct guc_lrc_desc *desc =__get_lrc_desc (guc, id); + +memset (desc,0 ,sizeof (*desc)); +xa_erase_irq (&guc->context_lookup, id); +} + +static inline bool lrc_desc_registered (struct intel_guc *guc,u32 id) +{ +return __get_context (guc, id); +} + +static inline void set_lrc_desc_registered (struct intel_guc *guc,u32 id, +struct intel_context *ce) +{ +xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); +} +static void guc_add_request (struct intel_guc *guc,struct i915_request *rq) {/* Leaving stub as this function will be used in future patches */
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c int intel_guc_submission_init(struct intel_guc *guc) · line 433
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-0@@ -400,6 +426,8 @@ int intel_guc_submission_init(struct intel_guc *guc)*/ GEM_BUG_ON (!guc->lrc_desc_pool); +xa_init_flags (&guc->context_lookup,XA_FLAGS_LOCK_IRQ ); +return 0 ; }
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 10/47] drm/i915/guc: Add lrc descriptor context lookup array
Quoted 11 lines · Michal Wajdeczko
Quoted 5 lines · Matthew Brost
Add lrc descriptor context lookup array which can resolve the
intel_contextfrom the lrc descriptor index. In addition to lookup, it can determine in the lrc descriptor context is currently registered with the GuC by checking if an entry for a descriptor index is present. Future patches in the series will make use of this array.s/lrc/LRC
I guess? lrc and LRC are used interchangeably throughout the current code base.
Quoted 16 lines
Quoted 16 lines
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 5 +++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 32 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc.h +0
-0@@ -6,6 +6,8 @@#ifndef _INTEL_GUC_H_#define _INTEL_GUC_H_
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h line 9
Quoted 1 line
drivers/gpu/drm/i915/gt/uc/intel_guc.h +1
-0+#include "linux/xarray.h" #include <
linux/xarray.h>
Yep.
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +1
-0+#include "intel_uncore.h" #include "intel_guc_fw.h" #include "intel_guc_fwif.h" @@ -46,6 +48,9 @@ struct intel_guc {struct i915_vma *lrc_desc_pool;void *lrc_desc_pool_vaddr;
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h struct intel_guc { · line 55
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +3
-0+/* guc_id to intel_context lookup */ +struct xarray context_lookup; +/* Control params for fw initialization */ u32 params[GUC_CTL_MAX_DWORDS ];btw, IIRC there was idea to move most struct definitions to
intel_guc_types.h, is this still a plan ?
I don't ever recall discussing this but we can certainly do this. For what it is worth we do introduce intel_guc_submission_types.h a bit later. I'll make a note about intel_guc_types.h though.
Matt
Quoted 60 lines
Quoted 60 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +28
-2@@ -65,8 +65,6 @@ static inline struct i915_priolist *to_priolist(struct rb_node *rb) return rb_entry(rb, struct i915_priolist, node); } -/* Future patches will use this function */ -__attribute__ ((unused))static struct guc_lrc_desc *__get_lrc_desc (struct intel_guc *guc,u32 index) {struct guc_lrc_desc *base = guc->lrc_desc_pool_vaddr;@@ -76,6 +74,15 @@ static struct guc_lrc_desc *__get_lrc_desc(struct intel_guc *guc, u32 index)return &base[index]; } +static inline struct intel_context *__get_context (struct intel_guc *guc,u32 id) +{ +struct intel_context *ce =xa_load (&guc->context_lookup, id); + +GEM_BUG_ON (id >=GUC_MAX_LRC_DESCRIPTORS ); + +return ce; +} +static int guc_lrc_desc_pool_create (struct intel_guc *guc) {u32 size;@@ -96,6 +103,25 @@ static void guc_lrc_desc_pool_destroy(struct intel_guc *guc)i915_vma_unpin_and_release (&guc->lrc_desc_pool,I915_VMA_RELEASE_MAP ); } +static inline void reset_lrc_desc (struct intel_guc *guc,u32 id) +{ +struct guc_lrc_desc *desc =__get_lrc_desc (guc, id); + +memset (desc,0 ,sizeof (*desc)); +xa_erase_irq (&guc->context_lookup, id); +} + +static inline bool lrc_desc_registered (struct intel_guc *guc,u32 id) +{ +return __get_context (guc, id); +} + +static inline void set_lrc_desc_registered (struct intel_guc *guc,u32 id, +struct intel_context *ce) +{ +xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); +} +static void guc_add_request (struct intel_guc *guc,struct i915_request *rq) {/* Leaving stub as this function will be used in future patches */ @@ -400,6 +426,8 @@ int intel_guc_submission_init(struct intel_guc *guc)*/ GEM_BUG_ON (!guc->lrc_desc_pool);
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c int intel_guc_submission_init(struct intel_guc *guc) · line 433
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-0+xa_init_flags (&guc->context_lookup,XA_FLAGS_LOCK_IRQ ); +return 0 ; }
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
John Harrison
Reviewed-byRe: [PATCH 10/47] drm/i915/guc: Add lrc descriptor context lookup array
Quoted 11 lines · Matthew Brost
Quoted 8 lines · Michal Wajdeczko
Quoted 5 lines · Matthew Brost
Add lrc descriptor context lookup array which can resolve the
intel_contextfrom the lrc descriptor index. In addition to lookup, it can determine in the lrc descriptor context is currently registered with the GuC by checking if an entry for a descriptor index is present. Future patches in the series will make use of this array.s/lrc/LRC
I guess? lrc and LRC are used interchangeably throughout the current code base.
It is an abbreviation so LRC is technically the correct version for a comment. The fact that other existing comments are incorrect is not a valid reason to perpetuate a mistake :). Might as well fix it if you are going to repost the patch anyway for any other reason, but I would not call it a blocking issue.
Also, 'can determine in the' should be 'can determine if the'. Again, not exactly a blocking issue but should be fixed.
Quoted 36 lines
Quoted 15 lines
Quoted 15 lines
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 5 +++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 32 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc.h +0
-0@@ -6,6 +6,8 @@#ifndef _INTEL_GUC_H_#define _INTEL_GUC_H_Quoted 3 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h line 9
Quoted 1 line
drivers/gpu/drm/i915/gt/uc/intel_guc.h +1
-0+#include "linux/xarray.h" #include <
linux/xarray.h>Yep.
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +1
-0+#include "intel_uncore.h" #include "intel_guc_fw.h" #include "intel_guc_fwif.h" @@ -46,6 +48,9 @@ struct intel_guc {struct i915_vma *lrc_desc_pool;void *lrc_desc_pool_vaddr;Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h struct intel_guc { · line 55
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +3
-0+/* guc_id to intel_context lookup */ +struct xarray context_lookup; +/* Control params for fw initialization */ u32 params[GUC_CTL_MAX_DWORDS ];btw, IIRC there was idea to move most struct definitions to
intel_guc_types.h, is this still a plan ?
Quoted 5 lines
I don't ever recall discussing this but we can certainly do this. For what it is worth we do introduce
intel_guc_submission_types.ha bit later. I'll make a note aboutintel_guc_types.hthough.Matt
Yeah, my only recollection was about the submission types header. Are there sufficient non-submission fields in the GuC structure to warrant a general GuC types header?
With the commit message tweaks and #include fix mentioned above, it looks good to me.
Quoted 60 lines
Quoted 60 lines
Quoted 60 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +28
-2@@ -65,8 +65,6 @@ static inline struct i915_priolist *to_priolist(struct rb_node *rb) return rb_entry(rb, struct i915_priolist, node); } -/* Future patches will use this function */ -__attribute__ ((unused))static struct guc_lrc_desc *__get_lrc_desc (struct intel_guc *guc,u32 index) {struct guc_lrc_desc *base = guc->lrc_desc_pool_vaddr;@@ -76,6 +74,15 @@ static struct guc_lrc_desc *__get_lrc_desc(struct intel_guc *guc, u32 index)return &base[index]; } +static inline struct intel_context *__get_context (struct intel_guc *guc,u32 id) +{ +struct intel_context *ce =xa_load (&guc->context_lookup, id); + +GEM_BUG_ON (id >=GUC_MAX_LRC_DESCRIPTORS ); + +return ce; +} +static int guc_lrc_desc_pool_create (struct intel_guc *guc) {u32 size;@@ -96,6 +103,25 @@ static void guc_lrc_desc_pool_destroy(struct intel_guc *guc)i915_vma_unpin_and_release (&guc->lrc_desc_pool,I915_VMA_RELEASE_MAP ); } +static inline void reset_lrc_desc (struct intel_guc *guc,u32 id) +{ +struct guc_lrc_desc *desc =__get_lrc_desc (guc, id); + +memset (desc,0 ,sizeof (*desc)); +xa_erase_irq (&guc->context_lookup, id); +} + +static inline bool lrc_desc_registered (struct intel_guc *guc,u32 id) +{ +return __get_context (guc, id); +} + +static inline void set_lrc_desc_registered (struct intel_guc *guc,u32 id, +struct intel_context *ce) +{ +xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); +} +static void guc_add_request (struct intel_guc *guc,struct i915_request *rq) {/* Leaving stub as this function will be used in future patches */ @@ -400,6 +426,8 @@ int intel_guc_submission_init(struct intel_guc *guc)*/ GEM_BUG_ON (!guc->lrc_desc_pool);
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c int intel_guc_submission_init(struct intel_guc *guc) · line 433
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-0+xa_init_flags (&guc->context_lookup,XA_FLAGS_LOCK_IRQ ); +return 0 ; }
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 11/47 drm/i915/guc: Implement GuC submission tasklet
In reply to Matthew BrostImplement GuC submission tasklet for new interface. The new GuC interface uses H2G to submit contexts to the GuC. Since H2G use a single channel, a single tasklet submits is used for the submission path.
Also the per engine interrupt handler has been updated to disable the rescheduling of the physical engine tasklet, when using GuC scheduling, as the physical engine tasklet is no longer used.
In this patch the field, guc_id, has been added to intel_context and is not assigned. Patches later in the series will assign this value.
--- drivers/gpu/drm/i915/gt/intel_context_types.h | 9 + drivers/gpu/drm/i915/gt/uc/intel_guc.h | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 231 +++++++++--------- 3 files changed, 127 insertions(+), 117 deletions(-)
drivers/gpu/drm/i915/gt/intel_context_types.h +9 -0
@@ -136,6 +136,15 @@ struct intel_context {struct intel_sseu sseu;u8 wa_bb_page;/* if set, page num reserved for context workarounds */ + +/* GuC scheduling state that does not require a lock. */ +atomic_t guc_sched_state_no_lock; + +/* +* GuC lrc descriptor ID - Not assigned in this patch but future patches +* in the series will. +*/ + u16 guc_id; };#endif /* __INTEL_CONTEXT_TYPES__ */
drivers/gpu/drm/i915/gt/uc/intel_guc.h +4 -0
@@ -30,6 +30,10 @@ struct intel_guc {struct intel_guc_log log;struct intel_guc_ct ct; +/* Global engine used to submit requests to GuC */ +struct i915_sched_engine *sched_engine; +struct i915_request *stalled_request; +/* intel_guc_recv interrupt related state */ spinlock_t irq_lock;unsigned int msg_enabled_mask;
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +114 -117
349 lines not on this page · raw message
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 11/47] drm/i915/guc: Implement GuC submission tasklet
Quoted 3 lines · Matthew Brost
Implement GuC submission tasklet for new interface. The new GuC interface uses H2G to submit contexts to the GuC. Since H2G use a single channel, a single tasklet submits is used for the submission path.
Re-word? 'a single tasklet submits is used...' doesn't make sense.
Quoted 20 lines
Also the per engine interrupt handler has been updated to disable the rescheduling of the physical engine tasklet, when using GuC scheduling, as the physical engine tasklet is no longer used.
In this patch the field,
guc_id, has been added tointel_contextand is not assigned. Patches later in the series will assign this value.Cc John Harrison<[email protected]>Signed-off-by Matthew Brost<[email protected]>--- drivers/gpu/drm/i915/gt/intel_context_types.h | 9 + drivers/gpu/drm/i915/gt/uc/intel_guc.h | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 231 +++++++++--------- 3 files changed, 127 insertions(+), 117 deletions(-)drivers/gpu/drm/i915/gt/intel_context_types.h +0
-0
drivers/gpu/drm/i915/gt/intel_context_types.h struct intel_context { · line 140
Quoted 5 lines
drivers/gpu/drm/i915/gt/intel_context_types.h +2
-0@@ -136,6 +136,15 @@ struct intel_context {struct intel_sseu sseu;u8 wa_bb_page;/* if set, page num reserved for context workarounds */ + +/* GuC scheduling state that does not require a lock. */
Maybe 'GuC scheduling state flags that do not require a lock'? Otherwise it just looks like a counter or something.
drivers/gpu/drm/i915/gt/intel_context_types.h struct intel_context { · line 144
Quoted 4 lines
drivers/gpu/drm/i915/gt/intel_context_types.h +4
-0+atomic_t guc_sched_state_no_lock; + +/* +* GuC lrc descriptor ID - Not assigned in this patch but future patches
Not a blocker but s/lrc/LRC/ would keep Michal happy ;). Although presumably this comment is at least being amended by later patches in the series.
Quoted 207 lines
drivers/gpu/drm/i915/gt/intel_context_types.h +3
-0+* in the series will. +*/ + u16 guc_id; };#endif /* __INTEL_CONTEXT_TYPES__ */ drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-0@@ -30,6 +30,10 @@ struct intel_guc {struct intel_guc_log log;struct intel_guc_ct ct; +/* Global engine used to submit requests to GuC */ +struct i915_sched_engine *sched_engine; +struct i915_request *stalled_request; +/* intel_guc_recv interrupt related state */ spinlock_t irq_lock;unsigned int msg_enabled_mask;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +57
-78@@ -60,6 +60,31 @@#define GUC_REQUEST_SIZE 64/* bytes */ +/* +* Below is a set of functions which control the GuC scheduling state which do +* not require a lock as all state transitions are mutually exclusive. i.e. It +* is not possible for the context pinning code and submission, for the same +* context, to be executing simultaneously. We still need an atomic as it is +* possible for some of the bits to changing at the same time though. +*/ +#define SCHED_STATE_NO_LOCK_ENABLED BIT(0) +static inline bool context_enabled (struct intel_context *ce) +{ +return (atomic_read (&ce->guc_sched_state_no_lock) & +SCHED_STATE_NO_LOCK_ENABLED ); +} + +static inline void set_context_enabled (struct intel_context *ce) +{ +atomic_or (SCHED_STATE_NO_LOCK_ENABLED , &ce->guc_sched_state_no_lock); +} + +static inline void clr_context_enabled (struct intel_context *ce) +{ +atomic_and ((u32 )~SCHED_STATE_NO_LOCK_ENABLED , + &ce->guc_sched_state_no_lock); +} +static inline struct i915_priolist *to_priolist (struct rb_node *rb) { return rb_entry(rb, struct i915_priolist, node);@@ -122,37 +147,29 @@ static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id,xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); } -static void guc_add_request (struct intel_guc *guc,struct i915_request *rq) +static int guc_add_request (struct intel_guc *guc,struct i915_request *rq) { -/* Leaving stub as this function will be used in future patches */ -} +int err; +struct intel_context *ce = rq->context; +u32 action[3 ]; +int len =0 ; +bool enabled =context_enabled (ce); -/* -* When we're doing submissions using regular execlists backend, writing to -* ELSP from CPU side is enough to make sure that writes to ringbuffer pages -* pinned in mappable aperture portion of GGTT are visible to command streamer. -* Writes done by GuC on our behalf are not guaranteeing such ordering, -* therefore, to ensure the flush, we're issuing a POSTING READ. -*/ -static void flush_ggtt_writes (struct i915_vma *vma) -{ -if (i915_vma_is_map_and_fenceable (vma)) -intel_uncore_posting_read_fw (vma->vm->gt->uncore, -GUC_STATUS ); -} +if (!enabled) { + action[len++] =INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_SET ; + action[len++] = ce->guc_id; + action[len++] =GUC_CONTEXT_ENABLE ; + }else { + action[len++] =INTEL_GUC_ACTION_SCHED_CONTEXT ; + action[len++] = ce->guc_id; + } -static void guc_submit (struct intel_engine_cs *engine, -struct i915_request **out, -struct i915_request **end) -{ -struct intel_guc *guc = &engine->gt->uc.guc; + err =intel_guc_send_nb (guc, action, len); -do { -struct i915_request *rq = *out++; +if (!enabled && !err) +set_context_enabled (ce); -flush_ggtt_writes (rq->ring->vma); -guc_add_request (guc, rq); - }while (out != end); +return err; }static inline int rq_prio (const struct i915_request *rq)@@ -160,125 +177,88 @@ static inline int rq_prio(const struct i915_request *rq)return rq->sched.attr.priority; } -static struct i915_request *schedule_in (struct i915_request *rq,int idx) +static int guc_dequeue_one_context (struct intel_guc *guc) { -trace_i915_request_in (rq, idx); - -/* -* Currently we are not tracking the rq->context being inflight -* (ce->inflight = rq->engine). It is only used by the execlists -* backend at the moment, a similar counting strategy would be -* required if we generalise the inflight tracking. -*/ - -__intel_gt_pm_get (rq->engine->gt); -return i915_request_get (rq); -} - -static void schedule_out (struct i915_request *rq) -{ -trace_i915_request_out (rq); - -intel_gt_pm_put_async (rq->engine->gt); -i915_request_put (rq); -} - -static void __guc_dequeue (struct intel_engine_cs *engine) -{ -struct intel_engine_execlists *const execlists = &engine->execlists; -struct i915_sched_engine *const sched_engine = engine->sched_engine; -struct i915_request **first = execlists->inflight; -struct i915_request **const last_port = first + execlists->port_mask; -struct i915_request *last = first[0 ]; -struct i915_request **port; +struct i915_sched_engine *const sched_engine = guc->sched_engine; +struct i915_request *last =NULL ;bool submit = false;struct rb_node *rb; +int ret;lockdep_assert_held (&sched_engine->lock); -if (last) { -if (*++first) -return ; - - last =NULL ; +if (guc->stalled_request) { + submit = true; + last = guc->stalled_request; + goto resubmit; } -/* -* We write directly into the execlists->inflight queue and don't use -* the execlists->pending queue, as we don't have a distinct switch -* event. -*/ - port = first;while ((rb =rb_first_cached (&sched_engine->queue))) {struct i915_priolist *p =to_priolist (rb);struct i915_request *rq, *rn;priolist_for_each_request_consume (rq, rn, p) { -if (last && rq->context != last->context) { -if (port == last_port) - goto done; - - *port =schedule_in (last, - port - execlists->inflight); - port++; - } +if (last && rq->context != last->context) + goto done;list_del_init (&rq->sched.link); +__i915_request_submit (rq); - submit = true; + +trace_i915_request_in (rq,0 ); last = rq; + submit = true; }rb_erase_cached (&p->node, &sched_engine->queue);i915_priolist_free (p); } done: - sched_engine->queue_priority_hint = - rb ?to_priolist (rb)->priority :INT_MIN ;if (submit) {
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static inline int rq_prio(const struct i915_request *rq) · line 224
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +7
-3- *port =schedule_in (last, port - execlists->inflight); - *++port =NULL ; -guc_submit (engine, first, port); + last->context->lrc_reg_state[CTX_RING_TAIL ] = +intel_ring_set_tail (last->ring, last->tail); +resubmit: +/* +* We only check for -EBUSY here even though it is possible for +* -EDEADLK to be returned. If -EDEADLK is returned, the GuC has +* died and a full GPU needs to be done. The hangcheck will
'full GPU reset'. Although I believe strictly speaking, it is a 'full GT reset'. There are other bits of the GPU beyond the GT.
Quoted 43 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +15
-18+* eventually detect that the GuC has died and trigger this +* reset so no need to handle -EDEADLK here. +*/ + ret =guc_add_request (guc, last); +if (ret == -EBUSY ) { +tasklet_schedule (&sched_engine->tasklet); + guc->stalled_request = last; +return false; + } } - execlists->active = execlists->inflight; + + guc->stalled_request =NULL ; +return submit; }static void guc_submission_tasklet (struct tasklet_struct *t) {struct i915_sched_engine *sched_engine =from_tasklet (sched_engine, t, tasklet); -struct intel_engine_cs *const engine = sched_engine->private_data; -struct intel_engine_execlists *const execlists = &engine->execlists; -struct i915_request **port, *rq;unsigned long flags; +bool loop; -spin_lock_irqsave (&engine->sched_engine->lock, flags); - -for (port = execlists->inflight; (rq = *port); port++) { -if (!i915_request_completed (rq)) -break ; - -schedule_out (rq); - } -if (port != execlists->inflight) { -int idx = port - execlists->inflight; -int rem =ARRAY_SIZE (execlists->inflight) - idx; -memmove (execlists->inflight, port, rem *sizeof (*port)); - } +spin_lock_irqsave (&sched_engine->lock, flags); -__guc_dequeue (engine); + do {
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static inline int rq_prio(const struct i915_request *rq) · line 257
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +4
-2+ loop =guc_dequeue_one_context (sched_engine->private_data); + }while (loop); -i915_sched_engine_reset_on_empty (engine->sched_engine); +i915_sched_engine_reset_on_empty (sched_engine); -spin_unlock_irqrestore (&engine->sched_engine->lock, flags); +spin_unlock_irqrestore (&sched_engine->lock, flags); }
Not a blocker but it has to be said that it would be much easier to remove all of the above if the delete was split into a separate patch. Having two completely disparate threads of code interwoven in the diff makes it much harder to see what the new version is doing!
Quoted 94 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +19
-15static void cs_irq_handler (struct intel_engine_cs *engine,u16 iir) { -if (iir >_RENDER_USER_INTERRUPT ) { +if (iir >_RENDER_USER_INTERRUPT )intel_engine_signal_breadcrumbs (engine); -tasklet_hi_schedule (&engine->sched_engine->tasklet); - } }static void guc_reset_prepare (struct intel_engine_cs *engine)@@ -349,6 +329,10 @@ static void guc_reset_cancel(struct intel_engine_cs *engine)struct rb_node *rb;unsigned long flags; +/* Can be called during boot if GuC fails to load */ +if (!engine->gt) +return ; +ENGINE_TRACE (engine,"\n" );/* @@ -433,8 +417,11 @@ int intel_guc_submission_init(struct intel_guc *guc)void intel_guc_submission_fini (struct intel_guc *guc) { -if (guc->lrc_desc_pool) -guc_lrc_desc_pool_destroy (guc); +if (!guc->lrc_desc_pool) +return ; + +guc_lrc_desc_pool_destroy (guc); +i915_sched_engine_put (guc->sched_engine); }static int guc_context_alloc (struct intel_context *ce)@@ -499,32 +486,32 @@ static int guc_request_alloc(struct i915_request *request)return 0 ; } -static inline void queue_request (struct intel_engine_cs *engine, +static inline void queue_request (struct i915_sched_engine *sched_engine,struct i915_request *rq,int prio) {GEM_BUG_ON (!list_empty (&rq->sched.link));list_add_tail (&rq->sched.link, -i915_sched_lookup_priolist (engine->sched_engine, prio)); +i915_sched_lookup_priolist (sched_engine, prio));set_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); }static void guc_submit_request (struct i915_request *rq) { -struct intel_engine_cs *engine = rq->engine; +struct i915_sched_engine *sched_engine = rq->engine->sched_engine;unsigned long flags;/* Will be called from irq-context when using foreign fences. */ -spin_lock_irqsave (&engine->sched_engine->lock, flags); +spin_lock_irqsave (&sched_engine->lock, flags); -queue_request (engine, rq,rq_prio (rq)); +queue_request (sched_engine, rq,rq_prio (rq)); -GEM_BUG_ON (i915_sched_engine_is_empty (engine->sched_engine)); +GEM_BUG_ON (i915_sched_engine_is_empty (sched_engine));GEM_BUG_ON (list_empty (&rq->sched.link)); -tasklet_hi_schedule (&engine->sched_engine->tasklet); +tasklet_hi_schedule (&sched_engine->tasklet); -spin_unlock_irqrestore (&engine->sched_engine->lock, flags); +spin_unlock_irqrestore (&sched_engine->lock, flags); }static void sanitize_hwsp (struct intel_engine_cs *engine)@@ -602,8 +589,6 @@ static void guc_release(struct intel_engine_cs *engine) { engine->sanitize =NULL ;/* no longer in control, nothing to sanitize */ -tasklet_kill (&engine->sched_engine->tasklet); -intel_engine_cleanup_common (engine);lrc_fini_wa_ctx (engine); }@@ -674,6 +659,7 @@ static inline void guc_default_irqs(struct intel_engine_cs *engine)int intel_guc_submission_setup (struct intel_engine_cs *engine) {struct drm_i915_private *i915 = engine->i915; +struct intel_guc *guc = &engine->gt->uc.guc;/* * The setup relies on several assumptions (e.g. irqs always enabled)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c int intel_guc_submission_setup(struct intel_engine_cs *engine) · line 671
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-1@@ -681,7 +667,18 @@ int intel_guc_submission_setup(struct intel_engine_cs *engine)*/ GEM_BUG_ON (GRAPHICS_VER (i915) <11 ); -tasklet_setup (&engine->sched_engine->tasklet, guc_submission_tasklet); +if (!guc->sched_engine) { + guc->sched_engine =i915_sched_engine_create (ENGINE_VIRTUAL );
Does the re-work of the sched_engine create/destroy happen later in this patch series? Wasn't there issues with the wrong destroy function being called in certain situations? Or do those issues (and fixes) only come in with the virtual engine support?
John.
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c int intel_guc_submission_setup(struct intel_engine_cs *engine) · line 684
Quoted 13 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0+if (!guc->sched_engine) +return -ENOMEM ; + + guc->sched_engine->schedule = i915_schedule; + guc->sched_engine->private_data = guc; +tasklet_setup (&guc->sched_engine->tasklet, + guc_submission_tasklet); + } +i915_sched_engine_put (engine->sched_engine); + engine->sched_engine =i915_sched_engine_get (guc->sched_engine);guc_default_vfuncs (engine);guc_default_irqs (engine);
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 11/47] drm/i915/guc: Implement GuC submission tasklet
Quoted 6 lines · John Harrison
Quoted 3 lines · Matthew Brost
Implement GuC submission tasklet for new interface. The new GuC interface uses H2G to submit contexts to the GuC. Since H2G use a single channel, a single tasklet submits is used for the submission path.
Re-word? 'a single tasklet submits is used...' doesn't make sense.
Will do.
Quoted 15 lines
Quoted 15 lines
Also the per engine interrupt handler has been updated to disable the rescheduling of the physical engine tasklet, when using GuC scheduling, as the physical engine tasklet is no longer used.
In this patch the field,
guc_id, has been added tointel_contextand is not assigned. Patches later in the series will assign this value.Cc John Harrison<[email protected]>Signed-off-by Matthew Brost<[email protected]>--- drivers/gpu/drm/i915/gt/intel_context_types.h | 9 + drivers/gpu/drm/i915/gt/uc/intel_guc.h | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 231 +++++++++--------- 3 files changed, 127 insertions(+), 117 deletions(-)
Quoted 12 lines
drivers/gpu/drm/i915/gt/intel_context_types.h struct intel_context { · line 139
Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_context_types.h +2
-0@@ -136,6 +136,15 @@ struct intel_context {struct intel_sseu sseu;u8 wa_bb_page;/* if set, page num reserved for context workarounds */ + +/* GuC scheduling state that does not require a lock. */ Maybe 'GuC scheduling state flags that do not require a lock'? Otherwise it just looks like a counter or something.
Sure.
Quoted 7 lines
drivers/gpu/drm/i915/gt/intel_context_types.h struct intel_context { · line 144
Quoted 4 lines
drivers/gpu/drm/i915/gt/intel_context_types.h +4
-0+atomic_t guc_sched_state_no_lock; + +/* +* GuC lrc descriptor ID - Not assigned in this patch but future patches Not a blocker but s/lrc/LRC/ would keep Michal happy ;). Although presumably this comment is at least being amended by later patches in the series.
Will fix.
Quoted 194 lines
Quoted 194 lines
drivers/gpu/drm/i915/gt/intel_context_types.h +3
-0+* in the series will. +*/ + u16 guc_id; };#endif /* __INTEL_CONTEXT_TYPES__ */ drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-0@@ -30,6 +30,10 @@ struct intel_guc {struct intel_guc_log log;struct intel_guc_ct ct; +/* Global engine used to submit requests to GuC */ +struct i915_sched_engine *sched_engine; +struct i915_request *stalled_request; +/* intel_guc_recv interrupt related state */ spinlock_t irq_lock;unsigned int msg_enabled_mask;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +58
-81@@ -60,6 +60,31 @@#define GUC_REQUEST_SIZE 64/* bytes */ +/* +* Below is a set of functions which control the GuC scheduling state which do +* not require a lock as all state transitions are mutually exclusive. i.e. It +* is not possible for the context pinning code and submission, for the same +* context, to be executing simultaneously. We still need an atomic as it is +* possible for some of the bits to changing at the same time though. +*/ +#define SCHED_STATE_NO_LOCK_ENABLED BIT(0) +static inline bool context_enabled (struct intel_context *ce) +{ +return (atomic_read (&ce->guc_sched_state_no_lock) & +SCHED_STATE_NO_LOCK_ENABLED ); +} + +static inline void set_context_enabled (struct intel_context *ce) +{ +atomic_or (SCHED_STATE_NO_LOCK_ENABLED , &ce->guc_sched_state_no_lock); +} + +static inline void clr_context_enabled (struct intel_context *ce) +{ +atomic_and ((u32 )~SCHED_STATE_NO_LOCK_ENABLED , + &ce->guc_sched_state_no_lock); +} +static inline struct i915_priolist *to_priolist (struct rb_node *rb) { return rb_entry(rb, struct i915_priolist, node);@@ -122,37 +147,29 @@ static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id,xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); } -static void guc_add_request (struct intel_guc *guc,struct i915_request *rq) +static int guc_add_request (struct intel_guc *guc,struct i915_request *rq) { -/* Leaving stub as this function will be used in future patches */ -} +int err; +struct intel_context *ce = rq->context; +u32 action[3 ]; +int len =0 ; +bool enabled =context_enabled (ce); -/* -* When we're doing submissions using regular execlists backend, writing to -* ELSP from CPU side is enough to make sure that writes to ringbuffer pages -* pinned in mappable aperture portion of GGTT are visible to command streamer. -* Writes done by GuC on our behalf are not guaranteeing such ordering, -* therefore, to ensure the flush, we're issuing a POSTING READ. -*/ -static void flush_ggtt_writes (struct i915_vma *vma) -{ -if (i915_vma_is_map_and_fenceable (vma)) -intel_uncore_posting_read_fw (vma->vm->gt->uncore, -GUC_STATUS ); -} +if (!enabled) { + action[len++] =INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_SET ; + action[len++] = ce->guc_id; + action[len++] =GUC_CONTEXT_ENABLE ; + }else { + action[len++] =INTEL_GUC_ACTION_SCHED_CONTEXT ; + action[len++] = ce->guc_id; + } -static void guc_submit (struct intel_engine_cs *engine, -struct i915_request **out, -struct i915_request **end) -{ -struct intel_guc *guc = &engine->gt->uc.guc; + err =intel_guc_send_nb (guc, action, len); -do { -struct i915_request *rq = *out++; +if (!enabled && !err) +set_context_enabled (ce); -flush_ggtt_writes (rq->ring->vma); -guc_add_request (guc, rq); - }while (out != end); +return err; }static inline int rq_prio (const struct i915_request *rq)@@ -160,125 +177,88 @@ static inline int rq_prio(const struct i915_request *rq)return rq->sched.attr.priority; } -static struct i915_request *schedule_in (struct i915_request *rq,int idx) +static int guc_dequeue_one_context (struct intel_guc *guc) { -trace_i915_request_in (rq, idx); - -/* -* Currently we are not tracking the rq->context being inflight -* (ce->inflight = rq->engine). It is only used by the execlists -* backend at the moment, a similar counting strategy would be -* required if we generalise the inflight tracking. -*/ - -__intel_gt_pm_get (rq->engine->gt); -return i915_request_get (rq); -} - -static void schedule_out (struct i915_request *rq) -{ -trace_i915_request_out (rq); - -intel_gt_pm_put_async (rq->engine->gt); -i915_request_put (rq); -} - -static void __guc_dequeue (struct intel_engine_cs *engine) -{ -struct intel_engine_execlists *const execlists = &engine->execlists; -struct i915_sched_engine *const sched_engine = engine->sched_engine; -struct i915_request **first = execlists->inflight; -struct i915_request **const last_port = first + execlists->port_mask; -struct i915_request *last = first[0 ]; -struct i915_request **port; +struct i915_sched_engine *const sched_engine = guc->sched_engine; +struct i915_request *last =NULL ;bool submit = false;struct rb_node *rb; +int ret;lockdep_assert_held (&sched_engine->lock); -if (last) { -if (*++first) -return ; - - last =NULL ; +if (guc->stalled_request) { + submit = true; + last = guc->stalled_request; + goto resubmit; } -/* -* We write directly into the execlists->inflight queue and don't use -* the execlists->pending queue, as we don't have a distinct switch -* event. -*/ - port = first;while ((rb =rb_first_cached (&sched_engine->queue))) {struct i915_priolist *p =to_priolist (rb);struct i915_request *rq, *rn;priolist_for_each_request_consume (rq, rn, p) { -if (last && rq->context != last->context) { -if (port == last_port) - goto done; - - *port =schedule_in (last, - port - execlists->inflight); - port++; - } +if (last && rq->context != last->context) + goto done;list_del_init (&rq->sched.link); +__i915_request_submit (rq); - submit = true; + +trace_i915_request_in (rq,0 ); last = rq; + submit = true; }rb_erase_cached (&p->node, &sched_engine->queue);i915_priolist_free (p); } done: - sched_engine->queue_priority_hint = - rb ?to_priolist (rb)->priority :INT_MIN ;if (submit) { - *port =schedule_in (last, port - execlists->inflight); - *++port =NULL ; -guc_submit (engine, first, port); + last->context->lrc_reg_state[CTX_RING_TAIL] =
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static inline int rq_prio(const struct i915_request *rq) · line 224
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +6
-0+intel_ring_set_tail (last->ring, last->tail); +resubmit: +/* +* We only check for -EBUSY here even though it is possible for +* -EDEADLK to be returned. If -EDEADLK is returned, the GuC has +* died and a full GPU needs to be done. The hangcheck will 'full GPU reset'. Although I believe strictly speaking, it is a 'full GT reset'. There are other bits of the GPU beyond the GT.
Yep, will fix.
Quoted 44 lines
Quoted 44 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +17
-19+* eventually detect that the GuC has died and trigger this +* reset so no need to handle -EDEADLK here. +*/ + ret =guc_add_request (guc, last); +if (ret == -EBUSY ) { +tasklet_schedule (&sched_engine->tasklet); + guc->stalled_request = last; +return false; + } } - execlists->active = execlists->inflight; + + guc->stalled_request =NULL ; +return submit; }static void guc_submission_tasklet (struct tasklet_struct *t) {struct i915_sched_engine *sched_engine =from_tasklet (sched_engine, t, tasklet); -struct intel_engine_cs *const engine = sched_engine->private_data; -struct intel_engine_execlists *const execlists = &engine->execlists; -struct i915_request **port, *rq;unsigned long flags; +bool loop; -spin_lock_irqsave (&engine->sched_engine->lock, flags); - -for (port = execlists->inflight; (rq = *port); port++) { -if (!i915_request_completed (rq)) -break ; - -schedule_out (rq); - } -if (port != execlists->inflight) { -int idx = port - execlists->inflight; -int rem =ARRAY_SIZE (execlists->inflight) - idx; -memmove (execlists->inflight, port, rem *sizeof (*port)); - } +spin_lock_irqsave (&sched_engine->lock, flags); -__guc_dequeue (engine); +do { + loop =guc_dequeue_one_context (sched_engine->private_data); + }while (loop); -i915_sched_engine_reset_on_empty (engine->sched_engine);
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static inline int rq_prio(const struct i915_request *rq) · line 256
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-1+i915_sched_engine_reset_on_empty (sched_engine); -spin_unlock_irqrestore (&engine->sched_engine->lock, flags); +spin_unlock_irqrestore (&sched_engine->lock, flags); }Not a blocker but it has to be said that it would be much easier to remove all of the above if the delete was split into a separate patch. Having two completely disparate threads of code interwoven in the diff makes it much harder to see what the new version is doing!
Yes, it would be easier to read if this code was deleted in a seperate patch. I'll keep that in mind going forward. No promises but perhaps I'll do this in the next rev.
Quoted 81 lines
Quoted 81 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +19
-15static void cs_irq_handler (struct intel_engine_cs *engine,u16 iir) { -if (iir >_RENDER_USER_INTERRUPT ) { +if (iir >_RENDER_USER_INTERRUPT )intel_engine_signal_breadcrumbs (engine); -tasklet_hi_schedule (&engine->sched_engine->tasklet); - } }static void guc_reset_prepare (struct intel_engine_cs *engine)@@ -349,6 +329,10 @@ static void guc_reset_cancel(struct intel_engine_cs *engine)struct rb_node *rb;unsigned long flags; +/* Can be called during boot if GuC fails to load */ +if (!engine->gt) +return ; +ENGINE_TRACE (engine,"\n" );/* @@ -433,8 +417,11 @@ int intel_guc_submission_init(struct intel_guc *guc)void intel_guc_submission_fini (struct intel_guc *guc) { -if (guc->lrc_desc_pool) -guc_lrc_desc_pool_destroy (guc); +if (!guc->lrc_desc_pool) +return ; + +guc_lrc_desc_pool_destroy (guc); +i915_sched_engine_put (guc->sched_engine); }static int guc_context_alloc (struct intel_context *ce)@@ -499,32 +486,32 @@ static int guc_request_alloc(struct i915_request *request)return 0 ; } -static inline void queue_request (struct intel_engine_cs *engine, +static inline void queue_request (struct i915_sched_engine *sched_engine,struct i915_request *rq,int prio) {GEM_BUG_ON (!list_empty (&rq->sched.link));list_add_tail (&rq->sched.link, -i915_sched_lookup_priolist (engine->sched_engine, prio)); +i915_sched_lookup_priolist (sched_engine, prio));set_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); }static void guc_submit_request (struct i915_request *rq) { -struct intel_engine_cs *engine = rq->engine; +struct i915_sched_engine *sched_engine = rq->engine->sched_engine;unsigned long flags;/* Will be called from irq-context when using foreign fences. */ -spin_lock_irqsave (&engine->sched_engine->lock, flags); +spin_lock_irqsave (&sched_engine->lock, flags); -queue_request (engine, rq,rq_prio (rq)); +queue_request (sched_engine, rq,rq_prio (rq)); -GEM_BUG_ON (i915_sched_engine_is_empty (engine->sched_engine)); +GEM_BUG_ON (i915_sched_engine_is_empty (sched_engine));GEM_BUG_ON (list_empty (&rq->sched.link)); -tasklet_hi_schedule (&engine->sched_engine->tasklet); +tasklet_hi_schedule (&sched_engine->tasklet); -spin_unlock_irqrestore (&engine->sched_engine->lock, flags); +spin_unlock_irqrestore (&sched_engine->lock, flags); }static void sanitize_hwsp (struct intel_engine_cs *engine)@@ -602,8 +589,6 @@ static void guc_release(struct intel_engine_cs *engine) { engine->sanitize =NULL ;/* no longer in control, nothing to sanitize */ -tasklet_kill (&engine->sched_engine->tasklet); -intel_engine_cleanup_common (engine);lrc_fini_wa_ctx (engine); }@@ -674,6 +659,7 @@ static inline void guc_default_irqs(struct intel_engine_cs *engine)int intel_guc_submission_setup (struct intel_engine_cs *engine) {struct drm_i915_private *i915 = engine->i915; +struct intel_guc *guc = &engine->gt->uc.guc;/* * The setup relies on several assumptions (e.g. irqs always enabled) @@ -681,7 +667,18 @@ int intel_guc_submission_setup(struct intel_engine_cs *engine)*/
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c int intel_guc_submission_setup(struct intel_engine_cs *engine) · line 671
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-1GEM_BUG_ON (GRAPHICS_VER (i915) <11 ); -tasklet_setup (&engine->sched_engine->tasklet, guc_submission_tasklet); +if (!guc->sched_engine) { + guc->sched_engine =i915_sched_engine_create (ENGINE_VIRTUAL );Does the re-work of the
sched_enginecreate/destroy happen later in this patch series? Wasn't there issues with the wrong destroy function being called in certain situations? Or do those issues (and fixes) only come in with the virtual engine support?
We didn't need the destroy until we introduce the guc_submit_engine, but that is changing after the kasan bug fix I sent out today for the internal version of this code. I've already reworked my upstream branch to add a destroy vfunc for sched_engine in seperate patch a bit later in the series.
Matt
Quoted 15 lines
John.
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c int intel_guc_submission_setup(struct intel_engine_cs *engine) · line 684
Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0+if (!guc->sched_engine) +return -ENOMEM ; + + guc->sched_engine->schedule = i915_schedule; + guc->sched_engine->private_data = guc; +tasklet_setup (&guc->sched_engine->tasklet, + guc_submission_tasklet); + } +i915_sched_engine_put (engine->sched_engine); + engine->sched_engine =i915_sched_engine_get (guc->sched_engine);guc_default_vfuncs (engine);guc_default_irqs (engine);
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 12/47 drm/i915/guc: Add bypass tasklet submission path to GuC
In reply to Matthew BrostAdd bypass tasklet submission path to GuC. The tasklet is only used if H2G channel has backpresure.
--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +29 -8
@@ -172,6 +172,12 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)return err; } +static inline void guc_set_lrc_tail (struct i915_request *rq) +{ + rq->context->lrc_reg_state[CTX_RING_TAIL ] = +intel_ring_set_tail (rq->ring, rq->tail); +} +static inline int rq_prio (const struct i915_request *rq) {return rq->sched.attr.priority;
@@ -215,8 +221,7 @@ static int guc_dequeue_one_context(struct intel_guc *guc) } done:if (submit) { - last->context->lrc_reg_state[CTX_RING_TAIL ] = -intel_ring_set_tail (last->ring, last->tail); +guc_set_lrc_tail (last); resubmit:/* * We only check for -EBUSY here even though it is possible for
@@ -496,20 +501,36 @@ static inline void queue_request(struct i915_sched_engine *sched_engine,set_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); } +static int guc_bypass_tasklet_submit (struct intel_guc *guc, +struct i915_request *rq) +{ +int ret; + +__i915_request_submit (rq); + +trace_i915_request_in (rq,0 ); + +guc_set_lrc_tail (rq); + ret =guc_add_request (guc, rq); +if (ret == -EBUSY ) + guc->stalled_request = rq; + +return ret; +} +static void guc_submit_request (struct i915_request *rq) {struct i915_sched_engine *sched_engine = rq->engine->sched_engine; +struct intel_guc *guc = &rq->engine->gt->uc.guc;unsigned long flags;/* Will be called from irq-context when using foreign fences. */ spin_lock_irqsave (&sched_engine->lock, flags); -queue_request (sched_engine, rq,rq_prio (rq)); - -GEM_BUG_ON (i915_sched_engine_is_empty (sched_engine)); -GEM_BUG_ON (list_empty (&rq->sched.link)); - -tasklet_hi_schedule (&sched_engine->tasklet); +if (guc->stalled_request || !i915_sched_engine_is_empty (sched_engine)) +queue_request (sched_engine, rq,rq_prio (rq)); +else if (guc_bypass_tasklet_submit (guc, rq) == -EBUSY ) +tasklet_hi_schedule (&sched_engine->tasklet);spin_unlock_irqrestore (&sched_engine->lock, flags); }
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 12/47] drm/i915/guc: Add bypass tasklet submission path to GuC
Quoted 4 lines · Matthew Brost
Add bypass tasklet submission path to GuC. The tasklet is only used if H2G channel has backpresure.
Signed-off-by Matthew Brost <[email protected]>
Quoted 74 lines
--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +29
-8@@ -172,6 +172,12 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)return err; } +static inline void guc_set_lrc_tail (struct i915_request *rq) +{ + rq->context->lrc_reg_state[CTX_RING_TAIL ] = +intel_ring_set_tail (rq->ring, rq->tail); +} +static inline int rq_prio (const struct i915_request *rq) {return rq->sched.attr.priority;@@ -215,8 +221,7 @@ static int guc_dequeue_one_context(struct intel_guc *guc) } done:if (submit) { - last->context->lrc_reg_state[CTX_RING_TAIL ] = -intel_ring_set_tail (last->ring, last->tail); +guc_set_lrc_tail (last); resubmit:/* * We only check for -EBUSY here even though it is possible for @@ -496,20 +501,36 @@ static inline void queue_request(struct i915_sched_engine *sched_engine,set_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); } +static int guc_bypass_tasklet_submit (struct intel_guc *guc, +struct i915_request *rq) +{ +int ret; + +__i915_request_submit (rq); + +trace_i915_request_in (rq,0 ); + +guc_set_lrc_tail (rq); + ret =guc_add_request (guc, rq); +if (ret == -EBUSY ) + guc->stalled_request = rq; + +return ret; +} +static void guc_submit_request (struct i915_request *rq) {struct i915_sched_engine *sched_engine = rq->engine->sched_engine; +struct intel_guc *guc = &rq->engine->gt->uc.guc;unsigned long flags;/* Will be called from irq-context when using foreign fences. */ spin_lock_irqsave (&sched_engine->lock, flags); -queue_request (sched_engine, rq,rq_prio (rq)); - -GEM_BUG_ON (i915_sched_engine_is_empty (sched_engine)); -GEM_BUG_ON (list_empty (&rq->sched.link)); - -tasklet_hi_schedule (&sched_engine->tasklet); +if (guc->stalled_request || !i915_sched_engine_is_empty (sched_engine)) +queue_request (sched_engine, rq,rq_prio (rq)); +else if (guc_bypass_tasklet_submit (guc, rq) == -EBUSY ) +tasklet_hi_schedule (&sched_engine->tasklet);spin_unlock_irqrestore (&sched_engine->lock, flags); }
PATCH 13/47 drm/i915/guc: Implement GuC context operations for new inteface
In reply to Matthew BrostImplement GuC context operations which includes GuC specific operations alloc, pin, unpin, and destroy.
--- drivers/gpu/drm/i915/gt/intel_context.c | 5 + drivers/gpu/drm/i915/gt/intel_context_types.h | 22 +- drivers/gpu/drm/i915/gt/intel_lrc_reg.h | 1 - drivers/gpu/drm/i915/gt/uc/intel_guc.h | 34 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 664 ++++++++++++++++-- drivers/gpu/drm/i915/i915_reg.h | 1 + drivers/gpu/drm/i915/i915_request.c | 1 + 8 files changed, 677 insertions(+), 55 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.c +5 -0
@@ -383,6 +383,11 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)mutex_init (&ce->pin_mutex); +spin_lock_init (&ce->guc_state.lock); + + ce->guc_id =GUC_INVALID_LRC_ID ; +INIT_LIST_HEAD (&ce->guc_id_link); +i915_active_init (&ce->active, __intel_context_active, __intel_context_retire,0 ); }
drivers/gpu/drm/i915/gt/intel_context_types.h +19 -3
@@ -95,6 +95,7 @@ struct intel_context {#define CONTEXT_BANNED 6#define CONTEXT_FORCE_SINGLE_SUBMISSION 7#define CONTEXT_NOPREEMPT 8 +#define CONTEXT_LRCA_DIRTY 9struct {u64 timeout_us;
@@ -137,14 +138,29 @@ struct intel_context {u8 wa_bb_page;/* if set, page num reserved for context workarounds */ +struct { +/** lock: protects everything in guc_state */ +spinlock_t lock; +/** +* sched_state: scheduling state of this context using GuC +* submission +*/ +u8 sched_state; + } guc_state; +/* GuC scheduling state that does not require a lock. */ atomic_t guc_sched_state_no_lock; +/* GuC lrc descriptor ID */ +u16 guc_id; + +/* GuC lrc descriptor reference count */ +atomic_t guc_id_ref; +/* -* GuC lrc descriptor ID - Not assigned in this patch but future patches -* in the series will. +* GuC ID link - in list when unpinned but guc_id still valid in GuC */ - u16 guc_id; + struct list_head guc_id_link; };#endif /* __INTEL_CONTEXT_TYPES__ */
drivers/gpu/drm/i915/gt/intel_lrc_reg.h +0 -1
@@ -87,7 +87,6 @@#define GEN11_CSB_WRITE_PTR_MASK (GEN11_CSB_PTR_MASK << 0)#define MAX_CONTEXT_HW_ID (1 << 21)/* exclusive */ -#define MAX_GUC_CONTEXT_HW_ID (1 << 20)/* exclusive */ #define GEN11_MAX_CONTEXT_HW_ID (1 << 11)/* exclusive */ /* in Gen12 ID 0x7FF is reserved to indicate idle */ #define GEN12_MAX_CONTEXT_HW_ID (GEN11_MAX_CONTEXT_HW_ID - 1)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +34 -0
@@ -44,6 +44,14 @@ struct intel_guc {void (*disable)(struct intel_guc *guc); } interrupts; +/* +* contexts_lock protects the pool of free guc ids and a linked list of +* guc ids available to be stolen +*/ +spinlock_t contexts_lock; +struct ida guc_ids; +struct list_head guc_id_list; +bool submission_selected;struct i915_vma *ads_vma;
@@ -102,6 +110,29 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, response_buf, response_buf_size, 0); } +static inline int intel_guc_send_busy_loop (struct intel_guc * guc, +const u32 *action, +u32 len, +bool loop) +{ +int err; + +/* No sleeping with spin locks, just busy loop */ +might_sleep_if (loop && (!in_atomic () && !irqs_disabled ())); + +retry: + err =intel_guc_send_nb (guc, action, len); +if (unlikely (err == -EBUSY && loop)) { +if (likely (!in_atomic () && !irqs_disabled ())) +cond_resched (); +else +cpu_relax (); + goto retry; + } + +return err; +} +static inline void intel_guc_to_host_event_handler (struct intel_guc *guc) {intel_guc_ct_event_handler (&guc->ct);
@@ -203,6 +234,9 @@ static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)int intel_guc_reset_engine (struct intel_guc *guc,struct intel_engine_cs *engine); +int intel_guc_deregister_done_process_msg (struct intel_guc *guc, +const u32 *msg,u32 len); +void intel_guc_load_status (struct intel_guc *guc,struct drm_printer *p);#endif
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4 -0
@@ -901,6 +901,10 @@ static int ct_process_request(struct intel_guc_ct *ct, struct ct_incoming_msg *rcase INTEL_GUC_ACTION_DEFAULT : ret =intel_guc_to_host_process_recv_msg (guc, payload, len);break ; +case INTEL_GUC_ACTION_DEREGISTER_CONTEXT_DONE : + ret =intel_guc_deregister_done_process_msg (guc, payload, + len); +break ;default : ret = -EOPNOTSUPP ;break ;
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +613 -51
754 lines not on this page · raw message
drivers/gpu/drm/i915/i915_reg.h +1 -0
@@ -4142,6 +4142,7 @@ enum { FAULT_AND_CONTINUE /* Unsupported */ }; +#define CTX_GTT_ADDRESS_MASK GENMASK(31, 12)#define GEN8_CTX_VALID (1 << 0)#define GEN8_CTX_FORCE_PD_RESTORE (1 << 1)#define GEN8_CTX_FORCE_RESTORE (1 << 2)
drivers/gpu/drm/i915/i915_request.c +1 -0
@@ -419,6 +419,7 @@ bool i915_request_retire(struct i915_request *rq)*/ if (!list_empty (&rq->sched.link))remove_from_engine (rq); +atomic_dec (&rq->context->guc_id_ref);GEM_BUG_ON (!llist_empty (&rq->execute_cb));__list_del_entry (&rq->link);/* poison neither prev/next (RCU walks) */
Signature · 1 line
2.28.0
Re: [PATCH 13/47] drm/i915/guc: Implement GuC context operations for new inteface
Quoted 64 lines · Matthew Brost
Implement GuC context operations which includes GuC specific operations alloc, pin, unpin, and destroy.
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/intel_context.c | 5 + drivers/gpu/drm/i915/gt/intel_context_types.h | 22 +- drivers/gpu/drm/i915/gt/intel_lrc_reg.h | 1 - drivers/gpu/drm/i915/gt/uc/intel_guc.h | 34 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 664 ++++++++++++++++-- drivers/gpu/drm/i915/i915_reg.h | 1 + drivers/gpu/drm/i915/i915_request.c | 1 + 8 files changed, 677 insertions(+), 55 deletions(-)drivers/gpu/drm/i915/gt/intel_context.c +5
-0@@ -383,6 +383,11 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)mutex_init (&ce->pin_mutex); +spin_lock_init (&ce->guc_state.lock); + + ce->guc_id =GUC_INVALID_LRC_ID ; +INIT_LIST_HEAD (&ce->guc_id_link); +i915_active_init (&ce->active, __intel_context_active, __intel_context_retire,0 ); }drivers/gpu/drm/i915/gt/intel_context_types.h +14
-0@@ -95,6 +95,7 @@ struct intel_context {#define CONTEXT_BANNED 6#define CONTEXT_FORCE_SINGLE_SUBMISSION 7#define CONTEXT_NOPREEMPT 8 +#define CONTEXT_LRCA_DIRTY 9struct {u64 timeout_us;@@ -137,14 +138,29 @@ struct intel_context {u8 wa_bb_page;/* if set, page num reserved for context workarounds */ +struct { +/** lock: protects everything in guc_state */ +spinlock_t lock; +/** +* sched_state: scheduling state of this context using GuC +* submission +*/ +u8 sched_state; + } guc_state; +/* GuC scheduling state that does not require a lock. */ atomic_t guc_sched_state_no_lock; +/* GuC lrc descriptor ID */ +u16 guc_id; +
drivers/gpu/drm/i915/gt/intel_context_types.h struct intel_context { · line 163
Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_context_types.h +5
-3+/* GuC lrc descriptor reference count */ +atomic_t guc_id_ref; +/* -* GuC lrc descriptor ID - Not assigned in this patch but future patches -* in the series will. +* GuC ID link - in list when unpinned but guc_id still valid in GuC */ -u16 guc_id; +struct list_head guc_id_link;
some fields are being added with kerneldoc, some without what's the rule ?
Quoted 319 lines
drivers/gpu/drm/i915/gt/intel_context_types.h +0
-0};#endif /* __INTEL_CONTEXT_TYPES__ */ drivers/gpu/drm/i915/gt/intel_lrc_reg.h +0
-1@@ -87,7 +87,6 @@#define GEN11_CSB_WRITE_PTR_MASK (GEN11_CSB_PTR_MASK << 0)#define MAX_CONTEXT_HW_ID (1 << 21)/* exclusive */ -#define MAX_GUC_CONTEXT_HW_ID (1 << 20)/* exclusive */ #define GEN11_MAX_CONTEXT_HW_ID (1 << 11)/* exclusive */ /* in Gen12 ID 0x7FF is reserved to indicate idle */ #define GEN12_MAX_CONTEXT_HW_ID (GEN11_MAX_CONTEXT_HW_ID - 1)drivers/gpu/drm/i915/gt/uc/intel_guc.h +34
-0@@ -44,6 +44,14 @@ struct intel_guc {void (*disable)(struct intel_guc *guc); } interrupts; +/* +* contexts_lock protects the pool of free guc ids and a linked list of +* guc ids available to be stolen +*/ +spinlock_t contexts_lock; +struct ida guc_ids; +struct list_head guc_id_list; +bool submission_selected;struct i915_vma *ads_vma;@@ -102,6 +110,29 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, response_buf, response_buf_size, 0); } +static inline int intel_guc_send_busy_loop (struct intel_guc * guc, +const u32 *action, +u32 len, +bool loop) +{ +int err; + +/* No sleeping with spin locks, just busy loop */ +might_sleep_if (loop && (!in_atomic () && !irqs_disabled ())); + +retry: + err =intel_guc_send_nb (guc, action, len); +if (unlikely (err == -EBUSY && loop)) { +if (likely (!in_atomic () && !irqs_disabled ())) +cond_resched (); +else +cpu_relax (); + goto retry; + } + +return err; +} +static inline void intel_guc_to_host_event_handler (struct intel_guc *guc) {intel_guc_ct_event_handler (&guc->ct);@@ -203,6 +234,9 @@ static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)int intel_guc_reset_engine (struct intel_guc *guc,struct intel_engine_cs *engine); +int intel_guc_deregister_done_process_msg (struct intel_guc *guc, +const u32 *msg,u32 len); +void intel_guc_load_status (struct intel_guc *guc,struct drm_printer *p);#endif drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-0@@ -901,6 +901,10 @@ static int ct_process_request(struct intel_guc_ct *ct, struct ct_incoming_msg *rcase INTEL_GUC_ACTION_DEFAULT : ret =intel_guc_to_host_process_recv_msg (guc, payload, len);break ; +case INTEL_GUC_ACTION_DEREGISTER_CONTEXT_DONE : + ret =intel_guc_deregister_done_process_msg (guc, payload, + len); +break ;default : ret = -EOPNOTSUPP ;break ;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +190
-2@@ -13,7 +13,9 @@#include "gt/intel_gt.h" #include "gt/intel_gt_irq.h" #include "gt/intel_gt_pm.h" +#include "gt/intel_gt_requests.h" #include "gt/intel_lrc.h" +#include "gt/intel_lrc_reg.h" #include "gt/intel_mocs.h" #include "gt/intel_ring.h" @@ -85,6 +87,73 @@ static inline void clr_context_enabled(struct intel_context *ce) &ce->guc_sched_state_no_lock); } +/* +* Below is a set of functions which control the GuC scheduling state which +* require a lock, aside from the special case where the functions are called +* from guc_lrc_desc_pin(). In that case it isn't possible for any other code +* path to be executing on the context. +*/ +#define SCHED_STATE_WAIT_FOR_DEREGISTER_TO_REGISTER BIT(0) +#define SCHED_STATE_DESTROYED BIT(1) +static inline void init_sched_state (struct intel_context *ce) +{ +/* Only should be called from guc_lrc_desc_pin() */ +atomic_set (&ce->guc_sched_state_no_lock,0 ); + ce->guc_state.sched_state =0 ; +} + +static inline bool +context_wait_for_deregister_to_register (struct intel_context *ce) +{ +return (ce->guc_state.sched_state & +SCHED_STATE_WAIT_FOR_DEREGISTER_TO_REGISTER ); +} + +static inline void +set_context_wait_for_deregister_to_register (struct intel_context *ce) +{ +/* Only should be called from guc_lrc_desc_pin() */ + ce->guc_state.sched_state |= +SCHED_STATE_WAIT_FOR_DEREGISTER_TO_REGISTER ; +} + +static inline void +clr_context_wait_for_deregister_to_register (struct intel_context *ce) +{ +lockdep_assert_held (&ce->guc_state.lock); + ce->guc_state.sched_state = + (ce->guc_state.sched_state & + ~SCHED_STATE_WAIT_FOR_DEREGISTER_TO_REGISTER ); +} + +static inline bool +context_destroyed (struct intel_context *ce) +{ +return (ce->guc_state.sched_state &SCHED_STATE_DESTROYED ); +} + +static inline void +set_context_destroyed (struct intel_context *ce) +{ +lockdep_assert_held (&ce->guc_state.lock); + ce->guc_state.sched_state |=SCHED_STATE_DESTROYED ; +} + +static inline bool context_guc_id_invalid (struct intel_context *ce) +{ +return (ce->guc_id ==GUC_INVALID_LRC_ID ); +} + +static inline void set_context_guc_id_invalid (struct intel_context *ce) +{ + ce->guc_id =GUC_INVALID_LRC_ID ; +} + +static inline struct intel_guc *ce_to_guc (struct intel_context *ce) +{ +return &ce->engine->gt->uc.guc; +} +static inline struct i915_priolist *to_priolist (struct rb_node *rb) { return rb_entry(rb, struct i915_priolist, node);@@ -155,6 +224,9 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)int len =0 ;bool enabled =context_enabled (ce); +GEM_BUG_ON (!atomic_read (&ce->guc_id_ref)); +GEM_BUG_ON (context_guc_id_invalid (ce)); +if (!enabled) { action[len++] =INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_SET ; action[len++] = ce->guc_id;@@ -417,6 +489,10 @@ int intel_guc_submission_init(struct intel_guc *guc)xa_init_flags (&guc->context_lookup,XA_FLAGS_LOCK_IRQ ); +spin_lock_init (&guc->contexts_lock); +INIT_LIST_HEAD (&guc->guc_id_list); +ida_init (&guc->guc_ids); +return 0 ; }@@ -429,9 +505,303 @@ void intel_guc_submission_fini(struct intel_guc *guc)i915_sched_engine_put (guc->sched_engine); } -static int guc_context_alloc (struct intel_context *ce) +static inline void queue_request (struct i915_sched_engine *sched_engine, +struct i915_request *rq, +int prio) { -return lrc_alloc (ce, ce->engine); +GEM_BUG_ON (!list_empty (&rq->sched.link)); +list_add_tail (&rq->sched.link, +i915_sched_lookup_priolist (sched_engine, prio)); +set_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); +} + +static int guc_bypass_tasklet_submit (struct intel_guc *guc, +struct i915_request *rq) +{ +int ret; + +__i915_request_submit (rq); + +trace_i915_request_in (rq,0 ); + +guc_set_lrc_tail (rq); + ret =guc_add_request (guc, rq); +if (ret == -EBUSY ) + guc->stalled_request = rq; + +return ret; +} + +static void guc_submit_request (struct i915_request *rq) +{ +struct i915_sched_engine *sched_engine = rq->engine->sched_engine; +struct intel_guc *guc = &rq->engine->gt->uc.guc; +unsigned long flags; + +/* Will be called from irq-context when using foreign fences. */ +spin_lock_irqsave (&sched_engine->lock, flags); + +if (guc->stalled_request || !i915_sched_engine_is_empty (sched_engine)) +queue_request (sched_engine, rq,rq_prio (rq)); +else if (guc_bypass_tasklet_submit (guc, rq) == -EBUSY ) +tasklet_hi_schedule (&sched_engine->tasklet); + +spin_unlock_irqrestore (&sched_engine->lock, flags); +} + +#define GUC_ID_START 64/* First 64 guc_ids reserved */ +static int new_guc_id (struct intel_guc *guc) +{ +return ida_simple_get (&guc->guc_ids,GUC_ID_START , +GUC_MAX_LRC_DESCRIPTORS ,GFP_KERNEL | + __GFP_RETRY_MAYFAIL | __GFP_NOWARN); +} + +static void __release_guc_id (struct intel_guc *guc,struct intel_context *ce) +{ +if (!context_guc_id_invalid (ce)) { +ida_simple_remove (&guc->guc_ids, ce->guc_id); +reset_lrc_desc (guc, ce->guc_id); +set_context_guc_id_invalid (ce); + } +if (!list_empty (&ce->guc_id_link)) +list_del_init (&ce->guc_id_link); +} + +static void release_guc_id (struct intel_guc *guc,struct intel_context *ce) +{ +unsigned long flags; + +spin_lock_irqsave (&guc->contexts_lock, flags); +__release_guc_id (guc, ce); +spin_unlock_irqrestore (&guc->contexts_lock, flags); +} + +static int steal_guc_id (struct intel_guc *guc) +{ +struct intel_context *ce; +int guc_id; + +if (!list_empty (&guc->guc_id_list)) { + ce =list_first_entry (&guc->guc_id_list, + struct intel_context, + guc_id_link); + +GEM_BUG_ON (atomic_read (&ce->guc_id_ref)); +GEM_BUG_ON (context_guc_id_invalid (ce)); + +list_del_init (&ce->guc_id_link); + guc_id = ce->guc_id; +set_context_guc_id_invalid (ce); +return guc_id; + }else { +return -EAGAIN ; + } +} + +static int assign_guc_id (struct intel_guc *guc,u16 *out) +{ +int ret; + + ret =new_guc_id (guc); +if (unlikely (ret <0 )) { + ret =steal_guc_id (guc); +if (ret <0 ) +return ret; + } + + *out = ret; +return 0 ; +} + +#define PIN_GUC_ID_TRIES 4 +static int pin_guc_id (struct intel_guc *guc,struct intel_context *ce) +{ +int ret =0 ; +unsigned long flags, tries =PIN_GUC_ID_TRIES ; +
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_fini(struct intel_guc *guc) · line 632
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0+GEM_BUG_ON (atomic_read (&ce->guc_id_ref)); + +try_again: +spin_lock_irqsave (&guc->contexts_lock, flags); + +if (context_guc_id_invalid (ce)) { + ret =assign_guc_id (guc, &ce->guc_id); +if (ret) + goto out_unlock; + ret =1 ;// Indidcates newly assigned HW context
C++ style comment
Quoted 468 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +354
-49+ } +if (!list_empty (&ce->guc_id_link)) +list_del_init (&ce->guc_id_link); +atomic_inc (&ce->guc_id_ref); + +out_unlock: +spin_unlock_irqrestore (&guc->contexts_lock, flags); + +/* +* -EAGAIN indicates no guc_ids are available, let's retire any +* outstanding requests to see if that frees up a guc_id. If the first +* retire didn't help, insert a sleep with the timeslice duration before +* attempting to retire more requests. Double the sleep period each +* subsequent pass before finally giving up. The sleep period has max of +* 100ms and minimum of 1ms. +*/ +if (ret == -EAGAIN && --tries) { +if (PIN_GUC_ID_TRIES - tries >1 ) { +unsigned int timeslice_shifted = + ce->engine->props.timeslice_duration_ms << + (PIN_GUC_ID_TRIES - tries -2 ); + unsigned int max = min_t(unsigned int, 100, + timeslice_shifted); + + msleep(max_t(unsigned int, max, 1)); + } +intel_gt_retire_requests (guc_to_gt (guc)); + goto try_again; + } + +return ret; +} + +static void unpin_guc_id (struct intel_guc *guc,struct intel_context *ce) +{ +unsigned long flags; + +GEM_BUG_ON (atomic_read (&ce->guc_id_ref) <0 ); + +spin_lock_irqsave (&guc->contexts_lock, flags); +if (!context_guc_id_invalid (ce) &&list_empty (&ce->guc_id_link) && + !atomic_read (&ce->guc_id_ref)) +list_add_tail (&ce->guc_id_link, &guc->guc_id_list); +spin_unlock_irqrestore (&guc->contexts_lock, flags); +} + +static int __guc_action_register_context (struct intel_guc *guc, +u32 guc_id, +u32 offset) +{ +u32 action[] = { +INTEL_GUC_ACTION_REGISTER_CONTEXT , + guc_id, + offset, + }; + +return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), true); +} + +static int register_context (struct intel_context *ce) +{ +struct intel_guc *guc =ce_to_guc (ce); +u32 offset =intel_guc_ggtt_offset (guc, guc->lrc_desc_pool) + + ce->guc_id *sizeof (struct guc_lrc_desc ); + +return __guc_action_register_context (guc, ce->guc_id, offset); +} + +static int __guc_action_deregister_context (struct intel_guc *guc, +u32 guc_id) +{ +u32 action[] = { +INTEL_GUC_ACTION_DEREGISTER_CONTEXT , + guc_id, + }; + +return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), true); +} + +static int deregister_context (struct intel_context *ce,u32 guc_id) +{ +struct intel_guc *guc =ce_to_guc (ce); + +return __guc_action_deregister_context (guc, guc_id); +} + +static intel_engine_mask_t adjust_engine_mask (u8 class,intel_engine_mask_t mask) +{ +switch (class) { +case RENDER_CLASS : +return mask >>RCS0 ; +case VIDEO_ENHANCEMENT_CLASS : +return mask >>VECS0 ; +case VIDEO_DECODE_CLASS : +return mask >>VCS0 ; +case COPY_ENGINE_CLASS : +return mask >>BCS0 ; +default : +GEM_BUG_ON ("Invalid Class" ); +return 0 ; + } +} + +static void guc_context_policy_init (struct intel_engine_cs *engine, +struct guc_lrc_desc *desc) +{ + desc->policy_flags =0 ; + + desc->execution_quantum =CONTEXT_POLICY_DEFAULT_EXECUTION_QUANTUM_US ; + desc->preemption_timeout =CONTEXT_POLICY_DEFAULT_PREEMPTION_TIME_US ; +} + +static int guc_lrc_desc_pin (struct intel_context *ce) +{ +struct intel_runtime_pm *runtime_pm = + &ce->engine->gt->i915->runtime_pm; +struct intel_engine_cs *engine = ce->engine; +struct intel_guc *guc = &engine->gt->uc.guc; +u32 desc_idx = ce->guc_id; +struct guc_lrc_desc *desc; +bool context_registered; +intel_wakeref_t wakeref; +int ret =0 ; + +GEM_BUG_ON (!engine->mask); + +/* +* Ensure LRC + CT vmas are is same region as write barrier is done +* based on CT vma region. +*/ +GEM_BUG_ON (i915_gem_object_is_lmem (guc->ct.vma->obj) != +i915_gem_object_is_lmem (ce->ring->vma->obj)); + + context_registered =lrc_desc_registered (guc, desc_idx); + +reset_lrc_desc (guc, desc_idx); +set_lrc_desc_registered (guc, desc_idx, ce); + + desc =__get_lrc_desc (guc, desc_idx); + desc->engine_class =engine_class_to_guc_class (engine->class); + desc->engine_submit_mask =adjust_engine_mask (engine->class, + engine->mask); + desc->hw_context_desc = ce->lrc.lrca; + desc->priority =GUC_CLIENT_PRIORITY_KMD_NORMAL ; + desc->context_flags =CONTEXT_REGISTRATION_FLAG_KMD ; +guc_context_policy_init (engine, desc); +init_sched_state (ce); + +/* +* The context_lookup xarray is used to determine if the hardware +* context is currently registered. There are two cases in which it +* could be regisgered either the guc_id has been stole from from +* another context or the lrc descriptor address of this context has +* changed. In either case the context needs to be deregistered with the +* GuC before registering this context. +*/ +if (context_registered) { +set_context_wait_for_deregister_to_register (ce); +intel_context_get (ce); + +/* +* If stealing the guc_id, this ce has the same guc_id as the +* context whos guc_id was stole. +*/ +with_intel_runtime_pm (runtime_pm, wakeref) + ret = deregister_context(ce, ce->guc_id); + }else { +with_intel_runtime_pm (runtime_pm, wakeref) + ret = register_context(ce); + } + +return ret; } static int guc_context_pre_pin(struct intel_context *ce,@@ -443,36 +813,137 @@ static int guc_context_pre_pin(struct intel_context *ce,static int guc_context_pin (struct intel_context *ce,void *vaddr) { +if (i915_ggtt_offset (ce->state) != + (ce->lrc.lrca &CTX_GTT_ADDRESS_MASK )) +set_bit (CONTEXT_LRCA_DIRTY , &ce->flags); +return lrc_pin (ce, ce->engine, vaddr); } +static void guc_context_unpin (struct intel_context *ce) +{ +unpin_guc_id (ce_to_guc (ce), ce); +lrc_unpin (ce); +} + +static void guc_context_post_unpin (struct intel_context *ce) +{ +lrc_post_unpin (ce); +} + +static inline void guc_lrc_desc_unpin (struct intel_context *ce) +{ +struct intel_engine_cs *engine = ce->engine; +struct intel_guc *guc = &engine->gt->uc.guc; +unsigned long flags; + +GEM_BUG_ON (!lrc_desc_registered (guc, ce->guc_id)); +GEM_BUG_ON (ce !=__get_context (guc, ce->guc_id)); + +spin_lock_irqsave (&ce->guc_state.lock, flags); +set_context_destroyed (ce); +spin_unlock_irqrestore (&ce->guc_state.lock, flags); + +deregister_context (ce, ce->guc_id); +} + +static void guc_context_destroy (struct kref *kref) +{ +struct intel_context *ce =container_of (kref,typeof (*ce), ref); +struct intel_runtime_pm *runtime_pm = &ce->engine->gt->i915->runtime_pm; +struct intel_guc *guc = &ce->engine->gt->uc.guc; +intel_wakeref_t wakeref; +unsigned long flags; + +/* +* If the guc_id is invalid this context has been stolen and we can free +* it immediately. Also can be freed immediately if the context is not +* registered with the GuC. +*/ +if (context_guc_id_invalid (ce) || + !lrc_desc_registered (guc, ce->guc_id)) { +release_guc_id (guc, ce); +lrc_destroy (kref); +return ; + } + +/* +* We have to acquire the context spinlock and check guc_id again, if it +* is valid it hasn't been stolen and needs to be deregistered. We +* delete this context from the list of unpinned guc_ids available to +* stole to seal a race with guc_lrc_desc_pin(). When the G2H CTB +* returns indicating this context has been deregistered the guc_id is +* returned to the pool of available guc_ids. +*/ +spin_lock_irqsave (&guc->contexts_lock, flags); +if (context_guc_id_invalid (ce)) { +__release_guc_id (guc, ce); +spin_unlock_irqrestore (&guc->contexts_lock, flags); +lrc_destroy (kref); +return ; + } + +if (!list_empty (&ce->guc_id_link)) +list_del_init (&ce->guc_id_link); +spin_unlock_irqrestore (&guc->contexts_lock, flags); + +/* +* We defer GuC context deregistration until the context is destroyed +* in order to save on CTBs. With this optimization ideally we only need +* 1 CTB to register the context during the first pin and 1 CTB to +* deregister the context when the context is destroyed. Without this +* optimization, a CTB would be needed every pin & unpin. +* +* XXX: Need to acqiure the runtime wakeref as this can be triggered +* from context_free_worker when not runtime wakeref is held. +* guc_lrc_desc_unpin requires the runtime as a GuC register is written +* in H2G CTB to deregister the context. A future patch may defer this +* H2G CTB if the runtime wakeref is zero. +*/ + with_intel_runtime_pm(runtime_pm, wakeref) +guc_lrc_desc_unpin (ce); +} + +static int guc_context_alloc (struct intel_context *ce) +{ +return lrc_alloc (ce, ce->engine); +} +static const struct intel_context_ops guc_context_ops = { .alloc = guc_context_alloc, .pre_pin = guc_context_pre_pin, .pin = guc_context_pin, - .unpin = lrc_unpin, - .post_unpin = lrc_post_unpin, + .unpin = guc_context_unpin, + .post_unpin = guc_context_post_unpin, .enter = intel_context_enter_engine, .exit = intel_context_exit_engine, .reset = lrc_reset, - .destroy = lrc_destroy, + .destroy = guc_context_destroy, }; -static int guc_request_alloc (struct i915_request *request) +static bool context_needs_register (struct intel_context *ce,bool new_guc_id) { +return new_guc_id ||test_bit (CONTEXT_LRCA_DIRTY , &ce->flags) || + !lrc_desc_registered (ce_to_guc (ce), ce->guc_id); +} + +static int guc_request_alloc (struct i915_request *rq) +{ +struct intel_context *ce = rq->context; +struct intel_guc *guc =ce_to_guc (ce);int ret; -GEM_BUG_ON (!intel_context_is_pinned (request->context)); +GEM_BUG_ON (!intel_context_is_pinned (rq->context));/* * Flush enough space to reduce the likelihood of waiting after * we start building the request - in which case we will just * have to repeat work. */ - request->reserved_space +=GUC_REQUEST_SIZE ; + rq->reserved_space +=GUC_REQUEST_SIZE ;/* * Note that after this point, we have committed to using @@ -483,56 +954,47 @@ static int guc_request_alloc(struct i915_request *request)*/ /* Unconditionally invalidate GPU caches and TLBs. */ - ret = request->engine->emit_flush (request,EMIT_INVALIDATE ); + ret = rq->engine->emit_flush (rq,EMIT_INVALIDATE );if (ret)return ret; - request->reserved_space -=GUC_REQUEST_SIZE ; -return 0 ; -} - -static inline void queue_request (struct i915_sched_engine *sched_engine, -struct i915_request *rq, -int prio) -{ -GEM_BUG_ON (!list_empty (&rq->sched.link)); -list_add_tail (&rq->sched.link, -i915_sched_lookup_priolist (sched_engine, prio)); -set_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); -} - -static int guc_bypass_tasklet_submit (struct intel_guc *guc, -struct i915_request *rq) -{ -int ret; - -__i915_request_submit (rq); + rq->reserved_space -=GUC_REQUEST_SIZE ; -trace_i915_request_in (rq,0 ); - -guc_set_lrc_tail (rq); - ret =guc_add_request (guc, rq); -if (ret == -EBUSY ) - guc->stalled_request = rq; - -return ret; -} - -static void guc_submit_request (struct i915_request *rq) -{ -struct i915_sched_engine *sched_engine = rq->engine->sched_engine; -struct intel_guc *guc = &rq->engine->gt->uc.guc; -unsigned long flags; +/* +* Call pin_guc_id here rather than in the pinning step as with +* dma_resv, contexts can be repeatedly pinned / unpinned trashing the +* guc_ids and creating horrible race conditions. This is especially bad +* when guc_ids are being stolen due to over subscription. By the time +* this function is reached, it is guaranteed that the guc_id will be +* persistent until the generated request is retired. Thus, sealing these +* race conditions. It is still safe to fail here if guc_ids are +* exhausted and return -EAGAIN to the user indicating that they can try +* again in the future. +* +* There is no need for a lock here as the timeline mutex ensures at +* most one context can be executing this code path at once. The +* guc_id_ref is incremented once for every request in flight and +* decremented on each retire. When it is zero, a lock around the +* increment (in pin_guc_id) is needed to seal a race with unpin_guc_id. +*/ +if (atomic_add_unless (&ce->guc_id_ref,1 ,0 )) +return 0 ; -/* Will be called from irq-context when using foreign fences. */ -spin_lock_irqsave (&sched_engine->lock, flags); + ret =pin_guc_id (guc, ce);/* returns 1 if new guc_id assigned */ +if (unlikely (ret <0 )) +return ret;; +if (context_needs_register (ce, !!ret)) { + ret =guc_lrc_desc_pin (ce); +if (unlikely (ret)) {/* unwind */ +atomic_dec (&ce->guc_id_ref); +unpin_guc_id (guc, ce); +return ret; + } + } -if (guc->stalled_request || !i915_sched_engine_is_empty (sched_engine)) -queue_request (sched_engine, rq,rq_prio (rq)); -else if (guc_bypass_tasklet_submit (guc, rq) == -EBUSY ) -tasklet_hi_schedule (&sched_engine->tasklet); +clear_bit (CONTEXT_LRCA_DIRTY , &ce->flags); -spin_unlock_irqrestore (&sched_engine->lock, flags); +return 0 ; }static void sanitize_hwsp (struct intel_engine_cs *engine)@@ -606,6 +1068,46 @@ static void guc_set_default_submission(struct intel_engine_cs *engine) engine->submit_request = guc_submit_request; } +static inline void guc_kernel_context_pin (struct intel_guc *guc, +struct intel_context *ce) +{ +if (context_guc_id_invalid (ce)) +pin_guc_id (guc, ce); +guc_lrc_desc_pin (ce); +} + +static inline void guc_init_lrc_mapping (struct intel_guc *guc) +{ +struct intel_gt *gt =guc_to_gt (guc); +struct intel_engine_cs *engine; +enum intel_engine_id id; + +/* make sure all descriptors are clean... */ +xa_destroy (&guc->context_lookup); + +/* +* Some contexts might have been pinned before we enabled GuC +* submission, so we need to add them to the GuC bookeeping. +* Also, after a reset the GuC we want to make sure that the information +* shared with GuC is properly reset. The kernel lrcs are not attached +* to the gem_context, so they need to be added separately. +* +* Note: we purposely do not check the error return of +* guc_lrc_desc_pin, because that function can only fail in two cases. +* One, if there aren't enough free IDs, but we're guaranteed to have +* enough here (we're either only pinning a handful of lrc on first boot +* or we're re-pinning lrcs that were already pinned before the reset). +* Two, if the GuC has died and CTBs can't make forward progress. +* Presumably, the GuC should be alive as this function is called on +* driver load or after a reset. Even if it is dead, another full GPU +* reset will be triggered and this function would be called again. +*/ + +for_each_engine (engine, gt, id) +if (engine->kernel_context) +guc_kernel_context_pin (guc, engine->kernel_context); +} +static void guc_release (struct intel_engine_cs *engine) { engine->sanitize =NULL ;/* no longer in control, nothing to sanitize */ @@ -718,6 +1220,7 @@ int intel_guc_submission_setup(struct intel_engine_cs *engine)void intel_guc_submission_enable (struct intel_guc *guc) { +guc_init_lrc_mapping (guc); }void intel_guc_submission_disable (struct intel_guc *guc)@@ -743,3 +1246,62 @@ void intel_guc_submission_init_early(struct intel_guc *guc) { guc->submission_selected =__guc_submission_selected (guc);
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_init_early(struct intel_guc *guc) · line 1257
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +9
-0} + +static inline struct intel_context * +g2h_context_lookup (struct intel_guc *guc,u32 desc_idx) +{ +struct intel_context *ce; + +if (unlikely (desc_idx >=GUC_MAX_LRC_DESCRIPTORS )) { +drm_dbg (&guc_to_gt (guc)->i915->drm, +"Invalid desc_idx %u" , desc_idx);
just debug? why not an (fatal) error ?
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_init_early(struct intel_guc *guc) · line 1264
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +7
-0+return NULL ; + } + + ce =__get_context (guc, desc_idx); +if (unlikely (!ce)) { +drm_dbg (&guc_to_gt (guc)->i915->drm, +"Context is NULL, desc_idx %u" , desc_idx);
not an error ?
Quoted 68 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +43
-0+return NULL ; + } + +return ce; +} + +int intel_guc_deregister_done_process_msg (struct intel_guc *guc, +const u32 *msg, +u32 len) +{ +struct intel_context *ce; +u32 desc_idx = msg[0 ]; + +if (unlikely (len <1 )) { +drm_dbg (&guc_to_gt (guc)->i915->drm,"Invalid length %u" , len); +return -EPROTO ; + } + + ce =g2h_context_lookup (guc, desc_idx); +if (unlikely (!ce)) +return -EPROTO ; + +if (context_wait_for_deregister_to_register (ce)) { +struct intel_runtime_pm *runtime_pm = + &ce->engine->gt->i915->runtime_pm; +intel_wakeref_t wakeref; + +/* +* Previous owner of this guc_id has been deregistered, now safe +* register this context. +*/ + with_intel_runtime_pm(runtime_pm, wakeref) +register_context (ce); +clr_context_wait_for_deregister_to_register (ce); +intel_context_put (ce); + }else if (context_destroyed (ce)) { +/* Context has been destroyed */ +release_guc_id (guc, ce); +lrc_destroy (&ce->ref); + } + +return 0 ; +}drivers/gpu/drm/i915/i915_reg.h +1
-0@@ -4142,6 +4142,7 @@ enum { FAULT_AND_CONTINUE /* Unsupported */ }; +#define CTX_GTT_ADDRESS_MASK GENMASK(31, 12)#define GEN8_CTX_VALID (1 << 0)#define GEN8_CTX_FORCE_PD_RESTORE (1 << 1)#define GEN8_CTX_FORCE_RESTORE (1 << 2)drivers/gpu/drm/i915/i915_request.c +1
-0@@ -419,6 +419,7 @@ bool i915_request_retire(struct i915_request *rq)*/ if (!list_empty (&rq->sched.link))remove_from_engine (rq); +atomic_dec (&rq->context->guc_id_ref);GEM_BUG_ON (!llist_empty (&rq->execute_cb));__list_del_entry (&rq->link);/* poison neither prev/next (RCU walks) */
Re: [PATCH 13/47] drm/i915/guc: Implement GuC context operations for new inteface
Quoted 64 lines · Michal Wajdeczko
Quoted 61 lines · Matthew Brost
Implement GuC context operations which includes GuC specific operations alloc, pin, unpin, and destroy.
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/intel_context.c | 5 + drivers/gpu/drm/i915/gt/intel_context_types.h | 22 +- drivers/gpu/drm/i915/gt/intel_lrc_reg.h | 1 - drivers/gpu/drm/i915/gt/uc/intel_guc.h | 34 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 664 ++++++++++++++++-- drivers/gpu/drm/i915/i915_reg.h | 1 + drivers/gpu/drm/i915/i915_request.c | 1 + 8 files changed, 677 insertions(+), 55 deletions(-)drivers/gpu/drm/i915/gt/intel_context.c +5
-0@@ -383,6 +383,11 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)mutex_init (&ce->pin_mutex); +spin_lock_init (&ce->guc_state.lock); + + ce->guc_id =GUC_INVALID_LRC_ID ; +INIT_LIST_HEAD (&ce->guc_id_link); +i915_active_init (&ce->active, __intel_context_active, __intel_context_retire,0 ); }drivers/gpu/drm/i915/gt/intel_context_types.h +11
-0@@ -95,6 +95,7 @@ struct intel_context {#define CONTEXT_BANNED 6#define CONTEXT_FORCE_SINGLE_SUBMISSION 7#define CONTEXT_NOPREEMPT 8 +#define CONTEXT_LRCA_DIRTY 9struct {u64 timeout_us;@@ -137,14 +138,29 @@ struct intel_context {u8 wa_bb_page;/* if set, page num reserved for context workarounds */ +struct { +/** lock: protects everything in guc_state */ +spinlock_t lock; +/** +* sched_state: scheduling state of this context using GuC +* submission +*/ +u8 sched_state; + } guc_state; +/* GuC scheduling state that does not require a lock. */ atomic_t guc_sched_state_no_lock;
Quoted 17 lines
drivers/gpu/drm/i915/gt/intel_context_types.h struct intel_context { · line 163
Quoted 13 lines
drivers/gpu/drm/i915/gt/intel_context_types.h +8
-3+/* GuC lrc descriptor ID */ +u16 guc_id; + +/* GuC lrc descriptor reference count */ +atomic_t guc_id_ref; +/* -* GuC lrc descriptor ID - Not assigned in this patch but future patches -* in the series will. +* GuC ID link - in list when unpinned but guc_id still valid in GuC */ -u16 guc_id; +struct list_head guc_id_link;some fields are being added with kerneldoc, some without what's the rule ?
Yea, idk. I think we need to scrub all the structures in the driver and add kernel doc everywhere. IMO not a blocker too as I think all the structures are going to be reworked with OO concepts after the GuC code lands before moving to DRM scheduler. That would be logical time to update all the kernel doc too.
Quoted 323 lines
Quoted 323 lines
drivers/gpu/drm/i915/gt/intel_context_types.h +0
-0};#endif /* __INTEL_CONTEXT_TYPES__ */ drivers/gpu/drm/i915/gt/intel_lrc_reg.h +0
-1@@ -87,7 +87,6 @@#define GEN11_CSB_WRITE_PTR_MASK (GEN11_CSB_PTR_MASK << 0)#define MAX_CONTEXT_HW_ID (1 << 21)/* exclusive */ -#define MAX_GUC_CONTEXT_HW_ID (1 << 20)/* exclusive */ #define GEN11_MAX_CONTEXT_HW_ID (1 << 11)/* exclusive */ /* in Gen12 ID 0x7FF is reserved to indicate idle */ #define GEN12_MAX_CONTEXT_HW_ID (GEN11_MAX_CONTEXT_HW_ID - 1)drivers/gpu/drm/i915/gt/uc/intel_guc.h +34
-0@@ -44,6 +44,14 @@ struct intel_guc {void (*disable)(struct intel_guc *guc); } interrupts; +/* +* contexts_lock protects the pool of free guc ids and a linked list of +* guc ids available to be stolen +*/ +spinlock_t contexts_lock; +struct ida guc_ids; +struct list_head guc_id_list; +bool submission_selected;struct i915_vma *ads_vma;@@ -102,6 +110,29 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, response_buf, response_buf_size, 0); } +static inline int intel_guc_send_busy_loop (struct intel_guc * guc, +const u32 *action, +u32 len, +bool loop) +{ +int err; + +/* No sleeping with spin locks, just busy loop */ +might_sleep_if (loop && (!in_atomic () && !irqs_disabled ())); + +retry: + err =intel_guc_send_nb (guc, action, len); +if (unlikely (err == -EBUSY && loop)) { +if (likely (!in_atomic () && !irqs_disabled ())) +cond_resched (); +else +cpu_relax (); + goto retry; + } + +return err; +} +static inline void intel_guc_to_host_event_handler (struct intel_guc *guc) {intel_guc_ct_event_handler (&guc->ct);@@ -203,6 +234,9 @@ static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)int intel_guc_reset_engine (struct intel_guc *guc,struct intel_engine_cs *engine); +int intel_guc_deregister_done_process_msg (struct intel_guc *guc, +const u32 *msg,u32 len); +void intel_guc_load_status (struct intel_guc *guc,struct drm_printer *p);#endif drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-0@@ -901,6 +901,10 @@ static int ct_process_request(struct intel_guc_ct *ct, struct ct_incoming_msg *rcase INTEL_GUC_ACTION_DEFAULT : ret =intel_guc_to_host_process_recv_msg (guc, payload, len);break ; +case INTEL_GUC_ACTION_DEREGISTER_CONTEXT_DONE : + ret =intel_guc_deregister_done_process_msg (guc, payload, + len); +break ;default : ret = -EOPNOTSUPP ;break ;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +194
-2@@ -13,7 +13,9 @@#include "gt/intel_gt.h" #include "gt/intel_gt_irq.h" #include "gt/intel_gt_pm.h" +#include "gt/intel_gt_requests.h" #include "gt/intel_lrc.h" +#include "gt/intel_lrc_reg.h" #include "gt/intel_mocs.h" #include "gt/intel_ring.h" @@ -85,6 +87,73 @@ static inline void clr_context_enabled(struct intel_context *ce) &ce->guc_sched_state_no_lock); } +/* +* Below is a set of functions which control the GuC scheduling state which +* require a lock, aside from the special case where the functions are called +* from guc_lrc_desc_pin(). In that case it isn't possible for any other code +* path to be executing on the context. +*/ +#define SCHED_STATE_WAIT_FOR_DEREGISTER_TO_REGISTER BIT(0) +#define SCHED_STATE_DESTROYED BIT(1) +static inline void init_sched_state (struct intel_context *ce) +{ +/* Only should be called from guc_lrc_desc_pin() */ +atomic_set (&ce->guc_sched_state_no_lock,0 ); + ce->guc_state.sched_state =0 ; +} + +static inline bool +context_wait_for_deregister_to_register (struct intel_context *ce) +{ +return (ce->guc_state.sched_state & +SCHED_STATE_WAIT_FOR_DEREGISTER_TO_REGISTER ); +} + +static inline void +set_context_wait_for_deregister_to_register (struct intel_context *ce) +{ +/* Only should be called from guc_lrc_desc_pin() */ + ce->guc_state.sched_state |= +SCHED_STATE_WAIT_FOR_DEREGISTER_TO_REGISTER ; +} + +static inline void +clr_context_wait_for_deregister_to_register (struct intel_context *ce) +{ +lockdep_assert_held (&ce->guc_state.lock); + ce->guc_state.sched_state = + (ce->guc_state.sched_state & + ~SCHED_STATE_WAIT_FOR_DEREGISTER_TO_REGISTER ); +} + +static inline bool +context_destroyed (struct intel_context *ce) +{ +return (ce->guc_state.sched_state &SCHED_STATE_DESTROYED ); +} + +static inline void +set_context_destroyed (struct intel_context *ce) +{ +lockdep_assert_held (&ce->guc_state.lock); + ce->guc_state.sched_state |=SCHED_STATE_DESTROYED ; +} + +static inline bool context_guc_id_invalid (struct intel_context *ce) +{ +return (ce->guc_id ==GUC_INVALID_LRC_ID ); +} + +static inline void set_context_guc_id_invalid (struct intel_context *ce) +{ + ce->guc_id =GUC_INVALID_LRC_ID ; +} + +static inline struct intel_guc *ce_to_guc (struct intel_context *ce) +{ +return &ce->engine->gt->uc.guc; +} +static inline struct i915_priolist *to_priolist (struct rb_node *rb) { return rb_entry(rb, struct i915_priolist, node);@@ -155,6 +224,9 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)int len =0 ;bool enabled =context_enabled (ce); +GEM_BUG_ON (!atomic_read (&ce->guc_id_ref)); +GEM_BUG_ON (context_guc_id_invalid (ce)); +if (!enabled) { action[len++] =INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_SET ; action[len++] = ce->guc_id;@@ -417,6 +489,10 @@ int intel_guc_submission_init(struct intel_guc *guc)xa_init_flags (&guc->context_lookup,XA_FLAGS_LOCK_IRQ ); +spin_lock_init (&guc->contexts_lock); +INIT_LIST_HEAD (&guc->guc_id_list); +ida_init (&guc->guc_ids); +return 0 ; }@@ -429,9 +505,303 @@ void intel_guc_submission_fini(struct intel_guc *guc)i915_sched_engine_put (guc->sched_engine); } -static int guc_context_alloc (struct intel_context *ce) +static inline void queue_request (struct i915_sched_engine *sched_engine, +struct i915_request *rq, +int prio) { -return lrc_alloc (ce, ce->engine); +GEM_BUG_ON (!list_empty (&rq->sched.link)); +list_add_tail (&rq->sched.link, +i915_sched_lookup_priolist (sched_engine, prio)); +set_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); +} + +static int guc_bypass_tasklet_submit (struct intel_guc *guc, +struct i915_request *rq) +{ +int ret; + +__i915_request_submit (rq); + +trace_i915_request_in (rq,0 ); + +guc_set_lrc_tail (rq); + ret =guc_add_request (guc, rq); +if (ret == -EBUSY ) + guc->stalled_request = rq; + +return ret; +} + +static void guc_submit_request (struct i915_request *rq) +{ +struct i915_sched_engine *sched_engine = rq->engine->sched_engine; +struct intel_guc *guc = &rq->engine->gt->uc.guc; +unsigned long flags; + +/* Will be called from irq-context when using foreign fences. */ +spin_lock_irqsave (&sched_engine->lock, flags); + +if (guc->stalled_request || !i915_sched_engine_is_empty (sched_engine)) +queue_request (sched_engine, rq,rq_prio (rq)); +else if (guc_bypass_tasklet_submit (guc, rq) == -EBUSY ) +tasklet_hi_schedule (&sched_engine->tasklet); + +spin_unlock_irqrestore (&sched_engine->lock, flags); +} + +#define GUC_ID_START 64/* First 64 guc_ids reserved */ +static int new_guc_id (struct intel_guc *guc) +{ +return ida_simple_get (&guc->guc_ids,GUC_ID_START , +GUC_MAX_LRC_DESCRIPTORS ,GFP_KERNEL | + __GFP_RETRY_MAYFAIL | __GFP_NOWARN); +} + +static void __release_guc_id (struct intel_guc *guc,struct intel_context *ce) +{ +if (!context_guc_id_invalid (ce)) { +ida_simple_remove (&guc->guc_ids, ce->guc_id); +reset_lrc_desc (guc, ce->guc_id); +set_context_guc_id_invalid (ce); + } +if (!list_empty (&ce->guc_id_link)) +list_del_init (&ce->guc_id_link); +} + +static void release_guc_id (struct intel_guc *guc,struct intel_context *ce) +{ +unsigned long flags; + +spin_lock_irqsave (&guc->contexts_lock, flags); +__release_guc_id (guc, ce); +spin_unlock_irqrestore (&guc->contexts_lock, flags); +} + +static int steal_guc_id (struct intel_guc *guc) +{ +struct intel_context *ce; +int guc_id; + +if (!list_empty (&guc->guc_id_list)) { + ce =list_first_entry (&guc->guc_id_list, + struct intel_context, + guc_id_link); + +GEM_BUG_ON (atomic_read (&ce->guc_id_ref)); +GEM_BUG_ON (context_guc_id_invalid (ce)); + +list_del_init (&ce->guc_id_link); + guc_id = ce->guc_id; +set_context_guc_id_invalid (ce); +return guc_id; + }else { +return -EAGAIN ; + } +} + +static int assign_guc_id (struct intel_guc *guc,u16 *out) +{ +int ret; + + ret =new_guc_id (guc); +if (unlikely (ret <0 )) { + ret =steal_guc_id (guc); +if (ret <0 ) +return ret; + } + + *out = ret; +return 0 ; +} + +#define PIN_GUC_ID_TRIES 4 +static int pin_guc_id (struct intel_guc *guc,struct intel_context *ce) +{ +int ret =0 ; +unsigned long flags, tries =PIN_GUC_ID_TRIES ; + +GEM_BUG_ON (atomic_read (&ce->guc_id_ref)); + +try_again: +spin_lock_irqsave (&guc->contexts_lock, flags);
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_fini(struct intel_guc *guc) · line 632
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +6
-0+ +if (context_guc_id_invalid (ce)) { + ret =assign_guc_id (guc, &ce->guc_id); +if (ret) + goto out_unlock; + ret =1 ;// Indidcates newly assigned HW context C++ style comment
Yep, will fix.
Quoted 464 lines
Quoted 464 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +354
-49+ } +if (!list_empty (&ce->guc_id_link)) +list_del_init (&ce->guc_id_link); +atomic_inc (&ce->guc_id_ref); + +out_unlock: +spin_unlock_irqrestore (&guc->contexts_lock, flags); + +/* +* -EAGAIN indicates no guc_ids are available, let's retire any +* outstanding requests to see if that frees up a guc_id. If the first +* retire didn't help, insert a sleep with the timeslice duration before +* attempting to retire more requests. Double the sleep period each +* subsequent pass before finally giving up. The sleep period has max of +* 100ms and minimum of 1ms. +*/ +if (ret == -EAGAIN && --tries) { +if (PIN_GUC_ID_TRIES - tries >1 ) { +unsigned int timeslice_shifted = + ce->engine->props.timeslice_duration_ms << + (PIN_GUC_ID_TRIES - tries -2 ); + unsigned int max = min_t(unsigned int, 100, + timeslice_shifted); + + msleep(max_t(unsigned int, max, 1)); + } +intel_gt_retire_requests (guc_to_gt (guc)); + goto try_again; + } + +return ret; +} + +static void unpin_guc_id (struct intel_guc *guc,struct intel_context *ce) +{ +unsigned long flags; + +GEM_BUG_ON (atomic_read (&ce->guc_id_ref) <0 ); + +spin_lock_irqsave (&guc->contexts_lock, flags); +if (!context_guc_id_invalid (ce) &&list_empty (&ce->guc_id_link) && + !atomic_read (&ce->guc_id_ref)) +list_add_tail (&ce->guc_id_link, &guc->guc_id_list); +spin_unlock_irqrestore (&guc->contexts_lock, flags); +} + +static int __guc_action_register_context (struct intel_guc *guc, +u32 guc_id, +u32 offset) +{ +u32 action[] = { +INTEL_GUC_ACTION_REGISTER_CONTEXT , + guc_id, + offset, + }; + +return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), true); +} + +static int register_context (struct intel_context *ce) +{ +struct intel_guc *guc =ce_to_guc (ce); +u32 offset =intel_guc_ggtt_offset (guc, guc->lrc_desc_pool) + + ce->guc_id *sizeof (struct guc_lrc_desc ); + +return __guc_action_register_context (guc, ce->guc_id, offset); +} + +static int __guc_action_deregister_context (struct intel_guc *guc, +u32 guc_id) +{ +u32 action[] = { +INTEL_GUC_ACTION_DEREGISTER_CONTEXT , + guc_id, + }; + +return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), true); +} + +static int deregister_context (struct intel_context *ce,u32 guc_id) +{ +struct intel_guc *guc =ce_to_guc (ce); + +return __guc_action_deregister_context (guc, guc_id); +} + +static intel_engine_mask_t adjust_engine_mask (u8 class,intel_engine_mask_t mask) +{ +switch (class) { +case RENDER_CLASS : +return mask >>RCS0 ; +case VIDEO_ENHANCEMENT_CLASS : +return mask >>VECS0 ; +case VIDEO_DECODE_CLASS : +return mask >>VCS0 ; +case COPY_ENGINE_CLASS : +return mask >>BCS0 ; +default : +GEM_BUG_ON ("Invalid Class" ); +return 0 ; + } +} + +static void guc_context_policy_init (struct intel_engine_cs *engine, +struct guc_lrc_desc *desc) +{ + desc->policy_flags =0 ; + + desc->execution_quantum =CONTEXT_POLICY_DEFAULT_EXECUTION_QUANTUM_US ; + desc->preemption_timeout =CONTEXT_POLICY_DEFAULT_PREEMPTION_TIME_US ; +} + +static int guc_lrc_desc_pin (struct intel_context *ce) +{ +struct intel_runtime_pm *runtime_pm = + &ce->engine->gt->i915->runtime_pm; +struct intel_engine_cs *engine = ce->engine; +struct intel_guc *guc = &engine->gt->uc.guc; +u32 desc_idx = ce->guc_id; +struct guc_lrc_desc *desc; +bool context_registered; +intel_wakeref_t wakeref; +int ret =0 ; + +GEM_BUG_ON (!engine->mask); + +/* +* Ensure LRC + CT vmas are is same region as write barrier is done +* based on CT vma region. +*/ +GEM_BUG_ON (i915_gem_object_is_lmem (guc->ct.vma->obj) != +i915_gem_object_is_lmem (ce->ring->vma->obj)); + + context_registered =lrc_desc_registered (guc, desc_idx); + +reset_lrc_desc (guc, desc_idx); +set_lrc_desc_registered (guc, desc_idx, ce); + + desc =__get_lrc_desc (guc, desc_idx); + desc->engine_class =engine_class_to_guc_class (engine->class); + desc->engine_submit_mask =adjust_engine_mask (engine->class, + engine->mask); + desc->hw_context_desc = ce->lrc.lrca; + desc->priority =GUC_CLIENT_PRIORITY_KMD_NORMAL ; + desc->context_flags =CONTEXT_REGISTRATION_FLAG_KMD ; +guc_context_policy_init (engine, desc); +init_sched_state (ce); + +/* +* The context_lookup xarray is used to determine if the hardware +* context is currently registered. There are two cases in which it +* could be regisgered either the guc_id has been stole from from +* another context or the lrc descriptor address of this context has +* changed. In either case the context needs to be deregistered with the +* GuC before registering this context. +*/ +if (context_registered) { +set_context_wait_for_deregister_to_register (ce); +intel_context_get (ce); + +/* +* If stealing the guc_id, this ce has the same guc_id as the +* context whos guc_id was stole. +*/ +with_intel_runtime_pm (runtime_pm, wakeref) + ret = deregister_context(ce, ce->guc_id); + }else { +with_intel_runtime_pm (runtime_pm, wakeref) + ret = register_context(ce); + } + +return ret; } static int guc_context_pre_pin(struct intel_context *ce,@@ -443,36 +813,137 @@ static int guc_context_pre_pin(struct intel_context *ce,static int guc_context_pin (struct intel_context *ce,void *vaddr) { +if (i915_ggtt_offset (ce->state) != + (ce->lrc.lrca &CTX_GTT_ADDRESS_MASK )) +set_bit (CONTEXT_LRCA_DIRTY , &ce->flags); +return lrc_pin (ce, ce->engine, vaddr); } +static void guc_context_unpin (struct intel_context *ce) +{ +unpin_guc_id (ce_to_guc (ce), ce); +lrc_unpin (ce); +} + +static void guc_context_post_unpin (struct intel_context *ce) +{ +lrc_post_unpin (ce); +} + +static inline void guc_lrc_desc_unpin (struct intel_context *ce) +{ +struct intel_engine_cs *engine = ce->engine; +struct intel_guc *guc = &engine->gt->uc.guc; +unsigned long flags; + +GEM_BUG_ON (!lrc_desc_registered (guc, ce->guc_id)); +GEM_BUG_ON (ce !=__get_context (guc, ce->guc_id)); + +spin_lock_irqsave (&ce->guc_state.lock, flags); +set_context_destroyed (ce); +spin_unlock_irqrestore (&ce->guc_state.lock, flags); + +deregister_context (ce, ce->guc_id); +} + +static void guc_context_destroy (struct kref *kref) +{ +struct intel_context *ce =container_of (kref,typeof (*ce), ref); +struct intel_runtime_pm *runtime_pm = &ce->engine->gt->i915->runtime_pm; +struct intel_guc *guc = &ce->engine->gt->uc.guc; +intel_wakeref_t wakeref; +unsigned long flags; + +/* +* If the guc_id is invalid this context has been stolen and we can free +* it immediately. Also can be freed immediately if the context is not +* registered with the GuC. +*/ +if (context_guc_id_invalid (ce) || + !lrc_desc_registered (guc, ce->guc_id)) { +release_guc_id (guc, ce); +lrc_destroy (kref); +return ; + } + +/* +* We have to acquire the context spinlock and check guc_id again, if it +* is valid it hasn't been stolen and needs to be deregistered. We +* delete this context from the list of unpinned guc_ids available to +* stole to seal a race with guc_lrc_desc_pin(). When the G2H CTB +* returns indicating this context has been deregistered the guc_id is +* returned to the pool of available guc_ids. +*/ +spin_lock_irqsave (&guc->contexts_lock, flags); +if (context_guc_id_invalid (ce)) { +__release_guc_id (guc, ce); +spin_unlock_irqrestore (&guc->contexts_lock, flags); +lrc_destroy (kref); +return ; + } + +if (!list_empty (&ce->guc_id_link)) +list_del_init (&ce->guc_id_link); +spin_unlock_irqrestore (&guc->contexts_lock, flags); + +/* +* We defer GuC context deregistration until the context is destroyed +* in order to save on CTBs. With this optimization ideally we only need +* 1 CTB to register the context during the first pin and 1 CTB to +* deregister the context when the context is destroyed. Without this +* optimization, a CTB would be needed every pin & unpin. +* +* XXX: Need to acqiure the runtime wakeref as this can be triggered +* from context_free_worker when not runtime wakeref is held. +* guc_lrc_desc_unpin requires the runtime as a GuC register is written +* in H2G CTB to deregister the context. A future patch may defer this +* H2G CTB if the runtime wakeref is zero. +*/ + with_intel_runtime_pm(runtime_pm, wakeref) +guc_lrc_desc_unpin (ce); +} + +static int guc_context_alloc (struct intel_context *ce) +{ +return lrc_alloc (ce, ce->engine); +} +static const struct intel_context_ops guc_context_ops = { .alloc = guc_context_alloc, .pre_pin = guc_context_pre_pin, .pin = guc_context_pin, - .unpin = lrc_unpin, - .post_unpin = lrc_post_unpin, + .unpin = guc_context_unpin, + .post_unpin = guc_context_post_unpin, .enter = intel_context_enter_engine, .exit = intel_context_exit_engine, .reset = lrc_reset, - .destroy = lrc_destroy, + .destroy = guc_context_destroy, }; -static int guc_request_alloc (struct i915_request *request) +static bool context_needs_register (struct intel_context *ce,bool new_guc_id) { +return new_guc_id ||test_bit (CONTEXT_LRCA_DIRTY , &ce->flags) || + !lrc_desc_registered (ce_to_guc (ce), ce->guc_id); +} + +static int guc_request_alloc (struct i915_request *rq) +{ +struct intel_context *ce = rq->context; +struct intel_guc *guc =ce_to_guc (ce);int ret; -GEM_BUG_ON (!intel_context_is_pinned (request->context)); +GEM_BUG_ON (!intel_context_is_pinned (rq->context));/* * Flush enough space to reduce the likelihood of waiting after * we start building the request - in which case we will just * have to repeat work. */ - request->reserved_space +=GUC_REQUEST_SIZE ; + rq->reserved_space +=GUC_REQUEST_SIZE ;/* * Note that after this point, we have committed to using @@ -483,56 +954,47 @@ static int guc_request_alloc(struct i915_request *request)*/ /* Unconditionally invalidate GPU caches and TLBs. */ - ret = request->engine->emit_flush (request,EMIT_INVALIDATE ); + ret = rq->engine->emit_flush (rq,EMIT_INVALIDATE );if (ret)return ret; - request->reserved_space -=GUC_REQUEST_SIZE ; -return 0 ; -} - -static inline void queue_request (struct i915_sched_engine *sched_engine, -struct i915_request *rq, -int prio) -{ -GEM_BUG_ON (!list_empty (&rq->sched.link)); -list_add_tail (&rq->sched.link, -i915_sched_lookup_priolist (sched_engine, prio)); -set_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); -} - -static int guc_bypass_tasklet_submit (struct intel_guc *guc, -struct i915_request *rq) -{ -int ret; - -__i915_request_submit (rq); + rq->reserved_space -=GUC_REQUEST_SIZE ; -trace_i915_request_in (rq,0 ); - -guc_set_lrc_tail (rq); - ret =guc_add_request (guc, rq); -if (ret == -EBUSY ) - guc->stalled_request = rq; - -return ret; -} - -static void guc_submit_request (struct i915_request *rq) -{ -struct i915_sched_engine *sched_engine = rq->engine->sched_engine; -struct intel_guc *guc = &rq->engine->gt->uc.guc; -unsigned long flags; +/* +* Call pin_guc_id here rather than in the pinning step as with +* dma_resv, contexts can be repeatedly pinned / unpinned trashing the +* guc_ids and creating horrible race conditions. This is especially bad +* when guc_ids are being stolen due to over subscription. By the time +* this function is reached, it is guaranteed that the guc_id will be +* persistent until the generated request is retired. Thus, sealing these +* race conditions. It is still safe to fail here if guc_ids are +* exhausted and return -EAGAIN to the user indicating that they can try +* again in the future. +* +* There is no need for a lock here as the timeline mutex ensures at +* most one context can be executing this code path at once. The +* guc_id_ref is incremented once for every request in flight and +* decremented on each retire. When it is zero, a lock around the +* increment (in pin_guc_id) is needed to seal a race with unpin_guc_id. +*/ +if (atomic_add_unless (&ce->guc_id_ref,1 ,0 )) +return 0 ; -/* Will be called from irq-context when using foreign fences. */ -spin_lock_irqsave (&sched_engine->lock, flags); + ret =pin_guc_id (guc, ce);/* returns 1 if new guc_id assigned */ +if (unlikely (ret <0 )) +return ret;; +if (context_needs_register (ce, !!ret)) { + ret =guc_lrc_desc_pin (ce); +if (unlikely (ret)) {/* unwind */ +atomic_dec (&ce->guc_id_ref); +unpin_guc_id (guc, ce); +return ret; + } + } -if (guc->stalled_request || !i915_sched_engine_is_empty (sched_engine)) -queue_request (sched_engine, rq,rq_prio (rq)); -else if (guc_bypass_tasklet_submit (guc, rq) == -EBUSY ) -tasklet_hi_schedule (&sched_engine->tasklet); +clear_bit (CONTEXT_LRCA_DIRTY , &ce->flags); -spin_unlock_irqrestore (&sched_engine->lock, flags); +return 0 ; }static void sanitize_hwsp (struct intel_engine_cs *engine)@@ -606,6 +1068,46 @@ static void guc_set_default_submission(struct intel_engine_cs *engine) engine->submit_request = guc_submit_request; } +static inline void guc_kernel_context_pin (struct intel_guc *guc, +struct intel_context *ce) +{ +if (context_guc_id_invalid (ce)) +pin_guc_id (guc, ce); +guc_lrc_desc_pin (ce); +} + +static inline void guc_init_lrc_mapping (struct intel_guc *guc) +{ +struct intel_gt *gt =guc_to_gt (guc); +struct intel_engine_cs *engine; +enum intel_engine_id id; + +/* make sure all descriptors are clean... */ +xa_destroy (&guc->context_lookup); + +/* +* Some contexts might have been pinned before we enabled GuC +* submission, so we need to add them to the GuC bookeeping. +* Also, after a reset the GuC we want to make sure that the information +* shared with GuC is properly reset. The kernel lrcs are not attached +* to the gem_context, so they need to be added separately. +* +* Note: we purposely do not check the error return of +* guc_lrc_desc_pin, because that function can only fail in two cases. +* One, if there aren't enough free IDs, but we're guaranteed to have +* enough here (we're either only pinning a handful of lrc on first boot +* or we're re-pinning lrcs that were already pinned before the reset). +* Two, if the GuC has died and CTBs can't make forward progress. +* Presumably, the GuC should be alive as this function is called on +* driver load or after a reset. Even if it is dead, another full GPU +* reset will be triggered and this function would be called again. +*/ + +for_each_engine (engine, gt, id) +if (engine->kernel_context) +guc_kernel_context_pin (guc, engine->kernel_context); +} +static void guc_release (struct intel_engine_cs *engine) { engine->sanitize =NULL ;/* no longer in control, nothing to sanitize */ @@ -718,6 +1220,7 @@ int intel_guc_submission_setup(struct intel_engine_cs *engine)void intel_guc_submission_enable (struct intel_guc *guc) { +guc_init_lrc_mapping (guc); }
Quoted 17 lines
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0void intel_guc_submission_disable (struct intel_guc *guc)@@ -743,3 +1246,62 @@ void intel_guc_submission_init_early(struct intel_guc *guc) { guc->submission_selected =__guc_submission_selected (guc);drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_init_early(struct intel_guc *guc) · line 1257
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +9
-0} + +static inline struct intel_context * +g2h_context_lookup (struct intel_guc *guc,u32 desc_idx) +{ +struct intel_context *ce; + +if (unlikely (desc_idx >=GUC_MAX_LRC_DESCRIPTORS )) { +drm_dbg (&guc_to_gt (guc)->i915->drm, +"Invalid desc_idx %u" , desc_idx);just debug? why not an (fatal) error ?
This is a G2H communication. We can't crash the driver if the GuC gives us crap.
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_init_early(struct intel_guc *guc) · line 1264
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +7
-0+return NULL ; + } + + ce =__get_context (guc, desc_idx); +if (unlikely (!ce)) { +drm_dbg (&guc_to_gt (guc)->i915->drm, +"Context is NULL, desc_idx %u" , desc_idx);not an error ?
It is an error, we return NULL.
BTW - Can you include your name on the last comment? That makes it easier to know when I've reached the end of your comments.
Matt
Quoted 68 lines
Quoted 68 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +43
-0+return NULL ; + } + +return ce; +} + +int intel_guc_deregister_done_process_msg (struct intel_guc *guc, +const u32 *msg, +u32 len) +{ +struct intel_context *ce; +u32 desc_idx = msg[0 ]; + +if (unlikely (len <1 )) { +drm_dbg (&guc_to_gt (guc)->i915->drm,"Invalid length %u" , len); +return -EPROTO ; + } + + ce =g2h_context_lookup (guc, desc_idx); +if (unlikely (!ce)) +return -EPROTO ; + +if (context_wait_for_deregister_to_register (ce)) { +struct intel_runtime_pm *runtime_pm = + &ce->engine->gt->i915->runtime_pm; +intel_wakeref_t wakeref; + +/* +* Previous owner of this guc_id has been deregistered, now safe +* register this context. +*/ + with_intel_runtime_pm(runtime_pm, wakeref) +register_context (ce); +clr_context_wait_for_deregister_to_register (ce); +intel_context_put (ce); + }else if (context_destroyed (ce)) { +/* Context has been destroyed */ +release_guc_id (guc, ce); +lrc_destroy (&ce->ref); + } + +return 0 ; +}drivers/gpu/drm/i915/i915_reg.h +1
-0@@ -4142,6 +4142,7 @@ enum { FAULT_AND_CONTINUE /* Unsupported */ }; +#define CTX_GTT_ADDRESS_MASK GENMASK(31, 12)#define GEN8_CTX_VALID (1 << 0)#define GEN8_CTX_FORCE_PD_RESTORE (1 << 1)#define GEN8_CTX_FORCE_RESTORE (1 << 2)drivers/gpu/drm/i915/i915_request.c +1
-0@@ -419,6 +419,7 @@ bool i915_request_retire(struct i915_request *rq)*/ if (!list_empty (&rq->sched.link))remove_from_engine (rq); +atomic_dec (&rq->context->guc_id_ref);GEM_BUG_ON (!llist_empty (&rq->execute_cb));__list_del_entry (&rq->link);/* poison neither prev/next (RCU walks) */
PATCH 14/47 drm/i915/guc: Insert fence on context when deregistering
In reply to Matthew BrostSometime during context pinning a context with the same guc_id is registered with the GuC. In this a case deregister must be before before the context can be registered. A fence is inserted on all requests while the deregister is in flight. Once the G2H is received indicating the deregistration is complete the context is registered and the fence is released.
--- drivers/gpu/drm/i915/gt/intel_context.c | 1 + drivers/gpu/drm/i915/gt/intel_context_types.h | 5 ++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 51 ++++++++++++++++++- drivers/gpu/drm/i915/i915_request.h | 8 +++ 4 files changed, 63 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.c +1 -0
@@ -384,6 +384,7 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)mutex_init (&ce->pin_mutex);spin_lock_init (&ce->guc_state.lock); +INIT_LIST_HEAD (&ce->guc_state.fences); ce->guc_id =GUC_INVALID_LRC_ID ;INIT_LIST_HEAD (&ce->guc_id_link);
drivers/gpu/drm/i915/gt/intel_context_types.h +5 -0
@@ -146,6 +146,11 @@ struct intel_context {* submission */ u8 sched_state; +/* +* fences: maintains of list of requests that have a submit +* fence related to GuC submission +*/ +struct list_head fences; } guc_state;/* GuC scheduling state that does not require a lock. */
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +49 -2
81 lines not on this page · raw message
drivers/gpu/drm/i915/i915_request.h +8 -0
@@ -285,6 +285,14 @@ struct i915_request {struct hrtimer timer; } watchdog; +/* +* Requests may need to be stalled when using GuC submission waiting for +* certain GuC operations to complete. If that is the case, stalled +* requests are added to a per context list of stalled requests. The +* below list_head is the link in that list. +*/ +struct list_head guc_fence_link; + I915_SELFTEST_DECLARE(struct { struct list_head link; unsigned long delay;
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 14/47] drm/i915/guc: Insert fence on context when deregistering
Quoted 1 line · Matthew Brost
Sometime during context pinning a context with the same
guc_idis
Sometime*s*
Quoted 1 line
registered with the GuC. In this a case deregister must be before before
before before -> done before
Quoted 7 lines
the context can be registered. A fence is inserted on all requests while the deregister is in flight. Once the G2H is received indicating the deregistration is complete the context is registered and the fence is released.
Cc John Harrison<[email protected]>Signed-off-by Matthew Brost<[email protected]>
With the above text fixed up:
Quoted 134 lines
--- drivers/gpu/drm/i915/gt/intel_context.c | 1 + drivers/gpu/drm/i915/gt/intel_context_types.h | 5 ++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 51 ++++++++++++++++++- drivers/gpu/drm/i915/i915_request.h | 8 +++ 4 files changed, 63 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gt/intel_context.c +1
-0@@ -384,6 +384,7 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)mutex_init (&ce->pin_mutex);spin_lock_init (&ce->guc_state.lock); +INIT_LIST_HEAD (&ce->guc_state.fences); ce->guc_id =GUC_INVALID_LRC_ID ;INIT_LIST_HEAD (&ce->guc_id_link);drivers/gpu/drm/i915/gt/intel_context_types.h +5
-0@@ -146,6 +146,11 @@ struct intel_context {* submission */ u8 sched_state; +/* +* fences: maintains of list of requests that have a submit +* fence related to GuC submission +*/ +struct list_head fences; } guc_state;/* GuC scheduling state that does not require a lock. */ drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +49
-2@@ -924,6 +924,30 @@ static const struct intel_context_ops guc_context_ops = { .destroy = guc_context_destroy, }; +static void __guc_signal_context_fence (struct intel_context *ce) +{ +struct i915_request *rq; + +lockdep_assert_held (&ce->guc_state.lock); + +list_for_each_entry (rq, &ce->guc_state.fences, guc_fence_link) +i915_sw_fence_complete (&rq->submit); + +INIT_LIST_HEAD (&ce->guc_state.fences); +} + +static void guc_signal_context_fence (struct intel_context *ce) +{ +unsigned long flags; + +GEM_BUG_ON (!context_wait_for_deregister_to_register (ce)); + +spin_lock_irqsave (&ce->guc_state.lock, flags); +clr_context_wait_for_deregister_to_register (ce); +__guc_signal_context_fence (ce); +spin_unlock_irqrestore (&ce->guc_state.lock, flags); +} +static bool context_needs_register (struct intel_context *ce,bool new_guc_id) { return new_guc_id || test_bit(CONTEXT_LRCA_DIRTY, &ce->flags) ||@@ -934,6 +958,7 @@ static int guc_request_alloc(struct i915_request *rq) {struct intel_context *ce = rq->context;struct intel_guc *guc =ce_to_guc (ce); +unsigned long flags;int ret;GEM_BUG_ON (!intel_context_is_pinned (rq->context));@@ -978,7 +1003,7 @@ static int guc_request_alloc(struct i915_request *rq)* increment (in pin_guc_id) is needed to seal a race with unpin_guc_id. */ if (atomic_add_unless (&ce->guc_id_ref,1 ,0 )) -return 0 ; + goto out; ret =pin_guc_id (guc, ce);/* returns 1 if new guc_id assigned */ if (unlikely (ret <0 ))@@ -994,6 +1019,28 @@ static int guc_request_alloc(struct i915_request *rq)clear_bit (CONTEXT_LRCA_DIRTY , &ce->flags); +out: +/* +* We block all requests on this context if a G2H is pending for a +* context deregistration as the GuC will fail a context registration +* while this G2H is pending. Once a G2H returns, the fence is released +* that is blocking these requests (see guc_signal_context_fence). +* +* We can safely check the below field outside of the lock as it isn't +* possible for this field to transition from being clear to set but +* converse is possible, hence the need for the check within the lock. +*/ +if (likely (!context_wait_for_deregister_to_register (ce))) +return 0 ; + +spin_lock_irqsave (&ce->guc_state.lock, flags); +if (context_wait_for_deregister_to_register (ce)) { +i915_sw_fence_await (&rq->submit); + +list_add_tail (&rq->guc_fence_link, &ce->guc_state.fences); + } +spin_unlock_irqrestore (&ce->guc_state.lock, flags); +return 0 ; }@@ -1295,7 +1342,7 @@ int intel_guc_deregister_done_process_msg(struct intel_guc *guc,*/ with_intel_runtime_pm(runtime_pm, wakeref)register_context (ce); -clr_context_wait_for_deregister_to_register (ce); +guc_signal_context_fence (ce);intel_context_put (ce); }else if (context_destroyed (ce)) {/* Context has been destroyed */ drivers/gpu/drm/i915/i915_request.h +1
-0@@ -285,6 +285,14 @@ struct i915_request {struct hrtimer timer; } watchdog; +/*
drivers/gpu/drm/i915/i915_request.h struct i915_request { · line 298
Quoted 10 lines
drivers/gpu/drm/i915/i915_request.h +7
-0+* Requests may need to be stalled when using GuC submission waiting for +* certain GuC operations to complete. If that is the case, stalled +* requests are added to a per context list of stalled requests. The +* below list_head is the link in that list. +*/ +struct list_head guc_fence_link; + I915_SELFTEST_DECLARE(struct { struct list_head link; unsigned long delay;
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 15/47 drm/i915/guc: Defer context unpin until scheduling is disabled
In reply to Matthew BrostWith GuC scheduling, it isn't safe to unpin a context while scheduling is enabled for that context as the GuC may touch some of the pinned state (e.g. LRC). To ensure scheduling isn't enabled when an unpin is done, a call back is added to intel_context_unpin when pin count == 1 to disable scheduling for that context. When the response CTB is received it is safe to do the final unpin.
Future patches may add a heuristic / delay to schedule the disable call back to avoid thrashing on schedule enable / disable.
--- drivers/gpu/drm/i915/gt/intel_context.c | 4 +- drivers/gpu/drm/i915/gt/intel_context.h | 27 +++- drivers/gpu/drm/i915/gt/intel_context_types.h | 2 + drivers/gpu/drm/i915/gt/uc/intel_guc.h | 2 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 3 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 145 +++++++++++++++++- 6 files changed, 179 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.c +2 -2
@@ -306,9 +306,9 @@ int __intel_context_do_pin(struct intel_context *ce)return err; } -void intel_context_unpin (struct intel_context *ce) +void __intel_context_do_unpin (struct intel_context *ce,int sub) { -if (!atomic_dec_and_test (&ce->pin_count)) +if (!atomic_sub_and_test (sub, &ce->pin_count))return ;CE_TRACE (ce,"unpin\n" );
drivers/gpu/drm/i915/gt/intel_context.h +26 -1
@@ -113,7 +113,32 @@ static inline void __intel_context_pin(struct intel_context *ce)atomic_inc (&ce->pin_count); } -void intel_context_unpin (struct intel_context *ce); +void __intel_context_do_unpin (struct intel_context *ce,int sub); + +static inline void intel_context_sched_disable_unpin (struct intel_context *ce) +{ +__intel_context_do_unpin (ce,2 ); +} + +static inline void intel_context_unpin (struct intel_context *ce) +{ +if (!ce->ops->sched_disable) { +__intel_context_do_unpin (ce,1 ); + }else { +/* +* Move ownership of this pin to the scheduling disable which is +* an async operation. When that operation completes the above +* intel_context_sched_disable_unpin is called potentially +* unpinning the context. +*/ +while (!atomic_add_unless (&ce->pin_count,-1 ,1 )) { +if (atomic_cmpxchg (&ce->pin_count,1 ,2 ) ==1 ) { + ce->ops->sched_disable (ce); +break ; + } + } + } +}void intel_context_enter_engine (struct intel_context *ce);void intel_context_exit_engine (struct intel_context *ce);
drivers/gpu/drm/i915/gt/intel_context_types.h +2 -0
@@ -43,6 +43,8 @@ struct intel_context_ops {void (*enter)(struct intel_context *ce);void (*exit)(struct intel_context *ce); +void (*sched_disable)(struct intel_context *ce); +void (*reset)(struct intel_context *ce);void (*destroy)(struct kref *kref); };
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2 -0
@@ -236,6 +236,8 @@ int intel_guc_reset_engine(struct intel_guc *guc,int intel_guc_deregister_done_process_msg (struct intel_guc *guc,const u32 *msg,u32 len); +int intel_guc_sched_done_process_msg (struct intel_guc *guc, +const u32 *msg,u32 len);void intel_guc_load_status (struct intel_guc *guc,struct drm_printer *p);
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3 -0
@@ -905,6 +905,9 @@ static int ct_process_request(struct intel_guc_ct *ct, struct ct_incoming_msg *r ret =intel_guc_deregister_done_process_msg (guc, payload, len);break ; +case INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_DONE : + ret =intel_guc_sched_done_process_msg (guc, payload, len); +break ;default : ret = -EOPNOTSUPP ;break ;
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +144 -1
203 lines not on this page · raw message
Signature · 1 line
2.28.0
Re: [PATCH 15/47] drm/i915/guc: Defer context unpin until scheduling is disabled
Quoted 7 lines · Matthew Brost
With GuC scheduling, it isn't safe to unpin a context while scheduling is enabled for that context as the GuC may touch some of the pinned state (e.g. LRC). To ensure scheduling isn't enabled when an unpin is done, a call back is added to
intel_context_unpinwhen pin count == 1 to disable scheduling for that context. When the response CTB is received it is safe to do the final unpin.
Quoted 5 lines
Future patches may add a heuristic / delay to schedule the disable call back to avoid thrashing on schedule enable / disable.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>
Quoted 310 lines
--- drivers/gpu/drm/i915/gt/intel_context.c | 4 +- drivers/gpu/drm/i915/gt/intel_context.h | 27 +++- drivers/gpu/drm/i915/gt/intel_context_types.h | 2 + drivers/gpu/drm/i915/gt/uc/intel_guc.h | 2 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 3 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 145 +++++++++++++++++- 6 files changed, 179 insertions(+), 4 deletions(-)drivers/gpu/drm/i915/gt/intel_context.c +2
-2@@ -306,9 +306,9 @@ int __intel_context_do_pin(struct intel_context *ce)return err; } -void intel_context_unpin (struct intel_context *ce) +void __intel_context_do_unpin (struct intel_context *ce,int sub) { -if (!atomic_dec_and_test (&ce->pin_count)) +if (!atomic_sub_and_test (sub, &ce->pin_count))return ;CE_TRACE (ce,"unpin\n" );drivers/gpu/drm/i915/gt/intel_context.h +26
-1@@ -113,7 +113,32 @@ static inline void __intel_context_pin(struct intel_context *ce)atomic_inc (&ce->pin_count); } -void intel_context_unpin (struct intel_context *ce); +void __intel_context_do_unpin (struct intel_context *ce,int sub); + +static inline void intel_context_sched_disable_unpin (struct intel_context *ce) +{ +__intel_context_do_unpin (ce,2 ); +} + +static inline void intel_context_unpin (struct intel_context *ce) +{ +if (!ce->ops->sched_disable) { +__intel_context_do_unpin (ce,1 ); + }else { +/* +* Move ownership of this pin to the scheduling disable which is +* an async operation. When that operation completes the above +* intel_context_sched_disable_unpin is called potentially +* unpinning the context. +*/ +while (!atomic_add_unless (&ce->pin_count,-1 ,1 )) { +if (atomic_cmpxchg (&ce->pin_count,1 ,2 ) ==1 ) { + ce->ops->sched_disable (ce); +break ; + } + } + } +}void intel_context_enter_engine (struct intel_context *ce);void intel_context_exit_engine (struct intel_context *ce);drivers/gpu/drm/i915/gt/intel_context_types.h +2
-0@@ -43,6 +43,8 @@ struct intel_context_ops {void (*enter)(struct intel_context *ce);void (*exit)(struct intel_context *ce); +void (*sched_disable)(struct intel_context *ce); +void (*reset)(struct intel_context *ce);void (*destroy)(struct kref *kref); };drivers/gpu/drm/i915/gt/uc/intel_guc.h +2
-0@@ -236,6 +236,8 @@ int intel_guc_reset_engine(struct intel_guc *guc,int intel_guc_deregister_done_process_msg (struct intel_guc *guc,const u32 *msg,u32 len); +int intel_guc_sched_done_process_msg (struct intel_guc *guc, +const u32 *msg,u32 len);void intel_guc_load_status (struct intel_guc *guc,struct drm_printer *p);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-0@@ -905,6 +905,9 @@ static int ct_process_request(struct intel_guc_ct *ct, struct ct_incoming_msg *r ret =intel_guc_deregister_done_process_msg (guc, payload, len);break ; +case INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_DONE : + ret =intel_guc_sched_done_process_msg (guc, payload, len); +break ;default : ret = -EOPNOTSUPP ;break ;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +134
-1@@ -70,6 +70,7 @@* possible for some of the bits to changing at the same time though. */ #define SCHED_STATE_NO_LOCK_ENABLED BIT(0) +#define SCHED_STATE_NO_LOCK_PENDING_ENABLE BIT(1)static inline bool context_enabled (struct intel_context *ce) { return (atomic_read(&ce->guc_sched_state_no_lock) &@@ -87,6 +88,24 @@ static inline void clr_context_enabled(struct intel_context *ce) &ce->guc_sched_state_no_lock); } +static inline bool context_pending_enable (struct intel_context *ce) +{ +return (atomic_read (&ce->guc_sched_state_no_lock) & +SCHED_STATE_NO_LOCK_PENDING_ENABLE ); +} + +static inline void set_context_pending_enable (struct intel_context *ce) +{ +atomic_or (SCHED_STATE_NO_LOCK_PENDING_ENABLE , + &ce->guc_sched_state_no_lock); +} + +static inline void clr_context_pending_enable (struct intel_context *ce) +{ +atomic_and ((u32 )~SCHED_STATE_NO_LOCK_PENDING_ENABLE , + &ce->guc_sched_state_no_lock); +} +/* * Below is a set of functions which control the GuC scheduling state which * require a lock, aside from the special case where the functions are called @@ -95,6 +114,7 @@ static inline void clr_context_enabled(struct intel_context *ce)*/ #define SCHED_STATE_WAIT_FOR_DEREGISTER_TO_REGISTER BIT(0)#define SCHED_STATE_DESTROYED BIT(1) +#define SCHED_STATE_PENDING_DISABLE BIT(2)static inline void init_sched_state (struct intel_context *ce) {/* Only should be called from guc_lrc_desc_pin() */ @@ -139,6 +159,24 @@ set_context_destroyed(struct intel_context *ce) ce->guc_state.sched_state |=SCHED_STATE_DESTROYED ; } +static inline bool context_pending_disable (struct intel_context *ce) +{ +return (ce->guc_state.sched_state &SCHED_STATE_PENDING_DISABLE ); +} + +static inline void set_context_pending_disable (struct intel_context *ce) +{ +lockdep_assert_held (&ce->guc_state.lock); + ce->guc_state.sched_state |=SCHED_STATE_PENDING_DISABLE ; +} + +static inline void clr_context_pending_disable (struct intel_context *ce) +{ +lockdep_assert_held (&ce->guc_state.lock); + ce->guc_state.sched_state = + (ce->guc_state.sched_state & ~SCHED_STATE_PENDING_DISABLE ); +} +static inline bool context_guc_id_invalid (struct intel_context *ce) {return (ce->guc_id ==GUC_INVALID_LRC_ID );@@ -231,6 +269,8 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq) action[len++] =INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_SET ; action[len++] = ce->guc_id; action[len++] =GUC_CONTEXT_ENABLE ; +set_context_pending_enable (ce); +intel_context_get (ce); }else { action[len++] =INTEL_GUC_ACTION_SCHED_CONTEXT ; action[len++] = ce->guc_id;@@ -238,8 +278,12 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq) err =intel_guc_send_nb (guc, action, len); -if (!enabled && !err) +if (!enabled && !err) {set_context_enabled (ce); + }else if (!enabled) { +clr_context_pending_enable (ce); +intel_context_put (ce); + }return err; }@@ -831,6 +875,60 @@ static void guc_context_post_unpin(struct intel_context *ce)lrc_post_unpin (ce); } +static void __guc_context_sched_disable (struct intel_guc *guc, +struct intel_context *ce, +u16 guc_id) +{ +u32 action[] = { +INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_SET , + guc_id,/* ce->guc_id not stable */ +GUC_CONTEXT_DISABLE + }; + +GEM_BUG_ON (guc_id ==GUC_INVALID_LRC_ID ); + +intel_context_get (ce); + +intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), true); +} + +static u16 prep_context_pending_disable (struct intel_context *ce) +{ +set_context_pending_disable (ce); +clr_context_enabled (ce); + +return ce->guc_id; +} + +static void guc_context_sched_disable (struct intel_context *ce) +{ +struct intel_guc *guc =ce_to_guc (ce); +struct intel_runtime_pm *runtime_pm = &ce->engine->gt->i915->runtime_pm; +unsigned long flags; +u16 guc_id; +intel_wakeref_t wakeref; + +if (context_guc_id_invalid (ce) || + !lrc_desc_registered (guc, ce->guc_id)) { +clr_context_enabled (ce); + goto unpin; + } + +if (!context_enabled (ce)) + goto unpin; + +spin_lock_irqsave (&ce->guc_state.lock, flags); + guc_id =prep_context_pending_disable (ce); +spin_unlock_irqrestore (&ce->guc_state.lock, flags); + + with_intel_runtime_pm(runtime_pm, wakeref) +__guc_context_sched_disable (guc, ce, guc_id); + +return ; +unpin: +intel_context_sched_disable_unpin (ce); +} +static inline void guc_lrc_desc_unpin (struct intel_context *ce) {struct intel_engine_cs *engine = ce->engine;@@ -839,6 +937,7 @@ static inline void guc_lrc_desc_unpin(struct intel_context *ce)GEM_BUG_ON (!lrc_desc_registered (guc, ce->guc_id));GEM_BUG_ON (ce !=__get_context (guc, ce->guc_id)); +GEM_BUG_ON (context_enabled (ce));spin_lock_irqsave (&ce->guc_state.lock, flags);set_context_destroyed (ce);@@ -920,6 +1019,8 @@ static const struct intel_context_ops guc_context_ops = { .enter = intel_context_enter_engine, .exit = intel_context_exit_engine, + .sched_disable = guc_context_sched_disable, + .reset = lrc_reset, .destroy = guc_context_destroy, };@@ -1352,3 +1453,45 @@ int intel_guc_deregister_done_process_msg(struct intel_guc *guc,return 0 ; } + +int intel_guc_sched_done_process_msg (struct intel_guc *guc, +const u32 *msg, +u32 len) +{ +struct intel_context *ce; +unsigned long flags; +u32 desc_idx = msg[0 ]; + +if (unlikely (len <2 )) { +drm_dbg (&guc_to_gt (guc)->i915->drm,"Invalid length %u" , len); +return -EPROTO ; + } + + ce =g2h_context_lookup (guc, desc_idx); +if (unlikely (!ce)) +return -EPROTO ; + +if (unlikely (context_destroyed (ce) || + (!context_pending_enable (ce) && + !context_pending_disable (ce)))) { +drm_dbg (&guc_to_gt (guc)->i915->drm, +"Bad context sched_state 0x%x, 0x%x, desc_idx %u" , +atomic_read (&ce->guc_sched_state_no_lock), + ce->guc_state.sched_state, desc_idx); +return -EPROTO ; + } + +if (context_pending_enable (ce)) { +clr_context_pending_enable (ce); + }else if (context_pending_disable (ce)) { +intel_context_sched_disable_unpin (ce);
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c int intel_guc_deregister_done_process_msg(struct intel_guc *guc, · line 1497
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0+ +spin_lock_irqsave (&ce->guc_state.lock, flags); +clr_context_pending_disable (ce); +spin_unlock_irqrestore (&ce->guc_state.lock, flags); + } + +intel_context_put (ce); + +return 0 ; +}
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 16/47 drm/i915/guc: Disable engine barriers with GuC during unpin
In reply to Matthew BrostDisable engine barriers for unpinning with GuC. This feature isn't needed with the GuC as it disables context scheduling before unpinning which guarantees the HW will not reference the context. Hence it is not necessary to defer unpinning until a kernel context request completes on each engine in the context engine mask.
--- drivers/gpu/drm/i915/gt/intel_context.c | 2 +- drivers/gpu/drm/i915/gt/intel_context.h | 1 + drivers/gpu/drm/i915/gt/selftest_context.c | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/gt/intel_context.c +1 -1
@@ -80,7 +80,7 @@ static int intel_context_active_acquire(struct intel_context *ce)__i915_active_acquire (&ce->active); -if (intel_context_is_barrier (ce)) +if (intel_context_is_barrier (ce) ||intel_engine_uses_guc (ce->engine))return 0 ;/* Preallocate tracking nodes */
drivers/gpu/drm/i915/gt/intel_context.h +1 -0
@@ -16,6 +16,7 @@#include "intel_engine_types.h" #include "intel_ring_types.h" #include "intel_timeline_types.h" +#include "uc/intel_guc_submission.h" #define CE_TRACE (ce, fmt, ...) do { \ const struct intel_context *ce__ = (ce); \
drivers/gpu/drm/i915/gt/selftest_context.c +10 -0
@@ -209,7 +209,13 @@ static int __live_active_context(struct intel_engine_cs *engine)* This test makes sure that the context is kept alive until a * subsequent idle-barrier (emitted when the engine wakeref hits 0 * with no more outstanding requests). +* +* In GuC submission mode we don't use idle barriers and we instead +* get a message from the GuC to signal that it is safe to unpin the +* context from memory. */ +if (intel_engine_uses_guc (engine)) +return 0 ;if (intel_engine_pm_is_awake (engine)) { pr_err("%s is awake before starting %s!\n",
@@ -357,7 +363,11 @@ static int __live_remote_context(struct intel_engine_cs *engine)* on the context image remotely (intel_context_prepare_remote_request), * which inserts foreign fences into intel_context.active, does not * clobber the idle-barrier. +* +* In GuC submission mode we don't use idle barriers. */ +if (intel_engine_uses_guc (engine)) +return 0 ;if (intel_engine_pm_is_awake (engine)) { pr_err("%s is awake before starting %s!\n",
Signature · 1 line
2.28.0
Re: [PATCH 16/47] drm/i915/guc: Disable engine barriers with GuC during unpin
Quoted 20 lines · Matthew Brost
Disable engine barriers for unpinning with GuC. This feature isn't needed with the GuC as it disables context scheduling before unpinning which guarantees the HW will not reference the context. Hence it is not necessary to defer unpinning until a kernel context request completes on each engine in the context engine mask.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>Signed-off-by Daniele Ceraolo Spurio <[email protected]>--- drivers/gpu/drm/i915/gt/intel_context.c | 2 +- drivers/gpu/drm/i915/gt/intel_context.h | 1 + drivers/gpu/drm/i915/gt/selftest_context.c | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/gt/intel_context.c +0
-0
drivers/gpu/drm/i915/gt/intel_context.c static int intel_context_active_acquire(struct intel_context *ce) · line 84
Quoted 6 lines
drivers/gpu/drm/i915/gt/intel_context.c +1
-1@@ -80,7 +80,7 @@ static int intel_context_active_acquire(struct intel_context *ce)__i915_active_acquire (&ce->active); -if (intel_context_is_barrier (ce)) +if (intel_context_is_barrier (ce) ||intel_engine_uses_guc (ce->engine))return 0 ;
Would be better to have a scheduler flag to say whether barriers are required or not. That would prevent polluting front end code with back end details.
John.
Quoted 44 lines
drivers/gpu/drm/i915/gt/intel_context.c +0
-0/* Preallocate tracking nodes */ drivers/gpu/drm/i915/gt/intel_context.h +1
-0@@ -16,6 +16,7 @@#include "intel_engine_types.h" #include "intel_ring_types.h" #include "intel_timeline_types.h" +#include "uc/intel_guc_submission.h" #define CE_TRACE (ce, fmt, ...) do { \ const struct intel_context *ce__ = (ce); \drivers/gpu/drm/i915/gt/selftest_context.c +10
-0@@ -209,7 +209,13 @@ static int __live_active_context(struct intel_engine_cs *engine)* This test makes sure that the context is kept alive until a * subsequent idle-barrier (emitted when the engine wakeref hits 0 * with no more outstanding requests). +* +* In GuC submission mode we don't use idle barriers and we instead +* get a message from the GuC to signal that it is safe to unpin the +* context from memory. */ +if (intel_engine_uses_guc (engine)) +return 0 ;if (intel_engine_pm_is_awake (engine)) { pr_err("%s is awake before starting %s!\n",@@ -357,7 +363,11 @@ static int __live_remote_context(struct intel_engine_cs *engine)* on the context image remotely (intel_context_prepare_remote_request), * which inserts foreign fences into intel_context.active, does not * clobber the idle-barrier. +* +* In GuC submission mode we don't use idle barriers. */ +if (intel_engine_uses_guc (engine)) +return 0 ;if (intel_engine_pm_is_awake (engine)) { pr_err("%s is awake before starting %s!\n",
Re: [PATCH 16/47] drm/i915/guc: Disable engine barriers with GuC during unpin
Quoted 16 lines · John Harrison
Quoted 15 lines · Matthew Brost
Disable engine barriers for unpinning with GuC. This feature isn't needed with the GuC as it disables context scheduling before unpinning which guarantees the HW will not reference the context. Hence it is not necessary to defer unpinning until a kernel context request completes on each engine in the context engine mask.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>Signed-off-by Daniele Ceraolo Spurio <[email protected]>--- drivers/gpu/drm/i915/gt/intel_context.c | 2 +- drivers/gpu/drm/i915/gt/intel_context.h | 1 + drivers/gpu/drm/i915/gt/selftest_context.c | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-)
Quoted 13 lines
drivers/gpu/drm/i915/gt/intel_context.c static int intel_context_active_acquire(struct intel_context *ce) · line 82
Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_context.c +1
-1@@ -80,7 +80,7 @@ static int intel_context_active_acquire(struct intel_context *ce)__i915_active_acquire (&ce->active); -if (intel_context_is_barrier (ce)) +if (intel_context_is_barrier (ce) ||intel_engine_uses_guc (ce->engine))return 0 ;Would be better to have a scheduler flag to say whether barriers are required or not. That would prevent polluting front end code with back end details.
I guess an engine flag is slightly better but I still don't love that as we have to test if the context is a barrier (kernel context) and then call a function that is basically backend specific after. IMO we really need to push all of this to a vfunc. If you really want me to make this an engine flag I can, but in the end it just seems like that will trash the code (adding an engine flag just to remove it). I think this is just a clean up we write down, and figure out a bit later as nothing is functionally wrong + quite clear that it is something that should be cleaned up.
Matt
Quoted 35 lines
John.
Quoted 32 lines
drivers/gpu/drm/i915/gt/intel_context.c +0
-0/* Preallocate tracking nodes */ drivers/gpu/drm/i915/gt/intel_context.h +1
-0@@ -16,6 +16,7 @@#include "intel_engine_types.h" #include "intel_ring_types.h" #include "intel_timeline_types.h" +#include "uc/intel_guc_submission.h" #define CE_TRACE (ce, fmt, ...) do { \ const struct intel_context *ce__ = (ce); \drivers/gpu/drm/i915/gt/selftest_context.c +6
-0@@ -209,7 +209,13 @@ static int __live_active_context(struct intel_engine_cs *engine)* This test makes sure that the context is kept alive until a * subsequent idle-barrier (emitted when the engine wakeref hits 0 * with no more outstanding requests). +* +* In GuC submission mode we don't use idle barriers and we instead +* get a message from the GuC to signal that it is safe to unpin the +* context from memory. */ +if (intel_engine_uses_guc (engine)) +return 0 ;if (intel_engine_pm_is_awake (engine)) { pr_err("%s is awake before starting %s!\n",@@ -357,7 +363,11 @@ static int __live_remote_context(struct intel_engine_cs *engine)* on the context image remotely (intel_context_prepare_remote_request), * which inserts foreign fences into intel_context.active, does not
Quoted 9 lines
drivers/gpu/drm/i915/gt/selftest_context.c static int __live_remote_context(struct intel_engine_cs *engine) · line 373
Quoted 8 lines
drivers/gpu/drm/i915/gt/selftest_context.c +4
-0* clobber the idle-barrier. +* +* In GuC submission mode we don't use idle barriers. */ +if (intel_engine_uses_guc (engine)) +return 0 ;if (intel_engine_pm_is_awake (engine)) { pr_err("%s is awake before starting %s!\n",
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
John Harrison
Reviewed-byRe: [PATCH 16/47] drm/i915/guc: Disable engine barriers with GuC during unpin
Quoted 40 lines · Matthew Brost
Quoted 16 lines · John Harrison
Quoted 15 lines · Matthew Brost
Disable engine barriers for unpinning with GuC. This feature isn't needed with the GuC as it disables context scheduling before unpinning which guarantees the HW will not reference the context. Hence it is not necessary to defer unpinning until a kernel context request completes on each engine in the context engine mask.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>Signed-off-by Daniele Ceraolo Spurio <[email protected]>--- drivers/gpu/drm/i915/gt/intel_context.c | 2 +- drivers/gpu/drm/i915/gt/intel_context.h | 1 + drivers/gpu/drm/i915/gt/selftest_context.c | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-)Quoted 13 lines
drivers/gpu/drm/i915/gt/intel_context.c static int intel_context_active_acquire(struct intel_context *ce) · line 82
Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_context.c +1
-1@@ -80,7 +80,7 @@ static int intel_context_active_acquire(struct intel_context *ce)__i915_active_acquire (&ce->active); -if (intel_context_is_barrier (ce)) +if (intel_context_is_barrier (ce) ||intel_engine_uses_guc (ce->engine))return 0 ;Would be better to have a scheduler flag to say whether barriers are required or not. That would prevent polluting front end code with back end details.
I guess an engine flag is slightly better but I still don't love that as we have to test if the context is a barrier (kernel context) and then call a function that is basically backend specific after. IMO we really need to push all of this to a vfunc. If you really want me to make this an engine flag I can, but in the end it just seems like that will trash the code (adding an engine flag just to remove it). I think this is just a clean up we write down, and figure out a bit later as nothing is functionally wrong + quite clear that it is something that should be cleaned up.
Quoted 1 line
Matt
Flag, vfunc, whatever. I just mean that it would be better to abstract it out in some manner. Maybe a flag/vfunc on the ce object? That way it would swallow the 'ignore kernel contexts' test as well. But yes, probably best to add it to the todo list and move on as it is not going to be a two minute quick fix. I've added a comment to the Jira, so...
Quoted 36 lines
Quoted 36 lines
John.
Quoted 32 lines
drivers/gpu/drm/i915/gt/intel_context.c +0
-0/* Preallocate tracking nodes */ drivers/gpu/drm/i915/gt/intel_context.h +1
-0@@ -16,6 +16,7 @@#include "intel_engine_types.h" #include "intel_ring_types.h" #include "intel_timeline_types.h" +#include "uc/intel_guc_submission.h" #define CE_TRACE (ce, fmt, ...) do { \ const struct intel_context *ce__ = (ce); \drivers/gpu/drm/i915/gt/selftest_context.c +6
-0@@ -209,7 +209,13 @@ static int __live_active_context(struct intel_engine_cs *engine)* This test makes sure that the context is kept alive until a * subsequent idle-barrier (emitted when the engine wakeref hits 0 * with no more outstanding requests). +* +* In GuC submission mode we don't use idle barriers and we instead +* get a message from the GuC to signal that it is safe to unpin the +* context from memory. */ +if (intel_engine_uses_guc (engine)) +return 0 ;if (intel_engine_pm_is_awake (engine)) { pr_err("%s is awake before starting %s!\n",@@ -357,7 +363,11 @@ static int __live_remote_context(struct intel_engine_cs *engine)* on the context image remotely (intel_context_prepare_remote_request), * which inserts foreign fences into intel_context.active, does not
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/gt/selftest_context.c static int __live_remote_context(struct intel_engine_cs *engine) · line 373
Quoted 8 lines
drivers/gpu/drm/i915/gt/selftest_context.c +4
-0* clobber the idle-barrier. +* +* In GuC submission mode we don't use idle barriers. */ +if (intel_engine_uses_guc (engine)) +return 0 ;if (intel_engine_pm_is_awake (engine)) { pr_err("%s is awake before starting %s!\n",
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 16/47] drm/i915/guc: Disable engine barriers with GuC during unpin
Quoted 42 lines · John Harrison
Quoted 40 lines · Matthew Brost
Quoted 16 lines · John Harrison
Quoted 15 lines · Matthew Brost
Disable engine barriers for unpinning with GuC. This feature isn't needed with the GuC as it disables context scheduling before unpinning which guarantees the HW will not reference the context. Hence it is not necessary to defer unpinning until a kernel context request completes on each engine in the context engine mask.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>Signed-off-by Daniele Ceraolo Spurio <[email protected]>--- drivers/gpu/drm/i915/gt/intel_context.c | 2 +- drivers/gpu/drm/i915/gt/intel_context.h | 1 + drivers/gpu/drm/i915/gt/selftest_context.c | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-)Quoted 13 lines
drivers/gpu/drm/i915/gt/intel_context.c static int intel_context_active_acquire(struct intel_context *ce) · line 82
Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_context.c +1
-1@@ -80,7 +80,7 @@ static int intel_context_active_acquire(struct intel_context *ce)__i915_active_acquire (&ce->active); -if (intel_context_is_barrier (ce)) +if (intel_context_is_barrier (ce) ||intel_engine_uses_guc (ce->engine))return 0 ;Would be better to have a scheduler flag to say whether barriers are required or not. That would prevent polluting front end code with back end details.
I guess an engine flag is slightly better but I still don't love that as we have to test if the context is a barrier (kernel context) and then call a function that is basically backend specific after. IMO we really need to push all of this to a vfunc. If you really want me to make this an engine flag I can, but in the end it just seems like that will trash the code (adding an engine flag just to remove it). I think this is just a clean up we write down, and figure out a bit later as nothing is functionally wrong + quite clear that it is something that should be cleaned up.
Quoted 6 lines
Quoted 1 line
Matt
Flag, vfunc, whatever. I just mean that it would be better to abstract it out in some manner. Maybe a flag/vfunc on the ce object? That way it would swallow the 'ignore kernel contexts' test as well. But yes, probably best to add it to the todo list and move on as it is not going to be a two minute quick fix. I've added a comment to the Jira, so...
The plan is:
- merge guc backend
- convert over to drm/scheduler as a proper interface between higher levels and the scheduler backend
- shovel as much as reasonable of the execlist specifics into the execlist backend
Right now our frontend code is essentially designed to assume the execlist backend is the true way to build a scheduler, and everything else is a special case. We can't reasonable fix this by sprinkling lots of vfuns all over the place, and hence we imo shouldn't try, at least not until the big picture is in much better shape. -Daniel
Quoted 52 lines
Reviewed-by John Harrison <[email protected]>Quoted 36 lines
Quoted 36 lines
John.
Quoted 32 lines
drivers/gpu/drm/i915/gt/intel_context.c +0
-0/* Preallocate tracking nodes */ drivers/gpu/drm/i915/gt/intel_context.h +1
-0@@ -16,6 +16,7 @@#include "intel_engine_types.h" #include "intel_ring_types.h" #include "intel_timeline_types.h" +#include "uc/intel_guc_submission.h" #define CE_TRACE (ce, fmt, ...) do { \ const struct intel_context *ce__ = (ce); \drivers/gpu/drm/i915/gt/selftest_context.c +6
-0@@ -209,7 +209,13 @@ static int __live_active_context(struct intel_engine_cs *engine)* This test makes sure that the context is kept alive until a * subsequent idle-barrier (emitted when the engine wakeref hits 0 * with no more outstanding requests). +* +* In GuC submission mode we don't use idle barriers and we instead +* get a message from the GuC to signal that it is safe to unpin the +* context from memory. */ +if (intel_engine_uses_guc (engine)) +return 0 ;if (intel_engine_pm_is_awake (engine)) { pr_err("%s is awake before starting %s!\n",@@ -357,7 +363,11 @@ static int __live_remote_context(struct intel_engine_cs *engine)* on the context image remotely (intel_context_prepare_remote_request), * which inserts foreign fences into intel_context.active, does not Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/gt/selftest_context.c static int __live_remote_context(struct intel_engine_cs *engine) · line 373
Quoted 8 lines
drivers/gpu/drm/i915/gt/selftest_context.c +4
-0* clobber the idle-barrier. +* +* In GuC submission mode we don't use idle barriers. */ +if (intel_engine_uses_guc (engine)) +return 0 ;if (intel_engine_pm_is_awake (engine)) { pr_err("%s is awake before starting %s!\n",_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 17/47 drm/i915/guc: Extend deregistration fence to schedule disable
In reply to Matthew BrostExtend the deregistration context fence to fence whne a GuC context has scheduling disable pending.
--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +30 -7
@@ -918,7 +918,19 @@ static void guc_context_sched_disable(struct intel_context *ce) goto unpin;spin_lock_irqsave (&ce->guc_state.lock, flags); + +/* +* We have to check if the context has been pinned again as another pin +* operation is allowed to pass this function. Checking the pin count +* here synchronizes this function with guc_request_alloc ensuring a +* request doesn't slip through the 'context_pending_disable' fence. +*/ +if (unlikely (atomic_add_unless (&ce->pin_count,-2 ,2 ))) { +spin_unlock_irqrestore (&ce->guc_state.lock, flags); +return ; + } guc_id =prep_context_pending_disable (ce); +spin_unlock_irqrestore (&ce->guc_state.lock, flags);with_intel_runtime_pm (runtime_pm, wakeref)
@@ -1123,19 +1135,22 @@ static int guc_request_alloc(struct i915_request *rq) out:/* * We block all requests on this context if a G2H is pending for a -* context deregistration as the GuC will fail a context registration -* while this G2H is pending. Once a G2H returns, the fence is released -* that is blocking these requests (see guc_signal_context_fence). +* schedule disable or context deregistration as the GuC will fail a +* schedule enable or context registration if either G2H is pending +* respectfully. Once a G2H returns, the fence is released that is +* blocking these requests (see guc_signal_context_fence). * -* We can safely check the below field outside of the lock as it isn't -* possible for this field to transition from being clear to set but +* We can safely check the below fields outside of the lock as it isn't +* possible for these fields to transition from being clear to set but * converse is possible, hence the need for the check within the lock. */ -if (likely (!context_wait_for_deregister_to_register (ce))) +if (likely (!context_wait_for_deregister_to_register (ce) && + !context_pending_disable (ce)))return 0 ;spin_lock_irqsave (&ce->guc_state.lock, flags); -if (context_wait_for_deregister_to_register (ce)) { +if (context_wait_for_deregister_to_register (ce) || +context_pending_disable (ce)) {i915_sw_fence_await (&rq->submit);list_add_tail (&rq->guc_fence_link, &ce->guc_state.fences);
@@ -1484,10 +1499,18 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,if (context_pending_enable (ce)) {clr_context_pending_enable (ce); }else if (context_pending_disable (ce)) { +/* +* Unpin must be done before __guc_signal_context_fence, +* otherwise a race exists between the requests getting +* submitted + retired before this unpin completes resulting in +* the pin_count going to zero and the context still being +* enabled. +*/ intel_context_sched_disable_unpin (ce);spin_lock_irqsave (&ce->guc_state.lock, flags);clr_context_pending_disable (ce); +__guc_signal_context_fence (ce);spin_unlock_irqrestore (&ce->guc_state.lock, flags); }
Signature · 1 line
2.28.0
Re: [PATCH 17/47] drm/i915/guc: Extend deregistration fence to schedule disable
Quoted 14 lines · Matthew Brost
Extend the deregistration context fence to fence whne a GuC context has scheduling disable pending.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void guc_context_sched_disable(struct intel_context *ce) · line 927
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +7
-0@@ -918,7 +918,19 @@ static void guc_context_sched_disable(struct intel_context *ce) goto unpin;spin_lock_irqsave (&ce->guc_state.lock, flags); + +/* +* We have to check if the context has been pinned again as another pin +* operation is allowed to pass this function. Checking the pin count +* here synchronizes this function with guc_request_alloc ensuring a +* request doesn't slip through the 'context_pending_disable' fence. +*/
The pin count is an atomic so doesn't need the spinlock. Also the above comment 'checking the pin count here synchronizes ...' seems wrong. Isn't the point that acquiring the spinlock is what synchronises with guc_request_alloc? So the comment should be before the spinlock acquire and should mention using the spinlock for this purpose?
John.
Quoted 48 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +20
-7+if (unlikely (atomic_add_unless (&ce->pin_count,-2 ,2 ))) { +spin_unlock_irqrestore (&ce->guc_state.lock, flags); +return ; + } guc_id =prep_context_pending_disable (ce); +spin_unlock_irqrestore (&ce->guc_state.lock, flags);with_intel_runtime_pm (runtime_pm, wakeref)@@ -1123,19 +1135,22 @@ static int guc_request_alloc(struct i915_request *rq) out:/* * We block all requests on this context if a G2H is pending for a -* context deregistration as the GuC will fail a context registration -* while this G2H is pending. Once a G2H returns, the fence is released -* that is blocking these requests (see guc_signal_context_fence). +* schedule disable or context deregistration as the GuC will fail a +* schedule enable or context registration if either G2H is pending +* respectfully. Once a G2H returns, the fence is released that is +* blocking these requests (see guc_signal_context_fence). * -* We can safely check the below field outside of the lock as it isn't -* possible for this field to transition from being clear to set but +* We can safely check the below fields outside of the lock as it isn't +* possible for these fields to transition from being clear to set but * converse is possible, hence the need for the check within the lock. */ -if (likely (!context_wait_for_deregister_to_register (ce))) +if (likely (!context_wait_for_deregister_to_register (ce) && + !context_pending_disable (ce)))return 0 ;spin_lock_irqsave (&ce->guc_state.lock, flags); -if (context_wait_for_deregister_to_register (ce)) { +if (context_wait_for_deregister_to_register (ce) || +context_pending_disable (ce)) {i915_sw_fence_await (&rq->submit);list_add_tail (&rq->guc_fence_link, &ce->guc_state.fences);@@ -1484,10 +1499,18 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,if (context_pending_enable (ce)) {clr_context_pending_enable (ce); }else if (context_pending_disable (ce)) { +/* +* Unpin must be done before __guc_signal_context_fence, +* otherwise a race exists between the requests getting +* submitted + retired before this unpin completes resulting in +* the pin_count going to zero and the context still being
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c int intel_guc_sched_done_process_msg(struct intel_guc *guc, · line 1516
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +3
-0+* enabled. +*/ intel_context_sched_disable_unpin (ce);spin_lock_irqsave (&ce->guc_state.lock, flags);clr_context_pending_disable (ce); +__guc_signal_context_fence (ce);spin_unlock_irqrestore (&ce->guc_state.lock, flags); }
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 17/47] drm/i915/guc: Extend deregistration fence to schedule disable
Quoted 10 lines · John Harrison
Quoted 9 lines · Matthew Brost
Extend the deregistration context fence to fence whne a GuC context has scheduling disable pending.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-)
Quoted 15 lines
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void guc_context_sched_disable(struct intel_context *ce) · line 926
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +7
-0@@ -918,7 +918,19 @@ static void guc_context_sched_disable(struct intel_context *ce) goto unpin;spin_lock_irqsave (&ce->guc_state.lock, flags); + +/* +* We have to check if the context has been pinned again as another pin +* operation is allowed to pass this function. Checking the pin count +* here synchronizes this function with guc_request_alloc ensuring a +* request doesn't slip through the 'context_pending_disable' fence. +*/ The pin count is an atomic so doesn't need the spinlock. Also the above
How about?
/*
* We have to check if the context has been pinned again as another pin
* operation is allowed to pass this function. Checking the pin count,
* within ce->guc_state.lock, synchronizes this function with
* guc_request_alloc ensuring a request doesn't slip through the
* 'context_pending_disable' fence. Checking within the spin lock (can't
* sleep) ensures another process doesn't pin this context and generate
* a request before we set the 'context_pending_disable' flag here. */
Matt
Quoted 53 lines
comment 'checking the pin count here synchronizes ...' seems wrong. Isn't the point that acquiring the spinlock is what synchronises with
guc_request_alloc? So the comment should be before the spinlock acquire and should mention using the spinlock for this purpose?John.
Quoted 45 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +20
-7+if (unlikely (atomic_add_unless (&ce->pin_count,-2 ,2 ))) { +spin_unlock_irqrestore (&ce->guc_state.lock, flags); +return ; + } guc_id =prep_context_pending_disable (ce); +spin_unlock_irqrestore (&ce->guc_state.lock, flags);with_intel_runtime_pm (runtime_pm, wakeref)@@ -1123,19 +1135,22 @@ static int guc_request_alloc(struct i915_request *rq) out:/* * We block all requests on this context if a G2H is pending for a -* context deregistration as the GuC will fail a context registration -* while this G2H is pending. Once a G2H returns, the fence is released -* that is blocking these requests (see guc_signal_context_fence). +* schedule disable or context deregistration as the GuC will fail a +* schedule enable or context registration if either G2H is pending +* respectfully. Once a G2H returns, the fence is released that is +* blocking these requests (see guc_signal_context_fence). * -* We can safely check the below field outside of the lock as it isn't -* possible for this field to transition from being clear to set but +* We can safely check the below fields outside of the lock as it isn't +* possible for these fields to transition from being clear to set but * converse is possible, hence the need for the check within the lock. */ -if (likely (!context_wait_for_deregister_to_register (ce))) +if (likely (!context_wait_for_deregister_to_register (ce) && + !context_pending_disable (ce)))return 0 ;spin_lock_irqsave (&ce->guc_state.lock, flags); -if (context_wait_for_deregister_to_register (ce)) { +if (context_wait_for_deregister_to_register (ce) || +context_pending_disable (ce)) {i915_sw_fence_await (&rq->submit);list_add_tail (&rq->guc_fence_link, &ce->guc_state.fences);@@ -1484,10 +1499,18 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,if (context_pending_enable (ce)) {clr_context_pending_enable (ce); }else if (context_pending_disable (ce)) { +/* +* Unpin must be done before __guc_signal_context_fence, +* otherwise a race exists between the requests getting +* submitted + retired before this unpin completes resulting in +* the pin_count going to zero and the context still being
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c int intel_guc_sched_done_process_msg(struct intel_guc *guc, · line 1515
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +3
-0+* enabled. +*/ intel_context_sched_disable_unpin (ce);spin_lock_irqsave (&ce->guc_state.lock, flags);clr_context_pending_disable (ce); +__guc_signal_context_fence (ce);spin_unlock_irqrestore (&ce->guc_state.lock, flags); }
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
John Harrison
Reviewed-byRe: [PATCH 17/47] drm/i915/guc: Extend deregistration fence to schedule disable
Quoted 38 lines · Matthew Brost
Quoted 10 lines · John Harrison
Quoted 9 lines · Matthew Brost
Extend the deregistration context fence to fence whne a GuC context has scheduling disable pending.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-)Quoted 15 lines
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void guc_context_sched_disable(struct intel_context *ce) · line 926
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +7
-0@@ -918,7 +918,19 @@ static void guc_context_sched_disable(struct intel_context *ce) goto unpin;spin_lock_irqsave (&ce->guc_state.lock, flags); + +/* +* We have to check if the context has been pinned again as another pin +* operation is allowed to pass this function. Checking the pin count +* here synchronizes this function with guc_request_alloc ensuring a +* request doesn't slip through the 'context_pending_disable' fence. +*/ The pin count is an atomic so doesn't need the spinlock. Also the above
How about?
/*
* We have to check if the context has been pinned again as another pin
* operation is allowed to pass this function. Checking the pin count,
* withince->guc_state.lock, synchronizes this function with
*guc_request_allocensuring a request doesn't slip through the
* 'context_pending_disable' fence. Checking within the spin lock (can't
* sleep) ensures another process doesn't pin this context and generate
* a request before we set the 'context_pending_disable' flag here. */
Quoted 1 line
Matt
Sounds good. With that added in:
Quoted 62 lines
Quoted 62 lines
comment 'checking the pin count here synchronizes ...' seems wrong. Isn't the point that acquiring the spinlock is what synchronises with
guc_request_alloc? So the comment should be before the spinlock acquire and should mention using the spinlock for this purpose?John.
Quoted 53 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +23
-7+if (unlikely (atomic_add_unless (&ce->pin_count,-2 ,2 ))) { +spin_unlock_irqrestore (&ce->guc_state.lock, flags); +return ; + } guc_id =prep_context_pending_disable (ce); +spin_unlock_irqrestore (&ce->guc_state.lock, flags);with_intel_runtime_pm (runtime_pm, wakeref)@@ -1123,19 +1135,22 @@ static int guc_request_alloc(struct i915_request *rq) out:/* * We block all requests on this context if a G2H is pending for a -* context deregistration as the GuC will fail a context registration -* while this G2H is pending. Once a G2H returns, the fence is released -* that is blocking these requests (see guc_signal_context_fence). +* schedule disable or context deregistration as the GuC will fail a +* schedule enable or context registration if either G2H is pending +* respectfully. Once a G2H returns, the fence is released that is +* blocking these requests (see guc_signal_context_fence). * -* We can safely check the below field outside of the lock as it isn't -* possible for this field to transition from being clear to set but +* We can safely check the below fields outside of the lock as it isn't +* possible for these fields to transition from being clear to set but * converse is possible, hence the need for the check within the lock. */ -if (likely (!context_wait_for_deregister_to_register (ce))) +if (likely (!context_wait_for_deregister_to_register (ce) && + !context_pending_disable (ce)))return 0 ;spin_lock_irqsave (&ce->guc_state.lock, flags); -if (context_wait_for_deregister_to_register (ce)) { +if (context_wait_for_deregister_to_register (ce) || +context_pending_disable (ce)) {i915_sw_fence_await (&rq->submit);list_add_tail (&rq->guc_fence_link, &ce->guc_state.fences);@@ -1484,10 +1499,18 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,if (context_pending_enable (ce)) {clr_context_pending_enable (ce); }else if (context_pending_disable (ce)) { +/* +* Unpin must be done before __guc_signal_context_fence, +* otherwise a race exists between the requests getting +* submitted + retired before this unpin completes resulting in +* the pin_count going to zero and the context still being +* enabled. +*/ intel_context_sched_disable_unpin (ce);spin_lock_irqsave (&ce->guc_state.lock, flags);clr_context_pending_disable (ce); +__guc_signal_context_fence (ce);spin_unlock_irqrestore (&ce->guc_state.lock, flags); }
PATCH 18/47 drm/i915: Disable preempt busywait when using GuC scheduling
In reply to Matthew BrostDisable preempt busywait when using GuC scheduling. This isn't need as the GuC control preemption when scheduling.
--- drivers/gpu/drm/i915/gt/gen8_engine_cs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/gen8_engine_cs.c +4 -2
@@ -506,7 +506,8 @@ gen8_emit_fini_breadcrumb_tail(struct i915_request *rq, u32 *cs) *cs++ =MI_USER_INTERRUPT ; *cs++ =MI_ARB_ON_OFF |MI_ARB_ENABLE ; -if (intel_engine_has_semaphores (rq->engine)) +if (intel_engine_has_semaphores (rq->engine) && + !intel_uc_uses_guc_submission (&rq->engine->gt->uc)) cs =emit_preempt_busywait (rq, cs); rq->tail =intel_ring_offset (rq, cs);
@@ -598,7 +599,8 @@ gen12_emit_fini_breadcrumb_tail(struct i915_request *rq, u32 *cs) *cs++ =MI_USER_INTERRUPT ; *cs++ =MI_ARB_ON_OFF |MI_ARB_ENABLE ; -if (intel_engine_has_semaphores (rq->engine)) +if (intel_engine_has_semaphores (rq->engine) && + !intel_uc_uses_guc_submission (&rq->engine->gt->uc)) cs =gen12_emit_preempt_busywait (rq, cs); rq->tail =intel_ring_offset (rq, cs);
Signature · 1 line
2.28.0
Re: [PATCH 18/47] drm/i915: Disable preempt busywait when using GuC scheduling
Quoted 1 line · Matthew Brost
Disable preempt busywait when using GuC scheduling. This isn't need as
needed
Quoted 1 line
the GuC control preemption when scheduling.
controls
With the above fixed:
Quoted 22 lines
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/gen8_engine_cs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gt/gen8_engine_cs.c +2
-1@@ -506,7 +506,8 @@ gen8_emit_fini_breadcrumb_tail(struct i915_request *rq, u32 *cs) *cs++ =MI_USER_INTERRUPT ; *cs++ =MI_ARB_ON_OFF |MI_ARB_ENABLE ; -if (intel_engine_has_semaphores (rq->engine)) +if (intel_engine_has_semaphores (rq->engine) && + !intel_uc_uses_guc_submission (&rq->engine->gt->uc)) cs =emit_preempt_busywait (rq, cs); rq->tail =intel_ring_offset (rq, cs);
drivers/gpu/drm/i915/gt/gen8_engine_cs.c gen12_emit_fini_breadcrumb_tail(struct i915_request *rq, u32 *cs) · line 606
Quoted 9 lines
drivers/gpu/drm/i915/gt/gen8_engine_cs.c +2
-1@@ -598,7 +599,8 @@ gen12_emit_fini_breadcrumb_tail(struct i915_request *rq, u32 *cs) *cs++ =MI_USER_INTERRUPT ; *cs++ =MI_ARB_ON_OFF |MI_ARB_ENABLE ; -if (intel_engine_has_semaphores (rq->engine)) +if (intel_engine_has_semaphores (rq->engine) && + !intel_uc_uses_guc_submission (&rq->engine->gt->uc)) cs =gen12_emit_preempt_busywait (rq, cs); rq->tail =intel_ring_offset (rq, cs);
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 19/47 drm/i915/guc: Ensure request ordering via completion fences
In reply to Matthew BrostIf two requests are on the same ring, they are explicitly ordered by the HW. So, a submission fence is sufficient to ensure ordering when using the new GuC submission interface. Conversely, if two requests share a timeline and are on the same physical engine but different context this doesn't ensure ordering on the new GuC submission interface. So, a completion fence needs to be used to ensure ordering.
--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 1 - drivers/gpu/drm/i915/i915_request.c | 17 +++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0 -1
@@ -926,7 +926,6 @@ static void guc_context_sched_disable(struct intel_context *ce)* request doesn't slip through the 'context_pending_disable' fence. */ if (unlikely (atomic_add_unless (&ce->pin_count,-2 ,2 ))) { -spin_unlock_irqrestore (&ce->guc_state.lock, flags);return ; } guc_id =prep_context_pending_disable (ce);
drivers/gpu/drm/i915/i915_request.c +13 -4
@@ -444,6 +444,7 @@ void i915_request_retire_upto(struct i915_request *rq)do { tmp =list_first_entry (&tl->requests,typeof (*tmp), link); +GEM_BUG_ON (!i915_request_completed (tmp)); }while (i915_request_retire (tmp) && tmp != rq); }
@@ -1405,6 +1406,9 @@ i915_request_await_external(struct i915_request *rq, struct dma_fence *fence)return err; } +static int +i915_request_await_request (struct i915_request *to,struct i915_request *from); + int i915_request_await_execution(struct i915_request *rq, struct dma_fence *fence,
@@ -1464,12 +1468,13 @@ await_request_submit(struct i915_request *to, struct i915_request *from)* the waiter to be submitted immediately to the physical engine * as it may then bypass the virtual request. */ -if (to->engine ==READ_ONCE (from->engine)) +if (to->engine ==READ_ONCE (from->engine)) {return i915_sw_fence_await_sw_fence_gfp (&to->submit, &from->submit,I915_FENCE_GFP ); -else + }else {return __i915_request_await_execution (to, from,NULL ); + } } static int
@@ -1493,7 +1498,8 @@ i915_request_await_request(struct i915_request *to, struct i915_request *from)return ret; } -if (is_power_of_2 (to->execution_mask |READ_ONCE (from->execution_mask))) +if (!intel_engine_uses_guc (to->engine) && +is_power_of_2 (to->execution_mask |READ_ONCE (from->execution_mask))) ret =await_request_submit (to, from);else ret =emit_semaphore_wait (to, from,I915_FENCE_GFP );
@@ -1654,6 +1660,8 @@ __i915_request_add_to_timeline(struct i915_request *rq) prev =to_request (__i915_active_fence_set (&timeline->last_request, &rq->fence));if (prev && !__i915_request_is_complete (prev)) { +bool uses_guc =intel_engine_uses_guc (rq->engine); +/* * The requests are supposed to be kept in order. However, * we need to be wary in case the timeline->last_request
@@ -1664,7 +1672,8 @@ __i915_request_add_to_timeline(struct i915_request *rq)i915_seqno_passed (prev->fence.seqno, rq->fence.seqno)); -if (is_power_of_2 (READ_ONCE (prev->engine)->mask | rq->engine->mask)) +if ((!uses_guc &&is_power_of_2 (READ_ONCE (prev->engine)->mask | rq->engine->mask)) || + (uses_guc && prev->context == rq->context))i915_sw_fence_await_sw_fence (&rq->submit, &prev->submit, &rq->submitq);
Signature · 1 line
2.28.0
Re: [PATCH 19/47] drm/i915/guc: Ensure request ordering via completion fences
Quoted 19 lines · Matthew Brost
If two requests are on the same ring, they are explicitly ordered by the HW. So, a submission fence is sufficient to ensure ordering when using the new GuC submission interface. Conversely, if two requests share a timeline and are on the same physical engine but different context this doesn't ensure ordering on the new GuC submission interface. So, a completion fence needs to be used to ensure ordering.
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 1 - drivers/gpu/drm/i915/i915_request.c | 17 +++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void guc_context_sched_disable(struct intel_context *ce) · line 929
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-1@@ -926,7 +926,6 @@ static void guc_context_sched_disable(struct intel_context *ce)* request doesn't slip through the 'context_pending_disable' fence. */ if (unlikely (atomic_add_unless (&ce->pin_count,-2 ,2 ))) { -spin_unlock_irqrestore (&ce->guc_state.lock, flags);
Why is this unlock() being dropped here?
drivers/gpu/drm/i915/i915_request.c void i915_request_retire_upto(struct i915_request *rq) · line 447
Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0return ; } guc_id =prep_context_pending_disable (ce);drivers/gpu/drm/i915/i915_request.c +1
-0@@ -444,6 +444,7 @@ void i915_request_retire_upto(struct i915_request *rq) do { tmp = list_first_entry(&tl->requests, typeof(*tmp), link); + GEM_BUG_ON(!i915_request_completed(tmp));
This condition in the BUG_ON is not a new requirement introduced by the changes below, right? just want to make sure I'm not missing anything.
Quoted 16 lines
drivers/gpu/drm/i915/i915_request.c +3
-0}while (i915_request_retire (tmp) && tmp != rq); }@@ -1405,6 +1406,9 @@ i915_request_await_external(struct i915_request *rq, struct dma_fence *fence)return err; } +static int +i915_request_await_request (struct i915_request *to,struct i915_request *from); + int i915_request_await_execution(struct i915_request *rq, struct dma_fence *fence,@@ -1464,12 +1468,13 @@ await_request_submit(struct i915_request *to, struct i915_request *from)* the waiter to be submitted immediately to the physical engine * as it may then bypass the virtual request.
drivers/gpu/drm/i915/i915_request.c await_request_submit(struct i915_request *to, struct i915_request *from) · line 1477
Quoted 10 lines
drivers/gpu/drm/i915/i915_request.c +3
-2*/ -if (to->engine ==READ_ONCE (from->engine)) +if (to->engine ==READ_ONCE (from->engine)) {return i915_sw_fence_await_sw_fence_gfp (&to->submit, &from->submit,I915_FENCE_GFP ); -else + }else {return __i915_request_await_execution (to, from,NULL ); + }
{ } are not needed here. I'm guessing they're leftover from a dropped change.
Quoted 23 lines
drivers/gpu/drm/i915/i915_request.c +4
-1} static int@@ -1493,7 +1498,8 @@ i915_request_await_request(struct i915_request *to, struct i915_request *from)return ret; } -if (is_power_of_2 (to->execution_mask |READ_ONCE (from->execution_mask))) +if (!intel_engine_uses_guc (to->engine) && +is_power_of_2 (to->execution_mask |READ_ONCE (from->execution_mask))) ret =await_request_submit (to, from);else ret =emit_semaphore_wait (to, from,I915_FENCE_GFP );@@ -1654,6 +1660,8 @@ __i915_request_add_to_timeline(struct i915_request *rq) prev =to_request (__i915_active_fence_set (&timeline->last_request, &rq->fence));if (prev && !__i915_request_is_complete (prev)) { +bool uses_guc =intel_engine_uses_guc (rq->engine); +/* * The requests are supposed to be kept in order. However, * we need to be wary in case the timeline->last_request
drivers/gpu/drm/i915/i915_request.c __i915_request_add_to_timeline(struct i915_request *rq) · line 1676
Quoted 6 lines
drivers/gpu/drm/i915/i915_request.c +2
-1@@ -1664,7 +1672,8 @@ __i915_request_add_to_timeline(struct i915_request *rq)i915_seqno_passed (prev->fence.seqno, rq->fence.seqno)); -if (is_power_of_2 (READ_ONCE (prev->engine)->mask | rq->engine->mask)) +if ((!uses_guc &&is_power_of_2 (READ_ONCE (prev->engine)->mask | rq->engine->mask)) || + (uses_guc && prev->context == rq->context))
Would it be worth adding an engine flag instead of checking which back-end is in use? I915_ENGINE_IS_FIFO or something. Not a blocker.
Daniele
Quoted 3 lines
drivers/gpu/drm/i915/i915_request.c +0
-0i915_sw_fence_await_sw_fence (&rq->submit, &prev->submit, &rq->submitq);
PATCH 20/47 drm/i915/guc: Disable semaphores when using GuC scheduling
In reply to Matthew BrostSemaphores are an optimization and not required for basic GuC submission to work properly. Disable until we have time to do the implementation to enable semaphores and tune them for performance. Also long direction is just to delete semaphores from the i915 so another reason to not enable these for GuC submission.
v2: Reword commit message
--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +4 -2
@@ -230,7 +230,8 @@ static void intel_context_set_gem(struct intel_context *ce, ce->timeline =intel_timeline_get (ctx->timeline);if (ctx->sched.priority >=I915_PRIORITY_NORMAL && -intel_engine_has_timeslices (ce->engine)) +intel_engine_has_timeslices (ce->engine) && +intel_engine_has_semaphores (ce->engine))__set_bit (CONTEXT_USE_SEMAPHORES , &ce->flags);intel_context_set_watchdog_us (ce, ctx->watchdog.timeout_us);
@@ -1938,7 +1939,8 @@ static int __apply_priority(struct intel_context *ce, void *arg)if (!intel_engine_has_timeslices (ce->engine))return 0 ; -if (ctx->sched.priority >=I915_PRIORITY_NORMAL ) +if (ctx->sched.priority >=I915_PRIORITY_NORMAL && +intel_engine_has_semaphores (ce->engine))intel_context_set_use_semaphores (ce);else intel_context_clear_use_semaphores (ce);
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 20/47] drm/i915/guc: Disable semaphores when using GuC scheduling
Quoted 10 lines · Matthew Brost
Semaphores are an optimization and not required for basic GuC submission to work properly. Disable until we have time to do the implementation to enable semaphores and tune them for performance. Also long direction is just to delete semaphores from the i915 so another reason to not enable these for GuC submission.
v2: Reword commit message
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>
I think the commit description does not really match the patch content. The description is valid but the 'disable' is done by simply not setting the enable flag (done in the execlist back end and presumably not done in the GuC back end). However, what the patch is actually doing seems to be fixing bugs with the 'are semaphores enabled' mechanism. I.e. correcting pieces of code that used semaphores without checking if they are enabled. And presumably this would be broken if someone tried to disable semaphores in execlist mode for any reason?
So I think keeping the existing comment text is fine but something should be added to explain the actual changes.
John.
Quoted 28 lines
--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_context.c +4
-2@@ -230,7 +230,8 @@ static void intel_context_set_gem(struct intel_context *ce, ce->timeline =intel_timeline_get (ctx->timeline);if (ctx->sched.priority >=I915_PRIORITY_NORMAL && -intel_engine_has_timeslices (ce->engine)) +intel_engine_has_timeslices (ce->engine) && +intel_engine_has_semaphores (ce->engine))__set_bit (CONTEXT_USE_SEMAPHORES , &ce->flags);intel_context_set_watchdog_us (ce, ctx->watchdog.timeout_us);@@ -1938,7 +1939,8 @@ static int __apply_priority(struct intel_context *ce, void *arg)if (!intel_engine_has_timeslices (ce->engine))return 0 ; -if (ctx->sched.priority >=I915_PRIORITY_NORMAL ) +if (ctx->sched.priority >=I915_PRIORITY_NORMAL && +intel_engine_has_semaphores (ce->engine))intel_context_set_use_semaphores (ce);else intel_context_clear_use_semaphores (ce);
Re: [PATCH 20/47] drm/i915/guc: Disable semaphores when using GuC scheduling
Quoted 20 lines · John Harrison
Quoted 10 lines · Matthew Brost
Semaphores are an optimization and not required for basic GuC submission to work properly. Disable until we have time to do the implementation to enable semaphores and tune them for performance. Also long direction is just to delete semaphores from the i915 so another reason to not enable these for GuC submission.
v2: Reword commit message
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>I think the commit description does not really match the patch content. The description is valid but the 'disable' is done by simply not setting the enable flag (done in the execlist back end and presumably not done in the GuC back end). However, what the patch is actually doing seems to be fixing bugs with the 'are semaphores enabled' mechanism. I.e. correcting pieces of code that used semaphores without checking if they are enabled. And presumably this would be broken if someone tried to disable semaphores in execlist mode for any reason?
Quoted 3 lines
So I think keeping the existing comment text is fine but something should be added to explain the actual changes.
Yes, commit is wrong. This more or less bug fix to the existing code. Will update.
Matt
Quoted 29 lines
John.
Quoted 25 lines
--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_context.c +4
-2@@ -230,7 +230,8 @@ static void intel_context_set_gem(struct intel_context *ce, ce->timeline =intel_timeline_get (ctx->timeline);if (ctx->sched.priority >=I915_PRIORITY_NORMAL && -intel_engine_has_timeslices (ce->engine)) +intel_engine_has_timeslices (ce->engine) && +intel_engine_has_semaphores (ce->engine))__set_bit (CONTEXT_USE_SEMAPHORES , &ce->flags);intel_context_set_watchdog_us (ce, ctx->watchdog.timeout_us);@@ -1938,7 +1939,8 @@ static int __apply_priority(struct intel_context *ce, void *arg)if (!intel_engine_has_timeslices (ce->engine))return 0 ; -if (ctx->sched.priority >=I915_PRIORITY_NORMAL ) +if (ctx->sched.priority >=I915_PRIORITY_NORMAL && +intel_engine_has_semaphores (ce->engine))intel_context_set_use_semaphores (ce);else intel_context_clear_use_semaphores (ce);
PATCH 21/47 drm/i915/guc: Ensure G2H response has space in buffer
In reply to Matthew BrostEnsure G2H response has space in the buffer before sending H2G CTB as the GuC can't handle any backpressure on the G2H interface.
--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 13 +++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 76 +++++++++++++++---- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 4 +- drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 13 ++-- 5 files changed, 87 insertions(+), 23 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +10 -3
@@ -95,11 +95,17 @@ inline int intel_guc_send(struct intel_guc *guc, const u32 *action, u32 len) }#define INTEL_GUC_SEND_NB BIT(31) +#define INTEL_GUC_SEND_G2H_DW_SHIFT 0 +#define INTEL_GUC_SEND_G2H_DW_MASK (0xff << INTEL_GUC_SEND_G2H_DW_SHIFT) +#define MAKE_SEND_FLAGS (len) \ + ({GEM_BUG_ON(!FIELD_FIT(INTEL_GUC_SEND_G2H_DW_MASK, len)); \ + (FIELD_PREP(INTEL_GUC_SEND_G2H_DW_MASK, len) | INTEL_GUC_SEND_NB);})static -inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len, +u32 g2h_len_dw) {return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , -INTEL_GUC_SEND_NB ); +MAKE_SEND_FLAGS (g2h_len_dw)); } static inline int
@@ -113,6 +119,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len,static inline int intel_guc_send_busy_loop (struct intel_guc * guc,const u32 *action,u32 len, +u32 g2h_len_dw,bool loop) {int err;
@@ -121,7 +128,7 @@ static inline int intel_guc_send_busy_loop(struct intel_guc* guc,might_sleep_if (loop && (!in_atomic () && !irqs_disabled ())); retry: - err =intel_guc_send_nb (guc, action, len); + err =intel_guc_send_nb (guc, action, len, g2h_len_dw);if (unlikely (err == -EBUSY && loop)) {if (likely (!in_atomic () && !irqs_disabled ()))cond_resched ();
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +62 -14
186 lines not on this page · raw message
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3 -1
@@ -33,6 +33,7 @@ struct intel_guc;* @desc: pointer to the buffer descriptor * @cmds: pointer to the commands buffer * @size: size of the commands buffer in dwords +* @resv_space: reserved space in buffer in dwords * @head: local shadow copy of head in dwords * @tail: local shadow copy of tail in dwords * @space: local shadow copy of space in dwords
@@ -43,9 +44,10 @@ struct intel_guc_ct_buffer {struct guc_ct_buffer_desc *desc;u32 *cmds;u32 size; +u32 resv_space;u32 tail;u32 head; -u32 space; +atomic_t space;bool broken; };
drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h +4 -0
@@ -17,6 +17,10 @@#include "abi/guc_communication_ctb_abi.h" #include "abi/guc_messages_abi.h" +/* Payload length only i.e. don't include G2H header length */ +#define G2H_LEN_DW_SCHED_CONTEXT_MODE_SET 2 +#define G2H_LEN_DW_DEREGISTER_CONTEXT 1 +#define GUC_CONTEXT_DISABLE 0#define GUC_CONTEXT_ENABLE 1
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +8 -5
@@ -260,6 +260,7 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)struct intel_context *ce = rq->context;u32 action[3 ];int len =0 ; +u32 g2h_len_dw =0 ;bool enabled =context_enabled (ce);GEM_BUG_ON (!atomic_read (&ce->guc_id_ref));
@@ -271,13 +272,13 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq) action[len++] =GUC_CONTEXT_ENABLE ;set_context_pending_enable (ce);intel_context_get (ce); + g2h_len_dw =G2H_LEN_DW_SCHED_CONTEXT_MODE_SET ; }else { action[len++] =INTEL_GUC_ACTION_SCHED_CONTEXT ; action[len++] = ce->guc_id; } - err =intel_guc_send_nb (guc, action, len); - + err =intel_guc_send_nb (guc, action, len, g2h_len_dw);if (!enabled && !err) {set_context_enabled (ce); }else if (!enabled) {
@@ -730,7 +731,7 @@ static int __guc_action_register_context(struct intel_guc *guc, offset, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), true); +return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); }static int register_context (struct intel_context *ce)
@@ -750,7 +751,8 @@ static int __guc_action_deregister_context(struct intel_guc *guc, guc_id, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), true); +return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +G2H_LEN_DW_DEREGISTER_CONTEXT , true); }static int deregister_context (struct intel_context *ce,u32 guc_id)
@@ -889,7 +891,8 @@ static void __guc_context_sched_disable(struct intel_guc *guc,intel_context_get (ce); -intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), true); +intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +G2H_LEN_DW_SCHED_CONTEXT_MODE_SET , true); }static u16 prep_context_pending_disable (struct intel_context *ce)
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 21/47] drm/i915/guc: Ensure G2H response has space in buffer
Quoted 59 lines · Matthew Brost
Ensure G2H response has space in the buffer before sending H2G CTB as the GuC can't handle any backpressure on the G2H interface.
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 13 +++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 76 +++++++++++++++---- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 4 +- drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 13 ++-- 5 files changed, 87 insertions(+), 23 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc.h +10
-3@@ -95,11 +95,17 @@ inline int intel_guc_send(struct intel_guc *guc, const u32 *action, u32 len) }#define INTEL_GUC_SEND_NB BIT(31) +#define INTEL_GUC_SEND_G2H_DW_SHIFT 0 +#define INTEL_GUC_SEND_G2H_DW_MASK (0xff << INTEL_GUC_SEND_G2H_DW_SHIFT) +#define MAKE_SEND_FLAGS (len) \ + ({GEM_BUG_ON(!FIELD_FIT(INTEL_GUC_SEND_G2H_DW_MASK, len)); \ + (FIELD_PREP(INTEL_GUC_SEND_G2H_DW_MASK, len) | INTEL_GUC_SEND_NB);})static -inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len, +u32 g2h_len_dw) {return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , -INTEL_GUC_SEND_NB ); +MAKE_SEND_FLAGS (g2h_len_dw)); } static inline int@@ -113,6 +119,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len,static inline int intel_guc_send_busy_loop (struct intel_guc * guc,const u32 *action,u32 len, +u32 g2h_len_dw,bool loop) {int err;@@ -121,7 +128,7 @@ static inline int intel_guc_send_busy_loop(struct intel_guc* guc,might_sleep_if (loop && (!in_atomic () && !irqs_disabled ())); retry: - err =intel_guc_send_nb (guc, action, len); + err =intel_guc_send_nb (guc, action, len, g2h_len_dw);if (unlikely (err == -EBUSY && loop)) {if (likely (!in_atomic () && !irqs_disabled ()))cond_resched ();drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct) · line 76
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0@@ -73,6 +73,7 @@ static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct)#define CTB_DESC_SIZE ALIGN(sizeof(struct guc_ct_buffer_desc), SZ_2K)#define CTB_H2G_BUFFER_SIZE (SZ_4K)#define CTB_G2H_BUFFER_SIZE (4 * CTB_H2G_BUFFER_SIZE) +#define G2H_ROOM_BUFFER_SIZE (PAGE_SIZE)
Any particular reason why PAGE_SIZE instead of SZ_4K? I'm not seeing anything in the code that is actually related to page sizes. Seems like '(CTB_G2H_BUFFER_SIZE / 4)' would be a more correct way to express it. Unless I'm missing something about how it's used?
John.
Quoted 279 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +61
-14struct ct_request {struct list_head link;@@ -129,23 +130,27 @@ static void guc_ct_buffer_desc_init(struct guc_ct_buffer_desc *desc)static void guc_ct_buffer_reset (struct intel_guc_ct_buffer *ctb) { +u32 space; + ctb->broken = false; ctb->tail =0 ; ctb->head =0 ; - ctb->space =CIRC_SPACE (ctb->tail, ctb->head, ctb->size); + space =CIRC_SPACE (ctb->tail, ctb->head, ctb->size) - ctb->resv_space; +atomic_set (&ctb->space, space);guc_ct_buffer_desc_init (ctb->desc); }static void guc_ct_buffer_init (struct intel_guc_ct_buffer *ctb,struct guc_ct_buffer_desc *desc, -u32 *cmds,u32 size_in_bytes) +u32 *cmds,u32 size_in_bytes,u32 resv_space) {GEM_BUG_ON (size_in_bytes %4 ); ctb->desc = desc; ctb->cmds = cmds; ctb->size = size_in_bytes /4 ; + ctb->resv_space = resv_space /4 ;guc_ct_buffer_reset (ctb); }@@ -226,6 +231,7 @@ int intel_guc_ct_init(struct intel_guc_ct *ct)struct guc_ct_buffer_desc *desc;u32 blob_size;u32 cmds_size; +u32 resv_space;void *blob;u32 *cmds;int err;@@ -250,19 +256,23 @@ int intel_guc_ct_init(struct intel_guc_ct *ct) desc = blob; cmds = blob +2 *CTB_DESC_SIZE ; cmds_size =CTB_H2G_BUFFER_SIZE ; -CT_DEBUG (ct,"%s desc %#tx cmds %#tx size %u\n" ,"send" , -ptrdiff (desc, blob),ptrdiff (cmds, blob), cmds_size); + resv_space =0 ; +CT_DEBUG (ct,"%s desc %#tx cmds %#tx size %u/%u\n" ,"send" , +ptrdiff (desc, blob),ptrdiff (cmds, blob), cmds_size, + resv_space); -guc_ct_buffer_init (&ct->ctbs.send, desc, cmds, cmds_size); +guc_ct_buffer_init (&ct->ctbs.send, desc, cmds, cmds_size, resv_space);/* store pointers to desc and cmds for recv ctb */ desc = blob +CTB_DESC_SIZE ; cmds = blob +2 *CTB_DESC_SIZE +CTB_H2G_BUFFER_SIZE ; cmds_size =CTB_G2H_BUFFER_SIZE ; -CT_DEBUG (ct,"%s desc %#tx cmds %#tx size %u\n" ,"recv" , -ptrdiff (desc, blob),ptrdiff (cmds, blob), cmds_size); + resv_space =G2H_ROOM_BUFFER_SIZE ; +CT_DEBUG (ct,"%s desc %#tx cmds %#tx size %u/%u\n" ,"recv" , +ptrdiff (desc, blob),ptrdiff (cmds, blob), cmds_size, + resv_space); -guc_ct_buffer_init (&ct->ctbs.recv, desc, cmds, cmds_size); +guc_ct_buffer_init (&ct->ctbs.recv, desc, cmds, cmds_size, resv_space);return 0 ; }@@ -458,7 +468,7 @@ static int ct_write(struct intel_guc_ct *ct,/* now update descriptor */ ctb->tail = tail;WRITE_ONCE (desc->tail, tail); - ctb->space -= len +1 ; +atomic_sub (len +1 , &ctb->space);return 0 ;@@ -521,13 +531,34 @@ static inline bool ct_deadlocked(struct intel_guc_ct *ct)return ret; } +static inline bool g2h_has_room (struct intel_guc_ct *ct,u32 g2h_len_dw) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.recv; + +/* +* We leave a certain amount of space in the G2H CTB buffer for +* unexpected G2H CTBs (e.g. logging, engine hang, etc...) +*/ +return !g2h_len_dw ||atomic_read (&ctb->space) >= g2h_len_dw; +} + +static inline void g2h_reserve_space (struct intel_guc_ct *ct,u32 g2h_len_dw) +{ +lockdep_assert_held (&ct->ctbs.send.lock); + +GEM_BUG_ON (!g2h_has_room (ct, g2h_len_dw)); + +if (g2h_len_dw) +atomic_sub (g2h_len_dw, &ct->ctbs.recv.space); +} +static inline bool h2g_has_room (struct intel_guc_ct *ct,u32 len_dw) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;u32 head;u32 space; -if (ctb->space >= len_dw) +if (atomic_read (&ctb->space) >= len_dw)return true; head =READ_ONCE (ctb->desc->head);@@ -540,16 +571,16 @@ static inline bool h2g_has_room(struct intel_guc_ct *ct, u32 len_dw) } space =CIRC_SPACE (ctb->tail, head, ctb->size); - ctb->space = space; +atomic_set (&ctb->space, space);return space >= len_dw; } -static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw) +static int has_room_nb (struct intel_guc_ct *ct,u32 h2g_dw,u32 g2h_dw) {lockdep_assert_held (&ct->ctbs.send.lock); -if (unlikely (!h2g_has_room (ct, len_dw))) { +if (unlikely (!h2g_has_room (ct, h2g_dw) || !g2h_has_room (ct, g2h_dw))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get ();@@ -563,6 +594,9 @@ static int has_room_nb(struct intel_guc_ct *ct, u32 len_dw)return 0 ; } +#define G2H_LEN_DW (f) \ + FIELD_GET(INTEL_GUC_SEND_G2H_DW_MASK, f) ? \ + FIELD_GET(INTEL_GUC_SEND_G2H_DW_MASK, f) + GUC_CTB_HXG_MSG_MIN_LEN : 0 static int ct_send_nb(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -570,12 +604,13 @@ static int ct_send_nb(struct intel_guc_ct *ct, {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;unsigned long spin_flags; +u32 g2h_len_dw =G2H_LEN_DW (flags);u32 fence;int ret;spin_lock_irqsave (&ctb->lock, spin_flags); - ret =has_room_nb (ct, len +1 ); + ret =has_room_nb (ct, len +1 , g2h_len_dw);if (unlikely (ret)) goto out;@@ -584,6 +619,7 @@ static int ct_send_nb(struct intel_guc_ct *ct,if (unlikely (ret)) goto out; +g2h_reserve_space (ct, g2h_len_dw);intel_guc_notify (ct_to_guc (ct)); out:@@ -965,10 +1001,22 @@ static void ct_incoming_request_worker_func(struct work_struct *w)static int ct_handle_event (struct intel_guc_ct *ct,struct ct_incoming_msg *request) {const u32 *hxg = &request->msg[GUC_CTB_MSG_MIN_LEN ]; +u32 action =FIELD_GET (GUC_HXG_EVENT_MSG_0_ACTION , hxg[0 ]);unsigned long flags;GEM_BUG_ON (FIELD_GET (GUC_HXG_MSG_0_TYPE , hxg[0 ]) !=GUC_HXG_TYPE_EVENT ); +/* +* Adjusting the space must be done in IRQ or deadlock can occur as the +* CTB processing in the below workqueue can send CTBs which creates a +* circular dependency if the space was returned there. +*/ +switch (action) { +case INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_DONE : +case INTEL_GUC_ACTION_DEREGISTER_CONTEXT_DONE : +atomic_add (request->size, &ct->ctbs.recv.space); + } +spin_lock_irqsave (&ct->requests.lock, flags);list_add_tail (&request->link, &ct->requests.incoming);spin_unlock_irqrestore (&ct->requests.lock, flags);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-1@@ -33,6 +33,7 @@ struct intel_guc;* @desc: pointer to the buffer descriptor * @cmds: pointer to the commands buffer * @size: size of the commands buffer in dwords +* @resv_space: reserved space in buffer in dwords * @head: local shadow copy of head in dwords * @tail: local shadow copy of tail in dwords * @space: local shadow copy of space in dwords @@ -43,9 +44,10 @@ struct intel_guc_ct_buffer {struct guc_ct_buffer_desc *desc;u32 *cmds;u32 size; +u32 resv_space;u32 tail;u32 head; -u32 space; +atomic_t space;bool broken; };drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h +4
-0@@ -17,6 +17,10 @@#include "abi/guc_communication_ctb_abi.h" #include "abi/guc_messages_abi.h" +/* Payload length only i.e. don't include G2H header length */ +#define G2H_LEN_DW_SCHED_CONTEXT_MODE_SET 2 +#define G2H_LEN_DW_DEREGISTER_CONTEXT 1 +#define GUC_CONTEXT_DISABLE 0#define GUC_CONTEXT_ENABLE 1drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +6
-4@@ -260,6 +260,7 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)struct intel_context *ce = rq->context;u32 action[3 ];int len =0 ; +u32 g2h_len_dw =0 ;bool enabled =context_enabled (ce);GEM_BUG_ON (!atomic_read (&ce->guc_id_ref));@@ -271,13 +272,13 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq) action[len++] =GUC_CONTEXT_ENABLE ;set_context_pending_enable (ce);intel_context_get (ce); + g2h_len_dw =G2H_LEN_DW_SCHED_CONTEXT_MODE_SET ; }else { action[len++] =INTEL_GUC_ACTION_SCHED_CONTEXT ; action[len++] = ce->guc_id; } - err =intel_guc_send_nb (guc, action, len); - + err =intel_guc_send_nb (guc, action, len, g2h_len_dw);if (!enabled && !err) {set_context_enabled (ce); }else if (!enabled) {@@ -730,7 +731,7 @@ static int __guc_action_register_context(struct intel_guc *guc, offset, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), true); +return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); }static int register_context (struct intel_context *ce)@@ -750,7 +751,8 @@ static int __guc_action_deregister_context(struct intel_guc *guc, guc_id, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), true); +return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +G2H_LEN_DW_DEREGISTER_CONTEXT , true); }static int deregister_context (struct intel_context *ce,u32 guc_id)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void __guc_context_sched_disable(struct intel_guc *guc, · line 898
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-1@@ -889,7 +891,8 @@ static void __guc_context_sched_disable(struct intel_guc *guc,intel_context_get (ce); -intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), true); +intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +G2H_LEN_DW_SCHED_CONTEXT_MODE_SET , true); }static u16 prep_context_pending_disable (struct intel_context *ce)
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 21/47] drm/i915/guc: Ensure G2H response has space in buffer
Quoted 57 lines · John Harrison
Quoted 56 lines · Matthew Brost
Ensure G2H response has space in the buffer before sending H2G CTB as the GuC can't handle any backpressure on the G2H interface.
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 13 +++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 76 +++++++++++++++---- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 4 +- drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 13 ++-- 5 files changed, 87 insertions(+), 23 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc.h +10
-3@@ -95,11 +95,17 @@ inline int intel_guc_send(struct intel_guc *guc, const u32 *action, u32 len) }#define INTEL_GUC_SEND_NB BIT(31) +#define INTEL_GUC_SEND_G2H_DW_SHIFT 0 +#define INTEL_GUC_SEND_G2H_DW_MASK (0xff << INTEL_GUC_SEND_G2H_DW_SHIFT) +#define MAKE_SEND_FLAGS (len) \ + ({GEM_BUG_ON(!FIELD_FIT(INTEL_GUC_SEND_G2H_DW_MASK, len)); \ + (FIELD_PREP(INTEL_GUC_SEND_G2H_DW_MASK, len) | INTEL_GUC_SEND_NB);})static -inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len, +u32 g2h_len_dw) {return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , -INTEL_GUC_SEND_NB ); +MAKE_SEND_FLAGS (g2h_len_dw)); } static inline int@@ -113,6 +119,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len,static inline int intel_guc_send_busy_loop (struct intel_guc * guc,const u32 *action,u32 len, +u32 g2h_len_dw,bool loop) {int err;@@ -121,7 +128,7 @@ static inline int intel_guc_send_busy_loop(struct intel_guc* guc,might_sleep_if (loop && (!in_atomic () && !irqs_disabled ())); retry: - err =intel_guc_send_nb (guc, action, len); + err =intel_guc_send_nb (guc, action, len, g2h_len_dw);if (unlikely (err == -EBUSY && loop)) {if (likely (!in_atomic () && !irqs_disabled ()))cond_resched ();drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0@@ -73,6 +73,7 @@ static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct)
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct) · line 76
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0#define CTB_DESC_SIZE ALIGN(sizeof(struct guc_ct_buffer_desc), SZ_2K)#define CTB_H2G_BUFFER_SIZE (SZ_4K)#define CTB_G2H_BUFFER_SIZE (4 * CTB_H2G_BUFFER_SIZE) +#define G2H_ROOM_BUFFER_SIZE (PAGE_SIZE)Any particular reason why
PAGE_SIZEinstead ofSZ_4K? I'm not seeing anything in the code that is actually related to page sizes. Seems like '(CTB_G2H_BUFFER_SIZE/ 4)' would be a more correct way to express it. Unless I'm missing something about how it's used?
Yes, CTB_G2H_BUFFER_SIZE / 4 is better.
Matt
Quoted 243 lines
John.
Quoted 240 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +61
-14struct ct_request {struct list_head link;@@ -129,23 +130,27 @@ static void guc_ct_buffer_desc_init(struct guc_ct_buffer_desc *desc)static void guc_ct_buffer_reset (struct intel_guc_ct_buffer *ctb) { +u32 space; + ctb->broken = false; ctb->tail =0 ; ctb->head =0 ; - ctb->space =CIRC_SPACE (ctb->tail, ctb->head, ctb->size); + space =CIRC_SPACE (ctb->tail, ctb->head, ctb->size) - ctb->resv_space; +atomic_set (&ctb->space, space);guc_ct_buffer_desc_init (ctb->desc); }static void guc_ct_buffer_init (struct intel_guc_ct_buffer *ctb,struct guc_ct_buffer_desc *desc, -u32 *cmds,u32 size_in_bytes) +u32 *cmds,u32 size_in_bytes,u32 resv_space) {GEM_BUG_ON (size_in_bytes %4 ); ctb->desc = desc; ctb->cmds = cmds; ctb->size = size_in_bytes /4 ; + ctb->resv_space = resv_space /4 ;guc_ct_buffer_reset (ctb); }@@ -226,6 +231,7 @@ int intel_guc_ct_init(struct intel_guc_ct *ct)struct guc_ct_buffer_desc *desc;u32 blob_size;u32 cmds_size; +u32 resv_space;void *blob;u32 *cmds;int err;@@ -250,19 +256,23 @@ int intel_guc_ct_init(struct intel_guc_ct *ct) desc = blob; cmds = blob +2 *CTB_DESC_SIZE ; cmds_size =CTB_H2G_BUFFER_SIZE ; -CT_DEBUG (ct,"%s desc %#tx cmds %#tx size %u\n" ,"send" , -ptrdiff (desc, blob),ptrdiff (cmds, blob), cmds_size); + resv_space =0 ; +CT_DEBUG (ct,"%s desc %#tx cmds %#tx size %u/%u\n" ,"send" , +ptrdiff (desc, blob),ptrdiff (cmds, blob), cmds_size, + resv_space); -guc_ct_buffer_init (&ct->ctbs.send, desc, cmds, cmds_size); +guc_ct_buffer_init (&ct->ctbs.send, desc, cmds, cmds_size, resv_space);/* store pointers to desc and cmds for recv ctb */ desc = blob +CTB_DESC_SIZE ; cmds = blob +2 *CTB_DESC_SIZE +CTB_H2G_BUFFER_SIZE ; cmds_size =CTB_G2H_BUFFER_SIZE ; -CT_DEBUG (ct,"%s desc %#tx cmds %#tx size %u\n" ,"recv" , -ptrdiff (desc, blob),ptrdiff (cmds, blob), cmds_size); + resv_space =G2H_ROOM_BUFFER_SIZE ; +CT_DEBUG (ct,"%s desc %#tx cmds %#tx size %u/%u\n" ,"recv" , +ptrdiff (desc, blob),ptrdiff (cmds, blob), cmds_size, + resv_space); -guc_ct_buffer_init (&ct->ctbs.recv, desc, cmds, cmds_size); +guc_ct_buffer_init (&ct->ctbs.recv, desc, cmds, cmds_size, resv_space);return 0 ; }@@ -458,7 +468,7 @@ static int ct_write(struct intel_guc_ct *ct,/* now update descriptor */ ctb->tail = tail;WRITE_ONCE (desc->tail, tail); - ctb->space -= len +1 ; +atomic_sub (len +1 , &ctb->space);return 0 ;@@ -521,13 +531,34 @@ static inline bool ct_deadlocked(struct intel_guc_ct *ct)return ret; } +static inline bool g2h_has_room (struct intel_guc_ct *ct,u32 g2h_len_dw) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.recv; + +/* +* We leave a certain amount of space in the G2H CTB buffer for +* unexpected G2H CTBs (e.g. logging, engine hang, etc...) +*/ +return !g2h_len_dw ||atomic_read (&ctb->space) >= g2h_len_dw; +} + +static inline void g2h_reserve_space (struct intel_guc_ct *ct,u32 g2h_len_dw) +{ +lockdep_assert_held (&ct->ctbs.send.lock); + +GEM_BUG_ON (!g2h_has_room (ct, g2h_len_dw)); + +if (g2h_len_dw) +atomic_sub (g2h_len_dw, &ct->ctbs.recv.space); +} +static inline bool h2g_has_room (struct intel_guc_ct *ct,u32 len_dw) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;u32 head;u32 space; -if (ctb->space >= len_dw) +if (atomic_read (&ctb->space) >= len_dw)return true; head =READ_ONCE (ctb->desc->head);@@ -540,16 +571,16 @@ static inline bool h2g_has_room(struct intel_guc_ct *ct, u32 len_dw) } space =CIRC_SPACE (ctb->tail, head, ctb->size); - ctb->space = space; +atomic_set (&ctb->space, space);return space >= len_dw; } -static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw) +static int has_room_nb (struct intel_guc_ct *ct,u32 h2g_dw,u32 g2h_dw) {lockdep_assert_held (&ct->ctbs.send.lock); -if (unlikely (!h2g_has_room (ct, len_dw))) { +if (unlikely (!h2g_has_room (ct, h2g_dw) || !g2h_has_room (ct, g2h_dw))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get ();@@ -563,6 +594,9 @@ static int has_room_nb(struct intel_guc_ct *ct, u32 len_dw)return 0 ; } +#define G2H_LEN_DW (f) \ + FIELD_GET(INTEL_GUC_SEND_G2H_DW_MASK, f) ? \ + FIELD_GET(INTEL_GUC_SEND_G2H_DW_MASK, f) + GUC_CTB_HXG_MSG_MIN_LEN : 0 static int ct_send_nb(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -570,12 +604,13 @@ static int ct_send_nb(struct intel_guc_ct *ct, {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;unsigned long spin_flags; +u32 g2h_len_dw =G2H_LEN_DW (flags);u32 fence;int ret;spin_lock_irqsave (&ctb->lock, spin_flags); - ret =has_room_nb (ct, len +1 ); + ret =has_room_nb (ct, len +1 , g2h_len_dw);if (unlikely (ret)) goto out;@@ -584,6 +619,7 @@ static int ct_send_nb(struct intel_guc_ct *ct,if (unlikely (ret)) goto out; +g2h_reserve_space (ct, g2h_len_dw);intel_guc_notify (ct_to_guc (ct)); out:@@ -965,10 +1001,22 @@ static void ct_incoming_request_worker_func(struct work_struct *w)static int ct_handle_event (struct intel_guc_ct *ct,struct ct_incoming_msg *request) {const u32 *hxg = &request->msg[GUC_CTB_MSG_MIN_LEN ]; +u32 action =FIELD_GET (GUC_HXG_EVENT_MSG_0_ACTION , hxg[0 ]);unsigned long flags;GEM_BUG_ON (FIELD_GET (GUC_HXG_MSG_0_TYPE , hxg[0 ]) !=GUC_HXG_TYPE_EVENT ); +/* +* Adjusting the space must be done in IRQ or deadlock can occur as the +* CTB processing in the below workqueue can send CTBs which creates a +* circular dependency if the space was returned there. +*/ +switch (action) { +case INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_DONE : +case INTEL_GUC_ACTION_DEREGISTER_CONTEXT_DONE : +atomic_add (request->size, &ct->ctbs.recv.space); + } +spin_lock_irqsave (&ct->requests.lock, flags);list_add_tail (&request->link, &ct->requests.incoming);spin_unlock_irqrestore (&ct->requests.lock, flags);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-1@@ -33,6 +33,7 @@ struct intel_guc;* @desc: pointer to the buffer descriptor * @cmds: pointer to the commands buffer * @size: size of the commands buffer in dwords +* @resv_space: reserved space in buffer in dwords * @head: local shadow copy of head in dwords * @tail: local shadow copy of tail in dwords * @space: local shadow copy of space in dwords @@ -43,9 +44,10 @@ struct intel_guc_ct_buffer {struct guc_ct_buffer_desc *desc;u32 *cmds;u32 size; +u32 resv_space;u32 tail;u32 head; -u32 space; +atomic_t space;bool broken; };drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h +4
-0@@ -17,6 +17,10 @@#include "abi/guc_communication_ctb_abi.h" #include "abi/guc_messages_abi.h" +/* Payload length only i.e. don't include G2H header length */ +#define G2H_LEN_DW_SCHED_CONTEXT_MODE_SET 2 +#define G2H_LEN_DW_DEREGISTER_CONTEXT 1 +#define GUC_CONTEXT_DISABLE 0#define GUC_CONTEXT_ENABLE 1drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +6
-4@@ -260,6 +260,7 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)struct intel_context *ce = rq->context;u32 action[3 ];int len =0 ; +u32 g2h_len_dw =0 ;bool enabled =context_enabled (ce);GEM_BUG_ON (!atomic_read (&ce->guc_id_ref));@@ -271,13 +272,13 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq) action[len++] =GUC_CONTEXT_ENABLE ;set_context_pending_enable (ce);intel_context_get (ce); + g2h_len_dw =G2H_LEN_DW_SCHED_CONTEXT_MODE_SET ; }else { action[len++] =INTEL_GUC_ACTION_SCHED_CONTEXT ; action[len++] = ce->guc_id; } - err =intel_guc_send_nb (guc, action, len); - + err =intel_guc_send_nb (guc, action, len, g2h_len_dw);if (!enabled && !err) {set_context_enabled (ce); }else if (!enabled) {@@ -730,7 +731,7 @@ static int __guc_action_register_context(struct intel_guc *guc, offset, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), true); +return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); }static int register_context (struct intel_context *ce)@@ -750,7 +751,8 @@ static int __guc_action_deregister_context(struct intel_guc *guc, guc_id, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), true); +return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +G2H_LEN_DW_DEREGISTER_CONTEXT , true); }
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void __guc_context_sched_disable(struct intel_guc *guc, · line 895
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-1static int deregister_context (struct intel_context *ce,u32 guc_id)@@ -889,7 +891,8 @@ static void __guc_context_sched_disable(struct intel_guc *guc,intel_context_get (ce); -intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), true); +intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +G2H_LEN_DW_SCHED_CONTEXT_MODE_SET , true); }static u16 prep_context_pending_disable (struct intel_context *ce)
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
John Harrison
Reviewed-byRe: [PATCH 21/47] drm/i915/guc: Ensure G2H response has space in buffer
Quoted 67 lines · Matthew Brost
Quoted 57 lines · John Harrison
Quoted 56 lines · Matthew Brost
Ensure G2H response has space in the buffer before sending H2G CTB as the GuC can't handle any backpressure on the G2H interface.
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 13 +++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 76 +++++++++++++++---- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 4 +- drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 13 ++-- 5 files changed, 87 insertions(+), 23 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc.h +10
-3@@ -95,11 +95,17 @@ inline int intel_guc_send(struct intel_guc *guc, const u32 *action, u32 len) }#define INTEL_GUC_SEND_NB BIT(31) +#define INTEL_GUC_SEND_G2H_DW_SHIFT 0 +#define INTEL_GUC_SEND_G2H_DW_MASK (0xff << INTEL_GUC_SEND_G2H_DW_SHIFT) +#define MAKE_SEND_FLAGS (len) \ + ({GEM_BUG_ON(!FIELD_FIT(INTEL_GUC_SEND_G2H_DW_MASK, len)); \ + (FIELD_PREP(INTEL_GUC_SEND_G2H_DW_MASK, len) | INTEL_GUC_SEND_NB);})static -inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len, +u32 g2h_len_dw) {return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , -INTEL_GUC_SEND_NB ); +MAKE_SEND_FLAGS (g2h_len_dw)); } static inline int@@ -113,6 +119,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len,static inline int intel_guc_send_busy_loop (struct intel_guc * guc,const u32 *action,u32 len, +u32 g2h_len_dw,bool loop) {int err;@@ -121,7 +128,7 @@ static inline int intel_guc_send_busy_loop(struct intel_guc* guc,might_sleep_if (loop && (!in_atomic () && !irqs_disabled ())); retry: - err =intel_guc_send_nb (guc, action, len); + err =intel_guc_send_nb (guc, action, len, g2h_len_dw);if (unlikely (err == -EBUSY && loop)) {if (likely (!in_atomic () && !irqs_disabled ()))cond_resched ();drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0@@ -73,6 +73,7 @@ static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct)Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct) · line 76
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0#define CTB_DESC_SIZE ALIGN(sizeof(struct guc_ct_buffer_desc), SZ_2K)#define CTB_H2G_BUFFER_SIZE (SZ_4K)#define CTB_G2H_BUFFER_SIZE (4 * CTB_H2G_BUFFER_SIZE) +#define G2H_ROOM_BUFFER_SIZE (PAGE_SIZE)Any particular reason why
PAGE_SIZEinstead ofSZ_4K? I'm not seeing anything in the code that is actually related to page sizes. Seems like '(CTB_G2H_BUFFER_SIZE/ 4)' would be a more correct way to express it. Unless I'm missing something about how it's used?
Quoted 3 lines
Yes,
CTB_G2H_BUFFER_SIZE/ 4 is better.Matt
Okay. With that changed:
Quoted 252 lines
Quoted 252 lines
John.
Quoted 248 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +61
-14struct ct_request {struct list_head link;@@ -129,23 +130,27 @@ static void guc_ct_buffer_desc_init(struct guc_ct_buffer_desc *desc)static void guc_ct_buffer_reset (struct intel_guc_ct_buffer *ctb) { +u32 space; + ctb->broken = false; ctb->tail =0 ; ctb->head =0 ; - ctb->space =CIRC_SPACE (ctb->tail, ctb->head, ctb->size); + space =CIRC_SPACE (ctb->tail, ctb->head, ctb->size) - ctb->resv_space; +atomic_set (&ctb->space, space);guc_ct_buffer_desc_init (ctb->desc); }static void guc_ct_buffer_init (struct intel_guc_ct_buffer *ctb,struct guc_ct_buffer_desc *desc, -u32 *cmds,u32 size_in_bytes) +u32 *cmds,u32 size_in_bytes,u32 resv_space) {GEM_BUG_ON (size_in_bytes %4 ); ctb->desc = desc; ctb->cmds = cmds; ctb->size = size_in_bytes /4 ; + ctb->resv_space = resv_space /4 ;guc_ct_buffer_reset (ctb); }@@ -226,6 +231,7 @@ int intel_guc_ct_init(struct intel_guc_ct *ct)struct guc_ct_buffer_desc *desc;u32 blob_size;u32 cmds_size; +u32 resv_space;void *blob;u32 *cmds;int err;@@ -250,19 +256,23 @@ int intel_guc_ct_init(struct intel_guc_ct *ct) desc = blob; cmds = blob +2 *CTB_DESC_SIZE ; cmds_size =CTB_H2G_BUFFER_SIZE ; -CT_DEBUG (ct,"%s desc %#tx cmds %#tx size %u\n" ,"send" , -ptrdiff (desc, blob),ptrdiff (cmds, blob), cmds_size); + resv_space =0 ; +CT_DEBUG (ct,"%s desc %#tx cmds %#tx size %u/%u\n" ,"send" , +ptrdiff (desc, blob),ptrdiff (cmds, blob), cmds_size, + resv_space); -guc_ct_buffer_init (&ct->ctbs.send, desc, cmds, cmds_size); +guc_ct_buffer_init (&ct->ctbs.send, desc, cmds, cmds_size, resv_space);/* store pointers to desc and cmds for recv ctb */ desc = blob +CTB_DESC_SIZE ; cmds = blob +2 *CTB_DESC_SIZE +CTB_H2G_BUFFER_SIZE ; cmds_size =CTB_G2H_BUFFER_SIZE ; -CT_DEBUG (ct,"%s desc %#tx cmds %#tx size %u\n" ,"recv" , -ptrdiff (desc, blob),ptrdiff (cmds, blob), cmds_size); + resv_space =G2H_ROOM_BUFFER_SIZE ; +CT_DEBUG (ct,"%s desc %#tx cmds %#tx size %u/%u\n" ,"recv" , +ptrdiff (desc, blob),ptrdiff (cmds, blob), cmds_size, + resv_space); -guc_ct_buffer_init (&ct->ctbs.recv, desc, cmds, cmds_size); +guc_ct_buffer_init (&ct->ctbs.recv, desc, cmds, cmds_size, resv_space);return 0 ; }@@ -458,7 +468,7 @@ static int ct_write(struct intel_guc_ct *ct,/* now update descriptor */ ctb->tail = tail;WRITE_ONCE (desc->tail, tail); - ctb->space -= len +1 ; +atomic_sub (len +1 , &ctb->space);return 0 ;@@ -521,13 +531,34 @@ static inline bool ct_deadlocked(struct intel_guc_ct *ct)return ret; } +static inline bool g2h_has_room (struct intel_guc_ct *ct,u32 g2h_len_dw) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.recv; + +/* +* We leave a certain amount of space in the G2H CTB buffer for +* unexpected G2H CTBs (e.g. logging, engine hang, etc...) +*/ +return !g2h_len_dw ||atomic_read (&ctb->space) >= g2h_len_dw; +} + +static inline void g2h_reserve_space (struct intel_guc_ct *ct,u32 g2h_len_dw) +{ +lockdep_assert_held (&ct->ctbs.send.lock); + +GEM_BUG_ON (!g2h_has_room (ct, g2h_len_dw)); + +if (g2h_len_dw) +atomic_sub (g2h_len_dw, &ct->ctbs.recv.space); +} +static inline bool h2g_has_room (struct intel_guc_ct *ct,u32 len_dw) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;u32 head;u32 space; -if (ctb->space >= len_dw) +if (atomic_read (&ctb->space) >= len_dw)return true; head =READ_ONCE (ctb->desc->head);@@ -540,16 +571,16 @@ static inline bool h2g_has_room(struct intel_guc_ct *ct, u32 len_dw) } space =CIRC_SPACE (ctb->tail, head, ctb->size); - ctb->space = space; +atomic_set (&ctb->space, space);return space >= len_dw; } -static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw) +static int has_room_nb (struct intel_guc_ct *ct,u32 h2g_dw,u32 g2h_dw) {lockdep_assert_held (&ct->ctbs.send.lock); -if (unlikely (!h2g_has_room (ct, len_dw))) { +if (unlikely (!h2g_has_room (ct, h2g_dw) || !g2h_has_room (ct, g2h_dw))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get ();@@ -563,6 +594,9 @@ static int has_room_nb(struct intel_guc_ct *ct, u32 len_dw)return 0 ; } +#define G2H_LEN_DW (f) \ + FIELD_GET(INTEL_GUC_SEND_G2H_DW_MASK, f) ? \ + FIELD_GET(INTEL_GUC_SEND_G2H_DW_MASK, f) + GUC_CTB_HXG_MSG_MIN_LEN : 0 static int ct_send_nb(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -570,12 +604,13 @@ static int ct_send_nb(struct intel_guc_ct *ct, {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;unsigned long spin_flags; +u32 g2h_len_dw =G2H_LEN_DW (flags);u32 fence;int ret;spin_lock_irqsave (&ctb->lock, spin_flags); - ret =has_room_nb (ct, len +1 ); + ret =has_room_nb (ct, len +1 , g2h_len_dw);if (unlikely (ret)) goto out;@@ -584,6 +619,7 @@ static int ct_send_nb(struct intel_guc_ct *ct,if (unlikely (ret)) goto out; +g2h_reserve_space (ct, g2h_len_dw);intel_guc_notify (ct_to_guc (ct)); out:@@ -965,10 +1001,22 @@ static void ct_incoming_request_worker_func(struct work_struct *w)static int ct_handle_event (struct intel_guc_ct *ct,struct ct_incoming_msg *request) {const u32 *hxg = &request->msg[GUC_CTB_MSG_MIN_LEN ]; +u32 action =FIELD_GET (GUC_HXG_EVENT_MSG_0_ACTION , hxg[0 ]);unsigned long flags;GEM_BUG_ON (FIELD_GET (GUC_HXG_MSG_0_TYPE , hxg[0 ]) !=GUC_HXG_TYPE_EVENT ); +/* +* Adjusting the space must be done in IRQ or deadlock can occur as the +* CTB processing in the below workqueue can send CTBs which creates a +* circular dependency if the space was returned there. +*/ +switch (action) { +case INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_DONE : +case INTEL_GUC_ACTION_DEREGISTER_CONTEXT_DONE : +atomic_add (request->size, &ct->ctbs.recv.space); + } +spin_lock_irqsave (&ct->requests.lock, flags);list_add_tail (&request->link, &ct->requests.incoming);spin_unlock_irqrestore (&ct->requests.lock, flags);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-1@@ -33,6 +33,7 @@ struct intel_guc;* @desc: pointer to the buffer descriptor * @cmds: pointer to the commands buffer * @size: size of the commands buffer in dwords +* @resv_space: reserved space in buffer in dwords * @head: local shadow copy of head in dwords * @tail: local shadow copy of tail in dwords * @space: local shadow copy of space in dwords @@ -43,9 +44,10 @@ struct intel_guc_ct_buffer {struct guc_ct_buffer_desc *desc;u32 *cmds;u32 size; +u32 resv_space;u32 tail;u32 head; -u32 space; +atomic_t space;bool broken; };drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h +4
-0@@ -17,6 +17,10 @@#include "abi/guc_communication_ctb_abi.h" #include "abi/guc_messages_abi.h" +/* Payload length only i.e. don't include G2H header length */ +#define G2H_LEN_DW_SCHED_CONTEXT_MODE_SET 2 +#define G2H_LEN_DW_DEREGISTER_CONTEXT 1 +#define GUC_CONTEXT_DISABLE 0#define GUC_CONTEXT_ENABLE 1drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +8
-5@@ -260,6 +260,7 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)struct intel_context *ce = rq->context;u32 action[3 ];int len =0 ; +u32 g2h_len_dw =0 ;bool enabled =context_enabled (ce);GEM_BUG_ON (!atomic_read (&ce->guc_id_ref));@@ -271,13 +272,13 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq) action[len++] =GUC_CONTEXT_ENABLE ;set_context_pending_enable (ce);intel_context_get (ce); + g2h_len_dw =G2H_LEN_DW_SCHED_CONTEXT_MODE_SET ; }else { action[len++] =INTEL_GUC_ACTION_SCHED_CONTEXT ; action[len++] = ce->guc_id; } - err =intel_guc_send_nb (guc, action, len); - + err =intel_guc_send_nb (guc, action, len, g2h_len_dw);if (!enabled && !err) {set_context_enabled (ce); }else if (!enabled) {@@ -730,7 +731,7 @@ static int __guc_action_register_context(struct intel_guc *guc, offset, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), true); +return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); }static int register_context (struct intel_context *ce)@@ -750,7 +751,8 @@ static int __guc_action_deregister_context(struct intel_guc *guc, guc_id, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), true); +return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +G2H_LEN_DW_DEREGISTER_CONTEXT , true); }static int deregister_context (struct intel_context *ce,u32 guc_id)@@ -889,7 +891,8 @@ static void __guc_context_sched_disable(struct intel_guc *guc,intel_context_get (ce); -intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), true); +intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +G2H_LEN_DW_SCHED_CONTEXT_MODE_SET , true); }static u16 prep_context_pending_disable (struct intel_context *ce)
PATCH 22/47 drm/i915/guc: Update intel_gt_wait_for_idle to work with GuC
In reply to Matthew BrostWhen running the GuC the GPU can't be considered idle if the GuC still has contexts pinned. As such, a call has been added in intel_gt_wait_for_idle to idle the UC and in turn the GuC by waiting for the number of unpinned contexts to go to zero.
v2: rtimeout -> remaining_timeout
--- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 3 +- drivers/gpu/drm/i915/gt/intel_gt.c | 19 ++++ drivers/gpu/drm/i915/gt/intel_gt.h | 2 + drivers/gpu/drm/i915/gt/intel_gt_requests.c | 22 ++--- drivers/gpu/drm/i915/gt/intel_gt_requests.h | 9 +- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 4 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 1 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 88 ++++++++++++++++++- drivers/gpu/drm/i915/gt/uc/intel_uc.h | 5 ++ drivers/gpu/drm/i915/i915_debugfs.c | 1 + drivers/gpu/drm/i915/i915_gem_evict.c | 1 + .../gpu/drm/i915/selftests/igt_live_test.c | 2 +- .../gpu/drm/i915/selftests/mock_gem_device.c | 3 +- 14 files changed, 137 insertions(+), 27 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_mman.c +2 -1
@@ -644,7 +644,8 @@ mmap_offset_attach(struct drm_i915_gem_object *obj, goto insert;/* Attempt to reap some mmap space from dead objects */ - err =intel_gt_retire_requests_timeout (&i915->gt,MAX_SCHEDULE_TIMEOUT ); + err =intel_gt_retire_requests_timeout (&i915->gt,MAX_SCHEDULE_TIMEOUT , +NULL );if (err) goto err;
drivers/gpu/drm/i915/gt/intel_gt.c +19 -0
@@ -585,6 +585,25 @@ static void __intel_gt_disable(struct intel_gt *gt)GEM_BUG_ON (intel_gt_pm_is_awake (gt)); } +int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout) +{ +long remaining_timeout; + +/* If the device is asleep, we have no requests outstanding */ +if (!intel_gt_pm_is_awake (gt)) +return 0 ; + +while ((timeout =intel_gt_retire_requests_timeout (gt, timeout, + &remaining_timeout)) >0 ) { +cond_resched (); +if (signal_pending (current)) +return -EINTR ; + } + +return timeout ? timeout :intel_uc_wait_for_idle (>->uc, + remaining_timeout); +} +int intel_gt_init (struct intel_gt *gt) {int err;
drivers/gpu/drm/i915/gt/intel_gt.h +2 -0
@@ -48,6 +48,8 @@ void intel_gt_driver_release(struct intel_gt *gt);void intel_gt_driver_late_release (struct intel_gt *gt); +int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout); +void intel_gt_check_and_clear_faults (struct intel_gt *gt);void intel_gt_clear_error_registers (struct intel_gt *gt,intel_engine_mask_t engine_mask);
drivers/gpu/drm/i915/gt/intel_gt_requests.c +6 -16
@@ -13,6 +13,7 @@#include "intel_gt_pm.h" #include "intel_gt_requests.h" #include "intel_timeline.h" +#include "uc/intel_uc.h" static bool retire_requests (struct intel_timeline *tl) {
@@ -130,7 +131,8 @@ void intel_engine_fini_retire(struct intel_engine_cs *engine)GEM_BUG_ON (engine->retire); } -long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout) +long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout, +long *remaining_timeout) {struct intel_gt_timelines *timelines = >->timelines;struct intel_timeline *tl, *tn;
@@ -195,22 +197,10 @@ out_active: spin_lock(&timelines->lock);if (flush_submission (gt, timeout))/* Wait, there's more! */ active_count++; -return active_count ? timeout :0 ; -} - -int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout) -{ -/* If the device is asleep, we have no requests outstanding */ -if (!intel_gt_pm_is_awake (gt)) -return 0 ; - -while ((timeout =intel_gt_retire_requests_timeout (gt, timeout)) >0 ) { -cond_resched (); -if (signal_pending (current)) -return -EINTR ; - } +if (remaining_timeout) + *remaining_timeout = timeout; -return timeout; +return active_count ? timeout :0 ; }static void retire_work_handler (struct work_struct *work)
drivers/gpu/drm/i915/gt/intel_gt_requests.h +5 -4
@@ -6,14 +6,17 @@#ifndef INTEL_GT_REQUESTS_H #define INTEL_GT_REQUESTS_H +#include <stddef.h> +struct intel_engine_cs ;struct intel_gt ;struct intel_timeline ; -long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout); +long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout, +long *remaining_timeout);static inline void intel_gt_retire_requests (struct intel_gt *gt) { -intel_gt_retire_requests_timeout (gt,0 ); +intel_gt_retire_requests_timeout (gt,0 ,NULL ); }void intel_engine_init_retire (struct intel_engine_cs *engine);
@@ -21,8 +24,6 @@ void intel_engine_add_retire(struct intel_engine_cs *engine, struct intel_timeline *tl);void intel_engine_fini_retire (struct intel_engine_cs *engine); -int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout); -void intel_gt_init_requests (struct intel_gt *gt);void intel_gt_park_requests (struct intel_gt *gt);void intel_gt_unpark_requests (struct intel_gt *gt);
drivers/gpu/drm/i915/gt/uc/intel_guc.h +4 -0
@@ -38,6 +38,8 @@ struct intel_guc {spinlock_t irq_lock;unsigned int msg_enabled_mask; +atomic_t outstanding_submission_g2h; +struct {void (*reset)(struct intel_guc *guc);void (*enable)(struct intel_guc *guc);
@@ -238,6 +240,8 @@ static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)spin_unlock_irq (&guc->irq_lock); } +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout); +int intel_guc_reset_engine (struct intel_guc *guc,struct intel_engine_cs *engine);
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1 -0
@@ -109,6 +109,7 @@ void intel_guc_ct_init_early(struct intel_guc_ct *ct)INIT_LIST_HEAD (&ct->requests.incoming);INIT_WORK (&ct->requests.worker, ct_incoming_request_worker_func);tasklet_setup (&ct->receive_tasklet, ct_receive_tasklet_func); +init_waitqueue_head (&ct->wq); }static inline const char *guc_ct_buffer_type_to_str (u32 type)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +4 -0
@@ -10,6 +10,7 @@#include <linux/spinlock.h> #include <linux/workqueue.h> #include <linux/ktime.h> +#include <linux/wait.h> #include "intel_guc_fwif.h"
@@ -68,6 +69,9 @@ struct intel_guc_ct {struct tasklet_struct receive_tasklet; +/** @wq: wait queue for g2h chanenl */ +wait_queue_head_t wq; +struct {u16 last_fence;/* last fence used to send request */
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +84 -4
142 lines not on this page · raw message
drivers/gpu/drm/i915/gt/uc/intel_uc.h +5 -0
@@ -81,6 +81,11 @@ uc_state_checkers(guc, guc_submission);#undef uc_state_checkers#undef __uc_state_checker +static inline int intel_uc_wait_for_idle (struct intel_uc *uc,long timeout) +{ +return intel_guc_wait_for_idle (&uc->guc, timeout); +} +#define intel_uc_ops_function (_NAME, _OPS, _TYPE, _RET) \ static inline _TYPE intel_uc_##_NAME(struct intel_uc *uc) \ { \
drivers/gpu/drm/i915/i915_debugfs.c +1 -0
@@ -36,6 +36,7 @@#include "gt/intel_gt_clock_utils.h" #include "gt/intel_gt.h" #include "gt/intel_gt_pm.h" +#include "gt/intel_gt.h" #include "gt/intel_gt_requests.h" #include "gt/intel_reset.h" #include "gt/intel_rc6.h"
drivers/gpu/drm/i915/i915_gem_evict.c +1 -0
@@ -27,6 +27,7 @@*/ #include "gem/i915_gem_context.h" +#include "gt/intel_gt.h" #include "gt/intel_gt_requests.h" #include "i915_drv.h"
drivers/gpu/drm/i915/selftests/igt_live_test.c +1 -1
@@ -5,7 +5,7 @@*/ #include "i915_drv.h" -#include "gt/intel_gt_requests.h" +#include "gt/intel_gt.h" #include "../i915_selftest.h" #include "igt_flush_test.h"
drivers/gpu/drm/i915/selftests/mock_gem_device.c +2 -1
@@ -52,7 +52,8 @@ void mock_device_flush(struct drm_i915_private *i915)do {for_each_engine (engine, gt, id)mock_engine_flush (engine); - }while (intel_gt_retire_requests_timeout (gt,MAX_SCHEDULE_TIMEOUT )); + }while (intel_gt_retire_requests_timeout (gt,MAX_SCHEDULE_TIMEOUT , +NULL )); }static void mock_device_release (struct drm_device *dev)
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 22/47] drm/i915/guc: Update intel_gt_wait_for_idle to work with GuC
Quoted 88 lines · Matthew Brost
When running the GuC the GPU can't be considered idle if the GuC still has contexts pinned. As such, a call has been added in
intel_gt_wait_for_idleto idle the UC and in turn the GuC by waiting for the number of unpinned contexts to go to zero.v2: rtimeout ->
remaining_timeoutCc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 3 +- drivers/gpu/drm/i915/gt/intel_gt.c | 19 ++++ drivers/gpu/drm/i915/gt/intel_gt.h | 2 + drivers/gpu/drm/i915/gt/intel_gt_requests.c | 22 ++--- drivers/gpu/drm/i915/gt/intel_gt_requests.h | 9 +- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 4 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 1 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 88 ++++++++++++++++++- drivers/gpu/drm/i915/gt/uc/intel_uc.h | 5 ++ drivers/gpu/drm/i915/i915_debugfs.c | 1 + drivers/gpu/drm/i915/i915_gem_evict.c | 1 + .../gpu/drm/i915/selftests/igt_live_test.c | 2 +- .../gpu/drm/i915/selftests/mock_gem_device.c | 3 +- 14 files changed, 137 insertions(+), 27 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_mman.c +2
-1@@ -644,7 +644,8 @@ mmap_offset_attach(struct drm_i915_gem_object *obj, goto insert;/* Attempt to reap some mmap space from dead objects */ - err =intel_gt_retire_requests_timeout (&i915->gt,MAX_SCHEDULE_TIMEOUT ); + err =intel_gt_retire_requests_timeout (&i915->gt,MAX_SCHEDULE_TIMEOUT , +NULL );if (err) goto err;drivers/gpu/drm/i915/gt/intel_gt.c +19
-0@@ -585,6 +585,25 @@ static void __intel_gt_disable(struct intel_gt *gt)GEM_BUG_ON (intel_gt_pm_is_awake (gt)); } +int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout) +{ +long remaining_timeout; + +/* If the device is asleep, we have no requests outstanding */ +if (!intel_gt_pm_is_awake (gt)) +return 0 ; + +while ((timeout =intel_gt_retire_requests_timeout (gt, timeout, + &remaining_timeout)) >0 ) { +cond_resched (); +if (signal_pending (current)) +return -EINTR ; + } + +return timeout ? timeout :intel_uc_wait_for_idle (>->uc, + remaining_timeout); +} +int intel_gt_init (struct intel_gt *gt) {int err;drivers/gpu/drm/i915/gt/intel_gt.h +2
-0@@ -48,6 +48,8 @@ void intel_gt_driver_release(struct intel_gt *gt);void intel_gt_driver_late_release (struct intel_gt *gt); +int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout); +void intel_gt_check_and_clear_faults (struct intel_gt *gt);void intel_gt_clear_error_registers (struct intel_gt *gt,intel_engine_mask_t engine_mask);drivers/gpu/drm/i915/gt/intel_gt_requests.c +0
-0
drivers/gpu/drm/i915/gt/intel_gt_requests.c line 16
Quoted 4 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c +1
-0@@ -13,6 +13,7 @@#include "intel_gt_pm.h" #include "intel_gt_requests.h" #include "intel_timeline.h" +#include "uc/intel_uc.h"
Why is this needed?
Quoted 44 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c +5
-16static bool retire_requests (struct intel_timeline *tl) {@@ -130,7 +131,8 @@ void intel_engine_fini_retire(struct intel_engine_cs *engine)GEM_BUG_ON (engine->retire); } -long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout) +long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout, +long *remaining_timeout) {struct intel_gt_timelines *timelines = >->timelines;struct intel_timeline *tl, *tn;@@ -195,22 +197,10 @@ out_active: spin_lock(&timelines->lock);if (flush_submission (gt, timeout))/* Wait, there's more! */ active_count++; -return active_count ? timeout :0 ; -} - -int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout) -{ -/* If the device is asleep, we have no requests outstanding */ -if (!intel_gt_pm_is_awake (gt)) -return 0 ; - -while ((timeout =intel_gt_retire_requests_timeout (gt, timeout)) >0 ) { -cond_resched (); -if (signal_pending (current)) -return -EINTR ; - } +if (remaining_timeout) + *remaining_timeout = timeout; -return timeout; +return active_count ? timeout :0 ; }static void retire_work_handler (struct work_struct *work)drivers/gpu/drm/i915/gt/intel_gt_requests.h +0
-0
drivers/gpu/drm/i915/gt/intel_gt_requests.h line 10
Quoted 5 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.h +2
-0@@ -6,14 +6,17 @@#ifndef INTEL_GT_REQUESTS_H #define INTEL_GT_REQUESTS_H +#include <stddef.h> +
Why is this needed?
Quoted 84 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.h +3
-4struct intel_engine_cs ;struct intel_gt ;struct intel_timeline ; -long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout); +long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout, +long *remaining_timeout);static inline void intel_gt_retire_requests (struct intel_gt *gt) { -intel_gt_retire_requests_timeout (gt,0 ); +intel_gt_retire_requests_timeout (gt,0 ,NULL ); }void intel_engine_init_retire (struct intel_engine_cs *engine);@@ -21,8 +24,6 @@ void intel_engine_add_retire(struct intel_engine_cs *engine, struct intel_timeline *tl);void intel_engine_fini_retire (struct intel_engine_cs *engine); -int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout); -void intel_gt_init_requests (struct intel_gt *gt);void intel_gt_park_requests (struct intel_gt *gt);void intel_gt_unpark_requests (struct intel_gt *gt);drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-0@@ -38,6 +38,8 @@ struct intel_guc {spinlock_t irq_lock;unsigned int msg_enabled_mask; +atomic_t outstanding_submission_g2h; +struct {void (*reset)(struct intel_guc *guc);void (*enable)(struct intel_guc *guc);@@ -238,6 +240,8 @@ static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)spin_unlock_irq (&guc->irq_lock); } +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout); +int intel_guc_reset_engine (struct intel_guc *guc,struct intel_engine_cs *engine);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0@@ -109,6 +109,7 @@ void intel_guc_ct_init_early(struct intel_guc_ct *ct)INIT_LIST_HEAD (&ct->requests.incoming);INIT_WORK (&ct->requests.worker, ct_incoming_request_worker_func);tasklet_setup (&ct->receive_tasklet, ct_receive_tasklet_func); +init_waitqueue_head (&ct->wq); }static inline const char *guc_ct_buffer_type_to_str (u32 type)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +4
-0@@ -10,6 +10,7 @@#include <linux/spinlock.h> #include <linux/workqueue.h> #include <linux/ktime.h> +#include <linux/wait.h> #include "intel_guc_fwif.h" @@ -68,6 +69,9 @@ struct intel_guc_ct {struct tasklet_struct receive_tasklet; +/** @wq: wait queue for g2h chanenl */ +wait_queue_head_t wq; +struct {u16 last_fence;/* last fence used to send request */ drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id, · line 257
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +1
-0@@ -254,6 +254,74 @@ static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id,xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); } +static int guc_submission_busy_loop(struct intel_guc* guc,
I think this name is misleading. It would be better as guc_submission_send_busy_loop.
Quoted 52 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +52
-0+const u32 *action, + u32 len, + u32 g2h_len_dw, + bool loop) +{ + int err; + + err =intel_guc_send_busy_loop (guc, action, len, g2h_len_dw, loop); + +if (!err && g2h_len_dw) +atomic_inc (&guc->outstanding_submission_g2h); + +return err; +} + +static int guc_wait_for_pending_msg (struct intel_guc *guc, +atomic_t *wait_var, +bool interruptible, +long timeout) +{ +const int state = interruptible ? +TASK_INTERRUPTIBLE :TASK_UNINTERRUPTIBLE ; +DEFINE_WAIT (wait); + +might_sleep (); +GEM_BUG_ON (timeout <0 ); + +if (!atomic_read (wait_var)) +return 0 ; + +if (!timeout) +return -ETIME ; + +for (;;) { +prepare_to_wait (&guc->ct.wq, &wait, state); + +if (!atomic_read (wait_var)) +break ; + +if (signal_pending_state (state, current)) { + timeout = -ERESTARTSYS ; +break ; + } + +if (!timeout) { + timeout = -ETIME ; +break ; + } + + timeout =io_schedule_timeout (timeout); + } +finish_wait (&guc->ct.wq, &wait);
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id, · line 319
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0+ +return (timeout <0 ) ? timeout :0 ; +} + +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout) +{ +bool interruptible = true; + +if (unlikely (timeout <0 )) + timeout = -timeout, interruptible = false;
Why is this a comma bridged statement rather than just two lines with braces on the if?
And overloading negative timeouts to mean non-interruptible seems unnecessarily convoluted in the first place. Why not just have an interruptible parameter? I'm also not seeing how the timeout gets to be negative in the first place?
Quoted 35 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +8
-2+ +return guc_wait_for_pending_msg (guc, &guc->outstanding_submission_g2h, + interruptible, timeout); +} +static int guc_add_request (struct intel_guc *guc,struct i915_request *rq) {int err;@@ -280,6 +348,7 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq) err =intel_guc_send_nb (guc, action, len, g2h_len_dw);if (!enabled && !err) { +atomic_inc (&guc->outstanding_submission_g2h);set_context_enabled (ce); }else if (!enabled) {clr_context_pending_enable (ce);@@ -731,7 +800,7 @@ static int __guc_action_register_context(struct intel_guc *guc, offset, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); +return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); }static int register_context (struct intel_context *ce)@@ -751,7 +820,7 @@ static int __guc_action_deregister_context(struct intel_guc *guc, guc_id, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),G2H_LEN_DW_DEREGISTER_CONTEXT , true); }
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static int guc_context_pin(struct intel_context *ce, void *vaddr) · line 942
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +3
-1@@ -868,7 +937,9 @@ static int guc_context_pin(struct intel_context *ce, void *vaddr)static void guc_context_unpin (struct intel_context *ce) { -unpin_guc_id (ce_to_guc (ce), ce); +struct intel_guc *guc =ce_to_guc (ce); + +unpin_guc_id (guc, ce);
Should this be part of this patch?
Quoted 63 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-1lrc_unpin (ce); }@@ -891,7 +962,7 @@ static void __guc_context_sched_disable(struct intel_guc *guc,intel_context_get (ce); -intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),G2H_LEN_DW_SCHED_CONTEXT_MODE_SET , true); }@@ -1433,6 +1504,12 @@ g2h_context_lookup(struct intel_guc *guc, u32 desc_idx)return ce; } +static void decr_outstanding_submission_g2h (struct intel_guc *guc) +{ +if (atomic_dec_and_test (&guc->outstanding_submission_g2h)) +wake_up_all (&guc->ct.wq); +} +int intel_guc_deregister_done_process_msg (struct intel_guc *guc,const u32 *msg,u32 len)@@ -1468,6 +1545,8 @@ int intel_guc_deregister_done_process_msg(struct intel_guc *guc,lrc_destroy (&ce->ref); } +decr_outstanding_submission_g2h (guc); +return 0 ; }@@ -1516,6 +1595,7 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,spin_unlock_irqrestore (&ce->guc_state.lock, flags); } +decr_outstanding_submission_g2h (guc);intel_context_put (ce);return 0 ;drivers/gpu/drm/i915/gt/uc/intel_uc.h +5
-0@@ -81,6 +81,11 @@ uc_state_checkers(guc, guc_submission);#undef uc_state_checkers#undef __uc_state_checker +static inline int intel_uc_wait_for_idle (struct intel_uc *uc,long timeout) +{ +return intel_guc_wait_for_idle (&uc->guc, timeout); +} +#define intel_uc_ops_function (_NAME, _OPS, _TYPE, _RET) \ static inline _TYPE intel_uc_##_NAME(struct intel_uc *uc) \ { \drivers/gpu/drm/i915/i915_debugfs.c +0
-0
drivers/gpu/drm/i915/i915_debugfs.c line 39
Quoted 4 lines
drivers/gpu/drm/i915/i915_debugfs.c +1
-0@@ -36,6 +36,7 @@#include "gt/intel_gt_clock_utils.h" #include "gt/intel_gt.h" #include "gt/intel_gt_pm.h" +#include "gt/intel_gt.h"
All of these extra includes seem incorrect. There is no code change in any of the files below that would warrant a new include.
John.
Quoted 33 lines
drivers/gpu/drm/i915/i915_debugfs.c +0
-0#include "gt/intel_gt_requests.h" #include "gt/intel_reset.h" #include "gt/intel_rc6.h" drivers/gpu/drm/i915/i915_gem_evict.c +1
-0@@ -27,6 +27,7 @@*/ #include "gem/i915_gem_context.h" +#include "gt/intel_gt.h" #include "gt/intel_gt_requests.h" #include "i915_drv.h" drivers/gpu/drm/i915/selftests/igt_live_test.c +1
-1@@ -5,7 +5,7 @@*/ #include "i915_drv.h" -#include "gt/intel_gt_requests.h" +#include "gt/intel_gt.h" #include "../i915_selftest.h" #include "igt_flush_test.h" drivers/gpu/drm/i915/selftests/mock_gem_device.c +0
-0
drivers/gpu/drm/i915/selftests/mock_gem_device.c void mock_device_flush(struct drm_i915_private *i915) · line 59
Quoted 9 lines
drivers/gpu/drm/i915/selftests/mock_gem_device.c +2
-1@@ -52,7 +52,8 @@ void mock_device_flush(struct drm_i915_private *i915)do {for_each_engine (engine, gt, id)mock_engine_flush (engine); - }while (intel_gt_retire_requests_timeout (gt,MAX_SCHEDULE_TIMEOUT )); + }while (intel_gt_retire_requests_timeout (gt,MAX_SCHEDULE_TIMEOUT , +NULL )); }static void mock_device_release (struct drm_device *dev)
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 22/47] drm/i915/guc: Update intel_gt_wait_for_idle to work with GuC
Quoted 81 lines · John Harrison
Quoted 80 lines · Matthew Brost
When running the GuC the GPU can't be considered idle if the GuC still has contexts pinned. As such, a call has been added in
intel_gt_wait_for_idleto idle the UC and in turn the GuC by waiting for the number of unpinned contexts to go to zero.v2: rtimeout ->
remaining_timeoutCc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 3 +- drivers/gpu/drm/i915/gt/intel_gt.c | 19 ++++ drivers/gpu/drm/i915/gt/intel_gt.h | 2 + drivers/gpu/drm/i915/gt/intel_gt_requests.c | 22 ++--- drivers/gpu/drm/i915/gt/intel_gt_requests.h | 9 +- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 4 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 1 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 88 ++++++++++++++++++- drivers/gpu/drm/i915/gt/uc/intel_uc.h | 5 ++ drivers/gpu/drm/i915/i915_debugfs.c | 1 + drivers/gpu/drm/i915/i915_gem_evict.c | 1 + .../gpu/drm/i915/selftests/igt_live_test.c | 2 +- .../gpu/drm/i915/selftests/mock_gem_device.c | 3 +- 14 files changed, 137 insertions(+), 27 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_mman.c +2
-1@@ -644,7 +644,8 @@ mmap_offset_attach(struct drm_i915_gem_object *obj, goto insert;/* Attempt to reap some mmap space from dead objects */ - err =intel_gt_retire_requests_timeout (&i915->gt,MAX_SCHEDULE_TIMEOUT ); + err =intel_gt_retire_requests_timeout (&i915->gt,MAX_SCHEDULE_TIMEOUT , +NULL );if (err) goto err;drivers/gpu/drm/i915/gt/intel_gt.c +19
-0@@ -585,6 +585,25 @@ static void __intel_gt_disable(struct intel_gt *gt)GEM_BUG_ON (intel_gt_pm_is_awake (gt)); } +int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout) +{ +long remaining_timeout; + +/* If the device is asleep, we have no requests outstanding */ +if (!intel_gt_pm_is_awake (gt)) +return 0 ; + +while ((timeout =intel_gt_retire_requests_timeout (gt, timeout, + &remaining_timeout)) >0 ) { +cond_resched (); +if (signal_pending (current)) +return -EINTR ; + } + +return timeout ? timeout :intel_uc_wait_for_idle (>->uc, + remaining_timeout); +} +int intel_gt_init (struct intel_gt *gt) {int err;drivers/gpu/drm/i915/gt/intel_gt.h +2
-0@@ -48,6 +48,8 @@ void intel_gt_driver_release(struct intel_gt *gt);void intel_gt_driver_late_release (struct intel_gt *gt); +int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout); +void intel_gt_check_and_clear_faults (struct intel_gt *gt);void intel_gt_clear_error_registers (struct intel_gt *gt,intel_engine_mask_t engine_mask);drivers/gpu/drm/i915/gt/intel_gt_requests.c +0
-0
Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c line 16
Quoted 7 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c +1
-0@@ -13,6 +13,7 @@#include "intel_gt_pm.h" #include "intel_gt_requests.h" #include "intel_timeline.h" +#include "uc/intel_uc.h" Why is this needed?
It is not, likely holdover from internal churn.
Quoted 36 lines
Quoted 36 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c +5
-16static bool retire_requests (struct intel_timeline *tl) {@@ -130,7 +131,8 @@ void intel_engine_fini_retire(struct intel_engine_cs *engine)GEM_BUG_ON (engine->retire); } -long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout) +long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout, +long *remaining_timeout) {struct intel_gt_timelines *timelines = >->timelines;struct intel_timeline *tl, *tn;@@ -195,22 +197,10 @@ out_active: spin_lock(&timelines->lock);if (flush_submission (gt, timeout))/* Wait, there's more! */ active_count++; -return active_count ? timeout :0 ; -} - -int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout) -{ -/* If the device is asleep, we have no requests outstanding */ -if (!intel_gt_pm_is_awake (gt)) -return 0 ; - -while ((timeout =intel_gt_retire_requests_timeout (gt, timeout)) >0 ) { -cond_resched (); -if (signal_pending (current)) -return -EINTR ; - } +if (remaining_timeout) + *remaining_timeout = timeout; -return timeout; +return active_count ? timeout :0 ; }static void retire_work_handler (struct work_struct *work)drivers/gpu/drm/i915/gt/intel_gt_requests.h +0
-0
Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.h line 9
Quoted 7 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.h +2
-0@@ -6,14 +6,17 @@#ifndef INTEL_GT_REQUESTS_H #define INTEL_GT_REQUESTS_H +#include <stddef.h> +Why is this needed?
I swear I needed stddef.h for NULL on a different machice of mine. It seems to be quite happy without it on my current machine. Can remove.
Quoted 69 lines
Quoted 69 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.h +3
-4struct intel_engine_cs ;struct intel_gt ;struct intel_timeline ; -long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout); +long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout, +long *remaining_timeout);static inline void intel_gt_retire_requests (struct intel_gt *gt) { -intel_gt_retire_requests_timeout (gt,0 ); +intel_gt_retire_requests_timeout (gt,0 ,NULL ); }void intel_engine_init_retire (struct intel_engine_cs *engine);@@ -21,8 +24,6 @@ void intel_engine_add_retire(struct intel_engine_cs *engine, struct intel_timeline *tl);void intel_engine_fini_retire (struct intel_engine_cs *engine); -int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout); -void intel_gt_init_requests (struct intel_gt *gt);void intel_gt_park_requests (struct intel_gt *gt);void intel_gt_unpark_requests (struct intel_gt *gt);drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-0@@ -38,6 +38,8 @@ struct intel_guc {spinlock_t irq_lock;unsigned int msg_enabled_mask; +atomic_t outstanding_submission_g2h; +struct {void (*reset)(struct intel_guc *guc);void (*enable)(struct intel_guc *guc);@@ -238,6 +240,8 @@ static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)spin_unlock_irq (&guc->irq_lock); } +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout); +int intel_guc_reset_engine (struct intel_guc *guc,struct intel_engine_cs *engine);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0@@ -109,6 +109,7 @@ void intel_guc_ct_init_early(struct intel_guc_ct *ct)INIT_LIST_HEAD (&ct->requests.incoming);INIT_WORK (&ct->requests.worker, ct_incoming_request_worker_func);tasklet_setup (&ct->receive_tasklet, ct_receive_tasklet_func); +init_waitqueue_head (&ct->wq); }static inline const char *guc_ct_buffer_type_to_str (u32 type)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +4
-0@@ -10,6 +10,7 @@#include <linux/spinlock.h> #include <linux/workqueue.h> #include <linux/ktime.h> +#include <linux/wait.h> #include "intel_guc_fwif.h" @@ -68,6 +69,9 @@ struct intel_guc_ct {struct tasklet_struct receive_tasklet; +/** @wq: wait queue for g2h chanenl */ +wait_queue_head_t wq; +struct {u16 last_fence;/* last fence used to send request */ drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id, · line 256
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +1
-0@@ -254,6 +254,74 @@ static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id,xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); } +static int guc_submission_busy_loop(struct intel_guc* guc,I think this name is misleading. It would be better as
guc_submission_send_busy_loop.
Yep, better name. Will fix.
Quoted 65 lines
Quoted 52 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +52
-0+const u32 *action, + u32 len, + u32 g2h_len_dw, + bool loop) +{ + int err; + + err =intel_guc_send_busy_loop (guc, action, len, g2h_len_dw, loop); + +if (!err && g2h_len_dw) +atomic_inc (&guc->outstanding_submission_g2h); + +return err; +} + +static int guc_wait_for_pending_msg (struct intel_guc *guc, +atomic_t *wait_var, +bool interruptible, +long timeout) +{ +const int state = interruptible ? +TASK_INTERRUPTIBLE :TASK_UNINTERRUPTIBLE ; +DEFINE_WAIT (wait); + +might_sleep (); +GEM_BUG_ON (timeout <0 ); + +if (!atomic_read (wait_var)) +return 0 ; + +if (!timeout) +return -ETIME ; + +for (;;) { +prepare_to_wait (&guc->ct.wq, &wait, state); + +if (!atomic_read (wait_var)) +break ; + +if (signal_pending_state (state, current)) { + timeout = -ERESTARTSYS ; +break ; + } + +if (!timeout) { + timeout = -ETIME ; +break ; + } + + timeout =io_schedule_timeout (timeout); + } +finish_wait (&guc->ct.wq, &wait);drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id, · line 319
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0+ +return (timeout <0 ) ? timeout :0 ; +} + +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout) +{ +bool interruptible = true; + +if (unlikely (timeout <0 )) + timeout = -timeout, interruptible = false;Why is this a comma bridged statement rather than just two lines with braces on the if?
Quoted 5 lines
And overloading negative timeouts to mean non-interruptible seems unnecessarily convoluted in the first place. Why not just have an interruptible parameter? I'm also not seeing how the timeout gets to be negative in the first place?
Copy paste from some other code, can remove the comma and replace with 2 lines.
This is how intel_gt_wait_for_idle works which in turn calls this. Not saying the negative parameter meaning something special is right, just how it is currently done. Now that you mention this with the remaining_timeout I may have broken this too. How about I just add parameter than this convoluted sceme as you suggest.
Quoted 30 lines
Quoted 30 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +8
-2+ +return guc_wait_for_pending_msg (guc, &guc->outstanding_submission_g2h, + interruptible, timeout); +} +static int guc_add_request (struct intel_guc *guc,struct i915_request *rq) {int err;@@ -280,6 +348,7 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq) err =intel_guc_send_nb (guc, action, len, g2h_len_dw);if (!enabled && !err) { +atomic_inc (&guc->outstanding_submission_g2h);set_context_enabled (ce); }else if (!enabled) {clr_context_pending_enable (ce);@@ -731,7 +800,7 @@ static int __guc_action_register_context(struct intel_guc *guc, offset, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); +return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); }static int register_context (struct intel_context *ce)@@ -751,7 +820,7 @@ static int __guc_action_deregister_context(struct intel_guc *guc, guc_id, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),G2H_LEN_DW_DEREGISTER_CONTEXT , true); }
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static int guc_context_pin(struct intel_context *ce, void *vaddr) · line 941
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +3
-1@@ -868,7 +937,9 @@ static int guc_context_pin(struct intel_context *ce, void *vaddr)static void guc_context_unpin (struct intel_context *ce) { -unpin_guc_id (ce_to_guc (ce), ce); +struct intel_guc *guc =ce_to_guc (ce); + +unpin_guc_id (guc, ce);Should this be part of this patch?
Not likely. Let me see what is going on here.
Quoted 51 lines
Quoted 51 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-1lrc_unpin (ce); }@@ -891,7 +962,7 @@ static void __guc_context_sched_disable(struct intel_guc *guc,intel_context_get (ce); -intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),G2H_LEN_DW_SCHED_CONTEXT_MODE_SET , true); }@@ -1433,6 +1504,12 @@ g2h_context_lookup(struct intel_guc *guc, u32 desc_idx)return ce; } +static void decr_outstanding_submission_g2h (struct intel_guc *guc) +{ +if (atomic_dec_and_test (&guc->outstanding_submission_g2h)) +wake_up_all (&guc->ct.wq); +} +int intel_guc_deregister_done_process_msg (struct intel_guc *guc,const u32 *msg,u32 len)@@ -1468,6 +1545,8 @@ int intel_guc_deregister_done_process_msg(struct intel_guc *guc,lrc_destroy (&ce->ref); } +decr_outstanding_submission_g2h (guc); +return 0 ; }@@ -1516,6 +1595,7 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,spin_unlock_irqrestore (&ce->guc_state.lock, flags); } +decr_outstanding_submission_g2h (guc);intel_context_put (ce);return 0 ;drivers/gpu/drm/i915/gt/uc/intel_uc.h +5
-0@@ -81,6 +81,11 @@ uc_state_checkers(guc, guc_submission);#undef uc_state_checkers#undef __uc_state_checker +static inline int intel_uc_wait_for_idle (struct intel_uc *uc,long timeout) +{ +return intel_guc_wait_for_idle (&uc->guc, timeout); +} +#define intel_uc_ops_function (_NAME, _OPS, _TYPE, _RET) \ static inline _TYPE intel_uc_##_NAME(struct intel_uc *uc) \ { \drivers/gpu/drm/i915/i915_debugfs.c +0
-1--- a/drivers/gpu/drm/i915/i915_debugfs.c
Quoted 9 lines
drivers/gpu/drm/i915/i915_debugfs.c line 39
Quoted 6 lines
+++
b/drivers/gpu/drm/i915/i915_debugfs.cdrivers/gpu/drm/i915/i915_debugfs.c +1
-0@@ -36,6 +36,7 @@#include "gt/intel_gt_clock_utils.h" #include "gt/intel_gt.h" #include "gt/intel_gt_pm.h" +#include "gt/intel_gt.h" All of these extra includes seem incorrect. There is no code change in any of the files below that would warrant a new include.
Well this is surely wrong as it is included two lines above. Will fix.
Matt
Quoted 41 lines
John.
Quoted 37 lines
drivers/gpu/drm/i915/i915_debugfs.c +0
-0#include "gt/intel_gt_requests.h" #include "gt/intel_reset.h" #include "gt/intel_rc6.h" drivers/gpu/drm/i915/i915_gem_evict.c +1
-0@@ -27,6 +27,7 @@*/ #include "gem/i915_gem_context.h" +#include "gt/intel_gt.h" #include "gt/intel_gt_requests.h" #include "i915_drv.h" drivers/gpu/drm/i915/selftests/igt_live_test.c +1
-1@@ -5,7 +5,7 @@*/ #include "i915_drv.h" -#include "gt/intel_gt_requests.h" +#include "gt/intel_gt.h" #include "../i915_selftest.h" #include "igt_flush_test.h" drivers/gpu/drm/i915/selftests/mock_gem_device.c +2
-1@@ -52,7 +52,8 @@ void mock_device_flush(struct drm_i915_private *i915)do {for_each_engine (engine, gt, id)mock_engine_flush (engine); - }while (intel_gt_retire_requests_timeout (gt,MAX_SCHEDULE_TIMEOUT )); + }while (intel_gt_retire_requests_timeout (gt,MAX_SCHEDULE_TIMEOUT , +NULL )); }static void mock_device_release (struct drm_device *dev)
Re: [PATCH 22/47] drm/i915/guc: Update intel_gt_wait_for_idle to work with GuC
Quoted 140 lines · Matthew Brost
Quoted 81 lines · John Harrison
Quoted 80 lines · Matthew Brost
When running the GuC the GPU can't be considered idle if the GuC still has contexts pinned. As such, a call has been added in
intel_gt_wait_for_idleto idle the UC and in turn the GuC by waiting for the number of unpinned contexts to go to zero.v2: rtimeout ->
remaining_timeoutCc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 3 +- drivers/gpu/drm/i915/gt/intel_gt.c | 19 ++++ drivers/gpu/drm/i915/gt/intel_gt.h | 2 + drivers/gpu/drm/i915/gt/intel_gt_requests.c | 22 ++--- drivers/gpu/drm/i915/gt/intel_gt_requests.h | 9 +- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 4 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 1 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 88 ++++++++++++++++++- drivers/gpu/drm/i915/gt/uc/intel_uc.h | 5 ++ drivers/gpu/drm/i915/i915_debugfs.c | 1 + drivers/gpu/drm/i915/i915_gem_evict.c | 1 + .../gpu/drm/i915/selftests/igt_live_test.c | 2 +- .../gpu/drm/i915/selftests/mock_gem_device.c | 3 +- 14 files changed, 137 insertions(+), 27 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_mman.c +2
-1@@ -644,7 +644,8 @@ mmap_offset_attach(struct drm_i915_gem_object *obj, goto insert;/* Attempt to reap some mmap space from dead objects */ - err =intel_gt_retire_requests_timeout (&i915->gt,MAX_SCHEDULE_TIMEOUT ); + err =intel_gt_retire_requests_timeout (&i915->gt,MAX_SCHEDULE_TIMEOUT , +NULL );if (err) goto err;drivers/gpu/drm/i915/gt/intel_gt.c +19
-0@@ -585,6 +585,25 @@ static void __intel_gt_disable(struct intel_gt *gt)GEM_BUG_ON (intel_gt_pm_is_awake (gt)); } +int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout) +{ +long remaining_timeout; + +/* If the device is asleep, we have no requests outstanding */ +if (!intel_gt_pm_is_awake (gt)) +return 0 ; + +while ((timeout =intel_gt_retire_requests_timeout (gt, timeout, + &remaining_timeout)) >0 ) { +cond_resched (); +if (signal_pending (current)) +return -EINTR ; + } + +return timeout ? timeout :intel_uc_wait_for_idle (>->uc, + remaining_timeout); +} +int intel_gt_init (struct intel_gt *gt) {int err;drivers/gpu/drm/i915/gt/intel_gt.h +2
-0@@ -48,6 +48,8 @@ void intel_gt_driver_release(struct intel_gt *gt);void intel_gt_driver_late_release (struct intel_gt *gt); +int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout); +void intel_gt_check_and_clear_faults (struct intel_gt *gt);void intel_gt_clear_error_registers (struct intel_gt *gt,intel_engine_mask_t engine_mask);drivers/gpu/drm/i915/gt/intel_gt_requests.c +0
-0Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c line 16
Quoted 7 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c +1
-0@@ -13,6 +13,7 @@#include "intel_gt_pm.h" #include "intel_gt_requests.h" #include "intel_timeline.h" +#include "uc/intel_uc.h" Why is this needed?
It is not, likely holdover from internal churn.
Quoted 36 lines
Quoted 36 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c +5
-16static bool retire_requests (struct intel_timeline *tl) {@@ -130,7 +131,8 @@ void intel_engine_fini_retire(struct intel_engine_cs *engine)GEM_BUG_ON (engine->retire); } -long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout) +long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout, +long *remaining_timeout) {struct intel_gt_timelines *timelines = >->timelines;struct intel_timeline *tl, *tn;@@ -195,22 +197,10 @@ out_active: spin_lock(&timelines->lock);if (flush_submission (gt, timeout))/* Wait, there's more! */ active_count++; -return active_count ? timeout :0 ; -} - -int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout) -{ -/* If the device is asleep, we have no requests outstanding */ -if (!intel_gt_pm_is_awake (gt)) -return 0 ; - -while ((timeout =intel_gt_retire_requests_timeout (gt, timeout)) >0 ) { -cond_resched (); -if (signal_pending (current)) -return -EINTR ; - } +if (remaining_timeout) + *remaining_timeout = timeout; -return timeout; +return active_count ? timeout :0 ; }static void retire_work_handler (struct work_struct *work)drivers/gpu/drm/i915/gt/intel_gt_requests.h +0
-0Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.h line 9
Quoted 7 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.h +2
-0@@ -6,14 +6,17 @@#ifndef INTEL_GT_REQUESTS_H #define INTEL_GT_REQUESTS_H +#include <stddef.h> +Why is this needed?
Quoted 3 lines
I swear I needed
stddef.hfor NULL on a different machice of mine. It seems to be quite happy without it on my current machine. Can remove.
And it in fact does need to be included. See CI results below:
https://patchwork.freedesktop.org/series/91840/#rev3
Matt
Quoted 309 lines
Quoted 69 lines
Quoted 69 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.h +3
-4struct intel_engine_cs ;struct intel_gt ;struct intel_timeline ; -long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout); +long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout, +long *remaining_timeout);static inline void intel_gt_retire_requests (struct intel_gt *gt) { -intel_gt_retire_requests_timeout (gt,0 ); +intel_gt_retire_requests_timeout (gt,0 ,NULL ); }void intel_engine_init_retire (struct intel_engine_cs *engine);@@ -21,8 +24,6 @@ void intel_engine_add_retire(struct intel_engine_cs *engine, struct intel_timeline *tl);void intel_engine_fini_retire (struct intel_engine_cs *engine); -int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout); -void intel_gt_init_requests (struct intel_gt *gt);void intel_gt_park_requests (struct intel_gt *gt);void intel_gt_unpark_requests (struct intel_gt *gt);drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-0@@ -38,6 +38,8 @@ struct intel_guc {spinlock_t irq_lock;unsigned int msg_enabled_mask; +atomic_t outstanding_submission_g2h; +struct {void (*reset)(struct intel_guc *guc);void (*enable)(struct intel_guc *guc);@@ -238,6 +240,8 @@ static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)spin_unlock_irq (&guc->irq_lock); } +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout); +int intel_guc_reset_engine (struct intel_guc *guc,struct intel_engine_cs *engine);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0@@ -109,6 +109,7 @@ void intel_guc_ct_init_early(struct intel_guc_ct *ct)INIT_LIST_HEAD (&ct->requests.incoming);INIT_WORK (&ct->requests.worker, ct_incoming_request_worker_func);tasklet_setup (&ct->receive_tasklet, ct_receive_tasklet_func); +init_waitqueue_head (&ct->wq); }static inline const char *guc_ct_buffer_type_to_str (u32 type)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +4
-0@@ -10,6 +10,7 @@#include <linux/spinlock.h> #include <linux/workqueue.h> #include <linux/ktime.h> +#include <linux/wait.h> #include "intel_guc_fwif.h" @@ -68,6 +69,9 @@ struct intel_guc_ct {struct tasklet_struct receive_tasklet; +/** @wq: wait queue for g2h chanenl */ +wait_queue_head_t wq; +struct {u16 last_fence;/* last fence used to send request */ drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id, · line 256
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +1
-0@@ -254,6 +254,74 @@ static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id,xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); } +static int guc_submission_busy_loop(struct intel_guc* guc,I think this name is misleading. It would be better as
guc_submission_send_busy_loop.Yep, better name. Will fix.
Quoted 65 lines
Quoted 52 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +52
-0+const u32 *action, + u32 len, + u32 g2h_len_dw, + bool loop) +{ + int err; + + err =intel_guc_send_busy_loop (guc, action, len, g2h_len_dw, loop); + +if (!err && g2h_len_dw) +atomic_inc (&guc->outstanding_submission_g2h); + +return err; +} + +static int guc_wait_for_pending_msg (struct intel_guc *guc, +atomic_t *wait_var, +bool interruptible, +long timeout) +{ +const int state = interruptible ? +TASK_INTERRUPTIBLE :TASK_UNINTERRUPTIBLE ; +DEFINE_WAIT (wait); + +might_sleep (); +GEM_BUG_ON (timeout <0 ); + +if (!atomic_read (wait_var)) +return 0 ; + +if (!timeout) +return -ETIME ; + +for (;;) { +prepare_to_wait (&guc->ct.wq, &wait, state); + +if (!atomic_read (wait_var)) +break ; + +if (signal_pending_state (state, current)) { + timeout = -ERESTARTSYS ; +break ; + } + +if (!timeout) { + timeout = -ETIME ; +break ; + } + + timeout =io_schedule_timeout (timeout); + } +finish_wait (&guc->ct.wq, &wait);drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id, · line 319
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0+ +return (timeout <0 ) ? timeout :0 ; +} + +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout) +{ +bool interruptible = true; + +if (unlikely (timeout <0 )) + timeout = -timeout, interruptible = false;Why is this a comma bridged statement rather than just two lines with braces on the if?
Quoted 5 lines
And overloading negative timeouts to mean non-interruptible seems unnecessarily convoluted in the first place. Why not just have an interruptible parameter? I'm also not seeing how the timeout gets to be negative in the first place?
Copy paste from some other code, can remove the comma and replace with 2 lines.
This is how
intel_gt_wait_for_idleworks which in turn calls this. Not saying the negative parameter meaning something special is right, just how it is currently done. Now that you mention this with theremaining_timeoutI may have broken this too. How about I just add parameter than this convoluted sceme as you suggest.Quoted 30 lines
Quoted 30 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +8
-2+ +return guc_wait_for_pending_msg (guc, &guc->outstanding_submission_g2h, + interruptible, timeout); +} +static int guc_add_request (struct intel_guc *guc,struct i915_request *rq) {int err;@@ -280,6 +348,7 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq) err =intel_guc_send_nb (guc, action, len, g2h_len_dw);if (!enabled && !err) { +atomic_inc (&guc->outstanding_submission_g2h);set_context_enabled (ce); }else if (!enabled) {clr_context_pending_enable (ce);@@ -731,7 +800,7 @@ static int __guc_action_register_context(struct intel_guc *guc, offset, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); +return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); }static int register_context (struct intel_context *ce)@@ -751,7 +820,7 @@ static int __guc_action_deregister_context(struct intel_guc *guc, guc_id, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),G2H_LEN_DW_DEREGISTER_CONTEXT , true); }Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static int guc_context_pin(struct intel_context *ce, void *vaddr) · line 941
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +3
-1@@ -868,7 +937,9 @@ static int guc_context_pin(struct intel_context *ce, void *vaddr)static void guc_context_unpin (struct intel_context *ce) { -unpin_guc_id (ce_to_guc (ce), ce); +struct intel_guc *guc =ce_to_guc (ce); + +unpin_guc_id (guc, ce);Should this be part of this patch?
Not likely. Let me see what is going on here.
Quoted 51 lines
Quoted 51 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-1lrc_unpin (ce); }@@ -891,7 +962,7 @@ static void __guc_context_sched_disable(struct intel_guc *guc,intel_context_get (ce); -intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),G2H_LEN_DW_SCHED_CONTEXT_MODE_SET , true); }@@ -1433,6 +1504,12 @@ g2h_context_lookup(struct intel_guc *guc, u32 desc_idx)return ce; } +static void decr_outstanding_submission_g2h (struct intel_guc *guc) +{ +if (atomic_dec_and_test (&guc->outstanding_submission_g2h)) +wake_up_all (&guc->ct.wq); +} +int intel_guc_deregister_done_process_msg (struct intel_guc *guc,const u32 *msg,u32 len)@@ -1468,6 +1545,8 @@ int intel_guc_deregister_done_process_msg(struct intel_guc *guc,lrc_destroy (&ce->ref); } +decr_outstanding_submission_g2h (guc); +return 0 ; }@@ -1516,6 +1595,7 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,spin_unlock_irqrestore (&ce->guc_state.lock, flags); } +decr_outstanding_submission_g2h (guc);intel_context_put (ce);return 0 ;drivers/gpu/drm/i915/gt/uc/intel_uc.h +5
-0@@ -81,6 +81,11 @@ uc_state_checkers(guc, guc_submission);#undef uc_state_checkers#undef __uc_state_checker +static inline int intel_uc_wait_for_idle (struct intel_uc *uc,long timeout) +{ +return intel_guc_wait_for_idle (&uc->guc, timeout); +} +#define intel_uc_ops_function (_NAME, _OPS, _TYPE, _RET) \ static inline _TYPE intel_uc_##_NAME(struct intel_uc *uc) \ { \drivers/gpu/drm/i915/i915_debugfs.c +0
-1--- a/drivers/gpu/drm/i915/i915_debugfs.cQuoted 9 lines
drivers/gpu/drm/i915/i915_debugfs.c line 39
Quoted 6 lines
+++
b/drivers/gpu/drm/i915/i915_debugfs.cdrivers/gpu/drm/i915/i915_debugfs.c +1
-0@@ -36,6 +36,7 @@#include "gt/intel_gt_clock_utils.h" #include "gt/intel_gt.h" #include "gt/intel_gt_pm.h" +#include "gt/intel_gt.h" All of these extra includes seem incorrect. There is no code change in any of the files below that would warrant a new include.
Well this is surely wrong as it is included two lines above. Will fix.
Matt
Quoted 41 lines
John.
Quoted 37 lines
drivers/gpu/drm/i915/i915_debugfs.c +0
-0#include "gt/intel_gt_requests.h" #include "gt/intel_reset.h" #include "gt/intel_rc6.h" drivers/gpu/drm/i915/i915_gem_evict.c +1
-0@@ -27,6 +27,7 @@*/ #include "gem/i915_gem_context.h" +#include "gt/intel_gt.h" #include "gt/intel_gt_requests.h" #include "i915_drv.h" drivers/gpu/drm/i915/selftests/igt_live_test.c +1
-1@@ -5,7 +5,7 @@*/ #include "i915_drv.h" -#include "gt/intel_gt_requests.h" +#include "gt/intel_gt.h" #include "../i915_selftest.h" #include "igt_flush_test.h" drivers/gpu/drm/i915/selftests/mock_gem_device.c +2
-1@@ -52,7 +52,8 @@ void mock_device_flush(struct drm_i915_private *i915)do {for_each_engine (engine, gt, id)mock_engine_flush (engine); - }while (intel_gt_retire_requests_timeout (gt,MAX_SCHEDULE_TIMEOUT )); + }while (intel_gt_retire_requests_timeout (gt,MAX_SCHEDULE_TIMEOUT , +NULL )); }static void mock_device_release (struct drm_device *dev)
PATCH 23/47 drm/i915/guc: Update GuC debugfs to support new GuC
In reply to Matthew BrostUpdate GuC debugfs to support the new GuC structures.
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 22 ++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 3 ++ .../gpu/drm/i915/gt/uc/intel_guc_debugfs.c | 23 +++++++- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 52 +++++++++++++++++++ .../gpu/drm/i915/gt/uc/intel_guc_submission.h | 4 ++ drivers/gpu/drm/i915/i915_debugfs.c | 1 + 6 files changed, 104 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +22 -0
@@ -1135,3 +1135,25 @@ void intel_guc_ct_event_handler(struct intel_guc_ct *ct)ct_try_receive_message (ct); } + +void intel_guc_log_ct_info (struct intel_guc_ct *ct, +struct drm_printer *p) +{ +if (!ct->enabled) { +drm_puts (p,"CT disabled\n" ); +return ; + } + +drm_printf (p,"H2G Space: %u\n" , +atomic_read (&ct->ctbs.send.space) *4 ); +drm_printf (p,"Head: %u\n" , + ct->ctbs.send.desc->head); +drm_printf (p,"Tail: %u\n" , + ct->ctbs.send.desc->tail); +drm_printf (p,"G2H Space: %u\n" , +atomic_read (&ct->ctbs.recv.space) *4 ); +drm_printf (p,"Head: %u\n" , + ct->ctbs.recv.desc->head); +drm_printf (p,"Tail: %u\n" , + ct->ctbs.recv.desc->tail); +}
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3 -0
@@ -16,6 +16,7 @@struct i915_vma ;struct intel_guc ; +struct drm_printer ;/** * DOC: Command Transport (CT).
@@ -106,4 +107,6 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size, u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct); +void intel_guc_log_ct_info (struct intel_guc_ct *ct,struct drm_printer *p); +#endif /* _INTEL_GUC_CT_H_ */
drivers/gpu/drm/i915/gt/uc/intel_guc_debugfs.c +22 -1
@@ -9,6 +9,8 @@#include "intel_guc.h" #include "intel_guc_debugfs.h" #include "intel_guc_log_debugfs.h" +#include "gt/uc/intel_guc_ct.h" +#include "gt/uc/intel_guc_submission.h" static int guc_info_show (struct seq_file *m,void *data) {
@@ -22,16 +24,35 @@ static int guc_info_show(struct seq_file *m, void *data)drm_puts (&p,"\n" );intel_guc_log_info (&guc->log, &p); -/* Add more as required ... */ +if (!intel_guc_submission_is_used (guc)) +return 0 ; + +intel_guc_log_ct_info (&guc->ct, &p); +intel_guc_log_submission_info (guc, &p);return 0 ; }DEFINE_GT_DEBUGFS_ATTRIBUTE (guc_info); +static int guc_registered_contexts_show (struct seq_file *m,void *data) +{ +struct intel_guc *guc = m->private; +struct drm_printer p =drm_seq_file_printer (m); + +if (!intel_guc_submission_is_used (guc)) +return -ENODEV ; + +intel_guc_log_context_info (guc, &p); + +return 0 ; +} +DEFINE_GT_DEBUGFS_ATTRIBUTE (guc_registered_contexts); +void intel_guc_debugfs_register (struct intel_guc *guc,struct dentry *root) {static const struct debugfs_gt_file files[] = { {"guc_info" , &guc_info_fops,NULL }, + {"guc_registered_contexts" , &guc_registered_contexts_fops,NULL }, };if (!intel_guc_is_supported (guc))
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +52 -0
55 lines not on this page · raw message
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.h +4 -0
@@ -10,6 +10,7 @@#include "intel_guc.h" +struct drm_printer ;struct intel_engine_cs ;void intel_guc_submission_init_early (struct intel_guc *guc);
@@ -20,6 +21,9 @@ void intel_guc_submission_fini(struct intel_guc *guc);int intel_guc_preempt_work_create (struct intel_guc *guc);void intel_guc_preempt_work_destroy (struct intel_guc *guc);int intel_guc_submission_setup (struct intel_engine_cs *engine); +void intel_guc_log_submission_info (struct intel_guc *guc, +struct drm_printer *p); +void intel_guc_log_context_info (struct intel_guc *guc,struct drm_printer *p);static inline bool intel_guc_submission_is_supported (struct intel_guc *guc) {
drivers/gpu/drm/i915/i915_debugfs.c +1 -0
@@ -50,6 +50,7 @@#include "i915_trace.h" #include "intel_pm.h" #include "intel_sideband.h" +#include "gt/intel_lrc_reg.h" static inline struct drm_i915_private *node_to_i915 (struct drm_info_node *node) {
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 23/47] drm/i915/guc: Update GuC debugfs to support new GuC
Quoted 122 lines · Matthew Brost
Update GuC debugfs to support the new GuC structures.
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 22 ++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 3 ++ .../gpu/drm/i915/gt/uc/intel_guc_debugfs.c | 23 +++++++- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 52 +++++++++++++++++++ .../gpu/drm/i915/gt/uc/intel_guc_submission.h | 4 ++ drivers/gpu/drm/i915/i915_debugfs.c | 1 + 6 files changed, 104 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +22
-0@@ -1135,3 +1135,25 @@ void intel_guc_ct_event_handler(struct intel_guc_ct *ct)ct_try_receive_message (ct); } + +void intel_guc_log_ct_info (struct intel_guc_ct *ct, +struct drm_printer *p) +{ +if (!ct->enabled) { +drm_puts (p,"CT disabled\n" ); +return ; + } + +drm_printf (p,"H2G Space: %u\n" , +atomic_read (&ct->ctbs.send.space) *4 ); +drm_printf (p,"Head: %u\n" , + ct->ctbs.send.desc->head); +drm_printf (p,"Tail: %u\n" , + ct->ctbs.send.desc->tail); +drm_printf (p,"G2H Space: %u\n" , +atomic_read (&ct->ctbs.recv.space) *4 ); +drm_printf (p,"Head: %u\n" , + ct->ctbs.recv.desc->head); +drm_printf (p,"Tail: %u\n" , + ct->ctbs.recv.desc->tail); +}drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0@@ -16,6 +16,7 @@struct i915_vma ;struct intel_guc ; +struct drm_printer ;/** * DOC: Command Transport (CT). @@ -106,4 +107,6 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size, u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct); +void intel_guc_log_ct_info (struct intel_guc_ct *ct,struct drm_printer *p); +#endif /* _INTEL_GUC_CT_H_ */ drivers/gpu/drm/i915/gt/uc/intel_guc_debugfs.c +22
-1@@ -9,6 +9,8 @@#include "intel_guc.h" #include "intel_guc_debugfs.h" #include "intel_guc_log_debugfs.h" +#include "gt/uc/intel_guc_ct.h" +#include "gt/uc/intel_guc_submission.h" static int guc_info_show (struct seq_file *m,void *data) {@@ -22,16 +24,35 @@ static int guc_info_show(struct seq_file *m, void *data)drm_puts (&p,"\n" );intel_guc_log_info (&guc->log, &p); -/* Add more as required ... */ +if (!intel_guc_submission_is_used (guc)) +return 0 ; + +intel_guc_log_ct_info (&guc->ct, &p); +intel_guc_log_submission_info (guc, &p);return 0 ; }DEFINE_GT_DEBUGFS_ATTRIBUTE (guc_info); +static int guc_registered_contexts_show (struct seq_file *m,void *data) +{ +struct intel_guc *guc = m->private; +struct drm_printer p =drm_seq_file_printer (m); + +if (!intel_guc_submission_is_used (guc)) +return -ENODEV ; + +intel_guc_log_context_info (guc, &p); + +return 0 ; +} +DEFINE_GT_DEBUGFS_ATTRIBUTE (guc_registered_contexts); +void intel_guc_debugfs_register (struct intel_guc *guc,struct dentry *root) {static const struct debugfs_gt_file files[] = { {"guc_info" , &guc_info_fops,NULL }, + {"guc_registered_contexts" , &guc_registered_contexts_fops,NULL }, };if (!intel_guc_is_supported (guc))drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-0@@ -1600,3 +1600,55 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,return 0 ; } + +void intel_guc_log_submission_info(struct intel_guc *guc,
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c int intel_guc_sched_done_process_msg(struct intel_guc *guc, · line 1614
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0+ struct drm_printer *p) +{ +struct i915_sched_engine *sched_engine = guc->sched_engine; +struct rb_node *rb; +unsigned long flags; + +drm_printf (p,"GuC Number Outstanding Submission G2H: %u\n" , +atomic_read (&guc->outstanding_submission_g2h)); +drm_printf (p,"GuC tasklet count: %u\n\n" , +atomic_read (&sched_engine->tasklet.count));
Does sched_engine need a null check?
Quoted 67 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +40
-0+ +spin_lock_irqsave (&sched_engine->lock, flags); +drm_printf (p,"Requests in GuC submit tasklet:\n" ); +for (rb =rb_first_cached (&sched_engine->queue); rb; rb =rb_next (rb)) { +struct i915_priolist *pl =to_priolist (rb); +struct i915_request *rq; + +priolist_for_each_request (rq, pl) +drm_printf (p,"guc_id=%u, seqno=%llu\n" , + rq->context->guc_id, + rq->fence.seqno); + } +spin_unlock_irqrestore (&sched_engine->lock, flags); +drm_printf (p,"\n" ); +} + +void intel_guc_log_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\tSchedule State: 0x%x, 0x%x\n\n" , + ce->guc_state.sched_state, +atomic_read (&ce->guc_sched_state_no_lock)); + } +}drivers/gpu/drm/i915/gt/uc/intel_guc_submission.h +4
-0@@ -10,6 +10,7 @@#include "intel_guc.h" +struct drm_printer ;struct intel_engine_cs ;void intel_guc_submission_init_early (struct intel_guc *guc);@@ -20,6 +21,9 @@ void intel_guc_submission_fini(struct intel_guc *guc);int intel_guc_preempt_work_create (struct intel_guc *guc);void intel_guc_preempt_work_destroy (struct intel_guc *guc);int intel_guc_submission_setup (struct intel_engine_cs *engine); +void intel_guc_log_submission_info (struct intel_guc *guc, +struct drm_printer *p); +void intel_guc_log_context_info (struct intel_guc *guc,struct drm_printer *p);static inline bool intel_guc_submission_is_supported (struct intel_guc *guc) {drivers/gpu/drm/i915/i915_debugfs.c +0
-0
drivers/gpu/drm/i915/i915_debugfs.c line 54
Quoted 5 lines
drivers/gpu/drm/i915/i915_debugfs.c +1
-0@@ -50,6 +50,7 @@#include "i915_trace.h" #include "intel_pm.h" #include "intel_sideband.h" +#include "gt/intel_lrc_reg.h"
Obsolete include again?
John.
drivers/gpu/drm/i915/i915_debugfs.c line 56
Quoted 2 lines
drivers/gpu/drm/i915/i915_debugfs.c +0
-0static inline struct drm_i915_private *node_to_i915 (struct drm_info_node *node) {
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 23/47] drm/i915/guc: Update GuC debugfs to support new GuC
Quoted 116 lines · John Harrison
Quoted 115 lines · Matthew Brost
Update GuC debugfs to support the new GuC structures.
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 22 ++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 3 ++ .../gpu/drm/i915/gt/uc/intel_guc_debugfs.c | 23 +++++++- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 52 +++++++++++++++++++ .../gpu/drm/i915/gt/uc/intel_guc_submission.h | 4 ++ drivers/gpu/drm/i915/i915_debugfs.c | 1 + 6 files changed, 104 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +22
-0@@ -1135,3 +1135,25 @@ void intel_guc_ct_event_handler(struct intel_guc_ct *ct)ct_try_receive_message (ct); } + +void intel_guc_log_ct_info (struct intel_guc_ct *ct, +struct drm_printer *p) +{ +if (!ct->enabled) { +drm_puts (p,"CT disabled\n" ); +return ; + } + +drm_printf (p,"H2G Space: %u\n" , +atomic_read (&ct->ctbs.send.space) *4 ); +drm_printf (p,"Head: %u\n" , + ct->ctbs.send.desc->head); +drm_printf (p,"Tail: %u\n" , + ct->ctbs.send.desc->tail); +drm_printf (p,"G2H Space: %u\n" , +atomic_read (&ct->ctbs.recv.space) *4 ); +drm_printf (p,"Head: %u\n" , + ct->ctbs.recv.desc->head); +drm_printf (p,"Tail: %u\n" , + ct->ctbs.recv.desc->tail); +}drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0@@ -16,6 +16,7 @@struct i915_vma ;struct intel_guc ; +struct drm_printer ;/** * DOC: Command Transport (CT). @@ -106,4 +107,6 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size, u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct); +void intel_guc_log_ct_info (struct intel_guc_ct *ct,struct drm_printer *p); +#endif /* _INTEL_GUC_CT_H_ */ drivers/gpu/drm/i915/gt/uc/intel_guc_debugfs.c +22
-1@@ -9,6 +9,8 @@#include "intel_guc.h" #include "intel_guc_debugfs.h" #include "intel_guc_log_debugfs.h" +#include "gt/uc/intel_guc_ct.h" +#include "gt/uc/intel_guc_submission.h" static int guc_info_show (struct seq_file *m,void *data) {@@ -22,16 +24,35 @@ static int guc_info_show(struct seq_file *m, void *data)drm_puts (&p,"\n" );intel_guc_log_info (&guc->log, &p); -/* Add more as required ... */ +if (!intel_guc_submission_is_used (guc)) +return 0 ; + +intel_guc_log_ct_info (&guc->ct, &p); +intel_guc_log_submission_info (guc, &p);return 0 ; }DEFINE_GT_DEBUGFS_ATTRIBUTE (guc_info); +static int guc_registered_contexts_show (struct seq_file *m,void *data) +{ +struct intel_guc *guc = m->private; +struct drm_printer p =drm_seq_file_printer (m); + +if (!intel_guc_submission_is_used (guc)) +return -ENODEV ; + +intel_guc_log_context_info (guc, &p); + +return 0 ; +} +DEFINE_GT_DEBUGFS_ATTRIBUTE (guc_registered_contexts); +void intel_guc_debugfs_register (struct intel_guc *guc,struct dentry *root) {static const struct debugfs_gt_file files[] = { {"guc_info" , &guc_info_fops,NULL }, + {"guc_registered_contexts" , &guc_registered_contexts_fops,NULL }, };if (!intel_guc_is_supported (guc))drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-0@@ -1600,3 +1600,55 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,return 0 ; } + +void intel_guc_log_submission_info (struct intel_guc *guc, +struct drm_printer *p) +{ +struct i915_sched_engine *sched_engine = guc->sched_engine;
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c int intel_guc_sched_done_process_msg(struct intel_guc *guc, · line 1614
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +7
-0+struct rb_node *rb; +unsigned long flags; + +drm_printf (p,"GuC Number Outstanding Submission G2H: %u\n" , +atomic_read (&guc->outstanding_submission_g2h)); +drm_printf (p,"GuC tasklet count: %u\n\n" , +atomic_read (&sched_engine->tasklet.count));Does
sched_engineneed a null check?
Yes it does. Have this fixed locally already.
Quoted 60 lines
Quoted 60 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +40
-0+ +spin_lock_irqsave (&sched_engine->lock, flags); +drm_printf (p,"Requests in GuC submit tasklet:\n" ); +for (rb =rb_first_cached (&sched_engine->queue); rb; rb =rb_next (rb)) { +struct i915_priolist *pl =to_priolist (rb); +struct i915_request *rq; + +priolist_for_each_request (rq, pl) +drm_printf (p,"guc_id=%u, seqno=%llu\n" , + rq->context->guc_id, + rq->fence.seqno); + } +spin_unlock_irqrestore (&sched_engine->lock, flags); +drm_printf (p,"\n" ); +} + +void intel_guc_log_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\tSchedule State: 0x%x, 0x%x\n\n" , + ce->guc_state.sched_state, +atomic_read (&ce->guc_sched_state_no_lock)); + } +}drivers/gpu/drm/i915/gt/uc/intel_guc_submission.h +4
-0@@ -10,6 +10,7 @@#include "intel_guc.h" +struct drm_printer ;struct intel_engine_cs ;void intel_guc_submission_init_early (struct intel_guc *guc);@@ -20,6 +21,9 @@ void intel_guc_submission_fini(struct intel_guc *guc);int intel_guc_preempt_work_create (struct intel_guc *guc);void intel_guc_preempt_work_destroy (struct intel_guc *guc);int intel_guc_submission_setup (struct intel_engine_cs *engine); +void intel_guc_log_submission_info (struct intel_guc *guc, +struct drm_printer *p); +void intel_guc_log_context_info (struct intel_guc *guc,struct drm_printer *p);static inline bool intel_guc_submission_is_supported (struct intel_guc *guc) {drivers/gpu/drm/i915/i915_debugfs.c +0
-0
Quoted 9 lines
drivers/gpu/drm/i915/i915_debugfs.c line 53
Quoted 7 lines
drivers/gpu/drm/i915/i915_debugfs.c +1
-0@@ -50,6 +50,7 @@#include "i915_trace.h" #include "intel_pm.h" #include "intel_sideband.h" +#include "gt/intel_lrc_reg.h" Obsolete include again?
CTX_RING_TAIL /CTX_RING_HEAD are in gt/intel_lrc_reg.h
Matt
Quoted 5 lines
John.
Quoted 2 lines
drivers/gpu/drm/i915/i915_debugfs.c +0
-0static inline struct drm_i915_private *node_to_i915 (struct drm_info_node *node) {