AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] amd/amdkfd: sync all devices to wait all processes being evicted
@ 2024-04-01 21:53 Zhigang Luo
  2024-04-01 21:53 ` [PATCH 2/2] amd/amdgpu: improve VF recover time Zhigang Luo
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Zhigang Luo @ 2024-04-01 21:53 UTC (permalink / raw)
  To: amd-gfx
  Cc: Hawking.Zhang, Sashank.Saye, Jeffrey.Chan, philip.yang,
	lijo.lazar, felix.kuehling, Zhigang Luo

If there are more than one device doing reset in parallel, the first
device will call kfd_suspend_all_processes() to evict all processes
on all devices, this call takes time to finish. other device will
start reset and recover without waiting. if the process has not been
evicted before doing recover, it will be restored, then caused page
fault.

Signed-off-by: Zhigang Luo <Zhigang.Luo@amd.com>
Change-Id: Ib1eddb56b69ecd41fe703abd169944154f48b0cd
---
 drivers/gpu/drm/amd/amdkfd/kfd_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
index 041ec3de55e7..55f89c858c7a 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
@@ -969,11 +969,11 @@ void kgd2kfd_suspend(struct kfd_dev *kfd, bool run_pm)
 	if (!run_pm) {
 		mutex_lock(&kfd_processes_mutex);
 		count = ++kfd_locked;
-		mutex_unlock(&kfd_processes_mutex);
 
 		/* For first KFD device suspend all the KFD processes */
 		if (count == 1)
 			kfd_suspend_all_processes();
+		mutex_unlock(&kfd_processes_mutex);
 	}
 
 	for (i = 0; i < kfd->num_nodes; i++) {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] amd/amdgpu: improve VF recover time
  2024-04-01 21:53 [PATCH 1/2] amd/amdkfd: sync all devices to wait all processes being evicted Zhigang Luo
@ 2024-04-01 21:53 ` Zhigang Luo
  2024-04-02 22:32 ` [PATCH 1/2] amd/amdkfd: sync all devices to wait all processes being evicted Felix Kuehling
  2024-04-03  1:31 ` Chen, Xiaogang
  2 siblings, 0 replies; 7+ messages in thread
From: Zhigang Luo @ 2024-04-01 21:53 UTC (permalink / raw)
  To: amd-gfx
  Cc: Hawking.Zhang, Sashank.Saye, Jeffrey.Chan, philip.yang,
	lijo.lazar, felix.kuehling, Zhigang Luo

1. change AMDGPU_VF2PF_UPDATE_MAX_RETRY_LIMIT from 30 to 5.
2. set fatel error detected flag.

Change-Id: If1e0357deffa4549d4e83e925c8d764f7f8c9f42
Signed-off-by: Zhigang Luo <Zhigang.Luo@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h   | 2 +-
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 70261eb9b0bb..5e88f6f6a481 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -4982,6 +4982,7 @@ static int amdgpu_device_reset_sriov(struct amdgpu_device *adev,
 		r = amdgpu_virt_reset_gpu(adev);
 	if (r)
 		return r;
+	amdgpu_ras_set_fed(adev, false);
 	amdgpu_irq_gpu_reset_resume_helper(adev);
 
 	/* some sw clean up VF needs to do before recover */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
index aed60aaf1a55..4b6e50cfba08 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
@@ -593,6 +593,7 @@ static void amdgpu_virt_update_vf2pf_work_item(struct work_struct *work)
 		adev->virt.vf2pf_update_retry_cnt++;
 		if ((adev->virt.vf2pf_update_retry_cnt >= AMDGPU_VF2PF_UPDATE_MAX_RETRY_LIMIT) &&
 		    amdgpu_sriov_runtime(adev) && !amdgpu_in_reset(adev)) {
+			amdgpu_ras_set_fed(adev, true);
 			if (amdgpu_reset_domain_schedule(adev->reset_domain,
 							  &adev->virt.flr_work))
 				return;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h
index a858bc98cad4..0a57b637c4bd 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h
@@ -52,7 +52,7 @@
 /* tonga/fiji use this offset */
 #define mmBIF_IOV_FUNC_IDENTIFIER 0x1503
 
-#define AMDGPU_VF2PF_UPDATE_MAX_RETRY_LIMIT 30
+#define AMDGPU_VF2PF_UPDATE_MAX_RETRY_LIMIT 5
 
 enum amdgpu_sriov_vf_mode {
 	SRIOV_VF_MODE_BARE_METAL = 0,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] amd/amdkfd: sync all devices to wait all processes being evicted
  2024-04-01 21:53 [PATCH 1/2] amd/amdkfd: sync all devices to wait all processes being evicted Zhigang Luo
  2024-04-01 21:53 ` [PATCH 2/2] amd/amdgpu: improve VF recover time Zhigang Luo
@ 2024-04-02 22:32 ` Felix Kuehling
  2024-04-03  1:31 ` Chen, Xiaogang
  2 siblings, 0 replies; 7+ messages in thread
From: Felix Kuehling @ 2024-04-02 22:32 UTC (permalink / raw)
  To: Zhigang Luo, amd-gfx
  Cc: Hawking.Zhang, Sashank.Saye, Jeffrey.Chan, philip.yang,
	lijo.lazar

[-- Attachment #1: Type: text/plain, Size: 1868 bytes --]

On 2024-04-01 17:53, Zhigang Luo wrote:
> If there are more than one device doing reset in parallel, the first
> device will call kfd_suspend_all_processes() to evict all processes
> on all devices, this call takes time to finish. other device will
> start reset and recover without waiting. if the process has not been
> evicted before doing recover, it will be restored, then caused page
> fault.
>
> Signed-off-by: Zhigang Luo<Zhigang.Luo@amd.com>
> Change-Id: Ib1eddb56b69ecd41fe703abd169944154f48b0cd

Please remove the Change-Id: before you push. Other than that, this patch is


> ---
>   drivers/gpu/drm/amd/amdkfd/kfd_device.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
> index 041ec3de55e7..55f89c858c7a 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
> @@ -969,11 +969,11 @@ void kgd2kfd_suspend(struct kfd_dev *kfd, bool run_pm)
>   	if (!run_pm) {
>   		mutex_lock(&kfd_processes_mutex);
>   		count = ++kfd_locked;
> -		mutex_unlock(&kfd_processes_mutex);
>   
>   		/* For first KFD device suspend all the KFD processes */
>   		if (count == 1)
>   			kfd_suspend_all_processes();

This could be simplified now. The variable "count" was only needed for 
the broken attempt to do call suspend outside the lock. Now you can just do:

	mutex_lock(&kfd_processes_mutex);
	if (++kfd_locked == 1)
		kfd_suspend_all_processes();
	mutex_unlock(&kfd_processes_mutex);

To be consistent, we probably need to make a similar change in 
kgd2kfd_resume and run kfd_resume_all_processes under the lock as well. 
Otherwise there could be a race condition between suspend and resume.

Regards,
   Felix


> +		mutex_unlock(&kfd_processes_mutex);
>   	}
>   
>   	for (i = 0; i < kfd->num_nodes; i++) {

[-- Attachment #2: Type: text/html, Size: 2677 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] amd/amdkfd: sync all devices to wait all processes being evicted
  2024-04-01 21:53 [PATCH 1/2] amd/amdkfd: sync all devices to wait all processes being evicted Zhigang Luo
  2024-04-01 21:53 ` [PATCH 2/2] amd/amdgpu: improve VF recover time Zhigang Luo
  2024-04-02 22:32 ` [PATCH 1/2] amd/amdkfd: sync all devices to wait all processes being evicted Felix Kuehling
@ 2024-04-03  1:31 ` Chen, Xiaogang
  2 siblings, 0 replies; 7+ messages in thread
From: Chen, Xiaogang @ 2024-04-03  1:31 UTC (permalink / raw)
  To: Zhigang Luo, amd-gfx
  Cc: Hawking.Zhang, Sashank.Saye, Jeffrey.Chan, philip.yang,
	lijo.lazar, felix.kuehling


On 4/1/2024 4:53 PM, Zhigang Luo wrote:
> Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
>
>
> If there are more than one device doing reset in parallel, the first
> device will call kfd_suspend_all_processes() to evict all processes
> on all devices, this call takes time to finish. other device will
> start reset and recover without waiting. if the process has not been
> evicted before doing recover, it will be restored, then caused page
> fault.
>
> Signed-off-by: Zhigang Luo <Zhigang.Luo@amd.com>
> Change-Id: Ib1eddb56b69ecd41fe703abd169944154f48b0cd
> ---
>   drivers/gpu/drm/amd/amdkfd/kfd_device.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
> index 041ec3de55e7..55f89c858c7a 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
> @@ -969,11 +969,11 @@ void kgd2kfd_suspend(struct kfd_dev *kfd, bool run_pm)
>          if (!run_pm) {
>                  mutex_lock(&kfd_processes_mutex);
>                  count = ++kfd_locked;
> -               mutex_unlock(&kfd_processes_mutex);
>
>                  /* For first KFD device suspend all the KFD processes */
>                  if (count == 1)
>                          kfd_suspend_all_processes();
> +               mutex_unlock(&kfd_processes_mutex);
>          }

I do not understand why use kfd_lock here. You want evict all processes 
when first device got suspended. The kfd_lock indicates if all kfd 
driver functions got locked. It is not same meaning as device suspend. 
That is not your patch issue, but I think using different flag to record 
device suspend is better. ex, if kfd_lock got set for some other 
reasons, we would skip evicting processes here.

Regards

Xiaogang

>          for (i = 0; i < kfd->num_nodes; i++) {
> --
> 2.25.1
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] amd/amdkfd: sync all devices to wait all processes being evicted
@ 2024-04-03 14:36 Zhigang Luo
  0 siblings, 0 replies; 7+ messages in thread
From: Zhigang Luo @ 2024-04-03 14:36 UTC (permalink / raw)
  To: amd-gfx
  Cc: Hawking.Zhang, Sashank.Saye, Jeffrey.Chan, philip.yang,
	lijo.lazar, felix.kuehling, Zhigang Luo

If there are more than one device doing reset in parallel, the first
device will call kfd_suspend_all_processes() to evict all processes
on all devices, this call takes time to finish. other device will
start reset and recover without waiting. if the process has not been
evicted before doing recover, it will be restored, then caused page
fault.

Signed-off-by: Zhigang Luo <Zhigang.Luo@amd.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_device.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
index 041ec3de55e7..cc9ac32182a6 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
@@ -960,7 +960,6 @@ void kgd2kfd_suspend(struct kfd_dev *kfd, bool run_pm)
 {
 	struct kfd_node *node;
 	int i;
-	int count;
 
 	if (!kfd->init_complete)
 		return;
@@ -968,12 +967,10 @@ void kgd2kfd_suspend(struct kfd_dev *kfd, bool run_pm)
 	/* for runtime suspend, skip locking kfd */
 	if (!run_pm) {
 		mutex_lock(&kfd_processes_mutex);
-		count = ++kfd_locked;
-		mutex_unlock(&kfd_processes_mutex);
-
 		/* For first KFD device suspend all the KFD processes */
-		if (count == 1)
+		if (++kfd_locked == 1)
 			kfd_suspend_all_processes();
+		mutex_unlock(&kfd_processes_mutex);
 	}
 
 	for (i = 0; i < kfd->num_nodes; i++) {
@@ -984,7 +981,7 @@ void kgd2kfd_suspend(struct kfd_dev *kfd, bool run_pm)
 
 int kgd2kfd_resume(struct kfd_dev *kfd, bool run_pm)
 {
-	int ret, count, i;
+	int ret, i;
 
 	if (!kfd->init_complete)
 		return 0;
@@ -998,12 +995,10 @@ int kgd2kfd_resume(struct kfd_dev *kfd, bool run_pm)
 	/* for runtime resume, skip unlocking kfd */
 	if (!run_pm) {
 		mutex_lock(&kfd_processes_mutex);
-		count = --kfd_locked;
-		mutex_unlock(&kfd_processes_mutex);
-
 		WARN_ONCE(count < 0, "KFD suspend / resume ref. error");
-		if (count == 0)
+		if (--kfd_locked == 0)
 			ret = kfd_resume_all_processes();
+		mutex_unlock(&kfd_processes_mutex);
 	}
 
 	return ret;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 1/2] amd/amdkfd: sync all devices to wait all processes being evicted
@ 2024-04-03 18:12 Zhigang Luo
  2024-04-03 19:49 ` Felix Kuehling
  0 siblings, 1 reply; 7+ messages in thread
From: Zhigang Luo @ 2024-04-03 18:12 UTC (permalink / raw)
  To: amd-gfx
  Cc: Hawking.Zhang, Sashank.Saye, Jeffrey.Chan, philip.yang,
	lijo.lazar, felix.kuehling, Zhigang Luo

If there are more than one device doing reset in parallel, the first
device will call kfd_suspend_all_processes() to evict all processes
on all devices, this call takes time to finish. other device will
start reset and recover without waiting. if the process has not been
evicted before doing recover, it will be restored, then caused page
fault.

Signed-off-by: Zhigang Luo <Zhigang.Luo@amd.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_device.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
index 041ec3de55e7..719d6d365e15 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
@@ -960,7 +960,6 @@ void kgd2kfd_suspend(struct kfd_dev *kfd, bool run_pm)
 {
 	struct kfd_node *node;
 	int i;
-	int count;
 
 	if (!kfd->init_complete)
 		return;
@@ -968,12 +967,10 @@ void kgd2kfd_suspend(struct kfd_dev *kfd, bool run_pm)
 	/* for runtime suspend, skip locking kfd */
 	if (!run_pm) {
 		mutex_lock(&kfd_processes_mutex);
-		count = ++kfd_locked;
-		mutex_unlock(&kfd_processes_mutex);
-
 		/* For first KFD device suspend all the KFD processes */
-		if (count == 1)
+		if (++kfd_locked == 1)
 			kfd_suspend_all_processes();
+		mutex_unlock(&kfd_processes_mutex);
 	}
 
 	for (i = 0; i < kfd->num_nodes; i++) {
@@ -984,7 +981,7 @@ void kgd2kfd_suspend(struct kfd_dev *kfd, bool run_pm)
 
 int kgd2kfd_resume(struct kfd_dev *kfd, bool run_pm)
 {
-	int ret, count, i;
+	int ret, i;
 
 	if (!kfd->init_complete)
 		return 0;
@@ -998,12 +995,10 @@ int kgd2kfd_resume(struct kfd_dev *kfd, bool run_pm)
 	/* for runtime resume, skip unlocking kfd */
 	if (!run_pm) {
 		mutex_lock(&kfd_processes_mutex);
-		count = --kfd_locked;
-		mutex_unlock(&kfd_processes_mutex);
-
-		WARN_ONCE(count < 0, "KFD suspend / resume ref. error");
-		if (count == 0)
+		if (--kfd_locked == 0)
 			ret = kfd_resume_all_processes();
+		WARN_ONCE(kfd_locked < 0, "KFD suspend / resume ref. error");
+		mutex_unlock(&kfd_processes_mutex);
 	}
 
 	return ret;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] amd/amdkfd: sync all devices to wait all processes being evicted
  2024-04-03 18:12 Zhigang Luo
@ 2024-04-03 19:49 ` Felix Kuehling
  0 siblings, 0 replies; 7+ messages in thread
From: Felix Kuehling @ 2024-04-03 19:49 UTC (permalink / raw)
  To: Zhigang Luo, amd-gfx
  Cc: Hawking.Zhang, Sashank.Saye, Jeffrey.Chan, philip.yang,
	lijo.lazar


On 2024-04-03 14:12, Zhigang Luo wrote:
> If there are more than one device doing reset in parallel, the first
> device will call kfd_suspend_all_processes() to evict all processes
> on all devices, this call takes time to finish. other device will
> start reset and recover without waiting. if the process has not been
> evicted before doing recover, it will be restored, then caused page
> fault.
>
> Signed-off-by: Zhigang Luo <Zhigang.Luo@amd.com>

This patch is

Reviewed-by: Felix Kuehling <felix.kuehling@amd.com>


> ---
>   drivers/gpu/drm/amd/amdkfd/kfd_device.c | 17 ++++++-----------
>   1 file changed, 6 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
> index 041ec3de55e7..719d6d365e15 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
> @@ -960,7 +960,6 @@ void kgd2kfd_suspend(struct kfd_dev *kfd, bool run_pm)
>   {
>   	struct kfd_node *node;
>   	int i;
> -	int count;
>   
>   	if (!kfd->init_complete)
>   		return;
> @@ -968,12 +967,10 @@ void kgd2kfd_suspend(struct kfd_dev *kfd, bool run_pm)
>   	/* for runtime suspend, skip locking kfd */
>   	if (!run_pm) {
>   		mutex_lock(&kfd_processes_mutex);
> -		count = ++kfd_locked;
> -		mutex_unlock(&kfd_processes_mutex);
> -
>   		/* For first KFD device suspend all the KFD processes */
> -		if (count == 1)
> +		if (++kfd_locked == 1)
>   			kfd_suspend_all_processes();
> +		mutex_unlock(&kfd_processes_mutex);
>   	}
>   
>   	for (i = 0; i < kfd->num_nodes; i++) {
> @@ -984,7 +981,7 @@ void kgd2kfd_suspend(struct kfd_dev *kfd, bool run_pm)
>   
>   int kgd2kfd_resume(struct kfd_dev *kfd, bool run_pm)
>   {
> -	int ret, count, i;
> +	int ret, i;
>   
>   	if (!kfd->init_complete)
>   		return 0;
> @@ -998,12 +995,10 @@ int kgd2kfd_resume(struct kfd_dev *kfd, bool run_pm)
>   	/* for runtime resume, skip unlocking kfd */
>   	if (!run_pm) {
>   		mutex_lock(&kfd_processes_mutex);
> -		count = --kfd_locked;
> -		mutex_unlock(&kfd_processes_mutex);
> -
> -		WARN_ONCE(count < 0, "KFD suspend / resume ref. error");
> -		if (count == 0)
> +		if (--kfd_locked == 0)
>   			ret = kfd_resume_all_processes();
> +		WARN_ONCE(kfd_locked < 0, "KFD suspend / resume ref. error");
> +		mutex_unlock(&kfd_processes_mutex);
>   	}
>   
>   	return ret;

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-04-03 19:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-01 21:53 [PATCH 1/2] amd/amdkfd: sync all devices to wait all processes being evicted Zhigang Luo
2024-04-01 21:53 ` [PATCH 2/2] amd/amdgpu: improve VF recover time Zhigang Luo
2024-04-02 22:32 ` [PATCH 1/2] amd/amdkfd: sync all devices to wait all processes being evicted Felix Kuehling
2024-04-03  1:31 ` Chen, Xiaogang
  -- strict thread matches above, loose matches on Subject: below --
2024-04-03 14:36 Zhigang Luo
2024-04-03 18:12 Zhigang Luo
2024-04-03 19:49 ` Felix Kuehling

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox