drm/amdkfd: handle IH ring1 overflow
Subsystems (3)
PATCH v2 1/1 drm/amdkfd: handle IH ring1 overflow
IH ring1 is used to process GPU retry fault, overflow is enabled to drain retry fault because we want receive other interrupts while handling retry fault to recover range. There is no overflow flag set when wptr pass rptr. Use timestamp of rptr and wptr to handle overflow and drain retry fault.
Add helper function amdgpu_ih_decode_iv_ts to get 48bit timestamp from IV entry. drain retry fault check timestamp of rptr is larger than timestamp of (checkpoint_wptr - 32).
Add function amdgpu_ih_process1 to process IH ring1 until timestamp of rptr is larger then timestamp of (rptr + 32).
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c | 98 +++++++++++++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h | 6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 2 +- 4 files changed, 80 insertions(+), 28 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +74 -24
@@ -165,51 +165,41 @@ void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, }/* Waiter helper that checks current rptr matches or passes checkpoint wptr */ -static bool amdgpu_ih_has_checkpoint_processed (struct amdgpu_device *adev, +static bool amdgpu_ih_has_checkpoint_processed_ts (struct amdgpu_device *adev,struct amdgpu_ih_ring *ih, -uint32_t checkpoint_wptr, -uint32_t *prev_rptr) +uint64_t checkpoint_ts) { -uint32_t cur_rptr = ih->rptr | (*prev_rptr & ~ih->ptr_mask); - -/* rptr has wrapped. */ -if (cur_rptr < *prev_rptr) - cur_rptr += ih->ptr_mask +1 ; - *prev_rptr = cur_rptr; - -/* check ring is empty to workaround missing wptr overflow flag */ -return cur_rptr >= checkpoint_wptr || - (cur_rptr & ih->ptr_mask) ==amdgpu_ih_get_wptr (adev, ih); +/* After wakeup, ih->rptr is the entry which is being processed, check +* the timestamp of previous entry which is processed. +*/ +return checkpoint_ts <=amdgpu_ih_decode_iv_ts (ih, ih->rptr -32 ); }/** -* amdgpu_ih_wait_on_checkpoint_process - wait to process IVs up to checkpoint +* amdgpu_ih_wait_on_checkpoint_process_ts - wait to process IVs up to checkpoint * * @adev: amdgpu_device pointer * @ih: ih ring to process * * Used to ensure ring has processed IVs up to the checkpoint write pointer. */ -int amdgpu_ih_wait_on_checkpoint_process (struct amdgpu_device *adev, +int amdgpu_ih_wait_on_checkpoint_process_ts (struct amdgpu_device *adev,struct amdgpu_ih_ring *ih) { -uint32_t checkpoint_wptr, rptr; +uint32_t checkpoint_wptr; +uint64_t checkpoint_ts;if (!ih->enabled || adev->shutdown)return -ENODEV ; checkpoint_wptr =amdgpu_ih_get_wptr (adev, ih); -/* Order wptr with rptr. */ +/* Order wptr with ring data. */ rmb (); - rptr =READ_ONCE (ih->rptr); - -/* wptr has wrapped. */ -if (rptr > checkpoint_wptr) - checkpoint_wptr += ih->ptr_mask +1 ; + checkpoint_ts =amdgpu_ih_decode_iv_ts (ih, checkpoint_wptr -32 );return wait_event_interruptible (ih->wait_process, -amdgpu_ih_has_checkpoint_processed (adev, ih, - checkpoint_wptr, &rptr)); +amdgpu_ih_has_checkpoint_processed_ts (adev, ih, + checkpoint_ts)); }/**
@@ -253,6 +243,56 @@ int amdgpu_ih_process(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih)return IRQ_HANDLED ; } +/** +* amdgpu_ih_process1 - interrupt handler work for IH ring1 +* +* @adev: amdgpu_device pointer +* @ih: ih ring to process +* +* Interrupt handler of IH ring1, walk the IH ring1. +* Returns irq process return code. +*/ +int amdgpu_ih_process1 (struct amdgpu_device *adev,struct amdgpu_ih_ring *ih) +{ +uint64_t ts, ts_next; +unsigned int count; +u32 wptr; + +if (!ih->enabled || adev->shutdown) +return IRQ_NONE ; + + wptr =amdgpu_ih_get_wptr (adev, ih); +if (ih->rptr == wptr) +return 0 ; + +restart_ih: + count =AMDGPU_IH_MAX_NUM_IVS ; + + ts =amdgpu_ih_decode_iv_ts (ih, ih->rptr); + ts_next =amdgpu_ih_decode_iv_ts (ih, ih->rptr +32 ); +while (ts < ts_next && --count) { +amdgpu_irq_dispatch (adev, ih); + ih->rptr &= ih->ptr_mask; + ts = ts_next; + ts_next =amdgpu_ih_decode_iv_ts (ih, ih->rptr +32 ); + } +/* +* Process the last timestamp updated entry or one more entry +* if count = 0, ts is timestamp of the entry. +*/ +amdgpu_irq_dispatch (adev, ih); +amdgpu_ih_set_rptr (adev, ih); +wake_up_all (&ih->wait_process); + + wptr =amdgpu_ih_get_wptr (adev, ih); +/* Order reading of wptr vs. reading of IH ring data */ +rmb (); +if (ts <amdgpu_ih_decode_iv_ts (ih, wptr -32 )) + goto restart_ih; + +return IRQ_HANDLED ; +} +/** * amdgpu_ih_decode_iv_helper - decode an interrupt vector *
@@ -298,3 +338,13 @@ void amdgpu_ih_decode_iv_helper(struct amdgpu_device *adev,/* wptr/rptr are in bytes! */ ih->rptr +=32 ; } + +uint64_t amdgpu_ih_decode_iv_ts (struct amdgpu_ih_ring *ih,u32 rptr) +{ +uint32_t index = (rptr & ih->ptr_mask) >>2 ; +uint32_t dw1, dw2; + + dw1 = ih->ring[index +1 ]; + dw2 = ih->ring[index +2 ]; +return dw1 | ((u64)(dw2 &0xffff ) <<32 ); +}
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +4 -2
@@ -89,10 +89,12 @@ int amdgpu_ih_ring_init(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih,void amdgpu_ih_ring_fini (struct amdgpu_device *adev,struct amdgpu_ih_ring *ih);void amdgpu_ih_ring_write (struct amdgpu_ih_ring *ih,const uint32_t *iv,unsigned int num_dw); -int amdgpu_ih_wait_on_checkpoint_process (struct amdgpu_device *adev, -struct amdgpu_ih_ring *ih); +int amdgpu_ih_wait_on_checkpoint_process_ts (struct amdgpu_device *adev, +struct amdgpu_ih_ring *ih);int amdgpu_ih_process (struct amdgpu_device *adev,struct amdgpu_ih_ring *ih); +int amdgpu_ih_process1 (struct amdgpu_device *adev,struct amdgpu_ih_ring *ih);void amdgpu_ih_decode_iv_helper (struct amdgpu_device *adev,struct amdgpu_ih_ring *ih,struct amdgpu_iv_entry *entry); +uint64_t amdgpu_ih_decode_iv_ts (struct amdgpu_ih_ring *ih,u32 rptr);#endif
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +1 -1
@@ -224,7 +224,7 @@ static void amdgpu_irq_handle_ih1(struct work_struct *work) struct amdgpu_device *adev = container_of(work, struct amdgpu_device, irq.ih1_work); -amdgpu_ih_process (adev, &adev->irq.ih1); +amdgpu_ih_process1 (adev, &adev->irq.ih1); }/**
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +1 -1
@@ -1968,7 +1968,7 @@ static void svm_range_drain_retry_fault(struct svm_range_list *svms)pr_debug ("drain retry fault gpu %d svms %p\n" , i, svms); -amdgpu_ih_wait_on_checkpoint_process (pdd->dev->adev, +amdgpu_ih_wait_on_checkpoint_process_ts (pdd->dev->adev, &pdd->dev->adev->irq.ih1);pr_debug ("drain retry fault gpu %d svms 0x%p done\n" , i, svms); }
Signature · 1 line
2.17.1
Felix Kuehling
maintainerQuoted 40 lines · Philip Yang
IH ring1 is used to process GPU retry fault, overflow is enabled to drain retry fault because we want receive other interrupts while handling retry fault to recover range. There is no overflow flag set when wptr pass rptr. Use timestamp of rptr and wptr to handle overflow and drain retry fault.
Add helper function
amdgpu_ih_decode_iv_tsto get 48bit timestamp from IV entry. drain retry fault check timestamp of rptr is larger than timestamp of (checkpoint_wptr- 32).Add function
amdgpu_ih_process1to process IH ring1 until timestamp of rptr is larger then timestamp of (rptr + 32).Signed-off-by Philip Yang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c | 98 +++++++++++++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h | 6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 2 +- 4 files changed, 80 insertions(+), 28 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +2
-7@@ -165,51 +165,41 @@ void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, }/* Waiter helper that checks current rptr matches or passes checkpoint wptr */ -static bool amdgpu_ih_has_checkpoint_processed (struct amdgpu_device *adev, +static bool amdgpu_ih_has_checkpoint_processed_ts (struct amdgpu_device *adev,struct amdgpu_ih_ring *ih, -uint32_t checkpoint_wptr, -uint32_t *prev_rptr) +uint64_t checkpoint_ts) { -uint32_t cur_rptr = ih->rptr | (*prev_rptr & ~ih->ptr_mask); - -/* rptr has wrapped. */ -if (cur_rptr < *prev_rptr)
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, · line 175
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +4
-6- cur_rptr += ih->ptr_mask +1 ; - *prev_rptr = cur_rptr; - -/* check ring is empty to workaround missing wptr overflow flag */ -return cur_rptr >= checkpoint_wptr || - (cur_rptr & ih->ptr_mask) ==amdgpu_ih_get_wptr (adev, ih); +/* After wakeup, ih->rptr is the entry which is being processed, check +* the timestamp of previous entry which is processed. +*/ +return checkpoint_ts <=amdgpu_ih_decode_iv_ts (ih, ih->rptr -32 );
This assumes a IV size of 32 bytes, which is not true for all ASICs. On GFXv8 and older GPUs it's on 16. OTOH, those chips don't have a ring1 and may not have a timestamp in the IV at all.
And I think you need to be better at handling when the time stamps wrap. Keep in mind that the number of valid bits may vary between ASICs.
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +0
-1}/** -* amdgpu_ih_wait_on_checkpoint_process - wait to process IVs up to checkpoint
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, · line 187
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +2
-1+* amdgpu_ih_wait_on_checkpoint_process_ts - wait to process IVs up to checkpoint * * @adev: amdgpu_device pointer * @ih: ih ring to process * * Used to ensure ring has processed IVs up to the checkpoint write pointer. */ -int amdgpu_ih_wait_on_checkpoint_process (struct amdgpu_device *adev, +int amdgpu_ih_wait_on_checkpoint_process_ts (struct amdgpu_device *adev,struct amdgpu_ih_ring *ih)
If this function is only meant to work on ring1 now, we should probably ensure that by checking that ih is really ring1.
Do we need to keep the old solution for Vega20, which doesn't reroute interrupts to ring1?
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +2
-1{ -uint32_t checkpoint_wptr, rptr; +uint32_t checkpoint_wptr; +uint64_t checkpoint_ts;if (!ih->enabled || adev->shutdown)return -ENODEV ;
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, · line 198
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +2
-6checkpoint_wptr =amdgpu_ih_get_wptr (adev, ih); -/* Order wptr with rptr. */ +/* Order wptr with ring data. */ rmb (); - rptr =READ_ONCE (ih->rptr); - -/* wptr has wrapped. */ -if (rptr > checkpoint_wptr) - checkpoint_wptr += ih->ptr_mask +1 ; + checkpoint_ts =amdgpu_ih_decode_iv_ts (ih, checkpoint_wptr -32 );
Same as above.
Quoted 30 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +19
-2return wait_event_interruptible (ih->wait_process, -amdgpu_ih_has_checkpoint_processed (adev, ih, - checkpoint_wptr, &rptr)); +amdgpu_ih_has_checkpoint_processed_ts (adev, ih, + checkpoint_ts)); }/** @@ -253,6 +243,56 @@ int amdgpu_ih_process(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih)return IRQ_HANDLED ; } +/** +* amdgpu_ih_process1 - interrupt handler work for IH ring1 +* +* @adev: amdgpu_device pointer +* @ih: ih ring to process +* +* Interrupt handler of IH ring1, walk the IH ring1. +* Returns irq process return code. +*/ +int amdgpu_ih_process1 (struct amdgpu_device *adev,struct amdgpu_ih_ring *ih) +{ +uint64_t ts, ts_next; +unsigned int count; +u32 wptr; + +if (!ih->enabled || adev->shutdown) +return IRQ_NONE ;
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c int amdgpu_ih_process(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih) · line 272
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +10
-0+ + wptr =amdgpu_ih_get_wptr (adev, ih); +if (ih->rptr == wptr) +return 0 ; + +restart_ih: + count =AMDGPU_IH_MAX_NUM_IVS ; + + ts =amdgpu_ih_decode_iv_ts (ih, ih->rptr); + ts_next =amdgpu_ih_decode_iv_ts (ih, ih->rptr +32 );
Same as above.
Quoted 27 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +23
-0+while (ts < ts_next && --count) { +amdgpu_irq_dispatch (adev, ih); + ih->rptr &= ih->ptr_mask; + ts = ts_next; + ts_next =amdgpu_ih_decode_iv_ts (ih, ih->rptr +32 ); + } +/* +* Process the last timestamp updated entry or one more entry +* if count = 0, ts is timestamp of the entry. +*/ +amdgpu_irq_dispatch (adev, ih); +amdgpu_ih_set_rptr (adev, ih); +wake_up_all (&ih->wait_process); + + wptr =amdgpu_ih_get_wptr (adev, ih); +/* Order reading of wptr vs. reading of IH ring data */ +rmb (); +if (ts <amdgpu_ih_decode_iv_ts (ih, wptr -32 )) + goto restart_ih; + +return IRQ_HANDLED ; +} +/** * amdgpu_ih_decode_iv_helper - decode an interrupt vector *
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_decode_iv_helper(struct amdgpu_device *adev, · line 342
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +2
-0@@ -298,3 +338,13 @@ void amdgpu_ih_decode_iv_helper(struct amdgpu_device *adev,/* wptr/rptr are in bytes! */ ih->rptr +=32 ; } + +uint64_t amdgpu_ih_decode_iv_ts (struct amdgpu_ih_ring *ih,u32 rptr)
This function needs to be in IP-version-specific code. Maybe add an offset parameter, that way you can handle different IV sizes in different ASIC generations.
Quoted 53 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +8
-0+{ +uint32_t index = (rptr & ih->ptr_mask) >>2 ; +uint32_t dw1, dw2; + + dw1 = ih->ring[index +1 ]; + dw2 = ih->ring[index +2 ]; +return dw1 | ((u64)(dw2 &0xffff ) <<32 ); +}drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +4
-2@@ -89,10 +89,12 @@ int amdgpu_ih_ring_init(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih,void amdgpu_ih_ring_fini (struct amdgpu_device *adev,struct amdgpu_ih_ring *ih);void amdgpu_ih_ring_write (struct amdgpu_ih_ring *ih,const uint32_t *iv,unsigned int num_dw); -int amdgpu_ih_wait_on_checkpoint_process (struct amdgpu_device *adev, -struct amdgpu_ih_ring *ih); +int amdgpu_ih_wait_on_checkpoint_process_ts (struct amdgpu_device *adev, +struct amdgpu_ih_ring *ih);int amdgpu_ih_process (struct amdgpu_device *adev,struct amdgpu_ih_ring *ih); +int amdgpu_ih_process1 (struct amdgpu_device *adev,struct amdgpu_ih_ring *ih);void amdgpu_ih_decode_iv_helper (struct amdgpu_device *adev,struct amdgpu_ih_ring *ih,struct amdgpu_iv_entry *entry); +uint64_t amdgpu_ih_decode_iv_ts (struct amdgpu_ih_ring *ih,u32 rptr);#endif drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +1
-1@@ -224,7 +224,7 @@ static void amdgpu_irq_handle_ih1(struct work_struct *work) struct amdgpu_device *adev = container_of(work, struct amdgpu_device, irq.ih1_work); -amdgpu_ih_process (adev, &adev->irq.ih1); +amdgpu_ih_process1 (adev, &adev->irq.ih1); }/** drivers/gpu/drm/amd/amdkfd/kfd_svm.c +1
-1@@ -1968,7 +1968,7 @@ static void svm_range_drain_retry_fault(struct svm_range_list *svms)pr_debug ("drain retry fault gpu %d svms %p\n" , i, svms); -amdgpu_ih_wait_on_checkpoint_process (pdd->dev->adev, +amdgpu_ih_wait_on_checkpoint_process_ts (pdd->dev->adev, &pdd->dev->adev->irq.ih1);pr_debug ("drain retry fault gpu %d svms 0x%p done\n" , i, svms); }
On 2021-11-19 5:59 p.m., Felix Kuehling wrote:
On 2021-11-19 3:22 p.m., Philip Yang wrote:
IH ring1 is used to process GPU retry fault, overflow is enabled to drain retry fault because we want receive other interrupts while handling retry fault to recover range. There is no overflow flag set when wptr pass rptr. Use timestamp of rptr and wptr to handle overflow and drain retry fault.
Add helper function amdgpu_ih_decode_iv_ts to get 48bit timestamp from IV entry. drain retry fault check timestamp of rptr is larger than timestamp of (checkpoint_wptr - 32).
Add function amdgpu_ih_process1 to process IH ring1 until timestamp of rptr is larger then timestamp of (rptr + 32).
---
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c | 98 +++++++++++++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h | 6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 2 +-
4 files changed, 80 insertions(+), 28 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +0 -0
@@ -165,51 +165,41 @@ void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv,
}
/* Waiter helper that checks current rptr matches or passes checkpoint wptr */ -static bool amdgpu_ih_has_checkpoint_processed(struct amdgpu_device *adev, +static bool amdgpu_ih_has_checkpoint_processed_ts(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih,
- uint32_t checkpoint_wptr,
- uint32_t *prev_rptr)
+ uint64_t checkpoint_ts)
{
- uint32_t cur_rptr = ih->rptr | (*prev_rptr & ~ih->ptr_mask);
-
- /* rptr has wrapped. */
- if (cur_rptr < *prev_rptr)
- cur_rptr += ih->ptr_mask + 1;
- *prev_rptr = cur_rptr;
-
- /* check ring is empty to workaround missing wptr overflow flag */ - return cur_rptr >= checkpoint_wptr ||
- (cur_rptr & ih->ptr_mask) == amdgpu_ih_get_wptr(adev, ih); + /* After wakeup, ih->rptr is the entry which is being processed, check + * the timestamp of previous entry which is processed.
+ */
+ return checkpoint_ts <= amdgpu_ih_decode_iv_ts(ih, ih->rptr - 32);
This assumes a IV size of 32 bytes, which is not true for all ASICs. On GFXv8 and older GPUs it's on 16. OTOH, those chips don't have a ring1 and may not have a timestamp in the IV at all.
ring1 process is enabled for vega10/20, navi10, not for older GPUs, as it is scheduled from self-irq.
And I think you need to be better at handling when the time stamps wrap. Keep in mind that the number of valid bits may vary between ASICs.
yes, 48bit time stamp will wrap around after 1 year, add function amdgpu_ih_ts_after to compare time stamp with wrap around case.
}
/**
- * amdgpu_ih_wait_on_checkpoint_process - wait to process IVs up to checkpoint
+ * amdgpu_ih_wait_on_checkpoint_process_ts - wait to process IVs up to checkpoint *
* @adev: amdgpu_device pointer
* @ih: ih ring to process
*
* Used to ensure ring has processed IVs up to the checkpoint write pointer. */
-int amdgpu_ih_wait_on_checkpoint_process(struct amdgpu_device *adev, +int amdgpu_ih_wait_on_checkpoint_process_ts(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih)
If this function is only meant to work on ring1 now, we should probably ensure that by checking that ih is really ring1.
Add dev_WARN_ONCE(adev->dev, ih != &adev->irq.ih1, "not ring1")) to ensure this is only for ring1.
Do we need to keep the old solution for Vega20, which doesn't reroute interrupts to ring1?
Vega20 is not changed, because Vega20 retry fault delegate to ih_soft, and wptr overflow is not enabled on ih_soft, no stale retry fault issue, keep old interrupt handler for ih_soft.
{
- uint32_t checkpoint_wptr, rptr;
+ uint32_t checkpoint_wptr;
+ uint64_t checkpoint_ts;
if (!ih->enabled || adev->shutdown)
return -ENODEV;
checkpoint_wptr = amdgpu_ih_get_wptr(adev, ih);
- /* Order wptr with rptr. */
+ /* Order wptr with ring data. */
rmb();
- rptr = READ_ONCE(ih->rptr);
-
- /* wptr has wrapped. */
- if (rptr > checkpoint_wptr)
- checkpoint_wptr += ih->ptr_mask + 1;
+ checkpoint_ts = amdgpu_ih_decode_iv_ts(ih, checkpoint_wptr - 32);
Same as above.
done in v3
return wait_event_interruptible(ih->wait_process,
- amdgpu_ih_has_checkpoint_processed(adev, ih,
- checkpoint_wptr, &rptr));
+ amdgpu_ih_has_checkpoint_processed_ts(adev, ih,
+ checkpoint_ts));
}
/**
@@ -253,6 +243,56 @@ int amdgpu_ih_process(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih) return IRQ_HANDLED;
}
+/**
+ * amdgpu_ih_process1 - interrupt handler work for IH ring1
+ *
+ * @adev: amdgpu_device pointer
+ * @ih: ih ring to process
+ *
+ * Interrupt handler of IH ring1, walk the IH ring1.
+ * Returns irq process return code.
+ */
+int amdgpu_ih_process1(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih)
+{
+ uint64_t ts, ts_next;
+ unsigned int count;
+ u32 wptr;
+
+ if (!ih->enabled || adev->shutdown)
+ return IRQ_NONE;
+
+ wptr = amdgpu_ih_get_wptr(adev, ih);
+ if (ih->rptr == wptr)
+ return 0;
+
+restart_ih:
+ count = AMDGPU_IH_MAX_NUM_IVS;
+
+ ts = amdgpu_ih_decode_iv_ts(ih, ih->rptr);
+ ts_next = amdgpu_ih_decode_iv_ts(ih, ih->rptr + 32);
Same as above.
Done in v3
+ while (ts < ts_next && --count) {
+ amdgpu_irq_dispatch(adev, ih);
+ ih->rptr &= ih->ptr_mask;
+ ts = ts_next;
+ ts_next = amdgpu_ih_decode_iv_ts(ih, ih->rptr + 32);
+ }
+ /*
+ * Process the last timestamp updated entry or one more entry + * if count = 0, ts is timestamp of the entry.
+ */
+ amdgpu_irq_dispatch(adev, ih);
+ amdgpu_ih_set_rptr(adev, ih);
+ wake_up_all(&ih->wait_process);
+
+ wptr = amdgpu_ih_get_wptr(adev, ih);
+ /* Order reading of wptr vs. reading of IH ring data */
+ rmb();
+ if (ts < amdgpu_ih_decode_iv_ts(ih, wptr - 32))
+ goto restart_ih;
+
+ return IRQ_HANDLED;
+}
+
/**
* amdgpu_ih_decode_iv_helper - decode an interrupt vector
*
@@ -298,3 +338,13 @@ void amdgpu_ih_decode_iv_helper(struct amdgpu_device *adev, /* wptr/rptr are in bytes! */
ih->rptr += 32;
}
+
+uint64_t amdgpu_ih_decode_iv_ts(struct amdgpu_ih_ring *ih, u32 rptr)
This function needs to be in IP-version-specific code. Maybe add an offset parameter, that way you can handle different IV sizes in different ASIC generations.
Add decode_iv_ts function interface to amdgpu_ih_function, this will be used for different ASICs, to handle different IV size and time stamp offset. vega*, navi* ASICs use this as helper function.
Regards,
Philip
+{
+ uint32_t index = (rptr & ih->ptr_mask) >> 2;
+ uint32_t dw1, dw2;
+
+ dw1 = ih->ring[index + 1];
+ dw2 = ih->ring[index + 2];
+ return dw1 | ((u64)(dw2 & 0xffff) << 32);
+}
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +0 -0
@@ -89,10 +89,12 @@ int amdgpu_ih_ring_init(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih,
void amdgpu_ih_ring_fini(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih); void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, unsigned int num_dw);
-int amdgpu_ih_wait_on_checkpoint_process(struct amdgpu_device *adev, - struct amdgpu_ih_ring *ih);
+int amdgpu_ih_wait_on_checkpoint_process_ts(struct amdgpu_device *adev, + struct amdgpu_ih_ring *ih);
int amdgpu_ih_process(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih); +int amdgpu_ih_process1(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih); void amdgpu_ih_decode_iv_helper(struct amdgpu_device *adev,
struct amdgpu_ih_ring *ih,
struct amdgpu_iv_entry *entry);
+uint64_t amdgpu_ih_decode_iv_ts(struct amdgpu_ih_ring *ih, u32 rptr); #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +0 -0
@@ -224,7 +224,7 @@ static void amdgpu_irq_handle_ih1(struct work_struct *work)
struct amdgpu_device *adev = container_of(work, struct amdgpu_device, irq.ih1_work);
- amdgpu_ih_process(adev, &adev->irq.ih1);
+ amdgpu_ih_process1(adev, &adev->irq.ih1);
}
/**
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0
@@ -1968,7 +1968,7 @@ static void svm_range_drain_retry_fault(struct svm_range_list *svms)
pr_debug("drain retry fault gpu %d svms %p\n", i, svms); - amdgpu_ih_wait_on_checkpoint_process(pdd->dev->adev, + amdgpu_ih_wait_on_checkpoint_process_ts(pdd->dev->adev, &pdd->dev->adev->irq.ih1); pr_debug("drain retry fault gpu %d svms 0x%p done\n", i, svms); }
Christian König
maintainerAm 21.11.21 um 03:13 schrieb philip yang:
Quoted 61 lines · Felix Kuehling
Quoted 50 lines · Philip Yang
Quoted 48 lines
IH ring1 is used to process GPU retry fault, overflow is enabled to drain retry fault because we want receive other interrupts while handling retry fault to recover range. There is no overflow flag set when wptr pass rptr. Use timestamp of rptr and wptr to handle overflow and drain retry fault.
Add helper function
amdgpu_ih_decode_iv_tsto get 48bit timestamp from IV entry. drain retry fault check timestamp of rptr is larger than timestamp of (checkpoint_wptr- 32).Add function
amdgpu_ih_process1to process IH ring1 until timestamp of rptr is larger then timestamp of (rptr + 32).Signed-off-by Philip Yang <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c | 98
+++++++++++++++++++------
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h | 6 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c| 2 +-
drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 2 +-4 files changed, 80 insertions(+), 28 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +2
-12@@ -165,51 +165,41 @@ void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, } /* Waiter helper that checks current rptr matches or passes checkpoint wptr */ -static bool amdgpu_ih_has_checkpoint_processed(struct amdgpu_device *adev, +static bool amdgpu_ih_has_checkpoint_processed_ts(structamdgpu_device *adev, struct amdgpu_ih_ring *ih, - uint32_t checkpoint_wptr, - uint32_t *prev_rptr) + uint64_t checkpoint_ts) { - uint32_t cur_rptr = ih->rptr | (*prev_rptr & ~ih->ptr_mask); - - /* rptr has wrapped. */ - if (cur_rptr < *prev_rptr) - cur_rptr += ih->ptr_mask + 1; - *prev_rptr = cur_rptr; - - /* check ring is empty to workaround missing wptr overflow flag */ - return cur_rptr >= checkpoint_wptr ||Quoted 9 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +1
-1- (cur_rptr & ih->ptr_mask) == amdgpu_ih_get_wptr(adev, ih); + /* After wakeup, ih->rptr is the entry which is beingprocessed, check
+ * the timestamp of previous entry which is processed. + */
+ returncheckpoint_ts<=amdgpu_ih_decode_iv_ts(ih, ih->rptr - 32);This assumes a IV size of 32 bytes, which is not true for all ASICs. On GFXv8 and older GPUs it's on 16. OTOH, those chips don't have a ring1 and may not have a timestamp in the IV at all.
Quoted 1 line
ring1 process is enabled for vega10/20, navi10, not for older GPUs, as it is scheduled from self-irq.
I think we should try to avoid accessing the IH ring buffer outside of the handler anyway.
So instead of that here we should probably just always update the last decoded timestamp after a call to amdgpu_ih_decode_iv_helper().
Quoted 3 lines
Quoted 2 lines
And I think you need to be better at handling when the time stamps wrap. Keep in mind that the number of valid bits may vary between ASICs.
yes, 48bit time stamp will wrap around after 1 year, add function
amdgpu_ih_ts_afterto compare time stamp with wrap around case.
Yeah, I think we need to handle that gracefully.
Regards,
Christian.
Quoted 188 lines
Quoted 11 lines
Quoted 11 lines
}
/**
- *amdgpu_ih_wait_on_checkpoint_process- wait to process IVs up to checkpoint
+ *amdgpu_ih_wait_on_checkpoint_process_ts- wait to process IVs up to checkpoint
*
* @adev:amdgpu_devicepointer
* @ih: ih ring to process
*Quoted 9 lines
Quoted 6 lines
* Used to ensure ring has processed IVs up to the checkpoint write pointer. */
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +1
-1-int amdgpu_ih_wait_on_checkpoint_process(struct amdgpu_device *adev, +int amdgpu_ih_wait_on_checkpoint_process_ts(struct amdgpu_device*adev,
structamdgpu_ih_ring*ih)If this function is only meant to work on ring1 now, we should probably ensure that by checking that ih is really ring1.
Add
dev_WARN_ONCE(adev->dev, ih != &adev->irq.ih1, "not ring1")) to ensure this is only for ring1.Quoted 2 lines
Do we need to keep the old solution for Vega20, which doesn't reroute interrupts to ring1?
Vega20 is not changed, because Vega20 retry fault delegate to
ih_soft, and wptr overflow is not enabled onih_soft, no stale retry fault issue, keep old interrupt handler forih_soft.Quoted 18 lines
Quoted 17 lines
{
-uint32_tcheckpoint_wptr, rptr;
+uint32_tcheckpoint_wptr;
+uint64_tcheckpoint_ts;
if (!ih->enabled ||adev->shutdown)
return-ENODEV;
checkpoint_wptr=amdgpu_ih_get_wptr(adev, ih);
- /* Order wptr with rptr. */
+ /* Order wptr with ring data. */
rmb();
- rptr =READ_ONCE(ih->rptr);
-
- /* wptr has wrapped. */
- if (rptr >checkpoint_wptr)
-checkpoint_wptr+=ih->ptr_mask+ 1;
+checkpoint_ts=amdgpu_ih_decode_iv_ts(ih, checkpoint_wptr - 32);Quoted 1 line
Same as above.
done in v3
Quoted 35 lines
Quoted 35 lines
return wait_event_interruptible(ih->wait_process, -
amdgpu_ih_has_checkpoint_processed(adev, ih, - checkpoint_wptr, &rptr));
+amdgpu_ih_has_checkpoint_processed_ts(adev, ih, + checkpoint_ts));
}
/**drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +0
-0@@ -253,6 +243,56 @@ int amdgpu_ih_process(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih) return IRQ_HANDLED; }+/**
+ *amdgpu_ih_process1- interrupt handler work for IH ring1
+ *
+ * @adev:amdgpu_devicepointer
+ * @ih: ih ring to process
+ *
+ * Interrupt handler of IH ring1, walk the IH ring1.
+ * Returns irq process return code.
+ */
+intamdgpu_ih_process1(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih)drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +11
-0+{ + uint64_t ts, ts_next; + unsigned int count; + u32 wptr; + + if (!ih->enabled || adev->shutdown) + return IRQ_NONE; + + wptr = amdgpu_ih_get_wptr(adev, ih); + if (ih->rptr == wptr) + return 0;Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +6
-0+ +restart_ih: + count = AMDGPU_IH_MAX_NUM_IVS; + + ts = amdgpu_ih_decode_iv_ts(ih, ih->rptr); + ts_next = amdgpu_ih_decode_iv_ts(ih, ih->rptr + 32);Same as above.
Done in v3
Quoted 28 lines
Quoted 28 lines
+ while (ts <
ts_next&& --count) {
+amdgpu_irq_dispatch(adev, ih);
+ih->rptr&=ih->ptr_mask;
+ ts =ts_next;
+ts_next=amdgpu_ih_decode_iv_ts(ih, ih->rptr + 32); + }
+ /*
+ * Process the last timestamp updated entry or one more entry + * if count = 0, ts is timestamp of the entry.
+ */
+amdgpu_irq_dispatch(adev, ih);
+amdgpu_ih_set_rptr(adev, ih);
+wake_up_all(&ih->wait_process);drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +10
-0+ + wptr = amdgpu_ih_get_wptr(adev, ih); + /* Order reading of wptr vs. reading of IH ring data */ + rmb(); + if (ts < amdgpu_ih_decode_iv_ts(ih, wptr - 32)) + goto restart_ih; + + return IRQ_HANDLED; +} +/**
*amdgpu_ih_decode_iv_helper- decode an interrupt vector *drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +0
-0@@ -298,3 +338,13 @@ void amdgpu_ih_decode_iv_helper(structQuoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +0
-0amdgpu_device *adev, /* wptr/rptr are in bytes! */ ih->rptr += 32;}
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +2
-0+ +uint64_t amdgpu_ih_decode_iv_ts (struct amdgpu_ih_ring *ih,u32 rptr)This function needs to be in IP-version-specific code. Maybe add an offset parameter, that way you can handle different IV sizes in different ASIC generations.
Add
decode_iv_tsfunction interface toamdgpu_ih_function, this will be used for different ASICs, to handle different IV size and time stamp offset. vega*, navi* ASICs use this as helper function.Regards,
Philip
Quoted 55 lines
Quoted 55 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +8
-0+{ + uint32_t index = (rptr & ih->ptr_mask) >> 2; + uint32_t dw1, dw2; + + dw1 = ih->ring[index + 1]; + dw2 = ih->ring[index + 2]; + return dw1 | ((u64)(dw2 & 0xffff) << 32); +}drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +3
-2@@ -89,10 +89,12 @@ int amdgpu_ih_ring_init(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih, void amdgpu_ih_ring_fini(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih); void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, unsigned int num_dw); -int amdgpu_ih_wait_on_checkpoint_process (struct amdgpu_device *adev, - struct amdgpu_ih_ring *ih); +int amdgpu_ih_wait_on_checkpoint_process_ts (struct amdgpu_device *adev, + struct amdgpu_ih_ring *ih); int amdgpu_ih_process(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih); +int amdgpu_ih_process1 (struct amdgpu_device *adev,struct amdgpu_ih_ring *ih); void amdgpu_ih_decode_iv_helper(struct amdgpu_device *adev,struct
amdgpu_ih_ring*ih,
structamdgpu_iv_entry*entry);
+uint64_tamdgpu_ih_decode_iv_ts(struct amdgpu_ih_ring *ih, u32 rptr); #endifdrivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +1
-0@@ -224,7 +224,7 @@ static void amdgpu_irq_handle_ih1(struct work_struct *work) struct amdgpu_device *adev = container_of(work, struct amdgpu_device, irq.ih1_work); - amdgpu_ih_process(adev, &adev->irq.ih1); + amdgpu_ih_process1(adev, &adev->irq.ih1); } /**drivers/gpu/drm/amd/amdkfd/kfd_svm.c +1
-0@@ -1968,7 +1968,7 @@ static void svm_range_drain_retry_fault(struct svm_range_list *svms) pr_debug("drain retry fault gpu %d svms %p\n", i, svms); - amdgpu_ih_wait_on_checkpoint_process(pdd->dev->adev, + amdgpu_ih_wait_on_checkpoint_process_ts(pdd->dev->adev, &pdd->dev->adev->irq.ih1); pr_debug("drain retry fault gpu %d svms 0x%p done\n", i, svms); }
On 2021-11-22 6:34 a.m., Christian König wrote:
Am 21.11.21 um 03:13 schrieb philip yang:
On 2021-11-19 5:59 p.m., Felix Kuehling wrote:
On 2021-11-19 3:22 p.m., Philip Yang wrote:
IH ring1 is used to process GPU retry fault, overflow is enabled to drain retry fault because we want receive other interrupts while handling retry fault to recover range. There is no overflow flag set when wptr pass rptr. Use timestamp of rptr and wptr to handle overflow and drain retry fault.
Add helper function amdgpu_ih_decode_iv_ts to get 48bit timestamp from IV entry. drain retry fault check timestamp of rptr is larger than timestamp of (checkpoint_wptr - 32).
Add function amdgpu_ih_process1 to process IH ring1 until timestamp of rptr is larger then timestamp of (rptr + 32).
---
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c | 98 +++++++++++++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h | 6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 2 +-
4 files changed, 80 insertions(+), 28 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +0 -0
@@ -165,51 +165,41 @@ void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv,
}
/* Waiter helper that checks current rptr matches or passes checkpoint wptr */ -static bool amdgpu_ih_has_checkpoint_processed(struct amdgpu_device *adev, +static bool amdgpu_ih_has_checkpoint_processed_ts(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih,
- uint32_t checkpoint_wptr,
- uint32_t *prev_rptr)
+ uint64_t checkpoint_ts)
{
- uint32_t cur_rptr = ih->rptr | (*prev_rptr & ~ih->ptr_mask);
-
- /* rptr has wrapped. */
- if (cur_rptr < *prev_rptr)
- cur_rptr += ih->ptr_mask + 1;
- *prev_rptr = cur_rptr;
-
- /* check ring is empty to workaround missing wptr overflow flag */ - return cur_rptr >= checkpoint_wptr ||
- (cur_rptr & ih->ptr_mask) == amdgpu_ih_get_wptr(adev, ih); + /* After wakeup, ih->rptr is the entry which is being processed, check + * the timestamp of previous entry which is processed.
+ */
+ return checkpoint_ts <= amdgpu_ih_decode_iv_ts(ih, ih->rptr - 32);
This assumes a IV size of 32 bytes, which is not true for all ASICs. On GFXv8 and older GPUs it's on 16. OTOH, those chips don't have a ring1 and may not have a timestamp in the IV at all.
ring1 process is enabled for vega10/20, navi10, not for older GPUs, as it is scheduled from self-irq.
I think we should try to avoid accessing the IH ring buffer outside of the handler anyway.
So instead of that here we should probably just always update the last decoded timestamp after a call to amdgpu_ih_decode_iv_helper(). Good point, add ih->processed_timstamp in v4 as the last decoded timestamp.
And I think you need to be better at handling when the time stamps wrap. Keep in mind that the number of valid bits may vary between ASICs.
yes, 48bit time stamp will wrap around after 1 year, add function amdgpu_ih_ts_after to compare time stamp with wrap around case.
Yeah, I think we need to handle that gracefully.
v4 also uses le32_to_cpu to read timestamp to support big endian platform.
Regards,
Philip
Regards,
Christian.
}
/**
- * amdgpu_ih_wait_on_checkpoint_process - wait to process IVs up to checkpoint
+ * amdgpu_ih_wait_on_checkpoint_process_ts - wait to process IVs up to checkpoint *
* @adev: amdgpu_device pointer
* @ih: ih ring to process
*
* Used to ensure ring has processed IVs up to the checkpoint write pointer. */
-int amdgpu_ih_wait_on_checkpoint_process(struct amdgpu_device *adev, +int amdgpu_ih_wait_on_checkpoint_process_ts(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih)
If this function is only meant to work on ring1 now, we should probably ensure that by checking that ih is really ring1.
Add dev_WARN_ONCE(adev->dev, ih != &adev->irq.ih1, "not ring1")) to ensure this is only for ring1.
Do we need to keep the old solution for Vega20, which doesn't reroute interrupts to ring1?
Vega20 is not changed, because Vega20 retry fault delegate to ih_soft, and wptr overflow is not enabled on ih_soft, no stale retry fault issue, keep old interrupt handler for ih_soft.
{
- uint32_t checkpoint_wptr, rptr;
+ uint32_t checkpoint_wptr;
+ uint64_t checkpoint_ts;
if (!ih->enabled || adev->shutdown)
return -ENODEV;
checkpoint_wptr = amdgpu_ih_get_wptr(adev, ih);
- /* Order wptr with rptr. */
+ /* Order wptr with ring data. */
rmb();
- rptr = READ_ONCE(ih->rptr);
-
- /* wptr has wrapped. */
- if (rptr > checkpoint_wptr)
- checkpoint_wptr += ih->ptr_mask + 1;
+ checkpoint_ts = amdgpu_ih_decode_iv_ts(ih, checkpoint_wptr - 32);
Same as above.
done in v3
return wait_event_interruptible(ih->wait_process,
- amdgpu_ih_has_checkpoint_processed(adev, ih,
- checkpoint_wptr, &rptr));
+ amdgpu_ih_has_checkpoint_processed_ts(adev, ih,
+ checkpoint_ts));
}
/**
@@ -253,6 +243,56 @@ int amdgpu_ih_process(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih) return IRQ_HANDLED;
}
+/**
+ * amdgpu_ih_process1 - interrupt handler work for IH ring1
+ *
+ * @adev: amdgpu_device pointer
+ * @ih: ih ring to process
+ *
+ * Interrupt handler of IH ring1, walk the IH ring1.
+ * Returns irq process return code.
+ */
+int amdgpu_ih_process1(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih)
+{
+ uint64_t ts, ts_next;
+ unsigned int count;
+ u32 wptr;
+
+ if (!ih->enabled || adev->shutdown)
+ return IRQ_NONE;
+
+ wptr = amdgpu_ih_get_wptr(adev, ih);
+ if (ih->rptr == wptr)
+ return 0;
+
+restart_ih:
+ count = AMDGPU_IH_MAX_NUM_IVS;
+
+ ts = amdgpu_ih_decode_iv_ts(ih, ih->rptr);
+ ts_next = amdgpu_ih_decode_iv_ts(ih, ih->rptr + 32);
Same as above.
Done in v3
+ while (ts < ts_next && --count) {
+ amdgpu_irq_dispatch(adev, ih);
+ ih->rptr &= ih->ptr_mask;
+ ts = ts_next;
+ ts_next = amdgpu_ih_decode_iv_ts(ih, ih->rptr + 32);
+ }
+ /*
+ * Process the last timestamp updated entry or one more entry + * if count = 0, ts is timestamp of the entry.
+ */
+ amdgpu_irq_dispatch(adev, ih);
+ amdgpu_ih_set_rptr(adev, ih);
+ wake_up_all(&ih->wait_process);
+
+ wptr = amdgpu_ih_get_wptr(adev, ih);
+ /* Order reading of wptr vs. reading of IH ring data */
+ rmb();
+ if (ts < amdgpu_ih_decode_iv_ts(ih, wptr - 32))
+ goto restart_ih;
+
+ return IRQ_HANDLED;
+}
+
/**
* amdgpu_ih_decode_iv_helper - decode an interrupt vector
*
@@ -298,3 +338,13 @@ void amdgpu_ih_decode_iv_helper(struct amdgpu_device *adev, /* wptr/rptr are in bytes! */
ih->rptr += 32;
}
+
+uint64_t amdgpu_ih_decode_iv_ts(struct amdgpu_ih_ring *ih, u32 rptr)
This function needs to be in IP-version-specific code. Maybe add an offset parameter, that way you can handle different IV sizes in different ASIC generations.
Add decode_iv_ts function interface to amdgpu_ih_function, this will be used for different ASICs, to handle different IV size and time stamp offset. vega*, navi* ASICs use this as helper function.
Regards,
Philip
+{
+ uint32_t index = (rptr & ih->ptr_mask) >> 2;
+ uint32_t dw1, dw2;
+
+ dw1 = ih->ring[index + 1];
+ dw2 = ih->ring[index + 2];
+ return dw1 | ((u64)(dw2 & 0xffff) << 32);
+}
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +0 -0
@@ -89,10 +89,12 @@ int amdgpu_ih_ring_init(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih,
void amdgpu_ih_ring_fini(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih); void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, unsigned int num_dw);
-int amdgpu_ih_wait_on_checkpoint_process(struct amdgpu_device *adev, - struct amdgpu_ih_ring *ih);
+int amdgpu_ih_wait_on_checkpoint_process_ts(struct amdgpu_device *adev, + struct amdgpu_ih_ring *ih);
int amdgpu_ih_process(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih); +int amdgpu_ih_process1(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih); void amdgpu_ih_decode_iv_helper(struct amdgpu_device *adev,
struct amdgpu_ih_ring *ih,
struct amdgpu_iv_entry *entry);
+uint64_t amdgpu_ih_decode_iv_ts(struct amdgpu_ih_ring *ih, u32 rptr); #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +0 -0
@@ -224,7 +224,7 @@ static void amdgpu_irq_handle_ih1(struct work_struct *work)
struct amdgpu_device *adev = container_of(work, struct amdgpu_device, irq.ih1_work);
- amdgpu_ih_process(adev, &adev->irq.ih1);
+ amdgpu_ih_process1(adev, &adev->irq.ih1);
}
/**
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0
@@ -1968,7 +1968,7 @@ static void svm_range_drain_retry_fault(struct svm_range_list *svms)
pr_debug("drain retry fault gpu %d svms %p\n", i, svms);
- amdgpu_ih_wait_on_checkpoint_process(pdd->dev->adev,
+ amdgpu_ih_wait_on_checkpoint_process_ts(pdd->dev->adev, &pdd->dev->adev->irq.ih1);
pr_debug("drain retry fault gpu %d svms 0x%p done\n", i, svms); }