drm/amdgpu: try again kiq access if not in IRQ(v2)
Subsystems (2)
PATCH 1/1 drm/amdgpu: try again kiq access if not in IRQ(v2)
sometimes GPU is switched to other VFs and won't swich back soon, so the kiq reg access will not signal within
a short period, instead of busy waiting a long time(MAX_KEQ_REG_WAIT) and returning TMO we can istead sleep 5ms and try again later (non irq context)
And since the waiting in kiq_r/weg is busy wait, so MAX_KIQ_REG_WAIT shouldn't set to a long time, set it to 10ms is more appropriate.
if gpu already in reset state, don't retry the KIQ reg access otherwise it would always hang because KIQ was already die usually.
v2:
replace schedule() with msleep() for the wait
--- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +13 -2
@@ -22,7 +22,7 @@*/ #include "amdgpu.h" -#define MAX_KIQ_REG_WAIT 100000000/* in usecs */ +#define MAX_KIQ_REG_WAIT 10000/* in usecs, 10ms */ uint64_t amdgpu_csa_vaddr (struct amdgpu_device *adev) {
@@ -152,9 +152,14 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg)amdgpu_ring_commit (ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_read: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT );if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) { +msleep (5 ); + goto retry_read; + }return ~0 ; } val = adev->wb.wb[adev->virt.reg_val_offs];
@@ -179,9 +184,15 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)amdgpu_ring_commit (ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_write: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT ); -if (r <1 ) +if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) { +msleep (5 ); + goto retry_write; + } + } }/**
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1519802862-9513-1-git-send-email-Monk.Liu-5C7GfCeVMHo@public.gmane.org
Anyone review this ?
-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Monk Liu
Sent: 2018年2月28日 15:28
To: [email protected]
Cc: Liu, Monk <[email protected]>
Subject: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)
sometimes GPU is switched to other VFs and won't swich back soon, so the kiq reg access will not signal within a short period, instead of busy waiting a long time(MAX_KEQ_REG_WAIT) and returning TMO we can istead sleep 5ms and try again later (non irq context)
And since the waiting in kiq_r/weg is busy wait, so MAX_KIQ_REG_WAIT shouldn't set to a long time, set it to 10ms is more appropriate.
if gpu already in reset state, don't retry the KIQ reg access otherwise it would always hang because KIQ was already die usually.
v2:
replace schedule() with msleep() for the wait
--- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1 -1
@@ -22,7 +22,7 @@*/ #include "amdgpu.h" -#define MAX_KIQ_REG_WAIT 100000000/* in usecs */ +#define MAX_KIQ_REG_WAIT 10000/* in usecs, 10ms */ uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev) { @@ -152,9 +152,14 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg) amdgpu_ring_commit(ring);
spin_unlock_irqrestore(&kiq->ring_lock, flags);
+retry_read:
r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
if (r < 1) {
DRM_ERROR("wait for kiq fence error: %ld\n", r);
+ if (!in_interrupt() && !adev->in_gpu_reset) {
+ msleep(5);
+ goto retry_read;
+ }
return ~0;
}
val = adev->wb.wb[adev->virt.reg_val_offs];
@@ -179,9 +184,15 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)
amdgpu_ring_commit(ring);
spin_unlock_irqrestore(&kiq->ring_lock, flags);
+retry_write:
r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
- if (r < 1)
+ if (r < 1) {
DRM_ERROR("wait for kiq fence error: %ld\n", r);
+ if (!in_interrupt() && !adev->in_gpu_reset) {
+ msleep(5);
+ goto retry_write;
+ }
+ }
}
/**
--
2.7.4
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): BLUPR12MB0449438D2E411F534071ED3684C60-7LeqcoF/[email protected]
From a coding style perspective a define for the 5ms timeout would be nice to have and it might be better to use a do { } while instead of the goto, but those are really minor issues.
But from the technical perspective I can't fully judge if that is a good idea or not cause I'm not so deeply know how the KIQ works.
Christian.
Am 01.03.2018 um 06:52 schrieb Liu, Monk:
Quoted 70 lines
Anyone review this ?
-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Monk Liu
Sent: 2018年2月28日 15:28
To: [email protected]
Cc: Liu, Monk <[email protected]>
Subject: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)sometimes GPU is switched to other VFs and won't swich back soon, so the kiq reg access will not signal within a short period, instead of busy waiting a long
time(MAX_KEQ_REG_WAIT)and returning TMO we can istead sleep 5ms and try again later (non irq context)And since the waiting in kiq_r/weg is busy wait, so
MAX_KIQ_REG_WAITshouldn't set to a long time, set it to 10ms is more appropriate.if gpu already in reset state, don't retry the KIQ reg access otherwise it would always hang because KIQ was already die usually.
v2:
replaceschedule()withmsleep()for the waitChange-Id I8fc807ce85a8d30d2b50153f3f3a6eda344ef994Signed-off-by Monk Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1
-1@@ -22,7 +22,7 @@*/ #include "amdgpu.h" -#define MAX_KIQ_REG_WAIT 100000000/* in usecs */ +#define MAX_KIQ_REG_WAIT 10000/* in usecs, 10ms */ uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev) { @@ -152,9 +152,14 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg) amdgpu_ring_commit(ring);spin_unlock_irqrestore(&kiq->ring_lock, flags);drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +12
-2+retry_read: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT );if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) { +msleep (5 ); + goto retry_read; + }return ~0 ; } val = adev->wb.wb[adev->virt.reg_val_offs];@@ -179,9 +184,15 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)amdgpu_ring_commit (ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_write: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT ); -if (r <1 ) +if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) { +msleep (5 ); + goto retry_write; + } + } }/** -- 2.7.4
Quoted 8 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 6362f78f-7b22-2fc1-5ce3-805190c4ffb0-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Hi Christian
KIQ is used by kernel, and we submit commands on it without gpu scheduler,
In sriov env, register access must go through KIQ in non-exclusive mode because we don’t want one VF access MMIO during the period that this VF is not occupying GPU resource,
But since now we use busy polling wait for the fence of KIQ, this way it is too latency to let KIQ wait before KIQ job finish, but since KIQ is also part of CP So it may serve other VFs, and that cause a situation that KIQ job in certain VF may need at least 1~2 seconds, which is not good to use busy wait,
So my patch changed something to let this busy wait bail out for a moment when not in IRQ context, another concern is if KIQ is in current VF, but current VF already die, then all KIQ job will not signal, so it's still need this bail out and retry scheme to make sure CPU not always in that busy polling status
Thanks
/Monk
-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: 2018年3月1日 16:13
To: Liu, Monk <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)
From a coding style perspective a define for the 5ms timeout would be nice to have and it might be better to use a do { } while instead of the goto, but those are really minor issues.
But from the technical perspective I can't fully judge if that is a good idea or not cause I'm not so deeply know how the KIQ works.
Christian.
Am 01.03.2018 um 06:52 schrieb Liu, Monk:
Quoted 75 lines
Anyone review this ?
-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Monk Liu
Sent: 2018年2月28日 15:28
To: [email protected]
Cc: Liu, Monk <[email protected]>
Subject: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)sometimes GPU is switched to other VFs and won't swich back soon, so the kiq reg access will not signal within a short period, instead of busy waiting a long
time(MAX_KEQ_REG_WAIT)and returning TMO we can istead sleep 5ms and try again later (non irq context)And since the waiting in kiq_r/weg is busy wait, so
MAX_KIQ_REG_WAITshouldn't set to a long time, set it to 10ms is more appropriate.if gpu already in reset state, don't retry the KIQ reg access otherwise it would always hang because KIQ was already die usually.
v2:
replaceschedule()withmsleep()for the waitChange-Id I8fc807ce85a8d30d2b50153f3f3a6eda344ef994Signed-off-by Monk Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1
-1@@ -22,7 +22,7 @@*/ #include "amdgpu.h" -#define MAX_KIQ_REG_WAIT 100000000/* in usecs */ +#define MAX_KIQ_REG_WAIT 10000/* in usecs, 10ms */ uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev) { @@ -152,9 +152,14 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg) amdgpu_ring_commit(ring);spin_unlock_irqrestore(&kiq->ring_lock, flags);drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +12
-2+retry_read: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT );if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) { +msleep (5 ); + goto retry_read; + }return ~0 ; } val = adev->wb.wb[adev->virt.reg_val_offs];@@ -179,9 +184,15 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)amdgpu_ring_commit (ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_write: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT ); -if (r <1 ) +if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) { +msleep (5 ); + goto retry_write; + } + } }/** -- 2.7.4
Quoted 8 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): BLUPR12MB0449EAA8B40EDA5D6BC762E284C60-7LeqcoF/[email protected]
Ding, Pixel
Reviewed-by Pixel Ding—
Sincerely Yours,
Pixel
On 01/03/2018, 4:21 PM, "amd-gfx on behalf of Liu, Monk" <[email protected] on behalf of [email protected]> wrote:
Hi Christian
KIQ is used by kernel, and we submit commands on it without gpu scheduler,
In sriov env, register access must go through KIQ in non-exclusive mode because we don’t want one VF access MMIO during the period that this VF is not occupying
GPU resource,
But since now we use busy polling wait for the fence of KIQ, this way it is too latency to let KIQ wait before KIQ job finish, but since KIQ is also part of CP
So it may serve other VFs, and that cause a situation that KIQ job in certain VF may need at least 1~2 seconds, which is not good to use busy wait,
So my patch changed something to let this busy wait bail out for a moment when not in IRQ context, another concern is if KIQ is in current VF, but current
VF already die, then all KIQ job will not signal, so it's still need this bail out and retry scheme to make sure CPU not always in that busy polling status
Thanks
/Monk
-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: 2018年3月1日 16:13
To: Liu, Monk <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)
From a coding style perspective a define for the 5ms timeout would be nice to have and it might be better to use a do { } while instead of the goto, but those are really minor issues.
But from the technical perspective I can't fully judge if that is a good idea or not cause I'm not so deeply know how the KIQ works.
Christian.
Am 01.03.2018 um 06:52 schrieb Liu, Monk:
> Anyone review this ?
>
> -----Original Message-----
> From: amd-gfx [mailto:[email protected]] On Behalf
> Of Monk Liu
> Sent: 2018年2月28日 15:28
> To: [email protected]
> Cc: Liu, Monk <[email protected]>
> Subject: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)
>
> sometimes GPU is switched to other VFs and won't swich back soon, so
> the kiq reg access will not signal within a short period, instead of
> busy waiting a long time(MAX_KEQ_REG_WAIT) and returning TMO we can
> istead sleep 5ms and try again later (non irq context)
>
> And since the waiting in kiq_r/weg is busy wait, so MAX_KIQ_REG_WAIT shouldn't set to a long time, set it to 10ms is more appropriate.
>
> if gpu already in reset state, don't retry the KIQ reg access otherwise it would always hang because KIQ was already die usually.
>
> v2:
> replace schedule() with msleep() for the wait
>
> Change-Id: I8fc807ce85a8d30d2b50153f3f3a6eda344ef994
> Signed-off-by: Monk Liu <[email protected]>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> index b832651..1672f5b 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> @@ -22,7 +22,7 @@
> */
>
> #include "amdgpu.h"
> -#define MAX_KIQ_REG_WAIT 100000000 /* in usecs */
> +#define MAX_KIQ_REG_WAIT 10000 /* in usecs, 10ms */
>
> uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev) { @@ -152,9 +152,14 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg)
> amdgpu_ring_commit(ring);
> spin_unlock_irqrestore(&kiq->ring_lock, flags);
>
> +retry_read:
> r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
> if (r < 1) {
> DRM_ERROR("wait for kiq fence error: %ld\n", r);
> + if (!in_interrupt() && !adev->in_gpu_reset) {
> + msleep(5);
> + goto retry_read;
> + }
> return ~0;
> }
> val = adev->wb.wb[adev->virt.reg_val_offs];
> @@ -179,9 +184,15 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)
> amdgpu_ring_commit(ring);
> spin_unlock_irqrestore(&kiq->ring_lock, flags);
>
> +retry_write:
> r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
> - if (r < 1)
> + if (r < 1) {
> DRM_ERROR("wait for kiq fence error: %ld\n", r);
> + if (!in_interrupt() && !adev->in_gpu_reset) {
> + msleep(5);
> + goto retry_write;
> + }
> + }
> }
>
> /**
> --
> 2.7.4
>
> _______________________________________________
> amd-gfx mailing list
> [email protected]
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
> _______________________________________________
> amd-gfx mailing list
> [email protected]
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 7624B23B-CE3F-4608-B9BF-F01DB29C8503-5C7GfCeVMHo@public.gmane.org
Sounds reasonable.
I would add a define for the 5ms timeout, with that done the patch is Reviewed-by: Christian König <[email protected]> as well.
Regards,
Christian.
Am 01.03.2018 um 09:40 schrieb Ding, Pixel:
Quoted 117 lines
Reviewed-by Pixel Ding <[email protected]>—
Sincerely Yours,
PixelOn 01/03/2018, 4:21 PM, "amd-gfx on behalf of Liu, Monk" <[email protected] on behalf of [email protected]> wrote:
Hi Christian KIQ is used by kernel, and we submit commands on it without gpu scheduler, In sriov env, register access must go through KIQ in non-exclusive mode because we don’t want one VF access MMIO during the period that this VF is not occupying GPU resource, But since now we use busy polling wait for the fence of KIQ, this way it is too latency to let KIQ wait before KIQ job finish, but since KIQ is also part of CP So it may serve other VFs, and that cause a situation that KIQ job in certain VF may need at least 1~2 seconds, which is not good to use busy wait, So my patch changed something to let this busy wait bail out for a moment when not in IRQ context, another concern is if KIQ is in current VF, but current VF already die, then all KIQ job will not signal, so it's still need this bail out and retry scheme to make sure CPU not always in that busy polling status Thanks /Monk -----Original Message----- From: Christian König [mailto:[email protected]] Sent: 2018年3月1日 16:13 To: Liu, Monk <[email protected]>; [email protected] Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2) From a coding style perspective a define for the 5ms timeout would be nice to have and it might be better to use a do { } while instead of the goto, but those are really minor issues. But from the technical perspective I can't fully judge if that is a good idea or not cause I'm not so deeply know how the KIQ works. Christian. Am 01.03.2018 um 06:52 schrieb Liu, Monk: > Anyone review this ? > > -----Original Message----- > From: amd-gfx [mailto:[email protected]] On Behalf > Of Monk Liu > Sent: 2018年2月28日 15:28 > To: [email protected] > Cc: Liu, Monk <[email protected]> > Subject: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2) > > sometimes GPU is switched to other VFs and won't swich back soon, so > the kiq reg access will not signal within a short period, instead of > busy waiting a long time(MAX_KEQ_REG_WAIT) and returning TMO we can > istead sleep 5ms and try again later (non irq context) > > And since the waiting in kiq_r/weg is busy wait, so MAX_KIQ_REG_WAIT shouldn't set to a long time, set it to 10ms is more appropriate. > > if gpu already in reset state, don't retry the KIQ reg access otherwise it would always hang because KIQ was already die usually. > > v2: > replace schedule() with msleep() for the wait > > Change-Id: I8fc807ce85a8d30d2b50153f3f3a6eda344ef994 > Signed-off-by: Monk Liu <[email protected]> > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 15 +++++++++++++-- > 1 file changed, 13 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c > b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c > index b832651..1672f5b 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c > @@ -22,7 +22,7 @@ > */ > > #include "amdgpu.h" > -#define MAX_KIQ_REG_WAIT 100000000 /* in usecs */ > +#define MAX_KIQ_REG_WAIT 10000 /* in usecs, 10ms */ > > uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev) { @@ -152,9 +152,14 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg) > amdgpu_ring_commit(ring); > spin_unlock_irqrestore(&kiq->ring_lock, flags); > > +retry_read: > r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT); > if (r < 1) { > DRM_ERROR("wait for kiq fence error: %ld\n", r); > + if (!in_interrupt() && !adev->in_gpu_reset) { > + msleep(5); > + goto retry_read; > + } > return ~0; > } > val = adev->wb.wb[adev->virt.reg_val_offs]; > @@ -179,9 +184,15 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v) > amdgpu_ring_commit(ring); > spin_unlock_irqrestore(&kiq->ring_lock, flags); > > +retry_write: > r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT); > - if (r < 1) > + if (r < 1) { > DRM_ERROR("wait for kiq fence error: %ld\n", r); > + if (!in_interrupt() && !adev->in_gpu_reset) { > + msleep(5); > + goto retry_write; > + } > + } > } > > /** > -- > 2.7.4 > > _______________________________________________ > amd-gfx mailing list > [email protected] > https://lists.freedesktop.org/mailman/listinfo/amd-gfx > _______________________________________________
Quoted 10 lines
> amd-gfx mailing list
> [email protected]
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 35 lines · Monk Liu
sometimes GPU is switched to other VFs and won't swich back soon, so the kiq reg access will not signal within
a short period, instead of busy waiting a longtime(MAX_KEQ_REG_WAIT)and returning TMO we can istead sleep 5ms and try again later (non irq context)And since the waiting in kiq_r/weg is busy wait, so
MAX_KIQ_REG_WAITshouldn't set to a long time, set it to 10ms is more appropriate.if gpu already in reset state, don't retry the KIQ reg access otherwise it would always hang because KIQ was already die usually.
v2:
replaceschedule()withmsleep()for the waitChange-Id I8fc807ce85a8d30d2b50153f3f3a6eda344ef994Signed-off-by Monk Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1
-1@@ -22,7 +22,7 @@*/ #include "amdgpu.h" -#define MAX_KIQ_REG_WAIT 100000000/* in usecs */ +#define MAX_KIQ_REG_WAIT 10000/* in usecs, 10ms */ uint64_t amdgpu_csa_vaddr (struct amdgpu_device *adev) {
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg) · line 159
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +2
-0@@ -152,9 +152,14 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg)amdgpu_ring_commit (ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_read: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT );if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) {
You should check in_atomic here. Because it's invalid to sleep in atomic context (e.g. while holding a spin lock) even when not in an interrupt. This seems to happen a lot for indirect register access, e.g. soc15_pcie_rreg.
Regards,
Felix
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +4
-1+msleep (5 ); + goto retry_read; + }return ~0 ; } val = adev->wb.wb[adev->virt.reg_val_offs];@@ -179,9 +184,15 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)amdgpu_ring_commit (ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_write: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT ); -if (r <1 )
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v) · line 198
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +6
-0+if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) { +msleep (5 ); + goto retry_write; + } + } }/**
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 3d12195d-44d3-d9b1-82cd-482f49534ec5-5C7GfCeVMHo@public.gmane.org
In_atomic() isnot encouraged to be used to judge if sleep is possible, see the macros of it
#define in_atomic() (preept_count() != 0)
/Monk
-----Original Message-----
From: Kuehling, Felix
Sent: 2018年3月1日 23:50
To: [email protected]; Liu, Monk <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)
Quoted 32 lines · Monk Liu
sometimes GPU is switched to other VFs and won't swich back soon, so the kiq reg access will not signal within a short period, instead of busy waiting a long
time(MAX_KEQ_REG_WAIT)and returning TMO we can istead sleep 5ms and try again later (non irq context)And since the waiting in kiq_r/weg is busy wait, so
MAX_KIQ_REG_WAITshouldn't set to a long time, set it to 10ms is more appropriate.if gpu already in reset state, don't retry the KIQ reg access otherwise it would always hang because KIQ was already die usually.
v2:
replaceschedule()withmsleep()for the waitChange-Id I8fc807ce85a8d30d2b50153f3f3a6eda344ef994Signed-off-by Monk Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1
-1@@ -22,7 +22,7 @@*/ #include "amdgpu.h" -#define MAX_KIQ_REG_WAIT 100000000/* in usecs */ +#define MAX_KIQ_REG_WAIT 10000/* in usecs, 10ms */
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg) · line 159
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +3
-0uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev) { @@ -152,9 +152,14 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg) amdgpu_ring_commit(ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_read: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT );if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) {
You should check in_atomic here. Because it's invalid to sleep in atomic context (e.g. while holding a spin lock) even when not in an interrupt. This seems to happen a lot for indirect register access, e.g.soc15_pcie_rreg.
Regards,
Felix
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +4
-1+msleep (5 ); + goto retry_read; + }return ~0 ; } val = adev->wb.wb[adev->virt.reg_val_offs];@@ -179,9 +184,15 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)amdgpu_ring_commit (ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_write: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT ); -if (r <1 )
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v) · line 198
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +6
-0+if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) { +msleep (5 ); + goto retry_write; + } + } }/**
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): BLUPR12MB04498B47E0BAFFF2A80A4CE684C50-7LeqcoF/[email protected]
Quoted 3 lines · Monk
In_atomic()isnot encouraged to be used to judge if sleep is possible, see the macros of it#define
in_atomic()(preept_count()!= 0)
OK. But my point is still that you're not testing the right thing when you check in_interrupt(). The comment before the in_atomic macro definition states the limitations and says "do not use in driver code". Unfortunately it doesn't suggest any alternative. I think in_interrupt is actually worse, because it misses even more cases than in_atomic.
Regards,
Felix
Quoted 82 lines
/Monk
-----Original Message-----
From: Kuehling, Felix
Sent: 2018年3月1日 23:50
To: [email protected]; Liu, Monk <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)Quoted 32 lines · Monk Liu
sometimes GPU is switched to other VFs and won't swich back soon, so the kiq reg access will not signal within a short period, instead of busy waiting a long
time(MAX_KEQ_REG_WAIT)and returning TMO we can istead sleep 5ms and try again later (non irq context)And since the waiting in kiq_r/weg is busy wait, so
MAX_KIQ_REG_WAITshouldn't set to a long time, set it to 10ms is more appropriate.if gpu already in reset state, don't retry the KIQ reg access otherwise it would always hang because KIQ was already die usually.
v2:
replaceschedule()withmsleep()for the waitChange-Id I8fc807ce85a8d30d2b50153f3f3a6eda344ef994Signed-off-by Monk Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1
-1@@ -22,7 +22,7 @@*/ #include "amdgpu.h" -#define MAX_KIQ_REG_WAIT 100000000/* in usecs */ +#define MAX_KIQ_REG_WAIT 10000/* in usecs, 10ms */ drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg) · line 159
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +3
-0uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev) { @@ -152,9 +152,14 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg) amdgpu_ring_commit(ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_read: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT );if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) {You should check
in_atomichere. Because it's invalid to sleep in atomic context (e.g. while holding a spin lock) even when not in an interrupt. This seems to happen a lot for indirect register access, e.g.soc15_pcie_rreg.Regards,
FelixQuoted 22 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +10
-1+msleep (5 ); + goto retry_read; + }return ~0 ; } val = adev->wb.wb[adev->virt.reg_val_offs];@@ -179,9 +184,15 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)amdgpu_ring_commit (ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_write: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT ); -if (r <1 ) +if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) { +msleep (5 ); + goto retry_write; + } + } }
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v) · line 198
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0
-0/**
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): e8a28819-c7fa-5b64-6b5b-723299d517f4-5C7GfCeVMHo@public.gmane.org
Am 02.03.2018 um 21:47 schrieb Felix Kuehling:
Quoted 9 lines · Monk
Quoted 3 lines
In_atomic()isnot encouraged to be used to judge if sleep is possible, see the macros of it#define
in_atomic()(preept_count()!= 0)OK. But my point is still that you're not testing the right thing when you check
in_interrupt(). The comment before thein_atomicmacro definition states the limitations and says "do not use in driver code". Unfortunately it doesn't suggest any alternative. I thinkin_interruptis actually worse, because it misses even more cases thanin_atomic.
Thinking about this, Felix seems to be absolutely right.
So we need to revert this patch since you can't reliable detect in a driver if sleeping is allowed or not.
Regards,
Christian.
Quoted 85 lines
Regards,
FelixQuoted 81 lines
/Monk
-----Original Message-----
From: Kuehling, Felix
Sent: 2018年3月1日 23:50
To: [email protected]; Liu, Monk <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)Quoted 32 lines · Monk Liu
sometimes GPU is switched to other VFs and won't swich back soon, so the kiq reg access will not signal within a short period, instead of busy waiting a long
time(MAX_KEQ_REG_WAIT)and returning TMO we can istead sleep 5ms and try again later (non irq context)And since the waiting in kiq_r/weg is busy wait, so
MAX_KIQ_REG_WAITshouldn't set to a long time, set it to 10ms is more appropriate.if gpu already in reset state, don't retry the KIQ reg access otherwise it would always hang because KIQ was already die usually.
v2:
replaceschedule()withmsleep()for the waitChange-Id I8fc807ce85a8d30d2b50153f3f3a6eda344ef994Signed-off-by Monk Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1
-1@@ -22,7 +22,7 @@*/ #include "amdgpu.h" -#define MAX_KIQ_REG_WAIT 100000000/* in usecs */ +#define MAX_KIQ_REG_WAIT 10000/* in usecs, 10ms */ drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +3
-0uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev) { @@ -152,9 +152,14 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg) amdgpu_ring_commit(ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_read: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT );if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) {You should check
in_atomichere. Because it's invalid to sleep in atomic context (e.g. while holding a spin lock) even when not in an interrupt. This seems to happen a lot for indirect register access, e.g.soc15_pcie_rreg.Regards,
FelixQuoted 22 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +10
-1+msleep (5 ); + goto retry_read; + }return ~0 ; } val = adev->wb.wb[adev->virt.reg_val_offs];@@ -179,9 +184,15 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)amdgpu_ring_commit (ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_write: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT ); -if (r <1 ) +if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) { +msleep (5 ); + goto retry_write; + } + } }
Quoted 5 lines
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v) · line 198
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0
-0/** _______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): ecccef01-fdab-0810-030a-cc0f0f0ee814-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Do you guys have a correct way to judge ?
Looks to me there won't be any issue:
1) there is no spin lock or atomic code wrapping the amdgpu_virt_kiq_rreg, ( see amdgpu_mm_rreg)
2) in_interrupt() at least could prevent you sleep in IRQ contest , why it is worse ?
For SRIOV this patch is needed, and for bare-metal kiq_reg routine won't be hit, I disagree revert it unless you Prove it is dangerous or give a solid example on how it break things
/Monk
-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: 2018年3月3日 21:38
To: Kuehling, Felix <[email protected]>; Liu, Monk <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)
Am 02.03.2018 um 21:47 schrieb Felix Kuehling:
Quoted 10 lines · Monk
Quoted 4 lines
In_atomic()isnot encouraged to be used to judge if sleep is possible, see the macros of it#define
in_atomic()(preept_count()!= 0)OK. But my point is still that you're not testing the right thing when you check
in_interrupt(). The comment before thein_atomicmacro definition states the limitations and says "do not use in driver code". Unfortunately it doesn't suggest any alternative. I thinkin_interruptis actually worse, because it misses even more cases thanin_atomic.
Thinking about this, Felix seems to be absolutely right.
So we need to revert this patch since you can't reliable detect in a driver if sleeping is allowed or not.
Regards,
Christian.
Quoted 87 lines
Regards,
FelixQuoted 83 lines
/Monk
-----Original Message-----
From: Kuehling, Felix
Sent: 2018年3月1日 23:50
To: [email protected]; Liu, Monk <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)Quoted 33 lines · Monk Liu
sometimes GPU is switched to other VFs and won't swich back soon, so the kiq reg access will not signal within a short period, instead of busy waiting a long
time(MAX_KEQ_REG_WAIT)and returning TMO we can istead sleep 5ms and try again later (non irq context)And since the waiting in kiq_r/weg is busy wait, so
MAX_KIQ_REG_WAITshouldn't set to a long time, set it to 10ms is more appropriate.if gpu already in reset state, don't retry the KIQ reg access otherwise it would always hang because KIQ was already die usually.
v2:
replaceschedule()withmsleep()for the waitChange-Id I8fc807ce85a8d30d2b50153f3f3a6eda344ef994Signed-off-by Monk Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1
-1@@ -22,7 +22,7 @@*/ #include "amdgpu.h" -#define MAX_KIQ_REG_WAIT 100000000/* in usecs */ +#define MAX_KIQ_REG_WAIT 10000/* in usecs, 10ms */ uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev) { @@ -152,9drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +4
-0+152,14 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, +uint32_t reg) amdgpu_ring_commit(ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_read: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT );if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) {You should check
in_atomichere. Because it's invalid to sleep in atomic context (e.g. while holding a spin lock) even when not in an interrupt. This seems to happen a lot for indirect register access, e.g.soc15_pcie_rreg.Regards,
FelixQuoted 22 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +10
-1+msleep (5 ); + goto retry_read; + }return ~0 ; } val = adev->wb.wb[adev->virt.reg_val_offs];@@ -179,9 +184,15 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)amdgpu_ring_commit (ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_write: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT ); -if (r <1 ) +if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) { +msleep (5 ); + goto retry_write; + } + } }
Quoted 5 lines
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v) · line 198
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0
-0/** _______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
When there are 16 VF/VM on one GPU, we can easily hit "sys lockup to 22s" kernel error/warning introduced by kiq_rreg/wreg routine That's why I must use this patch to let thread sleep a while and try again,
If you insist reverting this patch please give me a solution, otherwise I don't see how it is better by reverting it
/Monk
-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: 2018年3月3日 21:38
To: Kuehling, Felix <[email protected]>; Liu, Monk <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)
Am 02.03.2018 um 21:47 schrieb Felix Kuehling:
Quoted 10 lines · Monk
Quoted 4 lines
In_atomic()isnot encouraged to be used to judge if sleep is possible, see the macros of it#define
in_atomic()(preept_count()!= 0)OK. But my point is still that you're not testing the right thing when you check
in_interrupt(). The comment before thein_atomicmacro definition states the limitations and says "do not use in driver code". Unfortunately it doesn't suggest any alternative. I thinkin_interruptis actually worse, because it misses even more cases thanin_atomic.
Thinking about this, Felix seems to be absolutely right.
So we need to revert this patch since you can't reliable detect in a driver if sleeping is allowed or not.
Regards,
Christian.
Quoted 87 lines
Regards,
FelixQuoted 83 lines
/Monk
-----Original Message-----
From: Kuehling, Felix
Sent: 2018年3月1日 23:50
To: [email protected]; Liu, Monk <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)Quoted 33 lines · Monk Liu
sometimes GPU is switched to other VFs and won't swich back soon, so the kiq reg access will not signal within a short period, instead of busy waiting a long
time(MAX_KEQ_REG_WAIT)and returning TMO we can istead sleep 5ms and try again later (non irq context)And since the waiting in kiq_r/weg is busy wait, so
MAX_KIQ_REG_WAITshouldn't set to a long time, set it to 10ms is more appropriate.if gpu already in reset state, don't retry the KIQ reg access otherwise it would always hang because KIQ was already die usually.
v2:
replaceschedule()withmsleep()for the waitChange-Id I8fc807ce85a8d30d2b50153f3f3a6eda344ef994Signed-off-by Monk Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1
-1@@ -22,7 +22,7 @@*/ #include "amdgpu.h" -#define MAX_KIQ_REG_WAIT 100000000/* in usecs */ +#define MAX_KIQ_REG_WAIT 10000/* in usecs, 10ms */ uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev) { @@ -152,9drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +4
-0+152,14 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, +uint32_t reg) amdgpu_ring_commit(ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_read: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT );if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) {You should check
in_atomichere. Because it's invalid to sleep in atomic context (e.g. while holding a spin lock) even when not in an interrupt. This seems to happen a lot for indirect register access, e.g.soc15_pcie_rreg.Regards,
FelixQuoted 22 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +10
-1+msleep (5 ); + goto retry_read; + }return ~0 ; } val = adev->wb.wb[adev->virt.reg_val_offs];@@ -179,9 +184,15 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)amdgpu_ring_commit (ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_write: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT ); -if (r <1 ) +if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) { +msleep (5 ); + goto retry_write; + } + } }
Quoted 5 lines
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v) · line 198
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0
-0/** _______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): BLUPR12MB0449708DD427D1E744992FB584DA0-7LeqcoF/[email protected]
Quoted 1 line
otherwise I don't see how it is better by reverting it
Well it's better to revert it for now because it seems to create more problems than it solves.
To better approach this issue I suggest to do the following:
1. Revert the original patch.
2. Stop waiting to long for writes. E.g. use a separate timeout (20ms maybe?) to wait for the write. Then do a WARN_ON_ONCE when we timeout.
3. To the read function add a "if (!in_intterupt()) may_sleep();" and then retest. That should at least print a nice warning when called from atomic context.
4. Test the whole thing and try to fix all warnings about atomic contexts from the may_sleep();
5. Reapply the original patch, but this time only for the read function, not the write function.
Regards,
Christian.
Am 05.03.2018 um 05:20 schrieb Liu, Monk:
Quoted 121 lines
When there are 16 VF/VM on one GPU, we can easily hit "sys lockup to 22s" kernel error/warning introduced by kiq_rreg/wreg routine That's why I must use this patch to let thread sleep a while and try again,
If you insist reverting this patch please give me a solution, otherwise I don't see how it is better by reverting it
/Monk
-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: 2018年3月3日 21:38
To: Kuehling, Felix <[email protected]>; Liu, Monk <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)Am 02.03.2018 um 21:47 schrieb Felix Kuehling:
Quoted 10 lines · Monk
Quoted 4 lines
In_atomic()isnot encouraged to be used to judge if sleep is possible, see the macros of it#define
in_atomic()(preept_count()!= 0)OK. But my point is still that you're not testing the right thing when you check
in_interrupt(). The comment before thein_atomicmacro definition states the limitations and says "do not use in driver code". Unfortunately it doesn't suggest any alternative. I thinkin_interruptis actually worse, because it misses even more cases thanin_atomic.Thinking about this, Felix seems to be absolutely right.
So we need to revert this patch since you can't reliable detect in a driver if sleeping is allowed or not.
Regards,
Christian.Quoted 85 lines
Regards,
FelixQuoted 82 lines
/Monk
-----Original Message-----
From: Kuehling, Felix
Sent: 2018年3月1日 23:50
To: [email protected]; Liu, Monk <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)Quoted 33 lines · Monk Liu
sometimes GPU is switched to other VFs and won't swich back soon, so the kiq reg access will not signal within a short period, instead of busy waiting a long
time(MAX_KEQ_REG_WAIT)and returning TMO we can istead sleep 5ms and try again later (non irq context)And since the waiting in kiq_r/weg is busy wait, so
MAX_KIQ_REG_WAITshouldn't set to a long time, set it to 10ms is more appropriate.if gpu already in reset state, don't retry the KIQ reg access otherwise it would always hang because KIQ was already die usually.
v2:
replaceschedule()withmsleep()for the waitChange-Id I8fc807ce85a8d30d2b50153f3f3a6eda344ef994Signed-off-by Monk Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1
-1@@ -22,7 +22,7 @@*/ #include "amdgpu.h" -#define MAX_KIQ_REG_WAIT 100000000/* in usecs */ +#define MAX_KIQ_REG_WAIT 10000/* in usecs, 10ms */ uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev) { @@ -152,9drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +4
-0+152,14 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, +uint32_t reg) amdgpu_ring_commit(ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_read: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT );if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) {You should check
in_atomichere. Because it's invalid to sleep in atomic context (e.g. while holding a spin lock) even when not in an interrupt. This seems to happen a lot for indirect register access, e.g.soc15_pcie_rreg.Regards,
FelixQuoted 22 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +10
-1+msleep (5 ); + goto retry_read; + }return ~0 ; } val = adev->wb.wb[adev->virt.reg_val_offs];@@ -179,9 +184,15 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)amdgpu_ring_commit (ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_write: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT ); -if (r <1 ) +if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) { +msleep (5 ); + goto retry_write; + } + } }Quoted 5 lines
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v) · line 198
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0
-0/** _______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1df4fa9f-1a5c-f005-cfa8-e4346d7892c1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
To better approach this issue I suggest to do the following:
1. Revert the original patch.
2. Stop waiting to long for writes. E.g. use a separate timeout (20ms
maybe?) to wait for the write. Then do a WARN_ON_ONCE when we timeout.
Cannot do that 20ms is not enough, sometimes you need 10 seconds since other VFs may doing bad things like occupying GPU intentionally or they are doing TDR, so I don't think separate read and write is good idea, they should be treated equally
3. To the read function add a "if (!in_intterupt()) may_sleep();" and then retest. That should at least print a nice warning when called from atomic context. Sorry what is may_sleep() ??
4. Test the whole thing and try to fix all warnings about atomic contexts from the may_sleep();
5. Reapply the original patch, but this time only for the read function, not the write function.
From current LKG code, the only one spin lock may wrapping the kiq_rreg/wreg() is the pcie_idx_lock, and this lock is only used during init(), Since init() is run under the case of exclusive mode for SRIOV, which means:
1) register access is not go through KIQ (see admgpu_mm_reg)
2) those functions are only in bif_medium_grain_xxx part (vi.c and nbio_v6.c) , and they won't hit under SRIOV ( we return in the head if SRIOV detect) So I don' think this spin_lock may cause trouble...
/Monk
-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: 2018年3月5日 15:57
To: Liu, Monk <[email protected]>; Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)
Quoted 1 line
otherwise I don't see how it is better by reverting it
Well it's better to revert it for now because it seems to create more problems than it solves.
To better approach this issue I suggest to do the following:
1. Revert the original patch.
2. Stop waiting to long for writes. E.g. use a separate timeout (20ms maybe?) to wait for the write. Then do a WARN_ON_ONCE when we timeout.
3. To the read function add a "if (!in_intterupt()) may_sleep();" and then retest. That should at least print a nice warning when called from atomic context.
4. Test the whole thing and try to fix all warnings about atomic contexts from the may_sleep();
5. Reapply the original patch, but this time only for the read function, not the write function.
Regards,
Christian.
Am 05.03.2018 um 05:20 schrieb Liu, Monk:
Quoted 126 lines
When there are 16 VF/VM on one GPU, we can easily hit "sys lockup to 22s" kernel error/warning introduced by kiq_rreg/wreg routine That's why I must use this patch to let thread sleep a while and try again,
If you insist reverting this patch please give me a solution, otherwise I don't see how it is better by reverting it
/Monk
-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: 2018年3月3日 21:38
To: Kuehling, Felix <[email protected]>; Liu, Monk <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)Am 02.03.2018 um 21:47 schrieb Felix Kuehling:
Quoted 10 lines · Monk
Quoted 4 lines
In_atomic()isnot encouraged to be used to judge if sleep is possible, see the macros of it#define
in_atomic()(preept_count()!= 0)OK. But my point is still that you're not testing the right thing when you check
in_interrupt(). The comment before thein_atomicmacro definition states the limitations and says "do not use in driver code". Unfortunately it doesn't suggest any alternative. I thinkin_interruptis actually worse, because it misses even more cases thanin_atomic.Thinking about this, Felix seems to be absolutely right.
So we need to revert this patch since you can't reliable detect in a driver if sleeping is allowed or not.
Regards,
Christian.Quoted 86 lines
Regards,
FelixQuoted 83 lines
/Monk
-----Original Message-----
From: Kuehling, Felix
Sent: 2018年3月1日 23:50
To: [email protected]; Liu, Monk <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)Quoted 34 lines · Monk Liu
sometimes GPU is switched to other VFs and won't swich back soon, so the kiq reg access will not signal within a short period, instead of busy waiting a long
time(MAX_KEQ_REG_WAIT)and returning TMO we can istead sleep 5ms and try again later (non irq context)And since the waiting in kiq_r/weg is busy wait, so
MAX_KIQ_REG_WAITshouldn't set to a long time, set it to 10ms is more appropriate.if gpu already in reset state, don't retry the KIQ reg access otherwise it would always hang because KIQ was already die usually.
v2:
replaceschedule()withmsleep()for the waitChange-Id I8fc807ce85a8d30d2b50153f3f3a6eda344ef994Signed-off-by Monk Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1
-2@@ -22,7 +22,7 @@*/ #include "amdgpu.h" -#define MAX_KIQ_REG_WAIT 100000000/* in usecs */ +#define MAX_KIQ_REG_WAIT 10000/* in usecs, 10ms */ uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev) { @@ -152 ,9 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +4
-0+152,14 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device +*adev, uint32_t reg) amdgpu_ring_commit(ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_read: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT );if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) {You should check
in_atomichere. Because it's invalid to sleep in atomic context (e.g. while holding a spin lock) even when not in an interrupt. This seems to happen a lot for indirect register access, e.g.soc15_pcie_rreg.Regards,
FelixQuoted 22 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +10
-1+msleep (5 ); + goto retry_read; + }return ~0 ; } val = adev->wb.wb[adev->virt.reg_val_offs];@@ -179,9 +184,15 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)amdgpu_ring_commit (ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_write: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT ); -if (r <1 ) +if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) { +msleep (5 ); + goto retry_write; + } + } }Quoted 5 lines
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v) · line 198
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0
-0/** _______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): BLUPR12MB0449FFE3490C8EA3394D41DD84DA0-7LeqcoF/[email protected]
Am 05.03.2018 um 09:08 schrieb Liu, Monk:
Quoted 7 lines
To better approach this issue I suggest to do the following:
1. Revert the original patch.2. Stop waiting to long for writes. E.g. use a separate timeout (20ms
maybe?) to wait for the write. Then do aWARN_ON_ONCEwhen we timeout.
Cannot do that 20ms is not enough, sometimes you need 10 seconds since other VFs may doing bad things like occupying GPU intentionally or they are doing TDR, so I don't think separate read and write is good idea, they should be treated equally
Well the question is if separating read&writes would actually help.
Quoted 6 lines
3. To the read function add a "if (!in_intterupt())
may_sleep();" and then retest. That should at least print a nice warning when called from atomic context. Sorry what ismay_sleep()??4. Test the whole thing and try to fix all warnings about atomic contexts from the
may_sleep();
Quoted 8 lines
5. Reapply the original patch, but this time only for the read function, not the write function.
From current LKG code, the only one spin lock may wrapping the kiq_rreg/wreg() is the
pcie_idx_lock, and this lock is only used duringinit(),
Sinceinit()is run under the case of exclusive mode for SRIOV, which means:
1) register access is not go through KIQ (seeadmgpu_mm_reg)
2) those functions are only inbif_medium_grain_xxxpart (vi.candnbio_v6.c) , and they won't hit under SRIOV ( we return in the head if SRIOV detect) So I don' think thisspin_lockmay cause trouble...
Ok in this case let's keep the patch for now, but please provide a new patch which adds "if (!in_intterupt()) may_sleep();" in both the read and write function.
This way we should at least catch problems early on.
Christian.
Quoted 156 lines
/Monk
-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: 2018年3月5日 15:57
To: Liu, Monk <[email protected]>; Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)Quoted 1 line
otherwise I don't see how it is better by reverting it
Well it's better to revert it for now because it seems to create more problems than it solves.
To better approach this issue I suggest to do the following:
1. Revert the original patch.2. Stop waiting to long for writes. E.g. use a separate timeout (20ms maybe?) to wait for the write. Then do a
WARN_ON_ONCEwhen we timeout.3. To the read function add a "if (!in_intterupt())
may_sleep();" and then retest. That should at least print a nice warning when called from atomic context.4. Test the whole thing and try to fix all warnings about atomic contexts from the
may_sleep();5. Reapply the original patch, but this time only for the read function, not the write function.
Regards,
Christian.Am 05.03.2018 um 05:20 schrieb Liu, Monk:
Quoted 126 lines
When there are 16 VF/VM on one GPU, we can easily hit "sys lockup to 22s" kernel error/warning introduced by kiq_rreg/wreg routine That's why I must use this patch to let thread sleep a while and try again,
If you insist reverting this patch please give me a solution, otherwise I don't see how it is better by reverting it
/Monk
-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: 2018年3月3日 21:38
To: Kuehling, Felix <[email protected]>; Liu, Monk <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)Am 02.03.2018 um 21:47 schrieb Felix Kuehling:
Quoted 10 lines · Monk
Quoted 4 lines
In_atomic()isnot encouraged to be used to judge if sleep is possible, see the macros of it#define
in_atomic()(preept_count()!= 0)OK. But my point is still that you're not testing the right thing when you check
in_interrupt(). The comment before thein_atomicmacro definition states the limitations and says "do not use in driver code". Unfortunately it doesn't suggest any alternative. I thinkin_interruptis actually worse, because it misses even more cases thanin_atomic.Thinking about this, Felix seems to be absolutely right.
So we need to revert this patch since you can't reliable detect in a driver if sleeping is allowed or not.
Regards,
Christian.Quoted 91 lines
Regards,
FelixQuoted 83 lines
/Monk
-----Original Message-----
From: Kuehling, Felix
Sent: 2018年3月1日 23:50
To: [email protected]; Liu, Monk <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)Quoted 34 lines · Monk Liu
sometimes GPU is switched to other VFs and won't swich back soon, so the kiq reg access will not signal within a short period, instead of busy waiting a long
time(MAX_KEQ_REG_WAIT)and returning TMO we can istead sleep 5ms and try again later (non irq context)And since the waiting in kiq_r/weg is busy wait, so
MAX_KIQ_REG_WAITshouldn't set to a long time, set it to 10ms is more appropriate.if gpu already in reset state, don't retry the KIQ reg access otherwise it would always hang because KIQ was already die usually.
v2:
replaceschedule()withmsleep()for the waitChange-Id I8fc807ce85a8d30d2b50153f3f3a6eda344ef994Signed-off-by Monk Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1
-2@@ -22,7 +22,7 @@*/ #include "amdgpu.h" -#define MAX_KIQ_REG_WAIT 100000000/* in usecs */ +#define MAX_KIQ_REG_WAIT 10000/* in usecs, 10ms */ uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev) { @@ -152 ,9 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +4
-0+152,14 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device +*adev, uint32_t reg) amdgpu_ring_commit(ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_read: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT );if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) {You should check
in_atomichere. Because it's invalid to sleep in atomic context (e.g. while holding a spin lock) even when not in an interrupt. This seems to happen a lot for indirect register access, e.g.soc15_pcie_rreg.Regards,
FelixQuoted 22 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +10
-1+msleep (5 ); + goto retry_read; + }return ~0 ; } val = adev->wb.wb[adev->virt.reg_val_offs];@@ -179,9 +184,15 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)amdgpu_ring_commit (ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_write: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT ); -if (r <1 ) +if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) { +msleep (5 ); + goto retry_write; + } + } }Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v) · line 198
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0
-0/** _______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 8 lines
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 48b49b85-495f-c5bc-7d8b-447537a94c8f-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Hi Christian
I couln't find this "may_sleep()" in my 4.13kernel , did I miss something ??
Thanks
/Monk
-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: 2018年3月5日 19:21
To: Liu, Monk <[email protected]>; Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)
Am 05.03.2018 um 09:08 schrieb Liu, Monk:
Quoted 9 lines
To better approach this issue I suggest to do the following:
1. Revert the original patch.2. Stop waiting to long for writes. E.g. use a separate timeout (20ms maybe?) to wait for the write. Then do a
WARN_ON_ONCEwhen we timeout. Cannot do that 20ms is not enough, sometimes you need 10 seconds since other VFs may doing bad things like occupying GPU intentionally or they are doing TDR, so I don't think separate read and write is good idea, they should be treated equally
Well the question is if separating read&writes would actually help.
Quoted 7 lines
3. To the read function add a "if (!in_intterupt())
may_sleep();" and then retest. That should at least print a nice warning when called from atomic context. Sorry what ismay_sleep()??4. Test the whole thing and try to fix all warnings about atomic contexts from the
may_sleep();
Quoted 8 lines
5. Reapply the original patch, but this time only for the read function, not the write function.
From current LKG code, the only one spin lock may wrapping the
kiq_rreg/wreg() is thepcie_idx_lock, and this lock is only used duringinit(), Sinceinit()is run under the case of exclusive mode for SRIOV, which means:
1) register access is not go through KIQ (seeadmgpu_mm_reg)
2) those functions are only inbif_medium_grain_xxxpart (vi.candnbio_v6.c) , and they won't hit under SRIOV ( we return in the head if SRIOV detect) So I don' think thisspin_lockmay cause trouble...
Ok in this case let's keep the patch for now, but please provide a new patch which adds "if (!in_intterupt()) may_sleep();" in both the read and write function.
This way we should at least catch problems early on.
Christian.
Quoted 161 lines
/Monk
-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: 2018年3月5日 15:57
To: Liu, Monk <[email protected]>; Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)Quoted 1 line
otherwise I don't see how it is better by reverting it
Well it's better to revert it for now because it seems to create more problems than it solves.
To better approach this issue I suggest to do the following:
1. Revert the original patch.2. Stop waiting to long for writes. E.g. use a separate timeout (20ms maybe?) to wait for the write. Then do a
WARN_ON_ONCEwhen we timeout.3. To the read function add a "if (!in_intterupt())
may_sleep();" and then retest. That should at least print a nice warning when called from atomic context.4. Test the whole thing and try to fix all warnings about atomic contexts from the
may_sleep();5. Reapply the original patch, but this time only for the read function, not the write function.
Regards,
Christian.Am 05.03.2018 um 05:20 schrieb Liu, Monk:
Quoted 127 lines
When there are 16 VF/VM on one GPU, we can easily hit "sys lockup to 22s" kernel error/warning introduced by kiq_rreg/wreg routine That's why I must use this patch to let thread sleep a while and try again,
If you insist reverting this patch please give me a solution, otherwise I don't see how it is better by reverting it
/Monk
-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: 2018年3月3日 21:38
To: Kuehling, Felix <[email protected]>; Liu, Monk <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)Am 02.03.2018 um 21:47 schrieb Felix Kuehling:
Quoted 10 lines · Monk
Quoted 4 lines
In_atomic()isnot encouraged to be used to judge if sleep is possible, see the macros of it#define
in_atomic()(preept_count()!= 0)OK. But my point is still that you're not testing the right thing when you check
in_interrupt(). The comment before thein_atomicmacro definition states the limitations and says "do not use in driver code". Unfortunately it doesn't suggest any alternative. I thinkin_interruptis actually worse, because it misses even more cases thanin_atomic.Thinking about this, Felix seems to be absolutely right.
So we need to revert this patch since you can't reliable detect in a driver if sleeping is allowed or not.
Regards,
Christian.Quoted 92 lines
Regards,
FelixQuoted 84 lines
/Monk
-----Original Message-----
From: Kuehling, Felix
Sent: 2018年3月1日 23:50
To: [email protected]; Liu, Monk <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)Quoted 35 lines · Monk Liu
sometimes GPU is switched to other VFs and won't swich back soon, so the kiq reg access will not signal within a short period, instead of busy waiting a long
time(MAX_KEQ_REG_WAIT)and returning TMO we can istead sleep 5ms and try again later (non irq context)And since the waiting in kiq_r/weg is busy wait, so
MAX_KIQ_REG_WAITshouldn't set to a long time, set it to 10ms is more appropriate.if gpu already in reset state, don't retry the KIQ reg access otherwise it would always hang because KIQ was already die usually.
v2:
replaceschedule()withmsleep()for the waitChange-Id I8fc807ce85a8d30d2b50153f3f3a6eda344ef994Signed-off-by Monk Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1
-2@@ -22,7 +22,7 @@*/ #include "amdgpu.h" -#define MAX_KIQ_REG_WAIT 100000000/* in usecs */ +#define MAX_KIQ_REG_WAIT 10000/* in usecs, 10ms */ uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev) { @@ -152 ,9 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +4
-0+152,14 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device +*adev, uint32_t reg) amdgpu_ring_commit(ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_read: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT );if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) {You should check
in_atomichere. Because it's invalid to sleep in atomic context (e.g. while holding a spin lock) even when not in an interrupt. This seems to happen a lot for indirect register access, e.g.soc15_pcie_rreg.Regards,
FelixQuoted 22 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +10
-1+msleep (5 ); + goto retry_read; + }return ~0 ; } val = adev->wb.wb[adev->virt.reg_val_offs];@@ -179,9 +184,15 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)amdgpu_ring_commit (ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_write: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT ); -if (r <1 ) +if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) { +msleep (5 ); + goto retry_write; + } + } }Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v) · line 198
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0
-0/** _______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 8 lines
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): BLUPR12MB0449F42E6D448FA2C5A7BD2F84DA0-7LeqcoF/[email protected]
Hi Monk,
then that was written differently. Maybe "might_sleep()" or something like that?
It's just a checker which raises a nice warning when you try to sleep in atomic context on debug kernels.
Christian.
Am 05.03.2018 um 12:27 schrieb Liu, Monk:
Quoted 39 lines
Hi Christian
I couln't find this "
may_sleep()" in my 4.13kernel , did I miss something ??Thanks
/Monk-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: 2018年3月5日 19:21
To: Liu, Monk <[email protected]>; Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)Am 05.03.2018 um 09:08 schrieb Liu, Monk:
Quoted 9 lines
To better approach this issue I suggest to do the following:
1. Revert the original patch.2. Stop waiting to long for writes. E.g. use a separate timeout (20ms maybe?) to wait for the write. Then do a
WARN_ON_ONCEwhen we timeout. Cannot do that 20ms is not enough, sometimes you need 10 seconds since other VFs may doing bad things like occupying GPU intentionally or they are doing TDR, so I don't think separate read and write is good idea, they should be treated equallyWell the question is if separating read&writes would actually help.
Quoted 6 lines
3. To the read function add a "if (!in_intterupt())
may_sleep();" and then retest. That should at least print a nice warning when called from atomic context. Sorry what ismay_sleep()??4. Test the whole thing and try to fix all warnings about atomic contexts from the
may_sleep();Quoted 8 lines
5. Reapply the original patch, but this time only for the read function, not the write function.
From current LKG code, the only one spin lock may wrapping the
kiq_rreg/wreg() is thepcie_idx_lock, and this lock is only used duringinit(), Sinceinit()is run under the case of exclusive mode for SRIOV, which means:
1) register access is not go through KIQ (seeadmgpu_mm_reg)
2) those functions are only inbif_medium_grain_xxxpart (vi.candnbio_v6.c) , and they won't hit under SRIOV ( we return in the head if SRIOV detect) So I don' think thisspin_lockmay cause trouble...
Quoted 174 lines
Ok in this case let's keep the patch for now, but please provide a new patch which adds "if (!in_intterupt())
may_sleep();" in both the read and write function.This way we should at least catch problems early on.
Christian.
Quoted 168 lines
/Monk
-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: 2018年3月5日 15:57
To: Liu, Monk <[email protected]>; Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)Quoted 1 line
otherwise I don't see how it is better by reverting it
Well it's better to revert it for now because it seems to create more problems than it solves.
To better approach this issue I suggest to do the following:
1. Revert the original patch.2. Stop waiting to long for writes. E.g. use a separate timeout (20ms maybe?) to wait for the write. Then do a
WARN_ON_ONCEwhen we timeout.3. To the read function add a "if (!in_intterupt())
may_sleep();" and then retest. That should at least print a nice warning when called from atomic context.4. Test the whole thing and try to fix all warnings about atomic contexts from the
may_sleep();5. Reapply the original patch, but this time only for the read function, not the write function.
Regards,
Christian.Am 05.03.2018 um 05:20 schrieb Liu, Monk:
Quoted 127 lines
When there are 16 VF/VM on one GPU, we can easily hit "sys lockup to 22s" kernel error/warning introduced by kiq_rreg/wreg routine That's why I must use this patch to let thread sleep a while and try again,
If you insist reverting this patch please give me a solution, otherwise I don't see how it is better by reverting it
/Monk
-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: 2018年3月3日 21:38
To: Kuehling, Felix <[email protected]>; Liu, Monk <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)Am 02.03.2018 um 21:47 schrieb Felix Kuehling:
Quoted 10 lines · Monk
Quoted 4 lines
In_atomic()isnot encouraged to be used to judge if sleep is possible, see the macros of it#define
in_atomic()(preept_count()!= 0)OK. But my point is still that you're not testing the right thing when you check
in_interrupt(). The comment before thein_atomicmacro definition states the limitations and says "do not use in driver code". Unfortunately it doesn't suggest any alternative. I thinkin_interruptis actually worse, because it misses even more cases thanin_atomic.Thinking about this, Felix seems to be absolutely right.
So we need to revert this patch since you can't reliable detect in a driver if sleeping is allowed or not.
Regards,
Christian.Quoted 87 lines
Regards,
FelixQuoted 84 lines
/Monk
-----Original Message-----
From: Kuehling, Felix
Sent: 2018年3月1日 23:50
To: [email protected]; Liu, Monk <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)Quoted 35 lines · Monk Liu
sometimes GPU is switched to other VFs and won't swich back soon, so the kiq reg access will not signal within a short period, instead of busy waiting a long
time(MAX_KEQ_REG_WAIT)and returning TMO we can istead sleep 5ms and try again later (non irq context)And since the waiting in kiq_r/weg is busy wait, so
MAX_KIQ_REG_WAITshouldn't set to a long time, set it to 10ms is more appropriate.if gpu already in reset state, don't retry the KIQ reg access otherwise it would always hang because KIQ was already die usually.
v2:
replaceschedule()withmsleep()for the waitChange-Id I8fc807ce85a8d30d2b50153f3f3a6eda344ef994Signed-off-by Monk Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1
-2@@ -22,7 +22,7 @@*/ #include "amdgpu.h" -#define MAX_KIQ_REG_WAIT 100000000/* in usecs */ +#define MAX_KIQ_REG_WAIT 10000/* in usecs, 10ms */ uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev) { @@ -152 ,9 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +4
-0+152,14 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device +*adev, uint32_t reg) amdgpu_ring_commit(ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_read: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT );if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) {You should check
in_atomichere. Because it's invalid to sleep in atomic context (e.g. while holding a spin lock) even when not in an interrupt. This seems to happen a lot for indirect register access, e.g.soc15_pcie_rreg.Regards,
FelixQuoted 22 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +10
-1+msleep (5 ); + goto retry_read; + }return ~0 ; } val = adev->wb.wb[adev->virt.reg_val_offs];@@ -179,9 +184,15 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)amdgpu_ring_commit (ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_write: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT ); -if (r <1 ) +if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) { +msleep (5 ); + goto retry_write; + } + } }Quoted 5 lines
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v) · line 198
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0
-0/** _______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfxQuoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 1 line
You should check
in_atomichere. Because it's invalid to sleep in atomic context (e.g. while holding a spin lock) even when not in an interrupt.
This seems to happen a lot for indirect register access, e.g. soc15_pcie_rreg.
For this case you are right, but "in_atomic" cannot check what you want, because it fails to check atomic context in non-preemptible kernel
I have another method: inside of virt_kiq_rreg(), we can test if this "adev->pcie_idx_lock" is held, do you think it is enough ?
Except "pcie_idx_lock" I didn't find other spin lock wrapping kiq_virt_rreg by far,
/Monk
-----Original Message-----
From: Kuehling, Felix
Sent: 2018年3月1日 23:50
To: [email protected]; Liu, Monk <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: try again kiq access if not in IRQ(v2)
Quoted 32 lines · Monk Liu
sometimes GPU is switched to other VFs and won't swich back soon, so the kiq reg access will not signal within a short period, instead of busy waiting a long
time(MAX_KEQ_REG_WAIT)and returning TMO we can istead sleep 5ms and try again later (non irq context)And since the waiting in kiq_r/weg is busy wait, so
MAX_KIQ_REG_WAITshouldn't set to a long time, set it to 10ms is more appropriate.if gpu already in reset state, don't retry the KIQ reg access otherwise it would always hang because KIQ was already die usually.
v2:
replaceschedule()withmsleep()for the waitChange-Id I8fc807ce85a8d30d2b50153f3f3a6eda344ef994Signed-off-by Monk Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1
-1@@ -22,7 +22,7 @@*/ #include "amdgpu.h" -#define MAX_KIQ_REG_WAIT 100000000/* in usecs */ +#define MAX_KIQ_REG_WAIT 10000/* in usecs, 10ms */
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg) · line 159
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +3
-0uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev) { @@ -152,9 +152,14 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg) amdgpu_ring_commit(ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_read: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT );if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) {
You should check in_atomic here. Because it's invalid to sleep in atomic context (e.g. while holding a spin lock) even when not in an interrupt. This seems to happen a lot for indirect register access, e.g.soc15_pcie_rreg.
Regards,
Felix
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +4
-1+msleep (5 ); + goto retry_read; + }return ~0 ; } val = adev->wb.wb[adev->virt.reg_val_offs];@@ -179,9 +184,15 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)amdgpu_ring_commit (ring);spin_unlock_irqrestore (&kiq->ring_lock, flags); +retry_write: r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT ); -if (r <1 )
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v) · line 198
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +6
-0+if (r <1 ) {DRM_ERROR ("wait for kiq fence error: %ld\n" , r); +if (!in_interrupt () && !adev->in_gpu_reset) { +msleep (5 ); + goto retry_write; + } + } }/**
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx