Skip to contentSkip to conversation

drm/amdgpu: fix reload KMD hang on KIQ

PATCH In review Monk Liu 4 participants 8 messages Jul 31, 2020 – Oct 15, 2020

Subsystems (2)
lore
Share & tools
lore

Monk Liu

author
#0 lore raw

PATCH 1/2 drm/amdgpu: fix reload KMD hang on KIQ

KIQ will hang if we try below steps:
modprobe amdgpu
rmmod amdgpu
modprobe amdgpu sched_hw_submission=4

the cause is that due to KIQ is always living there even after we unload KMD thus when doing the realod of KMD KIQ will crash upon its register programed with different values with the previous configuration (the config like HQD addr, ring size, is easily changed if we alter the sched_hw_submission)

the fix is we must inactive KIQ first before touching any of its registgers

---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +3 -0
index db9f1e8..f571e25 100644
@@ -6433,6 +6433,9 @@ static int gfx_v10_0_kiq_init_register(struct amdgpu_ring *ring)
 	struct v10_compute_mqd *mqd = ring->mqd_ptr;
 	int j;
 
+	/* activate the queue */
+	WREG32_SOC15(GC, 0, mmCP_HQD_ACTIVE, 0);
+
 	/* disable wptr polling */
 	WREG32_FIELD15(GC, 0, CP_PQ_WPTR_POLL_CNTL, EN, 0);
 
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#1 lore raw

PATCH 2/2 drm/amdgpu: introduce a new parameter to configure how many KCQ we want(v5)

what:
the MQD's save and restore of KCQ (kernel compute queue) cost lots of clocks during world switch which impacts a lot to multi-VF performance

how:
introduce a paramter to control the number of KCQ to avoid performance drop if there is no kernel compute queue needed

notes:
this paramter only affects gfx 8/9/10

v2:
refine namings

v3:
choose queues for each ring to that try best to cross pipes evenly.

v4:
fix indentation
some cleanupsin the gfx_compute_queue_acquire()

v5:
further fix on indentations
more cleanupsin gfx_compute_queue_acquire()

TODO:
in the future we will let hypervisor driver to set this paramter automatically thus no need for user to configure it through modprobe in virtual machine

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  5 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    |  4 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c    | 49 ++++++++++++------------------
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c     | 30 +++++++++---------
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c      | 29 +++++++++---------
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c      | 31 ++++++++++---------
 7 files changed, 76 insertions(+), 73 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index e97c088..de11136 100644
@@ -201,6 +201,7 @@ extern int amdgpu_si_support;
 #ifdef CONFIG_DRM_AMDGPU_CIK
 extern int amdgpu_cik_support;
 #endif
+extern int amdgpu_num_kcq;
 
 #define AMDGPU_VM_MAX_NUM_CTX			4096
 #define AMDGPU_SG_THRESHOLD			(256*1024*1024)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5 -0
index 62ecac9..cf445bab 100644
@@ -1199,6 +1199,11 @@ static int amdgpu_device_check_arguments(struct amdgpu_device *adev)
 
 	amdgpu_gmc_tmz_set(adev);
 
+	if (amdgpu_num_kcq > 8 || amdgpu_num_kcq < 0) {
+		amdgpu_num_kcq = 8;
+		dev_warn(adev->dev, "set kernel compute queue number to 8 due to invalid paramter provided by user\n");
+	}
+
 	return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4 -0
index 6291f5f..b545c40 100644
@@ -150,6 +150,7 @@ int amdgpu_noretry;
 int amdgpu_force_asic_type = -1;
 int amdgpu_tmz = 0;
 int amdgpu_reset_method = -1; /* auto */
+int amdgpu_num_kcq = -1;
 
 struct amdgpu_mgpu_info mgpu_info = {
 	.mutex = __MUTEX_INITIALIZER(mgpu_info.mutex),
@@ -765,6 +766,9 @@ module_param_named(tmz, amdgpu_tmz, int, 0444);
 MODULE_PARM_DESC(reset_method, "GPU reset method (-1 = auto (default), 0 = legacy, 1 = mode0, 2 = mode1, 3 = mode2, 4 = baco)");
 module_param_named(reset_method, amdgpu_reset_method, int, 0444);
 
+MODULE_PARM_DESC(num_kcq, "number of kernel compute queue user want to setup (8 if set to greater than 8 or less than 0, only affect gfx 8+)");
+module_param_named(num_kcq, amdgpu_num_kcq, int, 0444);
+
 static const struct pci_device_id pciidlist[] = {
 #ifdef  CONFIG_DRM_AMDGPU_SI
 	{0x1002, 0x6780, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +19 -30

59 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +16 -14
index f571e25..4172bc8 100644
@@ -4022,21 +4022,23 @@ static int gfx_v10_0_mec_init(struct amdgpu_device *adev)
 	amdgpu_gfx_compute_queue_acquire(adev);
 	mec_hpd_size = adev->gfx.num_compute_rings * GFX10_MEC_HPD_SIZE;
 
-	r = amdgpu_bo_create_reserved(adev, mec_hpd_size, PAGE_SIZE,
-				      AMDGPU_GEM_DOMAIN_GTT,
-				      &adev->gfx.mec.hpd_eop_obj,
-				      &adev->gfx.mec.hpd_eop_gpu_addr,
-				      (void **)&hpd);
-	if (r) {
-		dev_warn(adev->dev, "(%d) create HDP EOP bo failed\n", r);
-		gfx_v10_0_mec_fini(adev);
-		return r;
-	}
+	if (mec_hpd_size) {
+		r = amdgpu_bo_create_reserved(adev, mec_hpd_size, PAGE_SIZE,
+					      AMDGPU_GEM_DOMAIN_GTT,
+					      &adev->gfx.mec.hpd_eop_obj,
+					      &adev->gfx.mec.hpd_eop_gpu_addr,
+					      (void **)&hpd);
+		if (r) {
+			dev_warn(adev->dev, "(%d) create HDP EOP bo failed\n", r);
+			gfx_v10_0_mec_fini(adev);
+			return r;
+		}
 
-	memset(hpd, 0, mec_hpd_size);
+		memset(hpd, 0, mec_hpd_size);
 
-	amdgpu_bo_kunmap(adev->gfx.mec.hpd_eop_obj);
-	amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
+		amdgpu_bo_kunmap(adev->gfx.mec.hpd_eop_obj);
+		amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
+	}
 
 	if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT) {
 		mec_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.mec_fw->data;
@@ -7162,7 +7164,7 @@ static int gfx_v10_0_early_init(void *handle)
 		break;
 	}
 
-	adev->gfx.num_compute_rings = AMDGPU_MAX_COMPUTE_RINGS;
+	adev->gfx.num_compute_rings = amdgpu_num_kcq;
 
 	gfx_v10_0_set_kiq_pm4_funcs(adev);
 	gfx_v10_0_set_ring_funcs(adev);
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +15 -14
index 8d72089..7df567a 100644
@@ -1343,21 +1343,22 @@ static int gfx_v8_0_mec_init(struct amdgpu_device *adev)
 	amdgpu_gfx_compute_queue_acquire(adev);
 
 	mec_hpd_size = adev->gfx.num_compute_rings * GFX8_MEC_HPD_SIZE;
+	if (mec_hpd_size) {
+		r = amdgpu_bo_create_reserved(adev, mec_hpd_size, PAGE_SIZE,
+					      AMDGPU_GEM_DOMAIN_VRAM,
+					      &adev->gfx.mec.hpd_eop_obj,
+					      &adev->gfx.mec.hpd_eop_gpu_addr,
+					      (void **)&hpd);
+		if (r) {
+			dev_warn(adev->dev, "(%d) create HDP EOP bo failed\n", r);
+			return r;
+		}
 
-	r = amdgpu_bo_create_reserved(adev, mec_hpd_size, PAGE_SIZE,
-				      AMDGPU_GEM_DOMAIN_VRAM,
-				      &adev->gfx.mec.hpd_eop_obj,
-				      &adev->gfx.mec.hpd_eop_gpu_addr,
-				      (void **)&hpd);
-	if (r) {
-		dev_warn(adev->dev, "(%d) create HDP EOP bo failed\n", r);
-		return r;
-	}
-
-	memset(hpd, 0, mec_hpd_size);
+		memset(hpd, 0, mec_hpd_size);
 
-	amdgpu_bo_kunmap(adev->gfx.mec.hpd_eop_obj);
-	amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
+		amdgpu_bo_kunmap(adev->gfx.mec.hpd_eop_obj);
+		amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
+	}
 
 	return 0;
 }
@@ -5294,7 +5295,7 @@ static int gfx_v8_0_early_init(void *handle)
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
 	adev->gfx.num_gfx_rings = GFX8_NUM_GFX_RINGS;
-	adev->gfx.num_compute_rings = AMDGPU_MAX_COMPUTE_RINGS;
+	adev->gfx.num_compute_rings = amdgpu_num_kcq;
 	adev->gfx.funcs = &gfx_v8_0_gfx_funcs;
 	gfx_v8_0_set_ring_funcs(adev);
 	gfx_v8_0_set_irq_funcs(adev);
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +16 -15
index e4e751f..ef07e59 100644
@@ -1938,22 +1938,23 @@ static int gfx_v9_0_mec_init(struct amdgpu_device *adev)
 	/* take ownership of the relevant compute queues */
 	amdgpu_gfx_compute_queue_acquire(adev);
 	mec_hpd_size = adev->gfx.num_compute_rings * GFX9_MEC_HPD_SIZE;
+	if (mec_hpd_size) {
+		r = amdgpu_bo_create_reserved(adev, mec_hpd_size, PAGE_SIZE,
+					      AMDGPU_GEM_DOMAIN_VRAM,
+					      &adev->gfx.mec.hpd_eop_obj,
+					      &adev->gfx.mec.hpd_eop_gpu_addr,
+					      (void **)&hpd);
+		if (r) {
+			dev_warn(adev->dev, "(%d) create HDP EOP bo failed\n", r);
+			gfx_v9_0_mec_fini(adev);
+			return r;
+		}
 
-	r = amdgpu_bo_create_reserved(adev, mec_hpd_size, PAGE_SIZE,
-				      AMDGPU_GEM_DOMAIN_VRAM,
-				      &adev->gfx.mec.hpd_eop_obj,
-				      &adev->gfx.mec.hpd_eop_gpu_addr,
-				      (void **)&hpd);
-	if (r) {
-		dev_warn(adev->dev, "(%d) create HDP EOP bo failed\n", r);
-		gfx_v9_0_mec_fini(adev);
-		return r;
-	}
-
-	memset(hpd, 0, mec_hpd_size);
+		memset(hpd, 0, mec_hpd_size);
 
-	amdgpu_bo_kunmap(adev->gfx.mec.hpd_eop_obj);
-	amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
+		amdgpu_bo_kunmap(adev->gfx.mec.hpd_eop_obj);
+		amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
+	}
 
 	mec_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.mec_fw->data;
 
@@ -4625,7 +4626,7 @@ static int gfx_v9_0_early_init(void *handle)
 		adev->gfx.num_gfx_rings = 0;
 	else
 		adev->gfx.num_gfx_rings = GFX9_NUM_GFX_RINGS;
-	adev->gfx.num_compute_rings = AMDGPU_MAX_COMPUTE_RINGS;
+	adev->gfx.num_compute_rings = amdgpu_num_kcq;
 	gfx_v9_0_set_kiq_pm4_funcs(adev);
 	gfx_v9_0_set_ring_funcs(adev);
 	gfx_v9_0_set_irq_funcs(adev);
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#2 lore raw

Re: [PATCH 2/2] drm/amdgpu: introduce a new parameter to configure how many KCQ we want(v5)

Am 2020-07-31 um 3:51 a.m. schrieb Monk Liu:

Quoted 26 lines

what:
the MQD's save and restore of KCQ (kernel compute queue) cost lots of clocks during world switch which impacts a lot to multi-VF performance

how:
introduce a paramter to control the number of KCQ to avoid performance drop if there is no kernel compute queue needed

notes:
this paramter only affects gfx 8/9/10

v2:
refine namings

v3:
choose queues for each ring to that try best to cross pipes evenly.

v4:
fix indentation
some cleanupsin the gfx_compute_queue_acquire()

v5:
further fix on indentations
more cleanupsin gfx_compute_queue_acquire()

Quoted 6 lines

TODO:
in the future we will let hypervisor driver to set this paramter automatically thus no need for user to configure it through modprobe in virtual machine

This patch is Reviewed-by: Felix Kuehling <[email protected]>

Quoted 266 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  5 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    |  4 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c    | 49 ++++++++++++------------------
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c     | 30 +++++++++---------
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c      | 29 +++++++++---------
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c      | 31 ++++++++++---------
 7 files changed, 76 insertions(+), 73 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index e97c088..de11136 100644
@@ -201,6 +201,7 @@ extern int amdgpu_si_support;
 #ifdef CONFIG_DRM_AMDGPU_CIK
 extern int amdgpu_cik_support;
 #endif
+extern int amdgpu_num_kcq;
 
 #define AMDGPU_VM_MAX_NUM_CTX			4096
 #define AMDGPU_SG_THRESHOLD			(256*1024*1024)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5 -0
index 62ecac9..cf445bab 100644
@@ -1199,6 +1199,11 @@ static int amdgpu_device_check_arguments(struct amdgpu_device *adev)
 
 	amdgpu_gmc_tmz_set(adev);
 
+	if (amdgpu_num_kcq > 8 || amdgpu_num_kcq < 0) {
+		amdgpu_num_kcq = 8;
+		dev_warn(adev->dev, "set kernel compute queue number to 8 due to invalid paramter provided by user\n");
+	}
+
 	return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4 -0
index 6291f5f..b545c40 100644
@@ -150,6 +150,7 @@ int amdgpu_noretry;
 int amdgpu_force_asic_type = -1;
 int amdgpu_tmz = 0;
 int amdgpu_reset_method = -1; /* auto */
+int amdgpu_num_kcq = -1;
 
 struct amdgpu_mgpu_info mgpu_info = {
 	.mutex = __MUTEX_INITIALIZER(mgpu_info.mutex),
@@ -765,6 +766,9 @@ module_param_named(tmz, amdgpu_tmz, int, 0444);
 MODULE_PARM_DESC(reset_method, "GPU reset method (-1 = auto (default), 0 = legacy, 1 = mode0, 2 = mode1, 3 = mode2, 4 = baco)");
 module_param_named(reset_method, amdgpu_reset_method, int, 0444);
 
+MODULE_PARM_DESC(num_kcq, "number of kernel compute queue user want to setup (8 if set to greater than 8 or less than 0, only affect gfx 8+)");
+module_param_named(num_kcq, amdgpu_num_kcq, int, 0444);
+
 static const struct pci_device_id pciidlist[] = {
 #ifdef  CONFIG_DRM_AMDGPU_SI
 	{0x1002, 0x6780, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +19 -30
index 8eff017..0cd9de6 100644
@@ -202,40 +202,29 @@ bool amdgpu_gfx_is_high_priority_compute_queue(struct amdgpu_device *adev,
 
 void amdgpu_gfx_compute_queue_acquire(struct amdgpu_device *adev)
 {
-	int i, queue, pipe, mec;
+	int i, queue, pipe;
 	bool multipipe_policy = amdgpu_gfx_is_multipipe_capable(adev);
-
-	/* policy for amdgpu compute queue ownership */
-	for (i = 0; i < AMDGPU_MAX_COMPUTE_QUEUES; ++i) {
-		queue = i % adev->gfx.mec.num_queue_per_pipe;
-		pipe = (i / adev->gfx.mec.num_queue_per_pipe)
-			% adev->gfx.mec.num_pipe_per_mec;
-		mec = (i / adev->gfx.mec.num_queue_per_pipe)
-			/ adev->gfx.mec.num_pipe_per_mec;
-
-		/* we've run out of HW */
-		if (mec >= adev->gfx.mec.num_mec)
-			break;
-
-		if (multipipe_policy) {
-			/* policy: amdgpu owns the first two queues of the first MEC */
-			if (mec == 0 && queue < 2)
-				set_bit(i, adev->gfx.mec.queue_bitmap);
-		} else {
-			/* policy: amdgpu owns all queues in the first pipe */
-			if (mec == 0 && pipe == 0)
-				set_bit(i, adev->gfx.mec.queue_bitmap);
+	int max_queues_per_mec = min(adev->gfx.mec.num_pipe_per_mec *
+				     adev->gfx.mec.num_queue_per_pipe,
+				     adev->gfx.num_compute_rings);
+
+	if (multipipe_policy) {
+		/* policy: make queues evenly cross all pipes on MEC1 only */
+		for (i = 0; i < max_queues_per_mec; i++) {
+			pipe = i % adev->gfx.mec.num_pipe_per_mec;
+			queue = (i / adev->gfx.mec.num_pipe_per_mec) %
+				adev->gfx.mec.num_queue_per_pipe;
+
+			set_bit(pipe * adev->gfx.mec.num_queue_per_pipe + queue,
+					adev->gfx.mec.queue_bitmap);
 		}
+	} else {
+		/* policy: amdgpu owns all queues in the given pipe */
+		for (i = 0; i < max_queues_per_mec; ++i)
+			set_bit(i, adev->gfx.mec.queue_bitmap);
 	}
 
-	/* update the number of active compute rings */
-	adev->gfx.num_compute_rings =
-		bitmap_weight(adev->gfx.mec.queue_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
-
-	/* If you hit this case and edited the policy, you probably just
-	 * need to increase AMDGPU_MAX_COMPUTE_RINGS */
-	if (WARN_ON(adev->gfx.num_compute_rings > AMDGPU_MAX_COMPUTE_RINGS))
-		adev->gfx.num_compute_rings = AMDGPU_MAX_COMPUTE_RINGS;
+	dev_dbg(adev->dev, "mec queue bitmap weight=%d\n", bitmap_weight(adev->gfx.mec.queue_bitmap, AMDGPU_MAX_COMPUTE_QUEUES));
 }
 
 void amdgpu_gfx_graphics_queue_acquire(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +16 -14
index f571e25..4172bc8 100644
@@ -4022,21 +4022,23 @@ static int gfx_v10_0_mec_init(struct amdgpu_device *adev)
 	amdgpu_gfx_compute_queue_acquire(adev);
 	mec_hpd_size = adev->gfx.num_compute_rings * GFX10_MEC_HPD_SIZE;
 
-	r = amdgpu_bo_create_reserved(adev, mec_hpd_size, PAGE_SIZE,
-				      AMDGPU_GEM_DOMAIN_GTT,
-				      &adev->gfx.mec.hpd_eop_obj,
-				      &adev->gfx.mec.hpd_eop_gpu_addr,
-				      (void **)&hpd);
-	if (r) {
-		dev_warn(adev->dev, "(%d) create HDP EOP bo failed\n", r);
-		gfx_v10_0_mec_fini(adev);
-		return r;
-	}
+	if (mec_hpd_size) {
+		r = amdgpu_bo_create_reserved(adev, mec_hpd_size, PAGE_SIZE,
+					      AMDGPU_GEM_DOMAIN_GTT,
+					      &adev->gfx.mec.hpd_eop_obj,
+					      &adev->gfx.mec.hpd_eop_gpu_addr,
+					      (void **)&hpd);
+		if (r) {
+			dev_warn(adev->dev, "(%d) create HDP EOP bo failed\n", r);
+			gfx_v10_0_mec_fini(adev);
+			return r;
+		}
 
-	memset(hpd, 0, mec_hpd_size);
+		memset(hpd, 0, mec_hpd_size);
 
-	amdgpu_bo_kunmap(adev->gfx.mec.hpd_eop_obj);
-	amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
+		amdgpu_bo_kunmap(adev->gfx.mec.hpd_eop_obj);
+		amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
+	}
 
 	if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT) {
 		mec_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.mec_fw->data;
@@ -7162,7 +7164,7 @@ static int gfx_v10_0_early_init(void *handle)
 		break;
 	}
 
-	adev->gfx.num_compute_rings = AMDGPU_MAX_COMPUTE_RINGS;
+	adev->gfx.num_compute_rings = amdgpu_num_kcq;
 
 	gfx_v10_0_set_kiq_pm4_funcs(adev);
 	gfx_v10_0_set_ring_funcs(adev);
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +15 -14
index 8d72089..7df567a 100644
@@ -1343,21 +1343,22 @@ static int gfx_v8_0_mec_init(struct amdgpu_device *adev)
 	amdgpu_gfx_compute_queue_acquire(adev);
 
 	mec_hpd_size = adev->gfx.num_compute_rings * GFX8_MEC_HPD_SIZE;
+	if (mec_hpd_size) {
+		r = amdgpu_bo_create_reserved(adev, mec_hpd_size, PAGE_SIZE,
+					      AMDGPU_GEM_DOMAIN_VRAM,
+					      &adev->gfx.mec.hpd_eop_obj,
+					      &adev->gfx.mec.hpd_eop_gpu_addr,
+					      (void **)&hpd);
+		if (r) {
+			dev_warn(adev->dev, "(%d) create HDP EOP bo failed\n", r);
+			return r;
+		}
 
-	r = amdgpu_bo_create_reserved(adev, mec_hpd_size, PAGE_SIZE,
-				      AMDGPU_GEM_DOMAIN_VRAM,
-				      &adev->gfx.mec.hpd_eop_obj,
-				      &adev->gfx.mec.hpd_eop_gpu_addr,
-				      (void **)&hpd);
-	if (r) {
-		dev_warn(adev->dev, "(%d) create HDP EOP bo failed\n", r);
-		return r;
-	}
-
-	memset(hpd, 0, mec_hpd_size);
+		memset(hpd, 0, mec_hpd_size);
 
-	amdgpu_bo_kunmap(adev->gfx.mec.hpd_eop_obj);
-	amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
+		amdgpu_bo_kunmap(adev->gfx.mec.hpd_eop_obj);
+		amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
+	}
 
 	return 0;
 }
@@ -5294,7 +5295,7 @@ static int gfx_v8_0_early_init(void *handle)
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
 	adev->gfx.num_gfx_rings = GFX8_NUM_GFX_RINGS;
-	adev->gfx.num_compute_rings = AMDGPU_MAX_COMPUTE_RINGS;
+	adev->gfx.num_compute_rings = amdgpu_num_kcq;
 	adev->gfx.funcs = &gfx_v8_0_gfx_funcs;
 	gfx_v8_0_set_ring_funcs(adev);
 	gfx_v8_0_set_irq_funcs(adev);
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +15 -14
index e4e751f..ef07e59 100644
@@ -1938,22 +1938,23 @@ static int gfx_v9_0_mec_init(struct amdgpu_device *adev)
 	/* take ownership of the relevant compute queues */
 	amdgpu_gfx_compute_queue_acquire(adev);
 	mec_hpd_size = adev->gfx.num_compute_rings * GFX9_MEC_HPD_SIZE;
+	if (mec_hpd_size) {
+		r = amdgpu_bo_create_reserved(adev, mec_hpd_size, PAGE_SIZE,
+					      AMDGPU_GEM_DOMAIN_VRAM,
+					      &adev->gfx.mec.hpd_eop_obj,
+					      &adev->gfx.mec.hpd_eop_gpu_addr,
+					      (void **)&hpd);
+		if (r) {
+			dev_warn(adev->dev, "(%d) create HDP EOP bo failed\n", r);
+			gfx_v9_0_mec_fini(adev);
+			return r;
+		}
 
-	r = amdgpu_bo_create_reserved(adev, mec_hpd_size, PAGE_SIZE,
-				      AMDGPU_GEM_DOMAIN_VRAM,
-				      &adev->gfx.mec.hpd_eop_obj,
-				      &adev->gfx.mec.hpd_eop_gpu_addr,
-				      (void **)&hpd);
-	if (r) {
-		dev_warn(adev->dev, "(%d) create HDP EOP bo failed\n", r);
-		gfx_v9_0_mec_fini(adev);
-		return r;
-	}
-
-	memset(hpd, 0, mec_hpd_size);
+		memset(hpd, 0, mec_hpd_size);
 
-	amdgpu_bo_kunmap(adev->gfx.mec.hpd_eop_obj);
-	amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
+		amdgpu_bo_kunmap(adev->gfx.mec.hpd_eop_obj);
+		amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
+	}
 
 	mec_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.mec_fw->data;
 

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static int gfx_v9_0_early_init(void *handle) · line 4632

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -1
@@ -4625,7 +4626,7 @@ static int gfx_v9_0_early_init(void *handle)
 		adev->gfx.num_gfx_rings = 0;
 	else
 		adev->gfx.num_gfx_rings = GFX9_NUM_GFX_RINGS;
-	adev->gfx.num_compute_rings = AMDGPU_MAX_COMPUTE_RINGS;
+	adev->gfx.num_compute_rings = amdgpu_num_kcq;
 	gfx_v9_0_set_kiq_pm4_funcs(adev);
 	gfx_v9_0_set_ring_funcs(adev);
 	gfx_v9_0_set_irq_funcs(adev);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#3 lore raw

Re: [PATCH 2/2] drm/amdgpu: introduce a new parameter to configure how many KCQ we want(v5)

Monk or perhaps Felix,

Do you by any chance know why the CS ioctl returns -EINVAL for all compute submissions if num_kcq <= 4 and what could cause that?

If not, is there any way to disable mid-IB preemption for compute?

Thanks,
Marek

Quoted 336 lines · Felix Kuehling

Am 2020-07-31 um 3:51 a.m. schrieb Monk Liu:

Quoted 26 lines

what:
the MQD's save and restore of KCQ (kernel compute queue) cost lots of clocks during world switch which impacts a lot to multi-VF performance

how:
introduce a paramter to control the number of KCQ to avoid performance drop if there is no kernel compute queue needed

notes:
this paramter only affects gfx 8/9/10

v2:
refine namings

v3:
choose queues for each ring to that try best to cross pipes evenly.

v4:
fix indentation
some cleanupsin the gfx_compute_queue_acquire()

v5:
further fix on indentations
more cleanupsin gfx_compute_queue_acquire()

Quoted 6 lines

TODO:
in the future we will let hypervisor driver to set this paramter automatically thus no need for user to configure it through modprobe in virtual machine

This patch is Reviewed-by: Felix Kuehling <[email protected]>

Quoted 5 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  5 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    |  4 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c    | 49

++++++++++++------------------

Review

Quoted 6 lines
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c     | 30 +++++++++---------
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c      | 29 +++++++++---------
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c      | 31 ++++++++++---------
 7 files changed, 76 insertions(+), 73 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu.h

Review

Quoted 12 lines

index e97c088..de11136 100644

drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
@@ -201,6 +201,7 @@ extern int amdgpu_si_support;
 #ifdef CONFIG_DRM_AMDGPU_CIK
 extern int amdgpu_cik_support;
 #endif
+extern int amdgpu_num_kcq;
 
 #define AMDGPU_VM_MAX_NUM_CTX                        4096
 #define AMDGPU_SG_THRESHOLD                  (256*1024*1024)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_check_arguments(struct

Quoted 4 lines

index 62ecac9..cf445bab 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
@@ -1199,6 +1199,11 @@ static int amdgpu_device_check_arguments(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_check_arguments(struct amdgpu_device *adev)

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
      amdgpu_gmc_tmz_set(adev);
 
+     if (amdgpu_num_kcq > 8 || amdgpu_num_kcq < 0) {
+             amdgpu_num_kcq = 8;
+             dev_warn(adev->dev, "set kernel compute queue number to 8

due to invalid paramter provided by user\n");

Review

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -0
+     }
+
      return 0;
 }
 
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c module_param_named(tmz, amdgpu_tmz, int, 0444); · line 766

Quoted 13 lines

index 6291f5f..b545c40 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
@@ -150,6 +150,7 @@ int amdgpu_noretry;
 int amdgpu_force_asic_type = -1;
 int amdgpu_tmz = 0;
 int amdgpu_reset_method = -1; /* auto */
+int amdgpu_num_kcq = -1;
 
 struct amdgpu_mgpu_info mgpu_info = {
      .mutex = __MUTEX_INITIALIZER(mgpu_info.mutex),
@@ -765,6 +766,9 @@ module_param_named(tmz, amdgpu_tmz, int, 0444);
 MODULE_PARM_DESC(reset_method, "GPU reset method (-1 = auto (default),

0 = legacy, 1 = mode0, 2 = mode1, 3 = mode2, 4 = baco)");

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c module_param_named(tmz, amdgpu_tmz, int, 0444);

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
 module_param_named(reset_method, amdgpu_reset_method, int, 0444);
 
+MODULE_PARM_DESC(num_kcq, "number of kernel compute queue user want to

setup (8 if set to greater than 8 or less than 0, only affect gfx 8+)");

Review

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -0
+module_param_named(num_kcq, amdgpu_num_kcq, int, 0444);
+
 static const struct pci_device_id pciidlist[] = {
 #ifdef  CONFIG_DRM_AMDGPU_SI
      {0x1002, 0x6780, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c bool

Quoted 4 lines

index 8eff017..0cd9de6 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -0
@@ -202,40 +202,29 @@ bool

amdgpu_gfx_is_high_priority_compute_queue(struct amdgpu_device *adev,

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +1 -6
 void amdgpu_gfx_compute_queue_acquire(struct amdgpu_device *adev)
 {
-     int i, queue, pipe, mec;
+     int i, queue, pipe;
      bool multipipe_policy = amdgpu_gfx_is_multipipe_capable(adev);
-
-     /* policy for amdgpu compute queue ownership */
-     for (i = 0; i < AMDGPU_MAX_COMPUTE_QUEUES; ++i) {
-             queue = i % adev->gfx.mec.num_queue_per_pipe;
-             pipe = (i / adev->gfx.mec.num_queue_per_pipe)

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c bool amdgpu_gfx_is_high_priority_compute_queue(struct amdgpu_device *adev,

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -10
-                     % adev->gfx.mec.num_pipe_per_mec;
-             mec = (i / adev->gfx.mec.num_queue_per_pipe)
-                     / adev->gfx.mec.num_pipe_per_mec;
-
-             /* we've run out of HW */
-             if (mec >= adev->gfx.mec.num_mec)
-                     break;
-
-             if (multipipe_policy) {
-                     /* policy: amdgpu owns the first two queues of the

first MEC */

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c bool amdgpu_gfx_is_high_priority_compute_queue(struct amdgpu_device *adev,

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -4
-                     if (mec == 0 && queue < 2)
-                             set_bit(i, adev->gfx.mec.queue_bitmap);
-             } else {
-                     /* policy: amdgpu owns all queues in the first

pipe */

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c bool amdgpu_gfx_is_high_priority_compute_queue(struct amdgpu_device *adev,

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +6 -2
-                     if (mec == 0 && pipe == 0)
-                             set_bit(i, adev->gfx.mec.queue_bitmap);
+     int max_queues_per_mec = min(adev->gfx.mec.num_pipe_per_mec *
+                                  adev->gfx.mec.num_queue_per_pipe,
+                                  adev->gfx.num_compute_rings);
+
+     if (multipipe_policy) {
+             /* policy: make queues evenly cross all pipes on MEC1 only

*/

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c bool amdgpu_gfx_is_high_priority_compute_queue(struct amdgpu_device *adev,

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +6 -0
+             for (i = 0; i < max_queues_per_mec; i++) {
+                     pipe = i % adev->gfx.mec.num_pipe_per_mec;
+                     queue = (i / adev->gfx.mec.num_pipe_per_mec) %
+                             adev->gfx.mec.num_queue_per_pipe;
+
+                     set_bit(pipe * adev->gfx.mec.num_queue_per_pipe +

queue,

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c bool amdgpu_gfx_is_high_priority_compute_queue(struct amdgpu_device *adev,

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +5 -3
+                                     adev->gfx.mec.queue_bitmap);
              }
+     } else {
+             /* policy: amdgpu owns all queues in the given pipe */
+             for (i = 0; i < max_queues_per_mec; ++i)
+                     set_bit(i, adev->gfx.mec.queue_bitmap);
      }
 
-     /* update the number of active compute rings */
-     adev->gfx.num_compute_rings =
-             bitmap_weight(adev->gfx.mec.queue_bitmap,

AMDGPU_MAX_COMPUTE_QUEUES);

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c bool amdgpu_gfx_is_high_priority_compute_queue(struct amdgpu_device *adev,

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -4
-
-     /* If you hit this case and edited the policy, you probably just
-      * need to increase AMDGPU_MAX_COMPUTE_RINGS */
-     if (WARN_ON(adev->gfx.num_compute_rings >

AMDGPU_MAX_COMPUTE_RINGS))

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c bool · line 226

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +1 -1
-             adev->gfx.num_compute_rings = AMDGPU_MAX_COMPUTE_RINGS;
+     dev_dbg(adev->dev, "mec queue bitmap weight=%d\n",

bitmap_weight(adev->gfx.mec.queue_bitmap, AMDGPU_MAX_COMPUTE_QUEUES));

Review

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -0
 }
 
 void amdgpu_gfx_graphics_queue_acquire(struct amdgpu_device *adev)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static int gfx_v10_0_mec_init(struct

Quoted 4 lines

index f571e25..4172bc8 100644

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0 -0
@@ -4022,21 +4022,23 @@ static int gfx_v10_0_mec_init(struct

amdgpu_device *adev)

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0 -2
      amdgpu_gfx_compute_queue_acquire(adev);
      mec_hpd_size = adev->gfx.num_compute_rings * GFX10_MEC_HPD_SIZE;
 
-     r = amdgpu_bo_create_reserved(adev, mec_hpd_size, PAGE_SIZE,
-                                   AMDGPU_GEM_DOMAIN_GTT,

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static int gfx_v10_0_mec_init(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +2 -8
-                                   &adev->gfx.mec.hpd_eop_obj,
-                                   &adev->gfx.mec.hpd_eop_gpu_addr,
-                                   (void **)&hpd);
-     if (r) {
-             dev_warn(adev->dev, "(%d) create HDP EOP bo failed\n", r);
-             gfx_v10_0_mec_fini(adev);
-             return r;
-     }
+     if (mec_hpd_size) {
+             r = amdgpu_bo_create_reserved(adev, mec_hpd_size,

PAGE_SIZE,

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static int gfx_v10_0_mec_init(struct amdgpu_device *adev)

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +3 -0
+                                           AMDGPU_GEM_DOMAIN_GTT,
+                                           &adev->gfx.mec.hpd_eop_obj,
+

&adev->gfx.mec.hpd_eop_gpu_addr,

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static int gfx_v10_0_mec_init(struct amdgpu_device *adev)

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +3 -0
+                                           (void **)&hpd);
+             if (r) {
+                     dev_warn(adev->dev, "(%d) create HDP EOP bo

failed\n", r);

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +3 -1
+                     gfx_v10_0_mec_fini(adev);
+                     return r;
+             }
 
-     memset(hpd, 0, mec_hpd_size);

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static int gfx_v10_0_mec_init(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +4 -2
+             memset(hpd, 0, mec_hpd_size);
 
-     amdgpu_bo_kunmap(adev->gfx.mec.hpd_eop_obj);
-     amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
+             amdgpu_bo_kunmap(adev->gfx.mec.hpd_eop_obj);
+             amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
+     }
 
      if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT) {
              mec_hdr = (const struct gfx_firmware_header_v1_0

*)adev->gfx.mec_fw->data;

Review

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1 -1
@@ -7162,7 +7164,7 @@ static int gfx_v10_0_early_init(void *handle)
              break;
      }
 
-     adev->gfx.num_compute_rings = AMDGPU_MAX_COMPUTE_RINGS;
+     adev->gfx.num_compute_rings = amdgpu_num_kcq;
 
      gfx_v10_0_set_kiq_pm4_funcs(adev);
      gfx_v10_0_set_ring_funcs(adev);
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c

drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c static int gfx_v8_0_mec_init(struct

Quoted 4 lines

index 8d72089..7df567a 100644

drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +0 -0
@@ -1343,21 +1343,22 @@ static int gfx_v8_0_mec_init(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c static int gfx_v8_0_mec_init(struct amdgpu_device *adev)

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +2 -0
      amdgpu_gfx_compute_queue_acquire(adev);
 
      mec_hpd_size = adev->gfx.num_compute_rings * GFX8_MEC_HPD_SIZE;
+     if (mec_hpd_size) {
+             r = amdgpu_bo_create_reserved(adev, mec_hpd_size,

PAGE_SIZE,

drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c static int gfx_v8_0_mec_init(struct amdgpu_device *adev)

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +3 -0
+                                           AMDGPU_GEM_DOMAIN_VRAM,
+                                           &adev->gfx.mec.hpd_eop_obj,
+

&adev->gfx.mec.hpd_eop_gpu_addr,

drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c static int gfx_v8_0_mec_init(struct · line 1353

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +3 -0
+                                           (void **)&hpd);
+             if (r) {
+                     dev_warn(adev->dev, "(%d) create HDP EOP bo

failed\n", r);

Review

Quoted 34 lines
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +7 -14
+                     return r;
+             }
 
-     r = amdgpu_bo_create_reserved(adev, mec_hpd_size, PAGE_SIZE,
-                                   AMDGPU_GEM_DOMAIN_VRAM,
-                                   &adev->gfx.mec.hpd_eop_obj,
-                                   &adev->gfx.mec.hpd_eop_gpu_addr,
-                                   (void **)&hpd);
-     if (r) {
-             dev_warn(adev->dev, "(%d) create HDP EOP bo failed\n", r);
-             return r;
-     }
-
-     memset(hpd, 0, mec_hpd_size);
+             memset(hpd, 0, mec_hpd_size);
 
-     amdgpu_bo_kunmap(adev->gfx.mec.hpd_eop_obj);
-     amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
+             amdgpu_bo_kunmap(adev->gfx.mec.hpd_eop_obj);
+             amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
+     }
 
      return 0;
 }
@@ -5294,7 +5295,7 @@ static int gfx_v8_0_early_init(void *handle)
      struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
      adev->gfx.num_gfx_rings = GFX8_NUM_GFX_RINGS;
-     adev->gfx.num_compute_rings = AMDGPU_MAX_COMPUTE_RINGS;
+     adev->gfx.num_compute_rings = amdgpu_num_kcq;
      adev->gfx.funcs = &gfx_v8_0_gfx_funcs;
      gfx_v8_0_set_ring_funcs(adev);
      gfx_v8_0_set_irq_funcs(adev);
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static int gfx_v9_0_mec_init(struct

Quoted 4 lines

index e4e751f..ef07e59 100644

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +0 -0
@@ -1938,22 +1938,23 @@ static int gfx_v9_0_mec_init(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static int gfx_v9_0_mec_init(struct amdgpu_device *adev)

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +2 -0
      /* take ownership of the relevant compute queues */
      amdgpu_gfx_compute_queue_acquire(adev);
      mec_hpd_size = adev->gfx.num_compute_rings * GFX9_MEC_HPD_SIZE;
+     if (mec_hpd_size) {
+             r = amdgpu_bo_create_reserved(adev, mec_hpd_size,

PAGE_SIZE,

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static int gfx_v9_0_mec_init(struct · line 1945

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +3 -0
+                                           AMDGPU_GEM_DOMAIN_VRAM,
+                                           &adev->gfx.mec.hpd_eop_obj,
+

&adev->gfx.mec.hpd_eop_gpu_addr,

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static int gfx_v9_0_mec_init(struct · line 1948

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +3 -0
+                                           (void **)&hpd);
+             if (r) {
+                     dev_warn(adev->dev, "(%d) create HDP EOP bo

failed\n", r);

Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +3 -11
+                     gfx_v9_0_mec_fini(adev);
+                     return r;
+             }
 
-     r = amdgpu_bo_create_reserved(adev, mec_hpd_size, PAGE_SIZE,
-                                   AMDGPU_GEM_DOMAIN_VRAM,
-                                   &adev->gfx.mec.hpd_eop_obj,
-                                   &adev->gfx.mec.hpd_eop_gpu_addr,
-                                   (void **)&hpd);
-     if (r) {
-             dev_warn(adev->dev, "(%d) create HDP EOP bo failed\n", r);
-             gfx_v9_0_mec_fini(adev);
-             return r;
-     }
-

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static int gfx_v9_0_mec_init(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +4 -3
-     memset(hpd, 0, mec_hpd_size);
+             memset(hpd, 0, mec_hpd_size);
 
-     amdgpu_bo_kunmap(adev->gfx.mec.hpd_eop_obj);
-     amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
+             amdgpu_bo_kunmap(adev->gfx.mec.hpd_eop_obj);
+             amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
+     }
 
      mec_hdr = (const struct gfx_firmware_header_v1_0

*)adev->gfx.mec_fw->data;

Quoted 1 line
Quoted 14 lines

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static int gfx_v9_0_early_init(void *handle) · line 4632

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -1
@@ -4625,7 +4626,7 @@ static int gfx_v9_0_early_init(void *handle)
              adev->gfx.num_gfx_rings = 0;
      else
              adev->gfx.num_gfx_rings = GFX9_NUM_GFX_RINGS;
-     adev->gfx.num_compute_rings = AMDGPU_MAX_COMPUTE_RINGS;
+     adev->gfx.num_compute_rings = amdgpu_num_kcq;
      gfx_v9_0_set_kiq_pm4_funcs(adev);
      gfx_v9_0_set_ring_funcs(adev);
      gfx_v9_0_set_irq_funcs(adev);

_______________________________________________
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

#4 lore raw
In reply to Monk Liu

In gfx_v10_0_sw_fini the KIQ ring gets freed. Wouldn't that be the right place to stop the KIQ? Otherwise KIQ will hang as soon as someone allocates the memory that was previously used for the KIQ ring buffer and overwrites it with something that's not a valid PM4 packet.

Regards,
  Felix

Am 2020-07-31 um 3:51 a.m. schrieb Monk Liu:

Quoted 25 lines

KIQ will hang if we try below steps:
modprobe amdgpu
rmmod amdgpu
modprobe amdgpu sched_hw_submission=4

the cause is that due to KIQ is always living there even after we unload KMD thus when doing the realod of KMD KIQ will crash upon its register programed with different values with the previous configuration (the config like HQD addr, ring size, is easily changed if we alter the sched_hw_submission)

the fix is we must inactive KIQ first before touching any of its registgers

---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0 -0
index db9f1e8..f571e25 100644

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static int gfx_v10_0_kiq_init_register(struct amdgpu_ring *ring) · line 6441

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +3 -0
@@ -6433,6 +6433,9 @@ static int gfx_v10_0_kiq_init_register(struct amdgpu_ring *ring)
 	struct v10_compute_mqd *mqd = ring->mqd_ptr;
 	int j;
 
+	/* activate the queue */
+	WREG32_SOC15(GC, 0, mmCP_HQD_ACTIVE, 0);
+
 	/* disable wptr polling */
 	WREG32_FIELD15(GC, 0, CP_PQ_WPTR_POLL_CNTL, EN, 0);
 

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#5 lore raw

[AMD Official Use Only - Internal Distribution Only]

Quoted 1 line
Quoted 1 line

In gfx_v10_0_sw_fini the KIQ ring gets freed. Wouldn't that be the right place to stop the KIQ

KIQ (CPC) will never being stopped (the DISABLE on CPC is skipped for SRIOV ) for SRIOV in SW_FINI because SRIOV relies on KIQ to do world switch

But this is really a weird bug because even with the same approach it doesn't make KIQ (CP) hang on GFX9, only GFX10 need this patch ....

By now I do not have other good explanation or better fix than this one

_____________________________________
Monk Liu|GPU Virtualization Team |AMD

-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Friday, July 31, 2020 9:57 PM
To: Liu, Monk <[email protected]>; [email protected]
Subject: Re: [PATCH 1/2] drm/amdgpu: fix reload KMD hang on KIQ

In gfx_v10_0_sw_fini the KIQ ring gets freed. Wouldn't that be the right place to stop the KIQ? Otherwise KIQ will hang as soon as someone allocates the memory that was previously used for the KIQ ring buffer and overwrites it with something that's not a valid PM4 packet.

Regards,
Felix

Am 2020-07-31 um 3:51 a.m. schrieb Monk Liu:

Quoted 25 lines

KIQ will hang if we try below steps:
modprobe amdgpu
rmmod amdgpu
modprobe amdgpu sched_hw_submission=4

the cause is that due to KIQ is always living there even after we unload KMD thus when doing the realod of KMD KIQ will crash upon its register programed with different values with the previous configuration (the config like HQD addr, ring size, is easily changed if we alter the sched_hw_submission)

the fix is we must inactive KIQ first before touching any of its registgers

---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0 -0
index db9f1e8..f571e25 100644

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static int gfx_v10_0_kiq_init_register(struct amdgpu_ring *ring) · line 6441

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +3 -0
@@ -6433,6 +6433,9 @@ static int gfx_v10_0_kiq_init_register(struct amdgpu_ring *ring)
 struct v10_compute_mqd *mqd = ring->mqd_ptr;
 int j;
 
+/* activate the queue */
+WREG32_SOC15(GC, 0, mmCP_HQD_ACTIVE, 0);
+
 /* disable wptr polling */
 WREG32_FIELD15(GC, 0, CP_PQ_WPTR_POLL_CNTL, EN, 0);
 

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#6 lore raw

[AMD Official Use Only - Internal Distribution Only]

Ping ... this is a severe bug fix

_____________________________________
Monk Liu|GPU Virtualization Team |AMD

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Liu, Monk
Sent: Monday, August 3, 2020 9:55 AM
To: Kuehling, Felix <[email protected]>; [email protected]
Subject: RE: [PATCH 1/2] drm/amdgpu: fix reload KMD hang on KIQ

[AMD Official Use Only - Internal Distribution Only]

[AMD Official Use Only - Internal Distribution Only]

Quoted 2 lines
Quoted 2 lines

In gfx_v10_0_sw_fini the KIQ ring gets freed. Wouldn't that be the right place to stop the KIQ

KIQ (CPC) will never being stopped (the DISABLE on CPC is skipped for SRIOV ) for SRIOV in SW_FINI because SRIOV relies on KIQ to do world switch

But this is really a weird bug because even with the same approach it doesn't make KIQ (CP) hang on GFX9, only GFX10 need this patch ....

By now I do not have other good explanation or better fix than this one

_____________________________________
Monk Liu|GPU Virtualization Team |AMD

-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Friday, July 31, 2020 9:57 PM
To: Liu, Monk <[email protected]>; [email protected]
Subject: Re: [PATCH 1/2] drm/amdgpu: fix reload KMD hang on KIQ

In gfx_v10_0_sw_fini the KIQ ring gets freed. Wouldn't that be the right place to stop the KIQ? Otherwise KIQ will hang as soon as someone allocates the memory that was previously used for the KIQ ring buffer and overwrites it with something that's not a valid PM4 packet.

Regards,
Felix

Am 2020-07-31 um 3:51 a.m. schrieb Monk Liu:

Quoted 29 lines

KIQ will hang if we try below steps:
modprobe amdgpu
rmmod amdgpu
modprobe amdgpu sched_hw_submission=4

the cause is that due to KIQ is always living there even after we unload KMD thus when doing the realod of KMD KIQ will crash upon its register programed with different values with the previous configuration (the config like HQD addr, ring size, is easily changed if we alter the sched_hw_submission)

the fix is we must inactive KIQ first before touching any of its registgers

---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0 -0
index db9f1e8..f571e25 100644
@@ -6433,6 +6433,9 @@ static int gfx_v10_0_kiq_init_register(struct

amdgpu_ring *ring) struct v10_compute_mqd *mqd = ring->mqd_ptr; int j;

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static int gfx_v10_0_kiq_init_register(struct amdgpu_ring *ring) · line 6440

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +3 -0
+/* activate the queue */
+WREG32_SOC15(GC, 0, mmCP_HQD_ACTIVE, 0);
+
 /* disable wptr polling */
 WREG32_FIELD15(GC, 0, CP_PQ_WPTR_POLL_CNTL, EN, 0);

_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=02%7C01%7Cmonk.liu%40amd.com%7C4837e2d566b44af845f608d837503a3b%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637320165018899834&amp;sdata=TED%2BkhlYyAIyTmLJAZBBBHHnE6PRg4fpUsZhD9ke%2BPU%3D&amp;reserved=0
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#7 lore raw

[AMD Official Use Only - Internal Distribution Only]

Quoted 86 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Liu, Monk
Sent: Tuesday, August 4, 2020 2:31 PM
To: [email protected]
Subject: RE: [PATCH 1/2] drm/amdgpu: fix reload KMD hang on KIQ

[AMD Official Use Only - Internal Distribution Only]

[AMD Official Use Only - Internal Distribution Only]

Ping ... this is a severe bug fix

_____________________________________
Monk Liu|GPU Virtualization Team |AMD

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Liu, Monk
Sent: Monday, August 3, 2020 9:55 AM
To: Kuehling, Felix <[email protected]>; [email protected]
Subject: RE: [PATCH 1/2] drm/amdgpu: fix reload KMD hang on KIQ

[AMD Official Use Only - Internal Distribution Only]

[AMD Official Use Only - Internal Distribution Only]

Quoted 2 lines
Quoted 2 lines

In gfx_v10_0_sw_fini the KIQ ring gets freed. Wouldn't that be the right place to stop the KIQ

KIQ (CPC) will never being stopped (the DISABLE on CPC is skipped for SRIOV ) for SRIOV in SW_FINI because SRIOV relies on KIQ to do world switch

But this is really a weird bug because even with the same approach it doesn't make KIQ (CP) hang on GFX9, only GFX10 need this patch ....

By now I do not have other good explanation or better fix than this one

_____________________________________
Monk Liu|GPU Virtualization Team |AMD

-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Friday, July 31, 2020 9:57 PM
To: Liu, Monk <[email protected]>; [email protected]
Subject: Re: [PATCH 1/2] drm/amdgpu: fix reload KMD hang on KIQ

In gfx_v10_0_sw_fini the KIQ ring gets freed. Wouldn't that be the right place to stop the KIQ? Otherwise KIQ will hang as soon as someone allocates the memory that was previously used for the KIQ ring buffer and overwrites it with something that's not a valid PM4 packet.

Regards,
Felix

Am 2020-07-31 um 3:51 a.m. schrieb Monk Liu:

Quoted 28 lines

KIQ will hang if we try below steps:
modprobe amdgpu
rmmod amdgpu
modprobe amdgpu sched_hw_submission=4

the cause is that due to KIQ is always living there even after we unload KMD thus when doing the realod of KMD KIQ will crash upon its register programed with different values with the previous configuration (the config like HQD addr, ring size, is easily changed if we alter the sched_hw_submission)

the fix is we must inactive KIQ first before touching any of its registgers

---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0 -0
index db9f1e8..f571e25 100644
@@ -6433,6 +6433,9 @@ static int gfx_v10_0_kiq_init_register(struct

amdgpu_ring *ring) struct v10_compute_mqd *mqd = ring->mqd_ptr; int j;

Quoted 3 lines

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static int gfx_v10_0_kiq_init_register(struct amdgpu_ring *ring) · line 6438

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +3 -0
+/* activate the queue */
+WREG32_SOC15(GC, 0, mmCP_HQD_ACTIVE, 0);
+

Could we move follow to here?
if (RREG32_SOC15(GC, 0, mmCP_HQD_ACTIVE) & 1) { WREG32_SOC15(GC, 0, mmCP_HQD_DEQUEUE_REQUEST, 1); for (j = 0; j < adev->usec_timeout; j++) { if (!(RREG32_SOC15(GC, 0, mmCP_HQD_ACTIVE) & 1)) break;
udelay(1);
}

Quoted 13 lines
Quoted 3 lines

/* disable wptr polling */ WREG32_FIELD15(GC, 0, CP_PQ_WPTR_POLL_CNTL, EN, 0);

_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.fre
edesktop.org%2Fmailman%2Flistinfo%2Famd- gfx&amp;data=02%7C01%7CEmily.Deng%40amd.com%7C1236f42617d246b20 bc108d8384007e4%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7 C637321194957236933&amp;sdata=0%2BzHvJ1n4TZOYss4v1pR6i8bxq46JE73 UIi%2B49x9joU%3D&amp;reserved=0
_______________________________________________

Quoted 8 lines

amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.fre
edesktop.org%2Fmailman%2Flistinfo%2Famd- gfx&amp;data=02%7C01%7CEmily.Deng%40amd.com%7C1236f42617d246b20 bc108d8384007e4%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7 C637321194957236933&amp;sdata=0%2BzHvJ1n4TZOYss4v1pR6i8bxq46JE73 UIi%2B49x9joU%3D&amp;reserved=0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx