Skip to contentSkip to conversation

drm/amdgpu: reduce the full gpu access time in amdgpu_device_init.

PATCH New chong li 1 participant 1 message Nov 7, 2025

Subsystems (3)
lore
Share & tools
lore

chong li

author
#0 lore raw

PATCH 1/1 drm/amdgpu: reduce the full gpu access time in amdgpu_device_init.

[Why]
the function "pci_p2pdma_add_resource" in function "kfd_ais_init", cost too much time.

[How]
move the function "kfd_ais_init" out of gpu full access regions.

Change-Id I2db38d905d9dd7fedc4c6a38e325320268c2d84d
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c |  8 ++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 10 +++++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c  |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c    |  1 +
 drivers/gpu/drm/amd/amdkfd/kfd_device.c    |  3 ---
 6 files changed, 20 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +8 -0
index 39d712e3e692..e6829e5c8801 100644
@@ -37,6 +37,7 @@
 #include "amdgpu_umc.h"
 #include "amdgpu_reset.h"
 #include "amdgpu_ras_mgr.h"
+#include "kfd_priv.h"
 
 /* Total memory size in system memory and all GPU VRAM. Used to
  * estimate worst case amount of memory to reserve for page tables
@@ -234,6 +235,13 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)
 	}
 }
 
+void amdgpu_amdkfd_device_late_init(struct amdgpu_device *adev)
+{
+	kfd_ais_init(adev);
+	adev->kfd.dev->init_complete = true;
+	adev->kfd.init_complete = true;
+}
+
 void amdgpu_amdkfd_device_fini_sw(struct amdgpu_device *adev)
 {
 	if (adev->kfd.dev) {
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1 -0
index 40c46e6c8898..504cf90b84e6 100644
@@ -170,6 +170,7 @@ void amdgpu_amdkfd_interrupt(struct amdgpu_device *adev,
 			const void *ih_ring_entry);
 void amdgpu_amdkfd_device_probe(struct amdgpu_device *adev);
 void amdgpu_amdkfd_device_init(struct amdgpu_device *adev);
+void amdgpu_amdkfd_device_late_init(struct amdgpu_device *adev);
 void amdgpu_amdkfd_device_fini_sw(struct amdgpu_device *adev);
 int amdgpu_amdkfd_check_and_lock_kfd(struct amdgpu_device *adev);
 void amdgpu_amdkfd_unlock_kfd(struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +9 -1
index eca11fbc637a..6c8f0de84727 100644
@@ -4760,6 +4760,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 	 * completed before the need for a different level is detected.
 	 */
 	amdgpu_set_init_level(adev, AMDGPU_INIT_LEVEL_DEFAULT);
+
 	/* early init functions */
 	r = amdgpu_device_ip_early_init(adev);
 	if (r)
@@ -4971,6 +4972,11 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 		flush_delayed_work(&adev->delayed_init_work);
 	}
 
+	/* Don't init kfd if whole hive need to be reset during init */
+	if (adev->init_lvl->level != AMDGPU_INIT_LEVEL_MINIMAL_XGMI) {
+		amdgpu_amdkfd_device_late_init(adev);
+	}
+
 	if (adev->init_lvl->level == AMDGPU_INIT_LEVEL_MINIMAL_XGMI)
 		amdgpu_xgmi_reset_on_init(adev);
 	/*
@@ -6628,8 +6634,10 @@ static void amdgpu_device_gpu_resume(struct amdgpu_device *adev,
 		/* kfd_post_reset will do nothing if kfd device is not initialized,
 		 * need to bring up kfd here if it's not be initialized before
 		 */
-		if (!adev->kfd.init_complete)
+		if (!adev->kfd.init_complete) {
 			amdgpu_amdkfd_device_init(adev);
+			amdgpu_amdkfd_device_late_init(adev);
+		}
 
 		if (tmp_adev->pcie_reset_ctx.audio_suspended)
 			amdgpu_device_resume_display_audio(tmp_adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c +1 -0
index 4c50530e7c32..423ff3c8502b 100644
@@ -89,6 +89,7 @@ static int amdgpu_reset_xgmi_reset_on_init_restore_hwctxt(
 		if (!tmp_adev->kfd.init_complete) {
 			kgd2kfd_init_zone_device(tmp_adev);
 			amdgpu_amdkfd_device_init(tmp_adev);
+			amdgpu_amdkfd_device_late_init(tmp_adev);
 			amdgpu_amdkfd_drm_client_create(tmp_adev);
 		}
 	}
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +1 -0
index 6b375665507d..65c3136413f2 100644
@@ -686,6 +686,7 @@ int amdgpu_xcp_post_partition_switch(struct amdgpu_xcp_mgr *xcp_mgr, u32 flags)
 	if (flags & AMDGPU_XCP_OPS_KFD) {
 		amdgpu_amdkfd_device_probe(xcp_mgr->adev);
 		amdgpu_amdkfd_device_init(xcp_mgr->adev);
+		amdgpu_amdkfd_device_late_init(xcp_mgr->adev);
 		/* If KFD init failed, return failure */
 		if (!xcp_mgr->adev->kfd.init_complete)
 			ret = -EIO;
drivers/gpu/drm/amd/amdkfd/kfd_device.c +0 -3
index 784c28fbadda..a4a91244cbc6 100644
@@ -935,9 +935,6 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd,
 
 	svm_range_set_max_pages(kfd->adev);
 
-	kfd_ais_init(kfd->adev);
-
-	kfd->init_complete = true;
 	dev_info(kfd_device, "added device %x:%x\n", kfd->adev->pdev->vendor,
 		 kfd->adev->pdev->device);
 
Signature · 1 line
2.48.1