Skip to contentSkip to conversation

drm/amdgpu/gfx8: rework kernel queue priority handling

PATCH New Alex Deucher 1 participant 8 messages Oct 21

Subsystems (2)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/8 drm/amdgpu/gfx8: rework kernel queue priority handling

Rather than setting a higher queue priority which could starve a lower priority queue, enable longer quantums for high priority kernel queues. This will avoid starvation, but provide longer runtime for high priority queues.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +4 -1
index 7e2f9c13dec39..80f3172f038c5 100644
@@ -4542,7 +4542,10 @@ static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)
 	if (ring != &adev->gfx.kiq[0].ring) {
 		tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_EN, 1);
 		tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_SCALE, 1);
-		tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_DURATION, 10);
+		if (amdgpu_gfx_is_high_priority_compute_queue(adev, ring))
+			tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_DURATION, 20);
+		else
+			tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_DURATION, 10);
 	}
 	mqd->cp_hqd_quantum = tmp;
 
Signature · 1 line
2.56.0
author maintainer
#1 lore raw

PATCH 2/8 drm/amdgpu/gfx9: rework kernel queue priority handling

Rather than setting a higher queue priority which could starve a lower priority queue, enable longer quantums for high priority kernel queues. This will avoid starvation, but provide longer runtime for high priority queues.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +4 -1
index 75d1bbdb421ff..020315156dad4 100644
@@ -3668,7 +3668,10 @@ static int gfx_v9_0_mqd_init(struct amdgpu_ring *ring)
 	tmp = RREG32_SOC15(GC, 0, mmCP_HQD_QUANTUM);
 	tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_EN, 1);
 	tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_SCALE, 1);
-	tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_DURATION, 1);
+	if (amdgpu_gfx_is_high_priority_compute_queue(adev, ring))
+		tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_DURATION, 2);
+	else
+		tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_DURATION, 1);
 	mqd->cp_hqd_quantum = tmp;
 
 	/* map_queues packet doesn't need activate the queue,
Signature · 1 line
2.56.0
author maintainer
#2 lore raw

PATCH 3/8 drm/amdgpu/gfx9.4.3: rework kernel queue priority handling

In reply to Alex Deucher

Rather than setting a higher queue priority which could starve a lower priority queue, enable longer quantums for high priority kernel queues. This will avoid starvation, but provide longer runtime for high priority queues.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +4 -1
index d66c7901783ed..2240f61c5e6bf 100644
@@ -1885,7 +1885,10 @@ static int gfx_v9_4_3_xcc_mqd_init(struct amdgpu_ring *ring, int xcc_id)
 	tmp = RREG32_SOC15(GC, GET_INST(GC, xcc_id), regCP_HQD_QUANTUM);
 	tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_EN, 1);
 	tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_SCALE, 1);
-	tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_DURATION, 1);
+	if (amdgpu_gfx_is_high_priority_compute_queue(adev, ring))
+		tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_DURATION, 2);
+	else
+		tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_DURATION, 1);
 	mqd->cp_hqd_quantum = tmp;
 
 	/* map_queues packet doesn't need activate the queue,
Signature · 1 line
2.56.0
author maintainer
#3 lore raw

PATCH 4/8 drm/amdgpu/gfx10: rework kernel queue priority handling

In reply to Alex Deucher

Rather than setting a higher queue priority which could starve a lower priority queue, enable longer quantums for high priority kernel queues. This will avoid starvation, but provide longer runtime for high priority queues.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +12 -1
index b6f61f4a08e5a..74b68b6048c89 100644
@@ -6800,6 +6800,12 @@ static int gfx_v10_0_gfx_mqd_init(struct amdgpu_device *adev, void *m,
 	/* set up time quantum */
 	tmp = RREG32_SOC15(GC, 0, mmCP_GFX_HQD_QUANTUM);
 	tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_QUANTUM, QUANTUM_EN, 1);
+	/* increase the duration of a high priority kernel queue */
+	if (prop->kernel_queue &&
+	    (prop->hqd_pipe_priority == AMDGPU_GFX_PIPE_PRIO_HIGH))
+		tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_QUANTUM, QUANTUM_DURATION, 20);
+	else
+		tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_QUANTUM, QUANTUM_DURATION, 10);
 	mqd->cp_gfx_hqd_quantum = tmp;
 
 	/* set up gfx hqd base. this is similar as CP_RB_BASE */
@@ -7019,7 +7025,12 @@ static int gfx_v10_0_compute_mqd_init(struct amdgpu_device *adev, void *m,
 
 	tmp = REG_SET_FIELD(0, CP_HQD_QUANTUM, QUANTUM_EN, 1);
 	tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_SCALE, 1);
-	tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_DURATION, 1);
+	/* increase the duration of a high priority kernel queue */
+	if (prop->kernel_queue &&
+	    (prop->hqd_pipe_priority == AMDGPU_GFX_PIPE_PRIO_HIGH))
+		tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_DURATION, 2);
+	else
+		tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_DURATION, 1);
 	mqd->cp_hqd_quantum = tmp;
 
 	/* set static priority for a compute queue/ring */
Signature · 1 line
2.56.0
author maintainer
#4 lore raw

PATCH 5/8 drm/amdgpu/gfx11: rework kernel queue priority handling

In reply to Alex Deucher

Rather than setting a higher queue priority which could starve a lower priority queue, enable longer quantums for high priority kernel queues. This will avoid starvation, but provide longer runtime for high priority queues.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +12 -1
index 315dfd806d56f..d44d21c0c332f 100644
@@ -4238,6 +4238,12 @@ static int gfx_v11_0_gfx_mqd_init(struct amdgpu_device *adev, void *m,
 	/* set up time quantum */
 	tmp = regCP_GFX_HQD_QUANTUM_DEFAULT;
 	tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_QUANTUM, QUANTUM_EN, 1);
+	/* increase the duration of a high priority kernel queue */
+	if (prop->kernel_queue &&
+	    (prop->hqd_pipe_priority == AMDGPU_GFX_PIPE_PRIO_HIGH))
+		tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_QUANTUM, QUANTUM_DURATION, 20);
+	else
+		tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_QUANTUM, QUANTUM_DURATION, 10);
 	mqd->cp_gfx_hqd_quantum = tmp;
 
 	/* set up gfx hqd base. this is similar as CP_RB_BASE */
@@ -4509,7 +4515,12 @@ static int gfx_v11_0_compute_mqd_init(struct amdgpu_device *adev, void *m,
 
 	tmp = REG_SET_FIELD(0, CP_HQD_QUANTUM, QUANTUM_EN, 1);
 	tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_SCALE, 1);
-	tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_DURATION, 1);
+	/* increase the duration of a high priority kernel queue */
+	if (prop->kernel_queue &&
+	    (prop->hqd_pipe_priority == AMDGPU_GFX_PIPE_PRIO_HIGH))
+		tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_DURATION, 2);
+	else
+		tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_DURATION, 1);
 	mqd->cp_hqd_quantum = tmp;
 
 	mqd->cp_hqd_active = prop->hqd_active;
Signature · 1 line
2.56.0
author maintainer
#5 lore raw

PATCH 6/8 drm/amdgpu/gfx12: rework kernel queue priority handling

In reply to Alex Deucher

Rather than setting a higher queue priority which could starve a lower priority queue, enable longer quantums for high priority kernel queues. This will avoid starvation, but provide longer runtime for high priority queues.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +12 -1
index d334fb8050201..b9f847d9c8dd9 100644
@@ -2945,6 +2945,12 @@ static int gfx_v12_0_gfx_mqd_init(struct amdgpu_device *adev, void *m,
 	/* set up time quantum */
 	tmp = regCP_GFX_HQD_QUANTUM_DEFAULT;
 	tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_QUANTUM, QUANTUM_EN, 1);
+	/* increase the duration of a high priority kernel queue */
+	if (prop->kernel_queue &&
+	    (prop->hqd_pipe_priority == AMDGPU_GFX_PIPE_PRIO_HIGH))
+		tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_QUANTUM, QUANTUM_DURATION, 20);
+	else
+		tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_QUANTUM, QUANTUM_DURATION, 10);
 	mqd->cp_gfx_hqd_quantum = tmp;
 
 	/* set up gfx hqd base. this is similar as CP_RB_BASE */
@@ -3213,7 +3219,12 @@ static int gfx_v12_0_compute_mqd_init(struct amdgpu_device *adev, void *m,
 
 	tmp = REG_SET_FIELD(0, CP_HQD_QUANTUM, QUANTUM_EN, 1);
 	tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_SCALE, 1);
-	tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_DURATION, 1);
+	/* increase the duration of a high priority kernel queue */
+	if (prop->kernel_queue &&
+	    (prop->hqd_pipe_priority == AMDGPU_GFX_PIPE_PRIO_HIGH))
+		tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_DURATION, 2);
+	else
+		tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_DURATION, 1);
 	mqd->cp_hqd_quantum = tmp;
 
 	mqd->cp_hqd_active = prop->hqd_active;
Signature · 1 line
2.56.0
author maintainer
#6 lore raw

PATCH 7/8 drm/amdgpu/gfx12.1: rework kernel queue priority handling

In reply to Alex Deucher

Rather than setting a higher queue priority which could starve a lower priority queue, enable longer quantums for high priority kernel queues. This will avoid starvation, but provide longer runtime for high priority queues.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +6 -1
index 1589fc6413af5..e3d3ca8e7900c 100644
@@ -2362,7 +2362,12 @@ static int gfx_v12_1_compute_mqd_init(struct amdgpu_device *adev, void *m,
 
 	tmp = REG_SET_FIELD(0, CP_HQD_QUANTUM, QUANTUM_EN, 1);
 	tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_SCALE, 1);
-	tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_DURATION, 1);
+	/* increase the duration of a high priority kernel queue */
+	if (prop->kernel_queue &&
+	    (prop->hqd_pipe_priority == AMDGPU_GFX_PIPE_PRIO_HIGH))
+		tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_DURATION, 2);
+	else
+		tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_DURATION, 1);
 	mqd->cp_hqd_quantum = tmp;
 
 	mqd->cp_hqd_active = prop->hqd_active;
Signature · 1 line
2.56.0
author maintainer
#7 lore raw

PATCH 8/8 drm/amdgpu: don't set queue priorities for kernel queues

In reply to Alex Deucher

Align with KFD and don't set queue priorities for kernel queues. This can result in starvation of lower priority queues.

v2: fix GC 8 and 9

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 4 +---
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c    | 2 --
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 2 --
 drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c  | 2 --
 4 files changed, 1 insertion(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +1 -3
index 2277345413165..4d472ce8cb710 100644
@@ -830,10 +830,8 @@ static void amdgpu_ring_to_mqd_prop(struct amdgpu_ring *ring,
 	prop->hqd_active = ring->funcs->type == AMDGPU_RING_TYPE_KIQ;
 
 	prop->allow_tunneling = is_high_prio_compute;
-	if (is_high_prio_compute || is_high_prio_gfx) {
+	if (is_high_prio_compute || is_high_prio_gfx)
 		prop->hqd_pipe_priority = AMDGPU_GFX_PIPE_PRIO_HIGH;
-		prop->hqd_queue_priority = AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM;
-	}
 }
 
 int amdgpu_ring_init_mqd(struct amdgpu_ring *ring)
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +0 -2
index 80f3172f038c5..0ad8b8614d927 100644
@@ -4396,8 +4396,6 @@ static void gfx_v8_0_mqd_set_priority(struct amdgpu_ring *ring, struct vi_mqd *m
 	if (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) {
 		if (amdgpu_gfx_is_high_priority_compute_queue(adev, ring)) {
 			mqd->cp_hqd_pipe_priority = AMDGPU_GFX_PIPE_PRIO_HIGH;
-			mqd->cp_hqd_queue_priority =
-				AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM;
 		}
 	}
 }
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +0 -2
index 020315156dad4..fe4454d0877b2 100644
@@ -3538,8 +3538,6 @@ static void gfx_v9_0_mqd_set_priority(struct amdgpu_ring *ring, struct v9_mqd *m
 	if (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) {
 		if (amdgpu_gfx_is_high_priority_compute_queue(adev, ring)) {
 			mqd->cp_hqd_pipe_priority = AMDGPU_GFX_PIPE_PRIO_HIGH;
-			mqd->cp_hqd_queue_priority =
-				AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM;
 		}
 	}
 }
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +0 -2
index 2240f61c5e6bf..19f05af61557c 100644
@@ -1756,8 +1756,6 @@ static void gfx_v9_4_3_mqd_set_priority(struct amdgpu_ring *ring, struct v9_mqd
 	if (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) {
 		if (amdgpu_gfx_is_high_priority_compute_queue(adev, ring)) {
 			mqd->cp_hqd_pipe_priority = AMDGPU_GFX_PIPE_PRIO_HIGH;
-			mqd->cp_hqd_queue_priority =
-				AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM;
 		}
 	}
 }
Signature · 1 line
2.56.0