Skip to contentSkip to conversation

Improve soft IH ring

PATCH Applied Timur Kristóf 4 participants 12 messages May 13 – Jun 16

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Improve soft IH ring

The soft interrupt handler ring is used in scenarios when it is beneficial to not process some interrupts in the interrupt handler of the HW interrupts.

Fix some bugs in the soft IH ring, eg. the kernel should not access HW registers when working with the soft IH ring and improve its effectiveness by dispatching it on the unbound workqueue.

These patches make it more feasible to use the soft IH ring for handling retry page faults on GPUs that don't have the filter CAM. The actual retry page fault improvements are in a separate series.

Timur Kristóf (3):
amdgpu/ih6.1: Fix minor version
amdgpu/ih: Don't perturb HW registers when accessing soft IH ring drm/amdgpu: Use system unbound workqueue for soft IH ring

 drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/ih_v6_0.c    | 7 +++++++
 drivers/gpu/drm/amd/amdgpu/ih_v6_1.c    | 9 ++++++++-
 drivers/gpu/drm/amd/amdgpu/ih_v7_0.c    | 7 +++++++
 drivers/gpu/drm/amd/amdgpu/navi10_ih.c  | 4 ++++
 5 files changed, 27 insertions(+), 2 deletions(-)
Signature · 1 line
2.54.0
#1 lore raw

PATCH 1/3 amdgpu/ih6.1: Fix minor version

Report the correct version of IH v6.1 (previously it showed v6.0).

---
 drivers/gpu/drm/amd/amdgpu/ih_v6_1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/ih_v6_1.c +1 -1
index 95b3f4e55ec3..699c274d357e 100644
@@ -790,7 +790,7 @@ static void ih_v6_1_set_interrupt_funcs(struct amdgpu_device *adev)
 const struct amdgpu_ip_block_version ih_v6_1_ip_block = {
 	.type = AMD_IP_BLOCK_TYPE_IH,
 	.major = 6,
-	.minor = 0,
+	.minor = 1,
 	.rev = 0,
 	.funcs = &ih_v6_1_ip_funcs,
 };
Signature · 1 line
2.54.0
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] amdgpu/ih6.1: Fix minor version

Quoted 12 lines · Timur Kristóf

Report the correct version of IH v6.1 (previously it showed v6.0).

---
  drivers/gpu/drm/amd/amdgpu/ih_v6_1.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/ih_v6_1.c +0 -0
index 95b3f4e55ec3..699c274d357e 100644

drivers/gpu/drm/amd/amdgpu/ih_v6_1.c static void ih_v6_1_set_interrupt_funcs(struct amdgpu_device *adev) · line 796

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/ih_v6_1.c +1 -1
@@ -790,7 +790,7 @@ static void ih_v6_1_set_interrupt_funcs(struct amdgpu_device *adev)
  const struct amdgpu_ip_block_version ih_v6_1_ip_block = {
  	.type = AMD_IP_BLOCK_TYPE_IH,
  	.major = 6,
-	.minor = 0,
+	.minor = 1,
  	.rev = 0,
  	.funcs = &ih_v6_1_ip_funcs,
  };

Finally an easy one! :)

Regards,

Tvrtko

Applied
#3 lore raw

Re: [PATCH 1/3] amdgpu/ih6.1: Fix minor version

In reply to Timur Kristóf

Applied. Thanks!

Quoted 24 lines · Timur Kristóf

Report the correct version of IH v6.1 (previously it showed v6.0).

---
 drivers/gpu/drm/amd/amdgpu/ih_v6_1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/ih_v6_1.c +1 -2
index 95b3f4e55ec3..699c274d357e 100644
@@ -790,7 +790,7 @@ static void ih_v6_1_set_interrupt_funcs(struct amdgpu_device *adev)
 const struct amdgpu_ip_block_version ih_v6_1_ip_block = {
        .type = AMD_IP_BLOCK_TYPE_IH,
        .major = 6,
-       .minor = 0,
+       .minor = 1,
        .rev = 0,
        .funcs = &ih_v6_1_ip_funcs,
 };
--

2.54.0

#4 lore raw

PATCH 2/3 amdgpu/ih: Don't perturb HW registers when accessing soft IH ring

In reply to Timur Kristóf

The soft IH ring is implemented entirely in software. We shouldn't read (or write) and HW registers when accessing it.

---
 drivers/gpu/drm/amd/amdgpu/ih_v6_0.c   | 7 +++++++
 drivers/gpu/drm/amd/amdgpu/ih_v6_1.c   | 7 +++++++
 drivers/gpu/drm/amd/amdgpu/ih_v7_0.c   | 7 +++++++
 drivers/gpu/drm/amd/amdgpu/navi10_ih.c | 4 ++++
 4 files changed, 25 insertions(+)
drivers/gpu/drm/amd/amdgpu/ih_v6_0.c +7 -0
index 333e9c30c091..65e5d21753f9 100644
@@ -439,6 +439,10 @@ static u32 ih_v6_0_get_wptr(struct amdgpu_device *adev,
 	struct amdgpu_ih_regs *ih_regs;
 
 	wptr = le32_to_cpu(*ih->wptr_cpu);
+
+	if (ih == &adev->irq.ih_soft)
+		goto out;
+
 	ih_regs = &ih->ih_regs;
 
 	if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))
@@ -514,6 +518,9 @@ static void ih_v6_0_set_rptr(struct amdgpu_device *adev,
 {
 	struct amdgpu_ih_regs *ih_regs;
 
+	if (ih == &adev->irq.ih_soft)
+		return;
+
 	if (ih->use_doorbell) {
 		/* XXX check if swapping is necessary on BE */
 		*ih->rptr_cpu = ih->rptr;
drivers/gpu/drm/amd/amdgpu/ih_v6_1.c +7 -0
index 699c274d357e..9dbc20131410 100644
@@ -410,6 +410,10 @@ static u32 ih_v6_1_get_wptr(struct amdgpu_device *adev,
 	struct amdgpu_ih_regs *ih_regs;
 
 	wptr = le32_to_cpu(*ih->wptr_cpu);
+
+	if (ih == &adev->irq.ih_soft)
+		goto out;
+
 	ih_regs = &ih->ih_regs;
 
 	if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))
@@ -481,6 +485,9 @@ static void ih_v6_1_irq_rearm(struct amdgpu_device *adev,
 static void ih_v6_1_set_rptr(struct amdgpu_device *adev,
 			       struct amdgpu_ih_ring *ih)
 {
+	if (ih == &adev->irq.ih_soft)
+		return;
+
 	struct amdgpu_ih_regs *ih_regs;
 
 	if (ih->use_doorbell) {
drivers/gpu/drm/amd/amdgpu/ih_v7_0.c +7 -0
index 6de9e87e04e1..bd332e8cc5bf 100644
@@ -457,6 +457,10 @@ static u32 ih_v7_0_get_wptr(struct amdgpu_device *adev,
 	struct amdgpu_ih_regs *ih_regs;
 
 	wptr = le32_to_cpu(*ih->wptr_cpu);
+
+	if (ih == &adev->irq.ih_soft)
+		goto out;
+
 	ih_regs = &ih->ih_regs;
 
 	if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))
@@ -527,6 +531,9 @@ static void ih_v7_0_set_rptr(struct amdgpu_device *adev,
 {
 	struct amdgpu_ih_regs *ih_regs;
 
+	if (ih == &adev->irq.ih_soft)
+		return;
+
 	if (ih->use_doorbell) {
 		/* XXX check if swapping is necessary on BE */
 		*ih->rptr_cpu = ih->rptr;
drivers/gpu/drm/amd/amdgpu/navi10_ih.c +4 -0
index 4cd325149b63..e7ed37bb48e0 100644
@@ -417,6 +417,10 @@ static u32 navi10_ih_get_wptr(struct amdgpu_device *adev,
 		 */
 		wptr = le32_to_cpu(*ih->wptr_cpu);
 
+		if (ih == &adev->irq.ih_soft)
+			goto out;
+
+
 		if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))
 			goto out;
 	}
Signature · 1 line
2.54.0
#5 lore raw

Re: [PATCH 2/3] amdgpu/ih: Don't perturb HW registers when accessing soft IH ring

Quoted 16 lines · Timur Kristóf

The soft IH ring is implemented entirely in software. We shouldn't read (or write) and HW registers when accessing it.

---
  drivers/gpu/drm/amd/amdgpu/ih_v6_0.c   | 7 +++++++
  drivers/gpu/drm/amd/amdgpu/ih_v6_1.c   | 7 +++++++
  drivers/gpu/drm/amd/amdgpu/ih_v7_0.c   | 7 +++++++
  drivers/gpu/drm/amd/amdgpu/navi10_ih.c | 4 ++++
  4 files changed, 25 insertions(+)
drivers/gpu/drm/amd/amdgpu/ih_v6_0.c +0 -0
index 333e9c30c091..65e5d21753f9 100644

drivers/gpu/drm/amd/amdgpu/ih_v6_0.c static u32 ih_v6_0_get_wptr(struct amdgpu_device *adev, · line 445

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/ih_v6_0.c +4 -0
@@ -439,6 +439,10 @@ static u32 ih_v6_0_get_wptr(struct amdgpu_device *adev,
  	struct amdgpu_ih_regs *ih_regs;
 
  	wptr = le32_to_cpu(*ih->wptr_cpu);
+
+	if (ih == &adev->irq.ih_soft)
+		goto out;
+

Would it be feasible to move amdgpu_ih_funcs from device global into the IH rings themselves? Then we could have soft IH ops and it would be very clean.

Possibly also cleanup all the protoptyes to operate only on ih and not the adev + ih pair.

Regards,

Tvrtko

Quoted 78 lines
drivers/gpu/drm/amd/amdgpu/ih_v6_0.c +3 -0
  	ih_regs = &ih->ih_regs;
 
  	if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))
@@ -514,6 +518,9 @@ static void ih_v6_0_set_rptr(struct amdgpu_device *adev,
  {
  	struct amdgpu_ih_regs *ih_regs;
 
+	if (ih == &adev->irq.ih_soft)
+		return;
+
  	if (ih->use_doorbell) {
  		/* XXX check if swapping is necessary on BE */
  		*ih->rptr_cpu = ih->rptr;
drivers/gpu/drm/amd/amdgpu/ih_v6_1.c +7 -0
index 699c274d357e..9dbc20131410 100644
@@ -410,6 +410,10 @@ static u32 ih_v6_1_get_wptr(struct amdgpu_device *adev,
  	struct amdgpu_ih_regs *ih_regs;
 
  	wptr = le32_to_cpu(*ih->wptr_cpu);
+
+	if (ih == &adev->irq.ih_soft)
+		goto out;
+
  	ih_regs = &ih->ih_regs;
 
  	if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))
@@ -481,6 +485,9 @@ static void ih_v6_1_irq_rearm(struct amdgpu_device *adev,
  static void ih_v6_1_set_rptr(struct amdgpu_device *adev,
  			       struct amdgpu_ih_ring *ih)
  {
+	if (ih == &adev->irq.ih_soft)
+		return;
+
  	struct amdgpu_ih_regs *ih_regs;
 
  	if (ih->use_doorbell) {
drivers/gpu/drm/amd/amdgpu/ih_v7_0.c +7 -0
index 6de9e87e04e1..bd332e8cc5bf 100644
@@ -457,6 +457,10 @@ static u32 ih_v7_0_get_wptr(struct amdgpu_device *adev,
  	struct amdgpu_ih_regs *ih_regs;
 
  	wptr = le32_to_cpu(*ih->wptr_cpu);
+
+	if (ih == &adev->irq.ih_soft)
+		goto out;
+
  	ih_regs = &ih->ih_regs;
 
  	if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))
@@ -527,6 +531,9 @@ static void ih_v7_0_set_rptr(struct amdgpu_device *adev,
  {
  	struct amdgpu_ih_regs *ih_regs;
 
+	if (ih == &adev->irq.ih_soft)
+		return;
+
  	if (ih->use_doorbell) {
  		/* XXX check if swapping is necessary on BE */
  		*ih->rptr_cpu = ih->rptr;
drivers/gpu/drm/amd/amdgpu/navi10_ih.c +4 -0
index 4cd325149b63..e7ed37bb48e0 100644
@@ -417,6 +417,10 @@ static u32 navi10_ih_get_wptr(struct amdgpu_device *adev,
  		 */
  		wptr = le32_to_cpu(*ih->wptr_cpu);
 
+		if (ih == &adev->irq.ih_soft)
+			goto out;
+
+
  		if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))
  			goto out;
  	}
#6 lore raw

Re: [PATCH 2/3] amdgpu/ih: Don't perturb HW registers when accessing soft IH ring

Quoted 33 lines · Central European Summer Time Tvrtko Ursulin
Quoted 18 lines · Timur Kristóf

The soft IH ring is implemented entirely in software. We shouldn't read (or write) and HW registers when accessing it.

---

  drivers/gpu/drm/amd/amdgpu/ih_v6_0.c   | 7 +++++++
  drivers/gpu/drm/amd/amdgpu/ih_v6_1.c   | 7 +++++++
  drivers/gpu/drm/amd/amdgpu/ih_v7_0.c   | 7 +++++++
  drivers/gpu/drm/amd/amdgpu/navi10_ih.c | 4 ++++
  4 files changed, 25 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/ih_v6_0.c index 333e9c30c091..65e5d21753f9 100644

drivers/gpu/drm/amd/amdgpu/ih_v6_0.c static u32 ih_v6_0_get_wptr(struct amdgpu_device · line 447

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/ih_v6_0.c +4 -0
@@ -439,6 +439,10 @@ static u32 ih_v6_0_get_wptr(struct amdgpu_device
 *adev,> 
  	struct amdgpu_ih_regs *ih_regs;
 
  	wptr = le32_to_cpu(*ih->wptr_cpu);
 
+
+	if (ih == &adev->irq.ih_soft)
+		goto out;
+

Would it be feasible to move amdgpu_ih_funcs from device global into the IH rings themselves? Then we could have soft IH ops and it would be very clean.

Quoted 2 lines

Possibly also cleanup all the protoptyes to operate only on ih and not the adev + ih pair.

Sure, we can do that in the future. The reason I chose not to do that is because that feels like an extremely intrusive refactor across all GPU generations with a high chance of introducing regressions and not much value to end users.

For now I would like to just focus on making the current code work well with minimal refactoring, ie. just get the current soft IH ring implementation to work reliably with retry faults.

In the meantime if you have a good idea how to refactor this code to make it cleaner without breaking it, I'm happy to listen and we can make a plan how to do that in a future series.

Thanks,
Timur

Quoted 112 lines
Quoted 112 lines
drivers/gpu/drm/amd/amdgpu/ih_v6_0.c +0 -0
  	ih_regs = &ih->ih_regs;

if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))

drivers/gpu/drm/amd/amdgpu/ih_v6_0.c +3 -0
@@ -514,6 +518,9 @@ static void ih_v6_0_set_rptr(struct amdgpu_device
 *adev,> 
  {
 
  	struct amdgpu_ih_regs *ih_regs;
 
+	if (ih == &adev->irq.ih_soft)
+		return;
+
 
  	if (ih->use_doorbell) {

/* XXX check if swapping is necessary on BE */ *ih->rptr_cpu = ih->rptr;

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/ih_v6_1.c index 699c274d357e..9dbc20131410 100644

drivers/gpu/drm/amd/amdgpu/ih_v6_1.c +4 -0
@@ -410,6 +410,10 @@ static u32 ih_v6_1_get_wptr(struct amdgpu_device
 *adev,> 
  	struct amdgpu_ih_regs *ih_regs;
 
  	wptr = le32_to_cpu(*ih->wptr_cpu);
 
+
+	if (ih == &adev->irq.ih_soft)
+		goto out;
+
 
  	ih_regs = &ih->ih_regs;

if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))

drivers/gpu/drm/amd/amdgpu/ih_v6_1.c +3 -0
@@ -481,6 +485,9 @@ static void ih_v6_1_irq_rearm(struct amdgpu_device
 *adev,> 
  static void ih_v6_1_set_rptr(struct amdgpu_device *adev,
 
  			       struct amdgpu_ih_ring *ih)
 
  {
 
+	if (ih == &adev->irq.ih_soft)
+		return;
+
 
  	struct amdgpu_ih_regs *ih_regs;
 
  	if (ih->use_doorbell) {
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/ih_v7_0.c index 6de9e87e04e1..bd332e8cc5bf 100644

drivers/gpu/drm/amd/amdgpu/ih_v7_0.c +4 -0
@@ -457,6 +457,10 @@ static u32 ih_v7_0_get_wptr(struct amdgpu_device
 *adev,> 
  	struct amdgpu_ih_regs *ih_regs;
 
  	wptr = le32_to_cpu(*ih->wptr_cpu);
 
+
+	if (ih == &adev->irq.ih_soft)
+		goto out;
+
 
  	ih_regs = &ih->ih_regs;

if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))

drivers/gpu/drm/amd/amdgpu/ih_v7_0.c +3 -0
@@ -527,6 +531,9 @@ static void ih_v7_0_set_rptr(struct amdgpu_device
 *adev,> 
  {
 
  	struct amdgpu_ih_regs *ih_regs;
 
+	if (ih == &adev->irq.ih_soft)
+		return;
+
 
  	if (ih->use_doorbell) {

/* XXX check if swapping is necessary on BE */ *ih->rptr_cpu = ih->rptr;

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/navi10_ih.c index 4cd325149b63..e7ed37bb48e0 100644

drivers/gpu/drm/amd/amdgpu/navi10_ih.c +4 -0
@@ -417,6 +417,10 @@ static u32 navi10_ih_get_wptr(struct amdgpu_device
 *adev,> 
  		 */
 
  		wptr = le32_to_cpu(*ih->wptr_cpu);
 
+		if (ih == &adev->irq.ih_soft)
+			goto out;
+
+
 

if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))

goto out;

  	}
Reviewed-by
#7 lore raw

Re: [PATCH 2/3] amdgpu/ih: Don't perturb HW registers when accessing soft IH ring

Quoted 43 lines · Timur Kristóf
Quoted 33 lines · Central European Summer Time Tvrtko Ursulin
Quoted 18 lines · Timur Kristóf

The soft IH ring is implemented entirely in software. We shouldn't read (or write) and HW registers when accessing it.

---

   drivers/gpu/drm/amd/amdgpu/ih_v6_0.c   | 7 +++++++
   drivers/gpu/drm/amd/amdgpu/ih_v6_1.c   | 7 +++++++
   drivers/gpu/drm/amd/amdgpu/ih_v7_0.c   | 7 +++++++
   drivers/gpu/drm/amd/amdgpu/navi10_ih.c | 4 ++++
   4 files changed, 25 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/ih_v6_0.c index 333e9c30c091..65e5d21753f9 100644

drivers/gpu/drm/amd/amdgpu/ih_v6_0.c static u32 ih_v6_0_get_wptr(struct amdgpu_device · line 447

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/ih_v6_0.c +4 -0
@@ -439,6 +439,10 @@ static u32 ih_v6_0_get_wptr(struct amdgpu_device
 *adev,>
   	struct amdgpu_ih_regs *ih_regs;
 
   	wptr = le32_to_cpu(*ih->wptr_cpu);
 
+
+	if (ih == &adev->irq.ih_soft)
+		goto out;
+

Would it be feasible to move amdgpu_ih_funcs from device global into the IH rings themselves? Then we could have soft IH ops and it would be very clean.

Quoted 2 lines

Possibly also cleanup all the protoptyes to operate only on ih and not the adev + ih pair.

Sure, we can do that in the future. The reason I chose not to do that is because that feels like an extremely intrusive refactor across all GPU generations with a high chance of introducing regressions and not much value to end users.

Quoted 7 lines

For now I would like to just focus on making the current code work well with minimal refactoring, ie. just get the current soft IH ring implementation to work reliably with retry faults.

In the meantime if you have a good idea how to refactor this code to make it cleaner without breaking it, I'm happy to listen and we can make a plan how to do that in a future series.

I can play with that refactor later, now that Christian gave a green light.

For this patch - it looks good to me. I am somewhat confused by the endianess conversion in amdgpu_ih_ring_write() (why is that needed for a software ring?), but even if unecessary it can be improved later so:

Regards,

Tvrtko

Quoted 115 lines
Quoted 111 lines
Quoted 111 lines
drivers/gpu/drm/amd/amdgpu/ih_v6_0.c +0 -0
   	ih_regs = &ih->ih_regs;

if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))

drivers/gpu/drm/amd/amdgpu/ih_v6_0.c +3 -0
@@ -514,6 +518,9 @@ static void ih_v6_0_set_rptr(struct amdgpu_device
 *adev,>
   {
 
   	struct amdgpu_ih_regs *ih_regs;
 
+	if (ih == &adev->irq.ih_soft)
+		return;
+
 
   	if (ih->use_doorbell) {
   		/* XXX check if swapping is necessary on BE */
   		*ih->rptr_cpu = ih->rptr;
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/ih_v6_1.c index 699c274d357e..9dbc20131410 100644

drivers/gpu/drm/amd/amdgpu/ih_v6_1.c +4 -0
@@ -410,6 +410,10 @@ static u32 ih_v6_1_get_wptr(struct amdgpu_device
 *adev,>
   	struct amdgpu_ih_regs *ih_regs;
 
   	wptr = le32_to_cpu(*ih->wptr_cpu);
 
+
+	if (ih == &adev->irq.ih_soft)
+		goto out;
+
 
   	ih_regs = &ih->ih_regs;

if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))

drivers/gpu/drm/amd/amdgpu/ih_v6_1.c +3 -0
@@ -481,6 +485,9 @@ static void ih_v6_1_irq_rearm(struct amdgpu_device
 *adev,>
   static void ih_v6_1_set_rptr(struct amdgpu_device *adev,
 
   			       struct amdgpu_ih_ring *ih)
 
   {
 
+	if (ih == &adev->irq.ih_soft)
+		return;
+
 
   	struct amdgpu_ih_regs *ih_regs;
 
   	if (ih->use_doorbell) {
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/ih_v7_0.c index 6de9e87e04e1..bd332e8cc5bf 100644

drivers/gpu/drm/amd/amdgpu/ih_v7_0.c +4 -0
@@ -457,6 +457,10 @@ static u32 ih_v7_0_get_wptr(struct amdgpu_device
 *adev,>
   	struct amdgpu_ih_regs *ih_regs;
 
   	wptr = le32_to_cpu(*ih->wptr_cpu);
 
+
+	if (ih == &adev->irq.ih_soft)
+		goto out;
+
 
   	ih_regs = &ih->ih_regs;

if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))

drivers/gpu/drm/amd/amdgpu/ih_v7_0.c +3 -0
@@ -527,6 +531,9 @@ static void ih_v7_0_set_rptr(struct amdgpu_device
 *adev,>
   {
 
   	struct amdgpu_ih_regs *ih_regs;
 
+	if (ih == &adev->irq.ih_soft)
+		return;
+
 
   	if (ih->use_doorbell) {
   		/* XXX check if swapping is necessary on BE */
   		*ih->rptr_cpu = ih->rptr;
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/navi10_ih.c index 4cd325149b63..e7ed37bb48e0 100644

drivers/gpu/drm/amd/amdgpu/navi10_ih.c +4 -0
@@ -417,6 +417,10 @@ static u32 navi10_ih_get_wptr(struct amdgpu_device
 *adev,>
   		 */
 
   		wptr = le32_to_cpu(*ih->wptr_cpu);
 
+		if (ih == &adev->irq.ih_soft)
+			goto out;
+
+
 
   		if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))
   		
   			goto out;
   	
   	}
maintainer
#8 lore raw

Re: [PATCH 2/3] amdgpu/ih: Don't perturb HW registers when accessing soft IH ring

In reply to Tvrtko Ursulin
Quoted 13 lines · Tvrtko Ursulin
Quoted 11 lines · Timur Kristóf

The soft IH ring is implemented entirely in software. We shouldn't read (or write) and HW registers when accessing it.

---

  drivers/gpu/drm/amd/amdgpu/ih_v6_0.c   | 7 +++++++
  drivers/gpu/drm/amd/amdgpu/ih_v6_1.c   | 7 +++++++
  drivers/gpu/drm/amd/amdgpu/ih_v7_0.c   | 7 +++++++
  drivers/gpu/drm/amd/amdgpu/navi10_ih.c | 4 ++++
  4 files changed, 25 insertions(+)
Quoted 13 lines

drivers/gpu/drm/amd/amdgpu/ih_v6_0.c static u32 ih_v6_0_get_wptr(struct amdgpu_device *adev, · line 444

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/ih_v6_0.c +4 -0
index 333e9c30c091..65e5d21753f9 100644
@@ -439,6 +439,10 @@ static u32 ih_v6_0_get_wptr(struct amdgpu_device *adev,
       struct amdgpu_ih_regs *ih_regs;
         wptr = le32_to_cpu(*ih->wptr_cpu);
+
+    if (ih == &adev->irq.ih_soft)
+        goto out;
+

Would it be feasible to move amdgpu_ih_funcs from device global into the IH rings themselves? Then we could have soft IH ops and it would be very clean.

I've thought about that multiple times as well but never had the time to actually do it.

So feel free to implement the idea.

Thanks,
Christian.

Quoted 77 lines

Possibly also cleanup all the protoptyes to operate only on ih and not the adev + ih pair.

Regards,

Tvrtko

Quoted 69 lines
drivers/gpu/drm/amd/amdgpu/ih_v6_0.c +2 -0
       ih_regs = &ih->ih_regs;
         if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))
@@ -514,6 +518,9 @@ static void ih_v6_0_set_rptr(struct amdgpu_device *adev,
   {
       struct amdgpu_ih_regs *ih_regs;
   +    if (ih == &adev->irq.ih_soft)
+        return;
+
       if (ih->use_doorbell) {
           /* XXX check if swapping is necessary on BE */
           *ih->rptr_cpu = ih->rptr;
drivers/gpu/drm/amd/amdgpu/ih_v6_1.c +7 -0
index 699c274d357e..9dbc20131410 100644
@@ -410,6 +410,10 @@ static u32 ih_v6_1_get_wptr(struct amdgpu_device *adev,
       struct amdgpu_ih_regs *ih_regs;
         wptr = le32_to_cpu(*ih->wptr_cpu);
+
+    if (ih == &adev->irq.ih_soft)
+        goto out;
+
       ih_regs = &ih->ih_regs;
         if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))
@@ -481,6 +485,9 @@ static void ih_v6_1_irq_rearm(struct amdgpu_device *adev,
   static void ih_v6_1_set_rptr(struct amdgpu_device *adev,
                      struct amdgpu_ih_ring *ih)
   {
+    if (ih == &adev->irq.ih_soft)
+        return;
+
       struct amdgpu_ih_regs *ih_regs;
         if (ih->use_doorbell) {
drivers/gpu/drm/amd/amdgpu/ih_v7_0.c +6 -0
index 6de9e87e04e1..bd332e8cc5bf 100644
@@ -457,6 +457,10 @@ static u32 ih_v7_0_get_wptr(struct amdgpu_device *adev,
       struct amdgpu_ih_regs *ih_regs;
         wptr = le32_to_cpu(*ih->wptr_cpu);
+
+    if (ih == &adev->irq.ih_soft)
+        goto out;
+
       ih_regs = &ih->ih_regs;
         if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))
@@ -527,6 +531,9 @@ static void ih_v7_0_set_rptr(struct amdgpu_device *adev,
   {
       struct amdgpu_ih_regs *ih_regs;
   +    if (ih == &adev->irq.ih_soft)
+        return;
+
       if (ih->use_doorbell) {
           /* XXX check if swapping is necessary on BE */
           *ih->rptr_cpu = ih->rptr;
drivers/gpu/drm/amd/amdgpu/navi10_ih.c +3 -0
index 4cd325149b63..e7ed37bb48e0 100644
@@ -417,6 +417,10 @@ static u32 navi10_ih_get_wptr(struct amdgpu_device *adev,
            */
           wptr = le32_to_cpu(*ih->wptr_cpu);
   +        if (ih == &adev->irq.ih_soft)
+            goto out;
+
+
           if (!REG_GET_FIELD(wptr, IH_RB_WPTR, RB_OVERFLOW))
               goto out;
       }
#9 lore raw

PATCH 3/3 drm/amdgpu: Use system unbound workqueue for soft IH ring

In reply to Timur Kristóf

Allow the kernel to dispatch the soft IH work on other CPUs.

Otherwise it can happen that the soft IH ring fills up before it actually starts processing anything, which can easily happen with retry page faults, in which case the CP repeatedly spams the CPU with a lot of interrupts.

This significantly improves retry page fault handling on GPUs that don't have the filter CAM and must rely on software based filtering.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +1 -1
index 82bc6d657e5a..515fc32051c8 100644
@@ -549,7 +549,7 @@ void amdgpu_irq_delegate(struct amdgpu_device *adev,
 			 unsigned int num_dw)
 {
 	amdgpu_ih_ring_write(adev, &adev->irq.ih_soft, entry->iv_entry, num_dw);
-	schedule_work(&adev->irq.ih_soft_work);
+	queue_work(system_unbound_wq, &adev->irq.ih_soft_work);
 }
 
 /**
Signature · 1 line
2.54.0
Reviewed-by on v1 3/3
#10 lore raw

Re: [PATCH 3/3] drm/amdgpu: Use system unbound workqueue for soft IH ring

Quoted 21 lines · Timur Kristóf

Allow the kernel to dispatch the soft IH work on other CPUs.

Otherwise it can happen that the soft IH ring fills up before it actually starts processing anything, which can easily happen with retry page faults, in which case the CP repeatedly spams the CPU with a lot of interrupts.

This significantly improves retry page fault handling on GPUs that don't have the filter CAM and must rely on software based filtering.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +0 -0
index 82bc6d657e5a..515fc32051c8 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_delegate(struct amdgpu_device *adev, · line 555

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +1 -1
@@ -549,7 +549,7 @@ void amdgpu_irq_delegate(struct amdgpu_device *adev,
  			 unsigned int num_dw)
  {
  	amdgpu_ih_ring_write(adev, &adev->irq.ih_soft, entry->iv_entry, num_dw);
-	schedule_work(&adev->irq.ih_soft_work);
+	queue_work(system_unbound_wq, &adev->irq.ih_soft_work);
  }
 
  /**

Look good to me.

Maybe later we can consider a high priority driver specific worker or something but for now moving away from default system percpu sounds like it addresses the problem statement.

Regards,

Tvrtko

Applied
#11 lore raw

Re: [PATCH 3/3] drm/amdgpu: Use system unbound workqueue for soft IH ring

Applied. Thanks!

Quoted 45 lines · Tvrtko Ursulin
Quoted 21 lines · Timur Kristóf

Allow the kernel to dispatch the soft IH work on other CPUs.

Otherwise it can happen that the soft IH ring fills up before it actually starts processing anything, which can easily happen with retry page faults, in which case the CP repeatedly spams the CPU with a lot of interrupts.

This significantly improves retry page fault handling on GPUs that don't have the filter CAM and must rely on software based filtering.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +0 -0
index 82bc6d657e5a..515fc32051c8 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_delegate(struct amdgpu_device *adev, · line 555

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +1 -1
@@ -549,7 +549,7 @@ void amdgpu_irq_delegate(struct amdgpu_device *adev,
                       unsigned int num_dw)
  {
      amdgpu_ih_ring_write(adev, &adev->irq.ih_soft, entry->iv_entry, num_dw);
-     schedule_work(&adev->irq.ih_soft_work);
+     queue_work(system_unbound_wq, &adev->irq.ih_soft_work);
  }
 
  /**

Look good to me.

Maybe later we can consider a high priority driver specific worker or something but for now moving away from default system percpu sounds like it addresses the problem statement.

Regards,

Tvrtko