drm/amdgpu: add ih call to process until checkpoint
Subsystems (2)
PATCH 1/1 drm/amdgpu: add ih call to process until checkpoint
Add IH function to allow caller to process ring entries until the checkpoint write pointer.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c | 46 +++++++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h | 2 ++ 2 files changed, 47 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +45 -1
@@ -22,7 +22,7 @@*/ #include <linux/dma-mapping.h> - +#include <linux/processor.h> #include "amdgpu.h" #include "amdgpu_ih.h"
@@ -160,6 +160,50 @@ void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, } } +/** +* amdgpu_ih_wait_on_checkpoint_process - wait to process IVs up to checkpoint +* +* @adev: amdgpu_device pointer +* @ih: ih ring to process +* +* Used to ensure ring has processed IVs up to the checkpoint write pointer. +*/ +int amdgpu_ih_wait_on_checkpoint_process (struct amdgpu_device *adev, +struct amdgpu_ih_ring *ih) +{ +u32 prev_rptr, cur_rptr, checkpoint_wptr; + +if (!ih->enabled || adev->shutdown) +return -ENODEV ; + + cur_rptr =READ_ONCE (ih->rptr); +/* Order read of current rptr with checktpoint wptr. */ +mb (); + checkpoint_wptr =amdgpu_ih_get_wptr (adev, ih); + +/* allow rptr to wrap around */ +if (cur_rptr > checkpoint_wptr) { +spin_begin (); +do { +spin_cpu_relax (); + prev_rptr = cur_rptr; + cur_rptr =READ_ONCE (ih->rptr); + }while (cur_rptr >= prev_rptr); +spin_end (); + } + +/* wait for rptr to catch up to or pass checkpoint. */ +spin_begin (); +do { +spin_cpu_relax (); + prev_rptr = cur_rptr; + cur_rptr =READ_ONCE (ih->rptr); + }while (cur_rptr >= prev_rptr && cur_rptr < checkpoint_wptr); +spin_end (); + +return 0 ; +} +/** * amdgpu_ih_process - interrupt handler *
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +2 -0
@@ -87,6 +87,8 @@ int amdgpu_ih_ring_init(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih,void amdgpu_ih_ring_fini (struct amdgpu_device *adev,struct amdgpu_ih_ring *ih);void amdgpu_ih_ring_write (struct amdgpu_ih_ring *ih,const uint32_t *iv,unsigned int num_dw); +int amdgpu_ih_wait_on_checkpoint_process (struct amdgpu_device *adev, +struct amdgpu_ih_ring *ih);int amdgpu_ih_process (struct amdgpu_device *adev,struct amdgpu_ih_ring *ih); void amdgpu_ih_decode_iv_helper(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih,
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 38 lines · Jonathan Kim
Add IH function to allow caller to process ring entries until the checkpoint write pointer.
Suggested-by Felix Kuehling <[email protected]>Signed-off-by Jonathan Kim <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c | 46 +++++++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h | 2 ++ 2 files changed, 47 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +12
-1@@ -22,7 +22,7 @@*/ #include <linux/dma-mapping.h> - +#include <linux/processor.h> #include "amdgpu.h" #include "amdgpu_ih.h" @@ -160,6 +160,50 @@ void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, } } +/** +* amdgpu_ih_wait_on_checkpoint_process - wait to process IVs up to checkpoint +* +* @adev: amdgpu_device pointer +* @ih: ih ring to process +* +* Used to ensure ring has processed IVs up to the checkpoint write pointer. +*/ +int amdgpu_ih_wait_on_checkpoint_process (struct amdgpu_device *adev, +struct amdgpu_ih_ring *ih) +{
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, · line 183
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +10
-0+u32 prev_rptr, cur_rptr, checkpoint_wptr; + +if (!ih->enabled || adev->shutdown) +return -ENODEV ; + + cur_rptr =READ_ONCE (ih->rptr); +/* Order read of current rptr with checktpoint wptr. */ +mb (); + checkpoint_wptr =amdgpu_ih_get_wptr (adev, ih); +
Isn't rmb() enough in this case ? If I understand correctly you just want to confirm that you are not reading stale checkpoint_wptr while reading fresh cur_rptr.
Andrey
Quoted 31 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +23
-0+/* allow rptr to wrap around */ +if (cur_rptr > checkpoint_wptr) { +spin_begin (); +do { +spin_cpu_relax (); + prev_rptr = cur_rptr; + cur_rptr =READ_ONCE (ih->rptr); + }while (cur_rptr >= prev_rptr); +spin_end (); + } + +/* wait for rptr to catch up to or pass checkpoint. */ +spin_begin (); +do { +spin_cpu_relax (); + prev_rptr = cur_rptr; + cur_rptr =READ_ONCE (ih->rptr); + }while (cur_rptr >= prev_rptr && cur_rptr < checkpoint_wptr); +spin_end (); + +return 0 ; +} +/** * amdgpu_ih_process - interrupt handler * drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h int amdgpu_ih_ring_init(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih, · line 94
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +2
-0@@ -87,6 +87,8 @@ int amdgpu_ih_ring_init(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih,void amdgpu_ih_ring_fini (struct amdgpu_device *adev,struct amdgpu_ih_ring *ih);void amdgpu_ih_ring_write (struct amdgpu_ih_ring *ih,const uint32_t *iv,unsigned int num_dw); +int amdgpu_ih_wait_on_checkpoint_process (struct amdgpu_device *adev, +struct amdgpu_ih_ring *ih);int amdgpu_ih_process (struct amdgpu_device *adev,struct amdgpu_ih_ring *ih); void amdgpu_ih_decode_iv_helper(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih,
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Christian König
maintainerAm 23.02.21 um 22:10 schrieb Jonathan Kim:
Quoted 2 lines
Add IH function to allow caller to process ring entries until the checkpoint write pointer.
This needs a better description of what this will be used for.
Quoted 45 lines
Suggested-by Felix Kuehling <[email protected]>Signed-off-by Jonathan Kim <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c | 46 +++++++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h | 2 ++ 2 files changed, 47 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +21
-1@@ -22,7 +22,7 @@*/ #include <linux/dma-mapping.h> - +#include <linux/processor.h> #include "amdgpu.h" #include "amdgpu_ih.h" @@ -160,6 +160,50 @@ void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, } } +/** +* amdgpu_ih_wait_on_checkpoint_process - wait to process IVs up to checkpoint +* +* @adev: amdgpu_device pointer +* @ih: ih ring to process +* +* Used to ensure ring has processed IVs up to the checkpoint write pointer. +*/ +int amdgpu_ih_wait_on_checkpoint_process (struct amdgpu_device *adev, +struct amdgpu_ih_ring *ih) +{ +u32 prev_rptr, cur_rptr, checkpoint_wptr; + +if (!ih->enabled || adev->shutdown) +return -ENODEV ; + + cur_rptr =READ_ONCE (ih->rptr); +/* Order read of current rptr with checktpoint wptr. */ +mb (); + checkpoint_wptr =amdgpu_ih_get_wptr (adev, ih);
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, · line 192
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +10
-0+ +/* allow rptr to wrap around */ +if (cur_rptr > checkpoint_wptr) { +spin_begin (); +do { +spin_cpu_relax (); + prev_rptr = cur_rptr; + cur_rptr =READ_ONCE (ih->rptr); + }while (cur_rptr >= prev_rptr); +spin_end ();
That's a certain NAK since it busy waits for IH processing. We need some event to trigger here.
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, · line 201
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +9
-0+ } + +/* wait for rptr to catch up to or pass checkpoint. */ +spin_begin (); +do { +spin_cpu_relax (); + prev_rptr = cur_rptr; + cur_rptr =READ_ONCE (ih->rptr); + }while (cur_rptr >= prev_rptr && cur_rptr < checkpoint_wptr);
Same of course here.
Christian.
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +5
-0+spin_end (); + +return 0 ; +} +/** * amdgpu_ih_process - interrupt handler * drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h int amdgpu_ih_ring_init(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih, · line 94
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +2
-0@@ -87,6 +87,8 @@ int amdgpu_ih_ring_init(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih,void amdgpu_ih_ring_fini (struct amdgpu_device *adev,struct amdgpu_ih_ring *ih);void amdgpu_ih_ring_write (struct amdgpu_ih_ring *ih,const uint32_t *iv,unsigned int num_dw); +int amdgpu_ih_wait_on_checkpoint_process (struct amdgpu_device *adev, +struct amdgpu_ih_ring *ih);int amdgpu_ih_process (struct amdgpu_device *adev,struct amdgpu_ih_ring *ih); void amdgpu_ih_decode_iv_helper(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih,
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
[AMD Official Use Only - Internal Distribution Only]
Quoted 9 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Wednesday, February 24, 2021 4:17 AM
To: Kim, Jonathan <[email protected]>; amd- [email protected]
Cc: Yang, Philip <[email protected]>; Kuehling, Felix <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: add ih call to process until checkpoint
Quoted 5 lines
Am 23.02.21 um 22:10 schrieb Jonathan Kim:
Quoted 2 lines
Add IH function to allow caller to process ring entries until the checkpoint write pointer.
This needs a better description of what this will be used for.
Felix or Philip could elaborate better for HMM needs.
Debugging tools requires this but it's in experimental mode at the moment so probably not the best place to describe here.
Quoted 57 lines
Quoted 6 lines
Suggested-by Felix Kuehling <[email protected]>Signed-off-by Jonathan Kim <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c | 46+++++++++++++++++++++++++-
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct
Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h | 2 ++ 2 files changed, 47 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +1
-1@@ -22,7 +22,7 @@*/ #include <linux/dma-mapping.h> - +#include <linux/processor.h> #include "amdgpu.h" #include "amdgpu_ih.h" @@ -160,6 +160,50 @@ void amdgpu_ih_ring_write(struct
amdgpu_ih_ring*ih, constuint32_t*iv,drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv,
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +8
-0} } +/** +* amdgpu_ih_wait_on_checkpoint_process - wait to process IVs up to +checkpoint +* +* @adev: amdgpu_device pointer +* @ih: ih ring to process +* +* Used to ensure ring has processed IVs up to the checkpoint write pointer.
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct · line 172
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +2
-0+*/ +int amdgpu_ih_wait_on_checkpoint_process(struct amdgpu_device*adev,
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +16
-0+struct amdgpu_ih_ring *ih) +{ +u32 prev_rptr, cur_rptr, checkpoint_wptr; + +if (!ih->enabled || adev->shutdown) +return -ENODEV ; + +cur_rptr =READ_ONCE (ih->rptr); +/* Order read of current rptr with checktpoint wptr. */ +mb (); +checkpoint_wptr =amdgpu_ih_get_wptr (adev, ih); + +/* allow rptr to wrap around */ +if (cur_rptr > checkpoint_wptr) { +spin_begin (); +do {
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, · line 192
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +5
-0+spin_cpu_relax (); +prev_rptr = cur_rptr; +cur_rptr =READ_ONCE (ih->rptr); +}while (cur_rptr >= prev_rptr); +spin_end ();That's a certain NAK since it busy waits for IH processing. We need some event to trigger here.
The function is meant to be just a waiter up to the checkpoint.
There's a need to guarantee that "stale" interrupts have been processed on check before doing other stuff after call. The description could be improved to clarify that.
Would busy waiting only on a locked ring help? I assume an unlocked ring means nothing to process so no need to wait and we can exit early. Or is it better to just to process the entries up to the checkpoint (maybe adjust amdgpu_ih_process for this need like adding a bool arg to skip restart or something)?
Thanks,
Jon
Quoted 31 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, · line 201
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +9
-0+} + +/* wait for rptr to catch up to or pass checkpoint. */ +spin_begin (); +do { +spin_cpu_relax (); +prev_rptr = cur_rptr; +cur_rptr =READ_ONCE (ih->rptr); +}while (cur_rptr >= prev_rptr && cur_rptr < checkpoint_wptr);Same of course here.
Christian.
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h int amdgpu_ih_ring_init(struct amdgpu_device *adev,
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +5
-0+spin_end (); + +return 0 ; +} +/** * amdgpu_ih_process - interrupt handler * drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +0
-0@@ -87,6 +87,8 @@ int amdgpu_ih_ring_init(struct amdgpu_device *adev,struct
amdgpu_ih_ring*ih,drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h int amdgpu_ih_ring_init(struct amdgpu_device *adev, · line 87
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +0
-0void amdgpu_ih_ring_fini(struct amdgpu_device *adev, struct
Quoted 10 lines
amdgpu_ih_ring*ih);drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h int amdgpu_ih_ring_init(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih,
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +1
-0void amdgpu_ih_ring_write (struct amdgpu_ih_ring *ih,const uint32_t *iv,unsigned int num_dw); +int amdgpu_ih_wait_on_checkpoint_process(struct amdgpu_device*adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h int amdgpu_ih_ring_init(struct amdgpu_device *adev, · line 92
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +1
-0+struct amdgpu_ih_ring *ih); int amdgpu_ih_process(struct amdgpu_device *adev, struct
amdgpu_ih_ring*ih);Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +0
-0void amdgpu_ih_decode_iv_helper(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih,
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 11 lines · Jonathan
[AMD Official Use Only - Internal Distribution Only]
Quoted 9 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Wednesday, February 24, 2021 4:17 AM
To: Kim, Jonathan <[email protected]>; amd- [email protected]
Cc: Yang, Philip <[email protected]>; Kuehling, Felix <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: add ih call to process until checkpoint
Quoted 6 lines
Quoted 4 lines
Am 23.02.21 um 22:10 schrieb Jonathan Kim:
Quoted 2 lines
Add IH function to allow caller to process ring entries until the checkpoint write pointer.
This needs a better description of what this will be used for.
Felix or Philip could elaborate better for HMM needs.
Debugging tools requires this but it's in experimental mode at the moment so probably not the best place to describe here.
On the HMM side we're planning to use this to drain pending page fault interrupts before we unmap memory. That should address phantom VM faults after memory is unmapped.
Regards,
Felix
Quoted 67 lines
Quoted 55 lines
Quoted 5 lines
Suggested-by Felix Kuehling <[email protected]>Signed-off-by Jonathan Kim <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c | 46+++++++++++++++++++++++++-
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct
Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h | 2 ++ 2 files changed, 47 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +1
-1@@ -22,7 +22,7 @@*/ #include <linux/dma-mapping.h> - +#include <linux/processor.h> #include "amdgpu.h" #include "amdgpu_ih.h" @@ -160,6 +160,50 @@ void amdgpu_ih_ring_write(struct
amdgpu_ih_ring*ih, constuint32_t*iv,drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv,
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +8
-0} } +/** +* amdgpu_ih_wait_on_checkpoint_process - wait to process IVs up to +checkpoint +* +* @adev: amdgpu_device pointer +* @ih: ih ring to process +* +* Used to ensure ring has processed IVs up to the checkpoint write pointer.
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct · line 172
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +2
-0+*/ +int amdgpu_ih_wait_on_checkpoint_process(struct amdgpu_device*adev,
Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +15
-0+struct amdgpu_ih_ring *ih) +{ +u32 prev_rptr, cur_rptr, checkpoint_wptr; + +if (!ih->enabled || adev->shutdown) +return -ENODEV ; + +cur_rptr =READ_ONCE (ih->rptr); +/* Order read of current rptr with checktpoint wptr. */ +mb (); +checkpoint_wptr =amdgpu_ih_get_wptr (adev, ih); + +/* allow rptr to wrap around */ +if (cur_rptr > checkpoint_wptr) { +spin_begin ();Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, · line 192
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +6
-0+do { +spin_cpu_relax (); +prev_rptr = cur_rptr; +cur_rptr =READ_ONCE (ih->rptr); +}while (cur_rptr >= prev_rptr); +spin_end ();That's a certain NAK since it busy waits for IH processing. We need some event to trigger here.
The function is meant to be just a waiter up to the checkpoint.
There's a need to guarantee that "stale" interrupts have been processed on check before doing other stuff after call. The description could be improved to clarify that.
Quoted 45 lines
Would busy waiting only on a locked ring help? I assume an unlocked ring means nothing to process so no need to wait and we can exit early. Or is it better to just to process the entries up to the checkpoint (maybe adjust
amdgpu_ih_processfor this need like adding a bool arg to skip restart or something)?Thanks,
Jon
Quoted 39 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, · line 201
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +9
-0+} + +/* wait for rptr to catch up to or pass checkpoint. */ +spin_begin (); +do { +spin_cpu_relax (); +prev_rptr = cur_rptr; +cur_rptr =READ_ONCE (ih->rptr); +}while (cur_rptr >= prev_rptr && cur_rptr < checkpoint_wptr);Same of course here.
Christian.
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h int amdgpu_ih_ring_init(struct amdgpu_device *adev,
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +5
-0+spin_end (); + +return 0 ; +} +/** * amdgpu_ih_process - interrupt handler * drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +0
-0@@ -87,6 +87,8 @@ int amdgpu_ih_ring_init(struct amdgpu_device *adev,struct
amdgpu_ih_ring*ih,drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h int amdgpu_ih_ring_init(struct amdgpu_device *adev, · line 87
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +0
-0void amdgpu_ih_ring_fini(struct amdgpu_device *adev, struct
amdgpu_ih_ring*ih);drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h int amdgpu_ih_ring_init(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih,
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +1
-0void amdgpu_ih_ring_write (struct amdgpu_ih_ring *ih,const uint32_t *iv,unsigned int num_dw); +int amdgpu_ih_wait_on_checkpoint_process(struct amdgpu_device*adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h int amdgpu_ih_ring_init(struct amdgpu_device *adev, · line 92
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +1
-0+struct amdgpu_ih_ring *ih); int amdgpu_ih_process(struct amdgpu_device *adev, struct
amdgpu_ih_ring*ih);Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +0
-0void amdgpu_ih_decode_iv_helper(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih,
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 25.02.21 um 04:15 schrieb Felix Kuehling:
Quoted 12 lines · Jonathan
Quoted 11 lines
[AMD Official Use Only - Internal Distribution Only]
Quoted 9 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Wednesday, February 24, 2021 4:17 AM
To: Kim, Jonathan <[email protected]>; amd- [email protected]
Cc: Yang, Philip <[email protected]>; Kuehling, Felix <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: add ih call to process until checkpoint
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Am 23.02.21 um 22:10 schrieb Jonathan Kim:
Quoted 2 lines
Add IH function to allow caller to process ring entries until the checkpoint write pointer.
This needs a better description of what this will be used for.
Felix or Philip could elaborate better for HMM needs.
Debugging tools requires this but it's in experimental mode at the moment so probably not the best place to describe here.On the HMM side we're planning to use this to drain pending page fault interrupts before we unmap memory. That should address phantom VM faults after memory is unmapped.
Thought so. I suggest to use a wait_event() here which on the waiter side checks ih->lock and add a wake_up_all() at the end of amdgpu_ih_process. I won't touch rptr or wptr at all for this.
Regards,
Christian.
Quoted 114 lines
Regards,
FelixQuoted 109 lines
Quoted 55 lines
Quoted 5 lines
Suggested-by Felix Kuehling <[email protected]>Signed-off-by Jonathan Kim <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c| 46+++++++++++++++++++++++++-
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct
Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h| 2 ++2 files changed, 47 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +1
-1@@ -22,7 +22,7 @@*/ #include <linux/dma-mapping.h> - +#include <linux/processor.h> #include "amdgpu.h" #include "amdgpu_ih.h"@@ -160,6 +160,50 @@ void amdgpu_ih_ring_write(struct
amdgpu_ih_ring*ih, constuint32_t*iv,drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv,
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +8
-0} } +/** +* amdgpu_ih_wait_on_checkpoint_process - wait to process IVs up to +checkpoint +* +* @adev: amdgpu_device pointer +* @ih: ih ring to process +* +* Used to ensure ring has processed IVs up to the checkpoint write pointer.
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct · line 172
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +2
-0+*/ +int amdgpu_ih_wait_on_checkpoint_process(struct amdgpu_device*adev,
Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +15
-0+struct amdgpu_ih_ring *ih) +{ +u32 prev_rptr, cur_rptr, checkpoint_wptr; + +if (!ih->enabled || adev->shutdown) +return -ENODEV ; + +cur_rptr =READ_ONCE (ih->rptr); +/* Order read of current rptr with checktpoint wptr. */ +mb (); +checkpoint_wptr =amdgpu_ih_get_wptr (adev, ih); + +/* allow rptr to wrap around */ +if (cur_rptr > checkpoint_wptr) { +spin_begin ();Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, · line 192
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +6
-0+do { +spin_cpu_relax (); +prev_rptr = cur_rptr; +cur_rptr =READ_ONCE (ih->rptr); +}while (cur_rptr >= prev_rptr); +spin_end ();That's a certain NAK since it busy waits for IH processing. We need some event to trigger here.
The function is meant to be just a waiter up to the checkpoint.
There's a need to guarantee that "stale" interrupts have been processed on check before doing other stuff after call. The description could be improved to clarify that.Would busy waiting only on a locked ring help? I assume an unlocked ring means nothing to process so no need to wait and we can exit early. Or is it better to just to process the entries up to the checkpoint (maybe adjust
amdgpu_ih_processfor this need like adding a bool arg to skip restart or something)?Thanks,
Jon
Quoted 36 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, · line 201
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +9
-0+} + +/* wait for rptr to catch up to or pass checkpoint. */ +spin_begin (); +do { +spin_cpu_relax (); +prev_rptr = cur_rptr; +cur_rptr =READ_ONCE (ih->rptr); +}while (cur_rptr >= prev_rptr && cur_rptr < checkpoint_wptr);Same of course here.
Christian.
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h int amdgpu_ih_ring_init(struct amdgpu_device *adev,
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +5
-0+spin_end (); + +return 0 ; +} + /*** amdgpu_ih_process - interrupt handler *
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +0
-0@@ -87,6 +87,8 @@ int amdgpu_ih_ring_init(struct amdgpu_device *adev,struct
amdgpu_ih_ring*ih,Quoted 1 line
void amdgpu_ih_ring_fini(struct
amdgpu_device*adev, struct
amdgpu_ih_ring*ih);Quoted 3 lines
void
amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, unsigned int num_dw);
+int amdgpu_ih_wait_on_checkpoint_process(structamdgpu_device*adev,
Quoted 2 lines
+struct
amdgpu_ih_ring*ih);
int amdgpu_ih_process(structamdgpu_device*adev, struct
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
amdgpu_ih_ring*ih);Quoted 2 lines
void amdgpu_ih_decode_iv_helper(struct
amdgpu_device*adev, structamdgpu_ih_ring*ih,_______________________________________________
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
Am 2021-02-25 um 8:53 a.m. schrieb Christian König:
Quoted 24 lines
Am 25.02.21 um 04:15 schrieb Felix Kuehling:
Quoted 21 lines · Jonathan
Quoted 19 lines
[AMD Official Use Only - Internal Distribution Only]
Quoted 10 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Wednesday, February 24, 2021 4:17 AM
To: Kim, Jonathan <[email protected]>; amd- [email protected]
Cc: Yang, Philip <[email protected]>; Kuehling, Felix <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: add ih call to process until checkpointQuoted 4 lines
Am 23.02.21 um 22:10 schrieb Jonathan Kim:
Quoted 2 lines
Add IH function to allow caller to process ring entries until the checkpoint write pointer.
This needs a better description of what this will be used for.
Felix or Philip could elaborate better for HMM needs. Debugging tools requires this but it's in experimental mode at the moment so probably not the best place to describe here.
Quoted 7 lines
Quoted 3 lines
On the HMM side we're planning to use this to drain pending page fault interrupts before we unmap memory. That should address phantom VM faults after memory is unmapped.
Thought so. I suggest to use a
wait_event()here which on the waiter side checksih->lockand add awake_up_all()at the end ofamdgpu_ih_process.
Right. I thought about that and it should be easy to add. The reason to suggest busy waiting first is, that interrupt processing is supposed to be fast. The IRQ handler itself doesn't sleep. So I'd expect the wait time to be short enough that sleeping and scheduling is not worth it.
Quoted 1 line
I won't touch rptr or wptr at all for this.
Not sure what's your idea here, using ih->lock. Is it to completely drain all IRQs until the IH ring is completely empty? That can live-lock, if the GPU produces IRQs faster than the kernel can process them. Therefore I was looking at rptr and wptr to drain only IRQs that were already in the queue when the drain call was made. That also ensures that the wait time is bounded and should be short (unless the ring size is huge).
Regards,
Felix
Quoted 134 lines
Regards,
Christian.Quoted 129 lines
Regards,
FelixQuoted 75 lines
Quoted 56 lines
Quoted 5 lines
Suggested-by Felix Kuehling <[email protected]>Signed-off-by Jonathan Kim <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c| 46+++++++++++++++++++++++++-
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct
Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h| 2 ++2 files changed, 47 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +1
-1@@ -22,7 +22,7 @@*/ #include <linux/dma-mapping.h> - +#include <linux/processor.h> #include "amdgpu.h" #include "amdgpu_ih.h"@@ -160,6 +160,50 @@ void amdgpu_ih_ring_write(struct
amdgpu_ih_ring*ih, constuint32_t*iv,drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv,
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +8
-0} } +/** +* amdgpu_ih_wait_on_checkpoint_process - wait to process IVs up to +checkpoint +* +* @adev: amdgpu_device pointer +* @ih: ih ring to process +* +* Used to ensure ring has processed IVs up to the checkpoint write pointer.
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct · line 172
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +2
-0+*/ +int amdgpu_ih_wait_on_checkpoint_process(struct amdgpu_device*adev,
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +16
-0+struct amdgpu_ih_ring *ih) +{ +u32 prev_rptr, cur_rptr, checkpoint_wptr; + +if (!ih->enabled || adev->shutdown) +return -ENODEV ; + +cur_rptr =READ_ONCE (ih->rptr); +/* Order read of current rptr with checktpoint wptr. */ +mb (); +checkpoint_wptr =amdgpu_ih_get_wptr (adev, ih); + +/* allow rptr to wrap around */ +if (cur_rptr > checkpoint_wptr) { +spin_begin (); +do {Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, · line 192
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +5
-0+spin_cpu_relax (); +prev_rptr = cur_rptr; +cur_rptr =READ_ONCE (ih->rptr); +}while (cur_rptr >= prev_rptr); +spin_end ();That's a certain NAK since it busy waits for IH processing. We need some
event to trigger here.The function is meant to be just a waiter up to the checkpoint. There's a need to guarantee that "stale" interrupts have been processed on check before doing other stuff after call. The description could be improved to clarify that.
Would busy waiting only on a locked ring help? I assume an unlocked ring means nothing to process so no need to wait and we can exit early. Or is it better to just to process the entries up to the checkpoint (maybe adjust
amdgpu_ih_processfor this need like adding a bool arg to skip restart or something)?Quoted 44 lines
Thanks,
Jon
Quoted 40 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, · line 201
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +9
-0+} + +/* wait for rptr to catch up to or pass checkpoint. */ +spin_begin (); +do { +spin_cpu_relax (); +prev_rptr = cur_rptr; +cur_rptr =READ_ONCE (ih->rptr); +}while (cur_rptr >= prev_rptr && cur_rptr < checkpoint_wptr);Same of course here.
Christian.
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h int amdgpu_ih_ring_init(struct amdgpu_device *adev,
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +5
-0+spin_end (); + +return 0 ; +} + /*** amdgpu_ih_process - interrupt handler *
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +0
-0@@ -87,6 +87,8 @@ int amdgpu_ih_ring_init(struct amdgpu_device *adev,struct
amdgpu_ih_ring*ih,Quoted 1 line
void amdgpu_ih_ring_fini(struct
amdgpu_device*adev, struct
amdgpu_ih_ring*ih);Quoted 4 lines
void amdgpu_ih_ring_write(struct
amdgpu_ih_ring*ih, constuint32_t*iv,
unsigned intnum_dw);
+int amdgpu_ih_wait_on_checkpoint_process(structamdgpu_device*adev,
Quoted 2 lines
+struct
amdgpu_ih_ring*ih);
int amdgpu_ih_process(structamdgpu_device*adev, struct
amdgpu_ih_ring*ih);Quoted 2 lines
void amdgpu_ih_decode_iv_helper(struct
amdgpu_device*adev, structamdgpu_ih_ring*ih,_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=04%7C01%7Cfelix.kuehling%40amd.com%7C84d85e54bdcb4593e07f08d8d994be77%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637498580167313193%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=RvRHB9l4O%2BpbpogUFKUmnMGkqKnecwQCYRHrkxICDqU%3D&reserved=0
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Christian König
maintainerAm 25.02.21 um 16:35 schrieb Felix Kuehling:
Quoted 26 lines
Am 2021-02-25 um 8:53 a.m. schrieb Christian König:
Quoted 25 lines
Am 25.02.21 um 04:15 schrieb Felix Kuehling:
Quoted 23 lines · Jonathan
Quoted 12 lines
[AMD Official Use Only - Internal Distribution Only]
Quoted 10 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Wednesday, February 24, 2021 4:17 AM
To: Kim, Jonathan <[email protected]>; amd- [email protected]
Cc: Yang, Philip <[email protected]>; Kuehling, Felix <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: add ih call to process until checkpointQuoted 7 lines
Quoted 4 lines
Am 23.02.21 um 22:10 schrieb Jonathan Kim:
Quoted 2 lines
Add IH function to allow caller to process ring entries until the checkpoint write pointer.
This needs a better description of what this will be used for.
Felix or Philip could elaborate better for HMM needs. Debugging tools requires this but it's in experimental mode at the moment so probably not the best place to describe here.
On the HMM side we're planning to use this to drain pending page fault interrupts before we unmap memory. That should address phantom VM faults after memory is unmapped.
Quoted 7 lines
Quoted 3 lines
Thought so. I suggest to use a
wait_event()here which on the waiter side checksih->lockand add awake_up_all()at the end ofamdgpu_ih_process.Right. I thought about that and it should be easy to add. The reason to suggest busy waiting first is, that interrupt processing is supposed to be fast. The IRQ handler itself doesn't sleep. So I'd expect the wait time to be short enough that sleeping and scheduling is not worth it.
Well the page fault IRQs are processed in a work item, so we busy wait for another thread here and not interrupt context.
This in turn can lead to starvation of the work handler and so a life lock as well.
Quoted 5 lines
Quoted 3 lines
I won't touch rptr or wptr at all for this.
Not sure what's your idea here, using
ih->lock. Is it to completely drain all IRQs until the IH ring is completely empty?
Correct.
Quoted 6 lines
That can
live-lock, if the GPU produces IRQs faster than the kernel can process them. Therefore I was looking at rptr and wptr to drain only IRQs that were already in the queue when the drain call was made. That also ensures that the wait time is bounded and should be short (unless the ring size is huge).
Correct as well, but the problem here is that Jonathan's implementation is not even remotely correct.
See when you look at the rptr and wptr you can't be sure that they haven't wrapped around between two looks.
What you could do is look at both the rptr as well as the original wptr, but that is tricky.
Regards,
Christian.
Quoted 135 lines
Regards,
FelixQuoted 130 lines
Regards,
Christian.Quoted 127 lines
Regards,
FelixQuoted 74 lines
Quoted 55 lines
Quoted 4 lines
Suggested-by Felix Kuehling <[email protected]>Signed-off-by Jonathan Kim <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c | 46+++++++++++++++++++++++++-
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct
Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h| 2 ++2 files changed, 47 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +1
-1@@ -22,7 +22,7 @@*/ #include <linux/dma-mapping.h> - +#include <linux/processor.h> #include "amdgpu.h" #include "amdgpu_ih.h"@@ -160,6 +160,50 @@ void amdgpu_ih_ring_write(struct
amdgpu_ih_ring*ih, constuint32_t*iv,drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv,
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +8
-0} } +/** +* amdgpu_ih_wait_on_checkpoint_process - wait to process IVs up to +checkpoint +* +* @adev: amdgpu_device pointer +* @ih: ih ring to process +* +* Used to ensure ring has processed IVs up to the checkpoint write pointer.
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct · line 172
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +2
-0+*/ +int amdgpu_ih_wait_on_checkpoint_process(struct amdgpu_device*adev,
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +16
-0+struct amdgpu_ih_ring *ih) +{ +u32 prev_rptr, cur_rptr, checkpoint_wptr; + +if (!ih->enabled || adev->shutdown) +return -ENODEV ; + +cur_rptr =READ_ONCE (ih->rptr); +/* Order read of current rptr with checktpoint wptr. */ +mb (); +checkpoint_wptr =amdgpu_ih_get_wptr (adev, ih); + +/* allow rptr to wrap around */ +if (cur_rptr > checkpoint_wptr) { +spin_begin (); +do {Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, · line 192
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +5
-0+spin_cpu_relax (); +prev_rptr = cur_rptr; +cur_rptr =READ_ONCE (ih->rptr); +}while (cur_rptr >= prev_rptr); +spin_end ();That's a certain NAK since it busy waits for IH processing. We need some
event to trigger here.The function is meant to be just a waiter up to the checkpoint. There's a need to guarantee that "stale" interrupts have been processed on check before doing other stuff after call. The description could be improved to clarify that.
Would busy waiting only on a locked ring help? I assume an unlocked ring means nothing to process so no need to wait and we can exit early. Or is it better to just to process the entries up to the checkpoint (maybe adjust
amdgpu_ih_processfor this need like adding a bool arg to skip restart or something)?Quoted 44 lines
Thanks,
Jon
Quoted 40 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, const uint32_t *iv, · line 201
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +9
-0+} + +/* wait for rptr to catch up to or pass checkpoint. */ +spin_begin (); +do { +spin_cpu_relax (); +prev_rptr = cur_rptr; +cur_rptr =READ_ONCE (ih->rptr); +}while (cur_rptr >= prev_rptr && cur_rptr < checkpoint_wptr);Same of course here.
Christian.
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h int amdgpu_ih_ring_init(struct amdgpu_device *adev,
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +5
-0+spin_end (); + +return 0 ; +} + /*** amdgpu_ih_process - interrupt handler * drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +0
-0@@ -87,6 +87,8 @@ int amdgpu_ih_ring_init(struct amdgpu_device *adev,struct
amdgpu_ih_ring*ih,drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h int amdgpu_ih_ring_init(struct amdgpu_device *adev, · line 87
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +0
-0void amdgpu_ih_ring_fini(struct amdgpu_device *adev, struct
amdgpu_ih_ring*ih);drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h int amdgpu_ih_ring_init(struct amdgpu_device *adev, · line 91
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +1
-0void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, constuint32_t *iv, unsigned int num_dw); +int amdgpu_ih_wait_on_checkpoint_process(struct amdgpu_device*adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h int amdgpu_ih_ring_init(struct amdgpu_device *adev, · line 93
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +1
-0+struct amdgpu_ih_ring *ih); int amdgpu_ih_process(struct amdgpu_device *adev, struct
amdgpu_ih_ring*ih);Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +0
-0void amdgpu_ih_decode_iv_helper(struct amdgpu_device *adev,struct
amdgpu_ih_ring*ih,_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=04%7C01%7Cfelix.kuehling%40amd.com%7C84d85e54bdcb4593e07f08d8d994be77%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637498580167313193%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=RvRHB9l4O%2BpbpogUFKUmnMGkqKnecwQCYRHrkxICDqU%3D&reserved=0
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 2021-02-25 um 11:48 a.m. schrieb Christian König:
Quoted 32 lines
Am 25.02.21 um 16:35 schrieb Felix Kuehling:
Quoted 29 lines
Am 2021-02-25 um 8:53 a.m. schrieb Christian König:
Quoted 28 lines
Am 25.02.21 um 04:15 schrieb Felix Kuehling:
Quoted 16 lines · Jonathan
Quoted 15 lines
[AMD Official Use Only - Internal Distribution Only]
Quoted 13 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Wednesday, February 24, 2021 4:17 AM
To: Kim, Jonathan <[email protected]>; amd- [email protected]
Cc: Yang, Philip <[email protected]>; Kuehling, Felix <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: add ih call to process until checkpointAm 23.02.21 um 22:10 schrieb Jonathan Kim:
Quoted 2 lines
Add IH function to allow caller to process ring entries until the checkpoint write pointer.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
This needs a better description of what this will be used for.
Felix or Philip could elaborate better for HMM needs. Debugging tools requires this but it's in experimental mode at the moment so probably not the best place to describe here.
On the HMM side we're planning to use this to drain pending page fault interrupts before we unmap memory. That should address phantom VM faults after memory is unmapped.
Thought so. I suggest to use a
wait_event()here which on the waiter side checksih->lockand add awake_up_all()at the end ofamdgpu_ih_process.
Quoted 7 lines
Quoted 4 lines
Right. I thought about that and it should be easy to add. The reason to suggest busy waiting first is, that interrupt processing is supposed to be fast. The IRQ handler itself doesn't sleep. So I'd expect the wait time to be short enough that sleeping and scheduling is not worth it.
Well the page fault IRQs are processed in a work item, so we busy wait for another thread here and not interrupt context.
Good point.
Quoted 19 lines
This in turn can lead to starvation of the work handler and so a life lock as well.
Quoted 5 lines
Quoted 3 lines
I won't touch rptr or wptr at all for this.
Not sure what's your idea here, using
ih->lock. Is it to completely drain all IRQs until the IH ring is completely empty?Correct.
Quoted 6 lines
That can
live-lock, if the GPU produces IRQs faster than the kernel can process them. Therefore I was looking at rptr and wptr to drain only IRQs that were already in the queue when the drain call was made. That also ensures that the wait time is bounded and should be short (unless the ring size is huge).
Quoted 8 lines
Correct as well, but the problem here is that Jonathan's implementation is not even remotely correct.
See when you look at the rptr and wptr you can't be sure that they haven't wrapped around between two looks.
What you could do is look at both the rptr as well as the original wptr, but that is tricky.
The code in Jon's patch was suggested by me. I check for wrapping by comparing rptr with the rptr from the previous loop iteration. Comparing rptr with wptr you can never be sure whether rptr has already passed wptr, or whether rptr has to wrap first.
I could see a compromise where we sleep and wake up the waiting threads when
1. the IH ring is empty
2. the IH rptr wraps
That should be good enough to ensure a quick response in the common case (no interrupt storm), and a reasonable response in the interrupt storm case.
But then it's still not clear what's the correct condition for checking that the interrupts the caller cares about have been drained. Looking at just rptr and wptr is always ambiguous. Maybe we could use timestamps of the last processed interrupt? Those 48-bit time stamps wrap much less frequently. The idea is this:
* At the start get the timestamp of the last written IH ring entry (checkpoint)
* Wait until the last_processed IH timestamp passes the checkpoint:
sign_extend(last_processed - checkpoint) >= 0
Regards,
Felix
Quoted 144 lines
Regards,
Christian.Quoted 139 lines
Regards,
FelixQuoted 134 lines
Regards,
Christian.Quoted 131 lines
Regards,
FelixQuoted 76 lines
Quoted 57 lines
Quoted 4 lines
Suggested-by Felix Kuehling <[email protected]>Signed-off-by Jonathan Kim <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c| 46+++++++++++++++++++++++++-
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct
Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h| 2 ++2 files changed, 47 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +1
-1@@ -22,7 +22,7 @@*/ #include <linux/dma-mapping.h> - +#include <linux/processor.h> #include "amdgpu.h" #include "amdgpu_ih.h"@@ -160,6 +160,50 @@ void amdgpu_ih_ring_write(struct
amdgpu_ih_ring*ih, constuint32_t*iv,Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +2
-0} } +/** +* amdgpu_ih_wait_on_checkpoint_process - wait to process IVs Quoted 8 lines
up to
+checkpoint
+ *
+ * @adev:amdgpu_devicepointer
+ * @ih: ih ring to process
+ *
+ * Used to ensure ring has processed IVs up to the checkpoint writepointer.
Quoted 2 lines
+ */
+int amdgpu_ih_wait_on_checkpoint_process(structamdgpu_device*adev,
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +16
-0+struct amdgpu_ih_ring *ih) +{ +u32 prev_rptr, cur_rptr, checkpoint_wptr; + +if (!ih->enabled || adev->shutdown) +return -ENODEV ; + +cur_rptr =READ_ONCE (ih->rptr); +/* Order read of current rptr with checktpoint wptr. */ +mb (); +checkpoint_wptr =amdgpu_ih_get_wptr (adev, ih); + +/* allow rptr to wrap around */ +if (cur_rptr > checkpoint_wptr) { +spin_begin (); +do {Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +5
-0+spin_cpu_relax (); +prev_rptr = cur_rptr; +cur_rptr =READ_ONCE (ih->rptr); +}while (cur_rptr >= prev_rptr); +spin_end ();That's a certain NAK since it busy waits for IH processing. We need some
event to trigger here.The function is meant to be just a waiter up to the checkpoint. There's a need to guarantee that "stale" interrupts have been processed on check before doing other stuff after call. The description could be improved to clarify that.
Would busy waiting only on a locked ring help? I assume an unlocked ring means nothing to process so no need to wait and we can exit early. Or is it better to just to process the entries up to the checkpoint (maybe adjust
amdgpu_ih_processfor this need like adding a bool arg to skip restart or something)?Quoted 45 lines
Thanks,
Jon
Quoted 41 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +9
-0+} + +/* wait for rptr to catch up to or pass checkpoint. */ +spin_begin (); +do { +spin_cpu_relax (); +prev_rptr = cur_rptr; +cur_rptr =READ_ONCE (ih->rptr); +}while (cur_rptr >= prev_rptr && cur_rptr < checkpoint_wptr);Same of course here.
Christian.
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +5
-0+spin_end (); + +return 0 ; +} +/**
*amdgpu_ih_process- interrupt handler
*drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h int amdgpu_ih_ring_init(struct amdgpu_device · line 87
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +0
-0@@ -87,6 +87,8 @@ int amdgpu_ih_ring_init(struct amdgpu_device *adev,struct
amdgpu_ih_ring*ih,Quoted 1 line
void amdgpu_ih_ring_fini(struct
amdgpu_device*adev, struct
amdgpu_ih_ring*ih);Quoted 4 lines
void amdgpu_ih_ring_write(struct
amdgpu_ih_ring*ih, constuint32_t*iv,
unsigned intnum_dw);
+int amdgpu_ih_wait_on_checkpoint_process(structamdgpu_device*adev,
Quoted 2 lines
+struct
amdgpu_ih_ring*ih);
int amdgpu_ih_process(structamdgpu_device*adev, struct
amdgpu_ih_ring*ih);Quoted 2 lines
void amdgpu_ih_decode_iv_helper(struct
amdgpu_device*adev, structamdgpu_ih_ring*ih,_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=04%7C01%7Cfelix.kuehling%40amd.com%7C84d85e54bdcb4593e07f08d8d994be77%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637498580167313193%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=RvRHB9l4O%2BpbpogUFKUmnMGkqKnecwQCYRHrkxICDqU%3D&reserved=0
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Christian König
maintainerAm 25.02.21 um 19:33 schrieb Felix Kuehling:
Quoted 22 lines
[SNIP]
Quoted 21 lines
This in turn can lead to starvation of the work handler and so a life lock as well.
Quoted 4 lines
Quoted 2 lines
I won't touch rptr or wptr at all for this.
Not sure what's your idea here, using
ih->lock. Is it to completely drain all IRQs until the IH ring is completely empty?Correct.
Quoted 6 lines
That can
live-lock, if the GPU produces IRQs faster than the kernel can process them. Therefore I was looking at rptr and wptr to drain only IRQs that were already in the queue when the drain call was made. That also ensures that the wait time is bounded and should be short (unless the ring size is huge).Correct as well, but the problem here is that Jonathan's implementation is not even remotely correct.
See when you look at the rptr and wptr you can't be sure that they haven't wrapped around between two looks.
Quoted 6 lines
Quoted 2 lines
What you could do is look at both the rptr as well as the original wptr, but that is tricky.
The code in Jon's patch was suggested by me. I check for wrapping by comparing rptr with the rptr from the previous loop iteration. Comparing rptr with wptr you can never be sure whether rptr has already passed wptr, or whether rptr has to wrap first.
Exactly that's my concern as well.
Quoted 15 lines
I could see a compromise where we sleep and wake up the waiting threads when
1. the IH ring is empty
2. the IH rptr wrapsThat should be good enough to ensure a quick response in the common case (no interrupt storm), and a reasonable response in the interrupt storm case.
But then it's still not clear what's the correct condition for checking that the interrupts the caller cares about have been drained. Looking at just rptr and wptr is always ambiguous. Maybe we could use timestamps of the last processed interrupt? Those 48-bit time stamps wrap much less frequently. The idea is this:
Quoted 4 lines
* At the start get the timestamp of the last written IH ring entry (checkpoint)
* Wait until thelast_processedIH timestamp passes the checkpoint:
sign_extend(last_processed - checkpoint)>= 0
Yeah that could work. Alternatively we could just have a rptr wrap around counter.
This way you do something like this:
1. get the wrap around counter.
2. get wptr
3. get rptr
4. compare the wrap around counter with the old one, if it has changed start over with #1
5. Use wrap around counter and rptr/wptr to come up with 64bit values.
6. Compare wptr with rptr/wrap around counter until we are sure the IHs are processed.
Regards,
Christian.
Quoted 146 lines
Regards,
FelixQuoted 141 lines
Regards,
Christian.Quoted 138 lines
Regards,
FelixQuoted 134 lines
Regards,
Christian.Quoted 131 lines
Regards,
FelixQuoted 76 lines
Quoted 57 lines
Quoted 4 lines
Suggested-by Felix Kuehling <[email protected]>Signed-off-by Jonathan Kim <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c | 46+++++++++++++++++++++++++-
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c void amdgpu_ih_ring_write(struct
Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h| 2 ++2 files changed, 47 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +1
-1@@ -22,7 +22,7 @@*/ #include <linux/dma-mapping.h> - +#include <linux/processor.h> #include "amdgpu.h" #include "amdgpu_ih.h"@@ -160,6 +160,50 @@ void amdgpu_ih_ring_write(struct
amdgpu_ih_ring*ih, constuint32_t*iv,Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +2
-0} } +/** +* amdgpu_ih_wait_on_checkpoint_process - wait to process IVs Quoted 8 lines
up to
+checkpoint
+ *
+ * @adev:amdgpu_devicepointer
+ * @ih: ih ring to process
+ *
+ * Used to ensure ring has processed IVs up to the checkpoint writepointer.
Quoted 2 lines
+ */
+int amdgpu_ih_wait_on_checkpoint_process(structamdgpu_device*adev,
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +16
-0+struct amdgpu_ih_ring *ih) +{ +u32 prev_rptr, cur_rptr, checkpoint_wptr; + +if (!ih->enabled || adev->shutdown) +return -ENODEV ; + +cur_rptr =READ_ONCE (ih->rptr); +/* Order read of current rptr with checktpoint wptr. */ +mb (); +checkpoint_wptr =amdgpu_ih_get_wptr (adev, ih); + +/* allow rptr to wrap around */ +if (cur_rptr > checkpoint_wptr) { +spin_begin (); +do {Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +5
-0+spin_cpu_relax (); +prev_rptr = cur_rptr; +cur_rptr =READ_ONCE (ih->rptr); +}while (cur_rptr >= prev_rptr); +spin_end ();That's a certain NAK since it busy waits for IH processing. We need some
event to trigger here.The function is meant to be just a waiter up to the checkpoint. There's a need to guarantee that "stale" interrupts have been processed on check before doing other stuff after call. The description could be improved to clarify that.
Would busy waiting only on a locked ring help? I assume an unlocked ring means nothing to process so no need to wait and we can exit early. Or is it better to just to process the entries up to the checkpoint (maybe adjust
amdgpu_ih_processfor this need like adding a bool arg to skip restart or something)?Quoted 45 lines
Thanks,
Jon
Quoted 41 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +9
-0+} + +/* wait for rptr to catch up to or pass checkpoint. */ +spin_begin (); +do { +spin_cpu_relax (); +prev_rptr = cur_rptr; +cur_rptr =READ_ONCE (ih->rptr); +}while (cur_rptr >= prev_rptr && cur_rptr < checkpoint_wptr);Same of course here.
Christian.
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +5
-0+spin_end (); + +return 0 ; +} + /*** amdgpu_ih_process - interrupt handler * drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h int amdgpu_ih_ring_init(struct amdgpu_device · line 87
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +0
-0@@ -87,6 +87,8 @@ int amdgpu_ih_ring_init(struct amdgpu_device *adev,struct
amdgpu_ih_ring*ih,drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h int amdgpu_ih_ring_init(struct amdgpu_device · line 88
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +0
-0void amdgpu_ih_ring_fini(struct amdgpu_device *adev, struct
amdgpu_ih_ring*ih);drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h int amdgpu_ih_ring_init(struct amdgpu_device · line 92
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +1
-0void amdgpu_ih_ring_write(struct amdgpu_ih_ring *ih, constuint32_t *iv, unsigned int num_dw); +int amdgpu_ih_wait_on_checkpoint_process(struct amdgpu_device*adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h int amdgpu_ih_ring_init(struct amdgpu_device · line 94
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h +1
-0+struct amdgpu_ih_ring *ih); int amdgpu_ih_process(struct amdgpu_device *adev, struct
amdgpu_ih_ring*ih);Quoted 2 lines
void amdgpu_ih_decode_iv_helper(struct
amdgpu_device*adev, structamdgpu_ih_ring*ih,_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=04%7C01%7Cfelix.kuehling%40amd.com%7C84d85e54bdcb4593e07f08d8d994be77%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637498580167313193%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=RvRHB9l4O%2BpbpogUFKUmnMGkqKnecwQCYRHrkxICDqU%3D&reserved=0
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx