Skip to contentSkip to conversation

drm/amdgpu: set compute queue priority at mqd_init

RFC PATCH Superseded Nirmoy Das 6 participants 15 messages Feb 27, 2020 – Mar 3, 2020

Subsystems (4)

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Nirmoy Das

author
#0 lore raw

RFC PATCH 1/4 drm/amdgpu: set compute queue priority at mqd_init

We were changing compute ring priority while rings were being used before every job submission which is not recommended. This patch sets compute queue priority at mqd initialization for gfx8 and gfx9.

Policy: Enable high priority compute queues only if gpu has >1 MEC, if so PIPE0 and PIPE1 will be in high priority.

high/normal priority compute sched list are generated from set of high/normal priority compute queues. At context creation, entity of compute queue get a sched list from high or normal priority depending on ctx->priority

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c   |  4 ----
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c  | 19 +++++++++++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c  | 14 ++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h  | 12 ++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c  |  6 ------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h |  1 +
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c    | 23 ++++++++++++++++++++---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 20 ++++++++++++++++++++
 8 files changed, 82 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -4
index f397ff97b4e4..8304d0c87899 100644
@@ -1205,7 +1205,6 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
 	struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
 	struct drm_sched_entity *entity = p->entity;
 	enum drm_sched_priority priority;
-	struct amdgpu_ring *ring;
 	struct amdgpu_bo_list_entry *e;
 	struct amdgpu_job *job;
 	uint64_t seq;
@@ -1258,9 +1257,6 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
 	priority = job->base.s_priority;
 	drm_sched_entity_push_job(&job->base, entity);
 
-	ring = to_amdgpu_ring(entity->rq->sched);
-	amdgpu_ring_priority_get(ring, priority);
-
 	amdgpu_vm_move_to_lru_tail(p->adev, &fpriv->vm);
 
 	ttm_eu_fence_buffer_objects(&p->ticket, &p->validated, p->fence);
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +15 -4
index 94a6c42f29ea..a1742b1d4f9c 100644
@@ -85,8 +85,14 @@ static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, const u32 hw_ip, const
 			num_scheds = 1;
 			break;
 		case AMDGPU_HW_IP_COMPUTE:
-			scheds = adev->gfx.compute_sched;
-			num_scheds = adev->gfx.num_compute_sched;
+			if (priority > DRM_SCHED_PRIORITY_NORMAL &&
+			    adev->gfx.num_compute_sched_high) {
+				scheds = adev->gfx.compute_sched_high;
+				num_scheds = adev->gfx.num_compute_sched_high;
+			} else {
+				scheds = adev->gfx.compute_sched;
+				num_scheds = adev->gfx.num_compute_sched;
+			}
 			break;
 		case AMDGPU_HW_IP_DMA:
 			scheds = adev->sdma.sdma_sched;
@@ -638,8 +644,13 @@ void amdgpu_ctx_init_sched(struct amdgpu_device *adev)
 	}
 
 	for (i = 0; i < adev->gfx.num_compute_rings; i++) {
-		adev->gfx.compute_sched[i] = &adev->gfx.compute_ring[i].sched;
-		adev->gfx.num_compute_sched++;
+		if (!adev->gfx.compute_ring[i].high_priority) {
+			adev->gfx.compute_sched[adev->gfx.num_compute_sched++] =
+				&adev->gfx.compute_ring[i].sched;
+		} else {
+			adev->gfx.compute_sched_high[adev->gfx.num_compute_sched_high++] =
+				&adev->gfx.compute_ring[i].sched;
+		}
 	}
 
 	for (i = 0; i < adev->sdma.num_instances; i++) {
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +14 -0
index 7403588684b3..bdea5d44edf4 100644
@@ -192,6 +192,20 @@ static bool amdgpu_gfx_is_multipipe_capable(struct amdgpu_device *adev)
 	return adev->gfx.mec.num_mec > 1;
 }
 
+bool amdgpu_gfx_is_high_priority_compute_queue(struct amdgpu_device *adev,
+					       int queue)
+{
+	bool multipipe_policy = amdgpu_gfx_is_multipipe_capable(adev);
+
+	/* only enable high priority queue if more than 1 MEC.
+	 * When multipipe_policy is true amdgpu gets queue 0,1 from each pipe of
+	 * 1st MEC. Policy: make queue 0 of each pipe as high priority compute queue */
+	if (multipipe_policy && queue == 0)
+		return true;
+
+	return false;
+}
+
 void amdgpu_gfx_compute_queue_acquire(struct amdgpu_device *adev)
 {
 	int i, queue, pipe, mec;
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +12 -0
index 37ba05b63b2a..13ee0ea66c6f 100644
@@ -41,6 +41,14 @@
 #define AMDGPU_MAX_GFX_QUEUES KGD_MAX_QUEUES
 #define AMDGPU_MAX_COMPUTE_QUEUES KGD_MAX_QUEUES
 
+#define AMDGPU_GFX_PIPE_PRIO_LOW    0
+#define AMDGPU_GFX_PIPE_PRIO_NORMAL 1
+#define AMDGPU_GFX_PIPE_PRIO_HIGH   2
+
+#define AMDGPU_GFX_QUEUE_PRIORITY_MINIMUM  0
+#define AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM  15
+
+
 struct amdgpu_mec {
 	struct amdgpu_bo	*hpd_eop_obj;
 	u64			hpd_eop_gpu_addr;
@@ -281,7 +289,9 @@ struct amdgpu_gfx {
 	unsigned			num_gfx_rings;
 	struct amdgpu_ring		compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
 	struct drm_gpu_scheduler	*compute_sched[AMDGPU_MAX_COMPUTE_RINGS];
+	struct drm_gpu_scheduler	*compute_sched_high[AMDGPU_MAX_COMPUTE_RINGS];
 	uint32_t			num_compute_sched;
+	uint32_t			num_compute_sched_high;
 	unsigned			num_compute_rings;
 	struct amdgpu_irq_src		eop_irq;
 	struct amdgpu_irq_src		priv_reg_irq;
@@ -363,6 +373,8 @@ void amdgpu_gfx_bit_to_mec_queue(struct amdgpu_device *adev, int bit,
 				 int *mec, int *pipe, int *queue);
 bool amdgpu_gfx_is_mec_queue_enabled(struct amdgpu_device *adev, int mec,
 				     int pipe, int queue);
+bool amdgpu_gfx_is_high_priority_compute_queue(struct amdgpu_device *adev,
+					       int queue);
 int amdgpu_gfx_me_queue_to_bit(struct amdgpu_device *adev, int me,
 			       int pipe, int queue);
 void amdgpu_gfx_bit_to_me_queue(struct amdgpu_device *adev, int bit,
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -6
index d42be880a236..4981e443a884 100644
@@ -117,12 +117,10 @@ void amdgpu_job_free_resources(struct amdgpu_job *job)
 
 static void amdgpu_job_free_cb(struct drm_sched_job *s_job)
 {
-	struct amdgpu_ring *ring = to_amdgpu_ring(s_job->sched);
 	struct amdgpu_job *job = to_amdgpu_job(s_job);
 
 	drm_sched_job_cleanup(s_job);
 
-	amdgpu_ring_priority_put(ring, s_job->s_priority);
 	dma_fence_put(job->fence);
 	amdgpu_sync_free(&job->sync);
 	amdgpu_sync_free(&job->sched_sync);
@@ -143,7 +141,6 @@ int amdgpu_job_submit(struct amdgpu_job *job, struct drm_sched_entity *entity,
 		      void *owner, struct dma_fence **f)
 {
 	enum drm_sched_priority priority;
-	struct amdgpu_ring *ring;
 	int r;
 
 	if (!f)
@@ -158,9 +155,6 @@ int amdgpu_job_submit(struct amdgpu_job *job, struct drm_sched_entity *entity,
 	priority = job->base.s_priority;
 	drm_sched_entity_push_job(&job->base, entity);
 
-	ring = to_amdgpu_ring(entity->rq->sched);
-	amdgpu_ring_priority_get(ring, priority);
-
 	return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +1 -0
index 24caff085d00..34fcd467f18d 100644
@@ -222,6 +222,7 @@ struct amdgpu_ring {
 	struct mutex		priority_mutex;
 	/* protected by priority_mutex */
 	int			priority;
+	bool			high_priority;
 
 #if defined(CONFIG_DEBUG_FS)
 	struct dentry *ent;
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +20 -3
index e63f98b2d389..4260becd569b 100644
@@ -4426,6 +4426,23 @@ static int gfx_v8_0_deactivate_hqd(struct amdgpu_device *adev, u32 req)
 	return r;
 }
 
+static void gfx_v8_0_mqd_set_priority(struct amdgpu_ring *ring, struct vi_mqd *mqd)
+{
+	struct amdgpu_device *adev = ring->adev;
+
+	if (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) {
+		if (amdgpu_gfx_is_high_priority_compute_queue(adev, ring->queue)) {
+			mqd->cp_hqd_pipe_priority = AMDGPU_GFX_PIPE_PRIO_HIGH;
+			ring->high_priority = true;
+			mqd->cp_hqd_queue_priority =
+				AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM;
+			mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);
+		}
+		else
+			ring->high_priority = false;
+	}
+}
+
 static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)
 {
 	struct amdgpu_device *adev = ring->adev;
@@ -4549,9 +4566,6 @@ static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)
 	/* defaults */
 	mqd->cp_hqd_eop_rptr = RREG32(mmCP_HQD_EOP_RPTR);
 	mqd->cp_hqd_eop_wptr = RREG32(mmCP_HQD_EOP_WPTR);
-	mqd->cp_hqd_pipe_priority = RREG32(mmCP_HQD_PIPE_PRIORITY);
-	mqd->cp_hqd_queue_priority = RREG32(mmCP_HQD_QUEUE_PRIORITY);
-	mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);
 	mqd->cp_hqd_ctx_save_base_addr_lo = RREG32(mmCP_HQD_CTX_SAVE_BASE_ADDR_LO);
 	mqd->cp_hqd_ctx_save_base_addr_hi = RREG32(mmCP_HQD_CTX_SAVE_BASE_ADDR_HI);
 	mqd->cp_hqd_cntl_stack_offset = RREG32(mmCP_HQD_CNTL_STACK_OFFSET);
@@ -4563,6 +4577,9 @@ static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)
 	mqd->cp_hqd_eop_wptr_mem = RREG32(mmCP_HQD_EOP_WPTR_MEM);
 	mqd->cp_hqd_eop_dones = RREG32(mmCP_HQD_EOP_DONES);
 
+	/* set static priority for a queue/ring */
+	gfx_v8_0_mqd_set_priority(ring, mqd);
+
 	/* map_queues packet doesn't need activate the queue,
 	 * so only kiq need set this field.
 	 */
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +20 -0
index 4135e4126e82..85a54849abd1 100644
@@ -3310,6 +3310,23 @@ static void gfx_v9_0_kiq_setting(struct amdgpu_ring *ring)
 	WREG32_SOC15_RLC(GC, 0, mmRLC_CP_SCHEDULERS, tmp);
 }
 
+static void gfx_v9_0_mqd_set_priority(struct amdgpu_ring *ring, struct v9_mqd *mqd)
+{
+	struct amdgpu_device *adev = ring->adev;
+
+	if (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) {
+		if (amdgpu_gfx_is_high_priority_compute_queue(adev, ring->queue)) {
+			mqd->cp_hqd_pipe_priority = AMDGPU_GFX_PIPE_PRIO_HIGH;
+			ring->high_priority = true;
+			mqd->cp_hqd_queue_priority =
+				AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM;
+			mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);
+		}
+		else
+			ring->high_priority = false;
+	}
+}
+
 static int gfx_v9_0_mqd_init(struct amdgpu_ring *ring)
 {
 	struct amdgpu_device *adev = ring->adev;
@@ -3446,6 +3463,9 @@ static int gfx_v9_0_mqd_init(struct amdgpu_ring *ring)
 	tmp = REG_SET_FIELD(tmp, CP_HQD_IB_CONTROL, MIN_IB_AVAIL_SIZE, 3);
 	mqd->cp_hqd_ib_control = tmp;
 
+	/* set static priority for a queue/ring */
+	gfx_v9_0_mqd_set_priority(ring, mqd);
+
 	/* map_queues packet doesn't need activate the queue,
 	 * so only kiq need set this field.
 	 */
Signature · 6 lines
2.25.0

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

RFC PATCH 2/4 drm/scheduler: implement a function to modify sched list

implement drm_sched_entity_modify_sched() which can modify existing sched_list with a different one. This is going to be helpful when userspace changes priority of a ctx/entity then driver can switch to corresponding hw shced list for that priority

---
 drivers/gpu/drm/scheduler/sched_entity.c | 24 ++++++++++++++++++++++++
 include/drm/gpu_scheduler.h              |  4 ++++
 2 files changed, 28 insertions(+)
drivers/gpu/drm/scheduler/sched_entity.c +24 -0
index 63bccd201b97..711e9d504bcb 100644
@@ -83,6 +83,30 @@ int drm_sched_entity_init(struct drm_sched_entity *entity,
 }
 EXPORT_SYMBOL(drm_sched_entity_init);
 
+/**
+ * drm_sched_entity_modify_sched - Modify sched of an entity
+ *
+ * @entity: scheduler entity to init
+ * @sched_list: the list of new drm scheds which will replace
+ *		existing entity->sched_list
+ * @num_sched_list: number of drm sched in sched_list
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+int drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
+				  struct drm_gpu_scheduler **sched_list,
+				  unsigned int num_sched_list)
+{
+	if (!(entity && sched_list && (num_sched_list == 0 || sched_list[0])))
+		return -EINVAL;
+
+	entity->sched_list = num_sched_list > 1 ? sched_list : NULL;
+	entity->num_sched_list = num_sched_list;
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_sched_entity_modify_sched);
+
 /**
  * drm_sched_entity_is_idle - Check if entity is idle
  *
include/drm/gpu_scheduler.h +4 -0
index 589be851f8a1..0c164a96d51b 100644
@@ -297,6 +297,10 @@ void drm_sched_fini(struct drm_gpu_scheduler *sched);
 int drm_sched_job_init(struct drm_sched_job *job,
 		       struct drm_sched_entity *entity,
 		       void *owner);
+int drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
+				  struct drm_gpu_scheduler **sched_list,
+                                  unsigned int num_sched_list);
+
 void drm_sched_job_cleanup(struct drm_sched_job *job);
 void drm_sched_wakeup(struct drm_gpu_scheduler *sched);
 void drm_sched_stop(struct drm_gpu_scheduler *sched, struct drm_sched_job *bad);
Signature · 6 lines
2.25.0

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

Re: [RFC PATCH 2/4] drm/scheduler: implement a function to modify sched list

Quoted 25 lines · Nirmoy Das

implement drm_sched_entity_modify_sched() which can modify existing sched_list with a different one. This is going to be helpful when userspace changes priority of a ctx/entity then driver can switch to corresponding hw shced list for that priority

---
 drivers/gpu/drm/scheduler/sched_entity.c | 24 ++++++++++++++++++++++++
 include/drm/gpu_scheduler.h              |  4 ++++
 2 files changed, 28 insertions(+)
drivers/gpu/drm/scheduler/sched_entity.c +6 -0
index 63bccd201b97..711e9d504bcb 100644
@@ -83,6 +83,30 @@ int drm_sched_entity_init(struct drm_sched_entity *entity,
 }
 EXPORT_SYMBOL(drm_sched_entity_init);
 
+/**
+ * drm_sched_entity_modify_sched - Modify sched of an entity
+ *
+ * @entity: scheduler entity to init
+ * @sched_list: the list of new drm scheds which will replace
+ *		existing entity->sched_list

drivers/gpu/drm/scheduler/sched_entity.c int drm_sched_entity_init(struct drm_sched_entity *entity, · line 101

Quoted 10 lines
drivers/gpu/drm/scheduler/sched_entity.c +10 -0
+ * @num_sched_list: number of drm sched in sched_list
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+int drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
+				  struct drm_gpu_scheduler **sched_list,
+				  unsigned int num_sched_list)
+{
+	if (!(entity && sched_list && (num_sched_list == 0 || sched_list[0])))
+		return -EINVAL;

This seems unmaintainable. I'd write it in its natural form:

int drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
struct drm_gpu_scheduler **sched_list, unsigned int num_sched_list)

{
	if (entity && sched_list && (num_sched_list == 0 || sched_list[0] != NULL)) {
		entity->sched_list = num_sched_list > 1 ? sched_list : NULL;
		entity->num_sched_list = num_sched_list;
		return 0;
	} else {
		return -EINVAL;
	}
}

That's too heavy. Can we improve the architecture
so we don't have to check for this in leaf functions like this one? We can just return a parameterization.

Why would this be called with entity being NULL?
Or with sched_list being NULL? Or num_sched_list being not zero yet sched_list[0] being NULL? Why not make sure that sched_list[0] is never NULL and that num_sched_list is greater than 0 always?

Does this make it to user space?
Why would the state of execution be one such that this is true/false
for the code to return -EINVAL?
From patch 3/4 it seems that an error is printed inside amdgpu_ctx_priority_override() and the result is not propagated up the stack.

I think we should improve the code where here this condition above is never true. Then we can use parameterization for those two statements below:

drivers/gpu/drm/scheduler/sched_entity.c int drm_sched_entity_init(struct drm_sched_entity *entity, · line 103

Quoted 2 lines
drivers/gpu/drm/scheduler/sched_entity.c +2 -0
+
+	entity->sched_list = num_sched_list > 1 ? sched_list : NULL;

So if we're here, we know from the top conditional that either num_sched_list is 0 or that sched_list[0] not NULL or both.

So if num_sched_list is 0 or 1 we return NULL? And if num_sched_list is 2 or greater we return sched_list of which sched_list[0] could be NULL?

Why not fix the architecture so that this is simply copied? (in which case we can simply index-parameterize it and simply copy it.
Why are there so many checks everywhere?

drivers/gpu/drm/scheduler/sched_entity.c int drm_sched_entity_init(struct drm_sched_entity *entity, · line 105

Quoted 2 lines
drivers/gpu/drm/scheduler/sched_entity.c +2 -0
+	entity->num_sched_list = num_sched_list;
+

I mean, all we're doing in this function is initializing entity->sched_list and entity->num_sched_list. Why does this function have to be so complex and do so many checks? Can we improve/fix the architecture instead?

Regards,
Luben

Quoted 13 lines
drivers/gpu/drm/scheduler/sched_entity.c +4 -0
+	return 0;
+}
+EXPORT_SYMBOL(drm_sched_entity_modify_sched);
+
 /**
  * drm_sched_entity_is_idle - Check if entity is idle
  *
include/drm/gpu_scheduler.h +0 -0
index 589be851f8a1..0c164a96d51b 100644

include/drm/gpu_scheduler.h void drm_sched_fini(struct drm_gpu_scheduler *sched); · line 306

Quoted 10 lines
include/drm/gpu_scheduler.h +4 -0
@@ -297,6 +297,10 @@ void drm_sched_fini(struct drm_gpu_scheduler *sched);
 int drm_sched_job_init(struct drm_sched_job *job,
 		       struct drm_sched_entity *entity,
 		       void *owner);
+int drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
+				  struct drm_gpu_scheduler **sched_list,
+                                  unsigned int num_sched_list);
+
 void drm_sched_job_cleanup(struct drm_sched_job *job);
 void drm_sched_wakeup(struct drm_gpu_scheduler *sched);
 void drm_sched_stop(struct drm_gpu_scheduler *sched, struct drm_sched_job *bad);

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

maintainer
#3 lore raw

Re: [RFC PATCH 2/4] drm/scheduler: implement a function to modify sched list

Am 28.02.20 um 06:08 schrieb Luben Tuikov:

Quoted 29 lines · Nirmoy Das
Quoted 28 lines

implement drm_sched_entity_modify_sched() which can modify existing sched_list with a different one. This is going to be helpful when userspace changes priority of a ctx/entity then driver can switch to corresponding hw shced list for that priority

---
  drivers/gpu/drm/scheduler/sched_entity.c | 24 ++++++++++++++++++++++++
  include/drm/gpu_scheduler.h              |  4 ++++
  2 files changed, 28 insertions(+)
drivers/gpu/drm/scheduler/sched_entity.c +9 -0
index 63bccd201b97..711e9d504bcb 100644
@@ -83,6 +83,30 @@ int drm_sched_entity_init(struct drm_sched_entity *entity,
  }
  EXPORT_SYMBOL(drm_sched_entity_init);
 
+/**
+ * drm_sched_entity_modify_sched - Modify sched of an entity
+ *
+ * @entity: scheduler entity to init
+ * @sched_list: the list of new drm scheds which will replace
+ *		existing entity->sched_list
+ * @num_sched_list: number of drm sched in sched_list
+ *
+ * Returns 0 on success or a negative error code on failure.
Quoted 8 lines

drivers/gpu/drm/scheduler/sched_entity.c int drm_sched_entity_init(struct drm_sched_entity *entity, · line 101

Quoted 7 lines
drivers/gpu/drm/scheduler/sched_entity.c +7 -0
+ */
+int drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
+				  struct drm_gpu_scheduler **sched_list,
+				  unsigned int num_sched_list)
+{
+	if (!(entity && sched_list && (num_sched_list == 0 || sched_list[0])))
+		return -EINVAL;

This seems unmaintainable. I'd write it in its natural form:

This is probably just copy & pasted from the init function and complete overkill here.

Quoted 4 lines

int drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
struct drm_gpu_scheduler **sched_list, unsigned int num_sched_list)

Quoted 9 lines
{
	if (entity && sched_list && (num_sched_list == 0 || sched_list[0] != NULL)) {
		entity->sched_list = num_sched_list > 1 ? sched_list : NULL;
		entity->num_sched_list = num_sched_list;
		return 0;
	} else {
		return -EINVAL;
	}
}

Actually that's a rather bad idea. Error handling should always be in the form of:

if (check_error || missing_prerequisite)
    return_or_goto_cleanup;

Quoted 25 lines

That's too heavy. Can we improve the architecture
so we don't have to check for this in leaf functions like this one? We can just return a parameterization.

Why would this be called with entity being NULL?
Or with sched_list being NULL? Or num_sched_list being not zero yet sched_list[0] being NULL? Why not make sure that sched_list[0] is never NULL and that num_sched_list is greater than 0 always?

Does this make it to user space?
Why would the state of execution be one such that this is true/false
for the code to return -EINVAL?
From patch 3/4 it seems that an error is printed inside amdgpu_ctx_priority_override()
and the result is not propagated up the stack.

I think we should improve the code where here this condition above is never true. Then we can use parameterization for those two statements below:

drivers/gpu/drm/scheduler/sched_entity.c int drm_sched_entity_init(struct drm_sched_entity *entity, · line 103

Quoted 2 lines
drivers/gpu/drm/scheduler/sched_entity.c +2 -0
+
+	entity->sched_list = num_sched_list > 1 ? sched_list : NULL;

So if we're here, we know from the top conditional that either num_sched_list is 0 or that sched_list[0] not NULL or both.

Quoted 3 lines

So if num_sched_list is 0 or 1 we return NULL? And if num_sched_list is 2 or greater we return sched_list of which sched_list[0] could be NULL?

This is also copy&pasted from the init code and completely wrong here.

What we should do instead is just: WARN_ON(!num_sched_list || !sched_list);

And to the checking for not keeping around the scheduler list in the init function.

Quoted 1 line

Why not fix the architecture so that this is simply copied?

We had that and moved away from it because the scheduler list is actually const and shouldn't be allocated with each entity (which we can easily have thousands of).

Regards,
Christian.

Quoted 30 lines

(in which case
we can simply index-parameterize it and simply copy it. Why are there so many checks everywhere?

drivers/gpu/drm/scheduler/sched_entity.c int drm_sched_entity_init(struct drm_sched_entity *entity, · line 105

Quoted 2 lines
drivers/gpu/drm/scheduler/sched_entity.c +2 -0
+	entity->num_sched_list = num_sched_list;
+

I mean, all we're doing in this function is initializing entity->sched_list and entity->num_sched_list. Why does this function have to be so complex and do so many checks? Can we improve/fix the architecture instead?

Regards,
Luben

Quoted 15 lines
drivers/gpu/drm/scheduler/sched_entity.c +4 -0
+	return 0;
+}
+EXPORT_SYMBOL(drm_sched_entity_modify_sched);
+
  /**
   * drm_sched_entity_is_idle - Check if entity is idle
   *
include/drm/gpu_scheduler.h +0 -0
index 589be851f8a1..0c164a96d51b 100644
@@ -297,6 +297,10 @@ void drm_sched_fini(struct drm_gpu_scheduler *sched);
  int drm_sched_job_init(struct drm_sched_job *job,
  		       struct drm_sched_entity *entity,
  		       void *owner);
Quoted 8 lines

include/drm/gpu_scheduler.h void drm_sched_fini(struct drm_gpu_scheduler *sched); · line 306

Quoted 8 lines
include/drm/gpu_scheduler.h +4 -0
+int drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
+				  struct drm_gpu_scheduler **sched_list,
+                                  unsigned int num_sched_list);
+
  void drm_sched_job_cleanup(struct drm_sched_job *job);
  void drm_sched_wakeup(struct drm_gpu_scheduler *sched);
  void drm_sched_stop(struct drm_gpu_scheduler *sched, struct drm_sched_job *bad);

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

#4 lore raw

Re: [RFC PATCH 2/4] drm/scheduler: implement a function to modify sched list

Quoted 41 lines · Christian König

Am 28.02.20 um 06:08 schrieb Luben Tuikov:

Quoted 31 lines · Nirmoy Das
Quoted 30 lines

implement drm_sched_entity_modify_sched() which can modify existing sched_list with a different one. This is going to be helpful when userspace changes priority of a ctx/entity then driver can switch to corresponding hw shced list for that priority

---
  drivers/gpu/drm/scheduler/sched_entity.c | 24
++++++++++++++++++++++++
  include/drm/gpu_scheduler.h              |  4 ++++

  2 files changed, 28 insertions(+)
drivers/gpu/drm/scheduler/sched_entity.c +0 -0
index 63bccd201b97..711e9d504bcb 100644
@@ -83,6 +83,30 @@ int drm_sched_entity_init(struct drm_sched_entity 
 *entity,
   }
   EXPORT_SYMBOL(drm_sched_entity_init);

  +/**
+ * drm_sched_entity_modify_sched - Modify sched of an entity
+ *
+ * @entity: scheduler entity to init
+ * @sched_list: the list of new drm scheds which will replace
+ *        existing entity->sched_list
+ * @num_sched_list: number of drm sched in sched_list
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */

Quoted 8 lines
Quoted 7 lines
drivers/gpu/drm/scheduler/sched_entity.c +5 -0
+int drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
+                  struct drm_gpu_scheduler **sched_list,
+                  unsigned int num_sched_list)
+{
+    if (!(entity && sched_list && (num_sched_list == 0 || 

sched_list[0])))
+        return -EINVAL;

This seems unmaintainable. I'd write it in its natural form:

Quoted 1 line

This is probably just copy & pasted from the init function and complete overkill here.

Was indeed lame copy paste from my side.

Quoted 9 lines
Quoted 5 lines

So if num_sched_list is 0 or 1 we return NULL? And if num_sched_list is 2 or greater we return sched_list of which sched_list[0] could be NULL?

This is also copy&pasted from the init code and completely wrong here.

What we should do instead is just: WARN_ON(!num_sched_list || !sched_list);

Thanks, this will make it much simple. I will have this in next version.

Nirmoy

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

#5 lore raw

Re: [RFC PATCH 2/4] drm/scheduler: implement a function to modify sched list

In reply to Christian König
Quoted 39 lines · Christian König

Am 28.02.20 um 06:08 schrieb Luben Tuikov:

Quoted 29 lines · Nirmoy Das
Quoted 28 lines

implement drm_sched_entity_modify_sched() which can modify existing sched_list with a different one. This is going to be helpful when userspace changes priority of a ctx/entity then driver can switch to corresponding hw shced list for that priority

---
  drivers/gpu/drm/scheduler/sched_entity.c | 24 ++++++++++++++++++++++++
  include/drm/gpu_scheduler.h              |  4 ++++
  2 files changed, 28 insertions(+)
drivers/gpu/drm/scheduler/sched_entity.c +9 -0
index 63bccd201b97..711e9d504bcb 100644
@@ -83,6 +83,30 @@ int drm_sched_entity_init(struct drm_sched_entity *entity,
  }
  EXPORT_SYMBOL(drm_sched_entity_init);
 
+/**
+ * drm_sched_entity_modify_sched - Modify sched of an entity
+ *
+ * @entity: scheduler entity to init
+ * @sched_list: the list of new drm scheds which will replace
+ *		existing entity->sched_list
+ * @num_sched_list: number of drm sched in sched_list
+ *
+ * Returns 0 on success or a negative error code on failure.
Quoted 8 lines

drivers/gpu/drm/scheduler/sched_entity.c int drm_sched_entity_init(struct drm_sched_entity *entity, · line 101

Quoted 7 lines
drivers/gpu/drm/scheduler/sched_entity.c +7 -0
+ */
+int drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
+				  struct drm_gpu_scheduler **sched_list,
+				  unsigned int num_sched_list)
+{
+	if (!(entity && sched_list && (num_sched_list == 0 || sched_list[0])))
+		return -EINVAL;

This seems unmaintainable. I'd write it in its natural form:

Quoted 2 lines

This is probably just copy & pasted from the init function and complete overkill here.

It should be an easy rejection then. Statements like this make the code unmaintainable. Regardless of whether it was copy-and-pasted I wanted to emphasize the lack of simplification of what was being done.

We need to put intention and sense into what we're doing, scrutinizing every line we put into a patch. This is why I suggested
the simplification here:

Quoted 15 lines
Quoted 5 lines

int drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
struct drm_gpu_scheduler **sched_list, unsigned int num_sched_list)

Quoted 9 lines
{
	if (entity && sched_list && (num_sched_list == 0 || sched_list[0] != NULL)) {
		entity->sched_list = num_sched_list > 1 ? sched_list : NULL;
		entity->num_sched_list = num_sched_list;
		return 0;
	} else {
		return -EINVAL;
	}
}
Quoted 1 line

Actually that's a rather bad idea. Error handling should always be in

I actually don't think that it is a "rather bad idea". At all. I actually think that it makes this leaf function more clear to understand as the conditional would read like a sentence in prose.

Quoted 4 lines

the form of:

if (check_error || missing_prerequisite)
    return_or_goto_cleanup;

I don't think we should generalize across the board. We should be more flexible in order to create clear and maintainable code.

Quoted 26 lines
Quoted 26 lines

That's too heavy. Can we improve the architecture
so we don't have to check for this in leaf functions like this one? We can just return a parameterization.

Why would this be called with entity being NULL?
Or with sched_list being NULL? Or num_sched_list being not zero yet sched_list[0] being NULL? Why not make sure that sched_list[0] is never NULL and that num_sched_list is greater than 0 always?

Does this make it to user space?
Why would the state of execution be one such that this is true/false
for the code to return -EINVAL?
From patch 3/4 it seems that an error is printed inside amdgpu_ctx_priority_override()
and the result is not propagated up the stack.

I think we should improve the code where here this condition above is never true. Then we can use parameterization for those two statements below:

drivers/gpu/drm/scheduler/sched_entity.c int drm_sched_entity_init(struct drm_sched_entity *entity, · line 103

Quoted 2 lines
drivers/gpu/drm/scheduler/sched_entity.c +2 -0
+
+	entity->sched_list = num_sched_list > 1 ? sched_list : NULL;

So if we're here, we know from the top conditional that either num_sched_list is 0 or that sched_list[0] not NULL or both.

Quoted 5 lines
Quoted 3 lines

So if num_sched_list is 0 or 1 we return NULL? And if num_sched_list is 2 or greater we return sched_list of which sched_list[0] could be NULL?

This is also copy&pasted from the init code and completely wrong here.

So even more reasons to reject this patch.

Quoted 2 lines

What we should do instead is just: WARN_ON(!num_sched_list || !sched_list);

Again, what does that *mean*? What does the check mean and what does the num_sched_list == 0 or sched_list == NULL mean? And how did we get into a situation like this where either or both could be nil?

Wouldn't it be better to simplify or re-architecture this (we only recently decided to hide physical rings from user-space), so that the code is elegant (meaning no if-else) yet flexible and straightforward?

Quoted 9 lines

And to the checking for not keeping around the scheduler list in the init function.

Quoted 1 line

Why not fix the architecture so that this is simply copied?

We had that and moved away from it because the scheduler list is actually const and shouldn't be allocated with each entity (which we can easily have thousands of).

I think that peppering the code with if-else conditionals everywhere as these patch-series into the DRM scheduler have been, would make the code unmaintainable in the long run.

Regards,
Luben

Quoted 34 lines

Regards,
Christian.

Quoted 30 lines

(in which case
we can simply index-parameterize it and simply copy it. Why are there so many checks everywhere?

drivers/gpu/drm/scheduler/sched_entity.c int drm_sched_entity_init(struct drm_sched_entity *entity, · line 105

Quoted 2 lines
drivers/gpu/drm/scheduler/sched_entity.c +2 -0
+	entity->num_sched_list = num_sched_list;
+

I mean, all we're doing in this function is initializing entity->sched_list and entity->num_sched_list. Why does this function have to be so complex and do so many checks? Can we improve/fix the architecture instead?

Regards,
Luben

Quoted 15 lines
drivers/gpu/drm/scheduler/sched_entity.c +4 -0
+	return 0;
+}
+EXPORT_SYMBOL(drm_sched_entity_modify_sched);
+
  /**
   * drm_sched_entity_is_idle - Check if entity is idle
   *
include/drm/gpu_scheduler.h +0 -0
index 589be851f8a1..0c164a96d51b 100644
@@ -297,6 +297,10 @@ void drm_sched_fini(struct drm_gpu_scheduler *sched);
  int drm_sched_job_init(struct drm_sched_job *job,
  		       struct drm_sched_entity *entity,
  		       void *owner);
Quoted 9 lines
Quoted 8 lines

include/drm/gpu_scheduler.h void drm_sched_fini(struct drm_gpu_scheduler *sched); · line 306

Quoted 8 lines
include/drm/gpu_scheduler.h +4 -0
+int drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
+				  struct drm_gpu_scheduler **sched_list,
+                                  unsigned int num_sched_list);
+
  void drm_sched_job_cleanup(struct drm_sched_job *job);
  void drm_sched_wakeup(struct drm_gpu_scheduler *sched);
  void drm_sched_stop(struct drm_gpu_scheduler *sched, struct drm_sched_job *bad);

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

maintainer
#6 lore raw

Re: [RFC PATCH 2/4] drm/scheduler: implement a function to modify sched list

Am 02.03.20 um 21:47 schrieb Luben Tuikov:

Quoted 7 lines · Christian König
Quoted 6 lines

Am 28.02.20 um 06:08 schrieb Luben Tuikov:

Quoted 5 lines · Nirmoy Das

drivers/gpu/drm/scheduler/sched_entity.c int drm_sched_entity_init(struct drm_sched_entity *entity, · line 101

Quoted 3 lines

[SNIP]

drivers/gpu/drm/scheduler/sched_entity.c +2 -0
+	if (!(entity && sched_list && (num_sched_list == 0 || sched_list[0])))
+		return -EINVAL;

This seems unmaintainable. I'd write it in its natural form:

Quoted 6 lines
Quoted 2 lines

This is probably just copy & pasted from the init function and complete overkill here.

It should be an easy rejection then. Statements like this make the code unmaintainable. Regardless of whether it was copy-and-pasted I wanted to emphasize the lack of simplification of what was being done.

The problem is even deeper. As you noticed as well this is checking for in kernel coding error and not application errors.

That check shouldn't have been in the init function in the first place, but nobody had time to look into that so far.

Quoted 16 lines

We need to put intention and sense into what we're doing, scrutinizing every line we put into a patch. This is why I suggested
the simplification here:

Quoted 12 lines
Quoted 12 lines

int drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
struct drm_gpu_scheduler **sched_list, unsigned int num_sched_list)

{
	if (entity && sched_list && (num_sched_list == 0 || sched_list[0] != NULL)) {
		entity->sched_list = num_sched_list > 1 ? sched_list : NULL;
		entity->num_sched_list = num_sched_list;
		return 0;
	} else {
		return -EINVAL;
	}
}
Quoted 4 lines
Quoted 1 line

Actually that's a rather bad idea. Error handling should always be in

I actually don't think that it is a "rather bad idea". At all. I actually think that it makes this leaf function more clear to understand as the conditional would read like a sentence in prose.

The condition is indeed easier to read, but for the sacrifice of earlier return and keeping prerequisite checking out of the code.

Quoted 6 lines

[SNIP]

Quoted 1 line

What we should do instead is just: WARN_ON(!num_sched_list || !sched_list);

Again, what does that *mean*? What does the check mean and what does the num_sched_list == 0 or sched_list == NULL mean? And how did we get into a situation like this where either or both could be nil?

It's an in kernel coding error to do this. The caller should at least always provide a list with some entries in it.

A WARN_ON() is appropriate since it helps to narrows down the incorrect behavior following from that.

Quoted 3 lines

Wouldn't it be better to simplify or re-architecture this (we only recently decided to hide physical rings from user-space), so that the code is elegant (meaning no if-else) yet flexible and straightforward?

That was not recently at all, hiding physical rings was done nearly 5 years ago shortly after the driver was initially released.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Why not fix the architecture so that this is simply copied?

We had that and moved away from it because the scheduler list is actually const and shouldn't be allocated with each entity (which we can easily have thousands of).

I think that peppering the code with if-else conditionals everywhere as these patch-series into the DRM scheduler have been, would make the code unmaintainable in the long run.

That's something I can agree on. Using a switch to map the priority to the backend implementation seems like the best idea to me.

E.g. function amdgpu_to_sched_priority() should not only map the IOCTL values to the scheduler values, but also return the array which hw rings to use.

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

#7 lore raw

Re: [RFC PATCH 2/4] drm/scheduler: implement a function to modify sched list

Quoted 10 lines · Christian König

Am 02.03.20 um 21:47 schrieb Luben Tuikov:

Quoted 9 lines · Christian König
Quoted 8 lines

Am 28.02.20 um 06:08 schrieb Luben Tuikov:

Quoted 5 lines · Nirmoy Das

drivers/gpu/drm/scheduler/sched_entity.c int drm_sched_entity_init(struct drm_sched_entity *entity, · line 101

Quoted 3 lines

[SNIP]

drivers/gpu/drm/scheduler/sched_entity.c +2 -0
+	if (!(entity && sched_list && (num_sched_list == 0 || sched_list[0])))
+		return -EINVAL;

This seems unmaintainable. I'd write it in its natural form:

This is probably just copy & pasted from the init function and complete overkill here.

Quoted 7 lines
Quoted 4 lines

It should be an easy rejection then. Statements like this make the code unmaintainable. Regardless of whether it was copy-and-pasted I wanted to emphasize the lack of simplification of what was being done.

The problem is even deeper. As you noticed as well this is checking for in kernel coding error and not application errors.

We shouldn't check the in-kernel implementation itself. If the kernel did this everywhere, it'd be twice the size. The kernel shouldn't be second-guessing itself.

Another way to see this is to ask "what would the kernel do here if XYZ was NULL", for instance? For userspace, it's clear. For the kernel, it shows inconsistent and incomplete implmentation--something which should be fixed.

Another way of seeing this is, if you break out a function into separate smaller functions, checking the input parameters in those leaf/helper functions (code which had been part of the original big function), would make the code larger and second-guessing itself.

That check shouldn't be there. The implementation should be consistent and complete in order to show an elegant code.

Quoted 20 lines

That check shouldn't have been in the init function in the first place, but nobody had time to look into that so far.

Quoted 16 lines

We need to put intention and sense into what we're doing, scrutinizing every line we put into a patch. This is why I suggested
the simplification here:

Quoted 12 lines
Quoted 12 lines

int drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
struct drm_gpu_scheduler **sched_list, unsigned int num_sched_list)

{
	if (entity && sched_list && (num_sched_list == 0 || sched_list[0] != NULL)) {
		entity->sched_list = num_sched_list > 1 ? sched_list : NULL;
		entity->num_sched_list = num_sched_list;
		return 0;
	} else {
		return -EINVAL;
	}
}
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Actually that's a rather bad idea. Error handling should always be in

I actually don't think that it is a "rather bad idea". At all. I actually think that it makes this leaf function more clear to understand as the conditional would read like a sentence in prose.

The condition is indeed easier to read, but for the sacrifice of earlier return and keeping prerequisite checking out of the code.

You know the compiler can reorder such code and invert this simple-for-the-compiler conditional. It is easier for human readers who might need to maintain it.

For instance, when you asked "Do you guys remember why we might not have a job here?" for amdgpu_ib_schedule() in a recent email--if that code had been split into code for test purposes and real IB processing code, then that question wouldn't even be on the table.

We need to achieve a balance of breaking out code and if-else statements. At the moment the code show everything bunched up into a single function and a ton of if-else statements, with the pretense "to avoid duplication". Such duplication can be avoided architecturally by redefining structures, what's in them, and what arguments functions take.

Quoted 25 lines
Quoted 7 lines

[SNIP]

Quoted 1 line

What we should do instead is just: WARN_ON(!num_sched_list || !sched_list);

Again, what does that *mean*? What does the check mean and what does the num_sched_list == 0 or sched_list == NULL mean? And how did we get into a situation like this where either or both could be nil?

It's an in kernel coding error to do this. The caller should at least always provide a list with some entries in it.

A WARN_ON() is appropriate since it helps to narrows down the incorrect behavior following from that.

Quoted 3 lines

Wouldn't it be better to simplify or re-architecture this (we only recently decided to hide physical rings from user-space), so that the code is elegant (meaning no if-else) yet flexible and straightforward?

That was not recently at all, hiding physical rings was done nearly 5 years ago shortly after the driver was initially released.

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

Why not fix the architecture so that this is simply copied?

We had that and moved away from it because the scheduler list is actually const and shouldn't be allocated with each entity (which we can easily have thousands of).

Quoted 6 lines
Quoted 3 lines

I think that peppering the code with if-else conditionals everywhere as these patch-series into the DRM scheduler have been, would make the code unmaintainable in the long run.

That's something I can agree on. Using a switch to map the priority to the backend implementation seems like the best idea to me.

Do you mean you don't agree with anything I write? (If you have to make a point of it here that *that* is something you can agree on?

I'd say, even a function is too heavy. A straightforward map should be used, no function call, no switch (if-else in disguise), just a map for instant lookup.

Regards,
Luben

Quoted 8 lines

E.g. function amdgpu_to_sched_priority() should not only map the IOCTL values to the scheduler values, but also return the array which hw rings to use.

Regards,
Christian.

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

author
#8 lore raw

RFC PATCH 3/4 drm/amdgpu: change hw sched list on ctx priority override

In reply to Nirmoy Das

Switch to appropriate sched list for an entity on priority override.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 54 ++++++++++++++++++++++++-
 1 file changed, 53 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +53 -1
index a1742b1d4f9c..69a791430b25 100644
@@ -508,11 +508,53 @@ struct dma_fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
 	return fence;
 }
 
+static int amdgpu_ctx_change_sched(struct amdgpu_ctx *ctx,
+				   struct amdgpu_ctx_entity *aentity,
+				   int hw_ip, enum drm_sched_priority priority)
+{
+	struct amdgpu_device *adev = ctx->adev;
+	struct drm_gpu_scheduler **scheds = NULL;
+	unsigned num_scheds = 0;
+
+	switch (hw_ip) {
+		case AMDGPU_HW_IP_COMPUTE:
+			if (priority > DRM_SCHED_PRIORITY_NORMAL &&
+			    adev->gfx.num_compute_sched_high) {
+				scheds = adev->gfx.compute_sched_high;
+				num_scheds = adev->gfx.num_compute_sched_high;
+			} else {
+				scheds = adev->gfx.compute_sched;
+				num_scheds = adev->gfx.num_compute_sched;
+			}
+			break;
+		default:
+			return 0;
+	}
+
+	return drm_sched_entity_modify_sched(&aentity->entity, scheds, num_scheds);
+}
+
+static int amdgpu_ctx_hw_priority_override(struct amdgpu_ctx *ctx,
+					    const u32 hw_ip,
+					    enum drm_sched_priority priority)
+{
+	int r = 0, i;
+
+	for (i = 0; i < amdgpu_ctx_num_entities[hw_ip]; ++i) {
+		if (!ctx->entities[hw_ip][i])
+			continue;
+		r = amdgpu_ctx_change_sched(ctx, ctx->entities[hw_ip][i],
+					    hw_ip, priority);
+	}
+
+	return r;
+}
+
 void amdgpu_ctx_priority_override(struct amdgpu_ctx *ctx,
 				  enum drm_sched_priority priority)
 {
 	enum drm_sched_priority ctx_prio;
-	unsigned i, j;
+	unsigned r, i, j;
 
 	ctx->override_priority = priority;
 
@@ -521,11 +563,21 @@ void amdgpu_ctx_priority_override(struct amdgpu_ctx *ctx,
 	for (i = 0; i < AMDGPU_HW_IP_NUM; ++i) {
 		for (j = 0; j < amdgpu_ctx_num_entities[i]; ++j) {
 			struct drm_sched_entity *entity;
+			struct amdgpu_ring *ring;
 
 			if (!ctx->entities[i][j])
 				continue;
 
 			entity = &ctx->entities[i][j]->entity;
+			ring = to_amdgpu_ring(entity->rq->sched);
+
+			if (ring->high_priority) {
+				r = amdgpu_ctx_hw_priority_override(ctx, i,
+								    ctx_prio);
+				if (r)
+					DRM_ERROR("Failed to override HW priority for %s",
+						  ring->name);
+			}
 			drm_sched_entity_set_priority(entity, ctx_prio);
 		}
 	}
Signature · 6 lines
2.25.0

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

Re: [RFC PATCH 3/4] drm/amdgpu: change hw sched list on ctx priority override

Quoted 15 lines · Nirmoy Das

Switch to appropriate sched list for an entity on priority override.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 54 ++++++++++++++++++++++++-
 1 file changed, 53 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0 -0
index a1742b1d4f9c..69a791430b25 100644
@@ -508,11 +508,53 @@ struct dma_fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
 	return fence;
 }
 

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c struct dma_fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx, · line 520

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +10 -0
+static int amdgpu_ctx_change_sched(struct amdgpu_ctx *ctx,
+				   struct amdgpu_ctx_entity *aentity,
+				   int hw_ip, enum drm_sched_priority priority)
+{
+	struct amdgpu_device *adev = ctx->adev;
+	struct drm_gpu_scheduler **scheds = NULL;
+	unsigned num_scheds = 0;
+
+	switch (hw_ip) {
+		case AMDGPU_HW_IP_COMPUTE:

NAK. Don't indent the "case".

LKCS says that "case" must not be indented:
https://www.kernel.org/doc/html/v4.10/process/coding-style.html#indentation

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c struct dma_fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx, · line 528

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +8 -0
+			if (priority > DRM_SCHED_PRIORITY_NORMAL &&
+			    adev->gfx.num_compute_sched_high) {
+				scheds = adev->gfx.compute_sched_high;
+				num_scheds = adev->gfx.num_compute_sched_high;
+			} else {
+				scheds = adev->gfx.compute_sched;
+				num_scheds = adev->gfx.num_compute_sched;
+			}

I feel that this is a regression in that we're having an if-conditional inside a switch-case. Could use just use maps to execute without any branching?

Surely priority could be used as an index into a map of DRM_SCHED_PRIORITY_MAX to find out which scheduler to use and the number thereof.

Quoted 44 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +25 -1
+			break;
+		default:
+			return 0;
+	}
 
 
+
+	return drm_sched_entity_modify_sched(&aentity->entity, scheds, num_scheds);
+}
+
+static int amdgpu_ctx_hw_priority_override(struct amdgpu_ctx *ctx,
+					    const u32 hw_ip,
+					    enum drm_sched_priority priority)
+{
+	int r = 0, i;
+
+	for (i = 0; i < amdgpu_ctx_num_entities[hw_ip]; ++i) {
+		if (!ctx->entities[hw_ip][i])
+			continue;
+		r = amdgpu_ctx_change_sched(ctx, ctx->entities[hw_ip][i],
+					    hw_ip, priority);
+	}
+
+	return r;
+}
+
 void amdgpu_ctx_priority_override(struct amdgpu_ctx *ctx,
 				  enum drm_sched_priority priority)
 {
 	enum drm_sched_priority ctx_prio;
-	unsigned i, j;
+	unsigned r, i, j;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +1 -0
 	ctx->override_priority = priority;
@@ -521,11 +563,21 @@ void amdgpu_ctx_priority_override(struct amdgpu_ctx *ctx,
 	for (i = 0; i < AMDGPU_HW_IP_NUM; ++i) {
 		for (j = 0; j < amdgpu_ctx_num_entities[i]; ++j) {
 			struct drm_sched_entity *entity;
+			struct amdgpu_ring *ring;
 
 			if (!ctx->entities[i][j])
 				continue;
 

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c void amdgpu_ctx_priority_override(struct amdgpu_ctx *ctx, · line 580

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +9 -0
 			entity = &ctx->entities[i][j]->entity;
+			ring = to_amdgpu_ring(entity->rq->sched);
+
+			if (ring->high_priority) {
+				r = amdgpu_ctx_hw_priority_override(ctx, i,
+								    ctx_prio);
+				if (r)
+					DRM_ERROR("Failed to override HW priority for %s",
+						  ring->name);
+			}

I can't see this an an improvement when we add branching inside a for-loop. Perhaps if we remove if-conditionals and use indexing to eliminate branching?

Regards,
Luben

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c void amdgpu_ctx_priority_override(struct amdgpu_ctx *ctx, · line 583

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0 -0
 			drm_sched_entity_set_priority(entity, ctx_prio);
 		}
 	}

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

author
#10 lore raw

RFC PATCH 4/4 drm/amdgpu: remove unused functions

In reply to Nirmoy Das

amdgpu statically set priority for compute queues at initialization so remove all the functions responsible changing compute queue priority dynamically

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c |  70 ----------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h |   7 --
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c    |  99 ----------------------
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 100 -----------------------
 4 files changed, 276 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0 -70
index 18e11b0fdc3e..4d603ee72b8c 100644
@@ -150,76 +150,6 @@ void amdgpu_ring_undo(struct amdgpu_ring *ring)
 		ring->funcs->end_use(ring);
 }
 
-/**
- * amdgpu_ring_priority_put - restore a ring's priority
- *
- * @ring: amdgpu_ring structure holding the information
- * @priority: target priority
- *
- * Release a request for executing at @priority
- */
-void amdgpu_ring_priority_put(struct amdgpu_ring *ring,
-			      enum drm_sched_priority priority)
-{
-	int i;
-
-	if (!ring->funcs->set_priority)
-		return;
-
-	if (atomic_dec_return(&ring->num_jobs[priority]) > 0)
-		return;
-
-	/* no need to restore if the job is already at the lowest priority */
-	if (priority == DRM_SCHED_PRIORITY_NORMAL)
-		return;
-
-	mutex_lock(&ring->priority_mutex);
-	/* something higher prio is executing, no need to decay */
-	if (ring->priority > priority)
-		goto out_unlock;
-
-	/* decay priority to the next level with a job available */
-	for (i = priority; i >= DRM_SCHED_PRIORITY_MIN; i--) {
-		if (i == DRM_SCHED_PRIORITY_NORMAL
-				|| atomic_read(&ring->num_jobs[i])) {
-			ring->priority = i;
-			ring->funcs->set_priority(ring, i);
-			break;
-		}
-	}
-
-out_unlock:
-	mutex_unlock(&ring->priority_mutex);
-}
-
-/**
- * amdgpu_ring_priority_get - change the ring's priority
- *
- * @ring: amdgpu_ring structure holding the information
- * @priority: target priority
- *
- * Request a ring's priority to be raised to @priority (refcounted).
- */
-void amdgpu_ring_priority_get(struct amdgpu_ring *ring,
-			      enum drm_sched_priority priority)
-{
-	if (!ring->funcs->set_priority)
-		return;
-
-	if (atomic_inc_return(&ring->num_jobs[priority]) <= 0)
-		return;
-
-	mutex_lock(&ring->priority_mutex);
-	if (priority <= ring->priority)
-		goto out_unlock;
-
-	ring->priority = priority;
-	ring->funcs->set_priority(ring, priority);
-
-out_unlock:
-	mutex_unlock(&ring->priority_mutex);
-}
-
 /**
  * amdgpu_ring_init - init driver ring struct.
  *
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +0 -7
index 34fcd467f18d..87ec35b68bfd 100644
@@ -167,9 +167,6 @@ struct amdgpu_ring_funcs {
 					uint32_t reg0, uint32_t reg1,
 					uint32_t ref, uint32_t mask);
 	void (*emit_tmz)(struct amdgpu_ring *ring, bool start);
-	/* priority functions */
-	void (*set_priority) (struct amdgpu_ring *ring,
-			      enum drm_sched_priority priority);
 	/* Try to soft recover the ring to make the fence signal */
 	void (*soft_recovery)(struct amdgpu_ring *ring, unsigned vmid);
 	int (*preempt_ib)(struct amdgpu_ring *ring);
@@ -259,10 +256,6 @@ void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count);
 void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
 void amdgpu_ring_commit(struct amdgpu_ring *ring);
 void amdgpu_ring_undo(struct amdgpu_ring *ring);
-void amdgpu_ring_priority_get(struct amdgpu_ring *ring,
-			      enum drm_sched_priority priority);
-void amdgpu_ring_priority_put(struct amdgpu_ring *ring,
-			      enum drm_sched_priority priority);
 int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
 		     unsigned ring_size, struct amdgpu_irq_src *irq_src,
 		     unsigned irq_type);
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +0 -99

111 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +0 -100

112 lines not on this page · raw message

Signature · 6 lines
2.25.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#11 lore raw
In reply to Nirmoy Das
Quoted 6 lines · Nirmoy Das

We were changing compute ring priority while rings were being used before every job submission which is not recommended. This patch sets compute queue priority at mqd initialization for gfx8 and gfx9.

Policy: Enable high priority compute queues only if gpu has >1 MEC, if so PIPE0 and PIPE1 will be in high priority.

s/PIPE0 and PIPE1 will be in high priority/ 1st queue of each pipe will set to high priority
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#12 lore raw
In reply to Nirmoy Das
Quoted 7 lines · Nirmoy Das

We were changing compute ring priority while rings were being used before every job submission which is not recommended. This patch sets compute queue priority at mqd initialization for gfx8 and gfx9.

Policy: Enable high priority compute queues only if gpu has >1 MEC, if so PIPE0 and PIPE1 will be in high priority.

I think we still want high priority queues on even when there is only one MEC. It might work better on multi-MEC chips, but it should still work on single MEC chips.

Quoted 195 lines

high/normal priority compute sched list are generated from set of high/normal priority compute queues. At context creation, entity of compute queue get a sched list from high or normal priority depending on ctx->priority

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c   |  4 ----
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c  | 19 +++++++++++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c  | 14 ++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h  | 12 ++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c  |  6 ------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h |  1 +
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c    | 23 ++++++++++++++++++++---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 20 ++++++++++++++++++++
 8 files changed, 82 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -4
index f397ff97b4e4..8304d0c87899 100644
@@ -1205,7 +1205,6 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
        struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
        struct drm_sched_entity *entity = p->entity;
        enum drm_sched_priority priority;
-       struct amdgpu_ring *ring;
        struct amdgpu_bo_list_entry *e;
        struct amdgpu_job *job;
        uint64_t seq;
@@ -1258,9 +1257,6 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
        priority = job->base.s_priority;
        drm_sched_entity_push_job(&job->base, entity);
 
-       ring = to_amdgpu_ring(entity->rq->sched);
-       amdgpu_ring_priority_get(ring, priority);
-
        amdgpu_vm_move_to_lru_tail(p->adev, &fpriv->vm);
 
        ttm_eu_fence_buffer_objects(&p->ticket, &p->validated, p->fence);
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +15 -4
index 94a6c42f29ea..a1742b1d4f9c 100644
@@ -85,8 +85,14 @@ static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, const u32 hw_ip, const
                        num_scheds = 1;
                        break;
                case AMDGPU_HW_IP_COMPUTE:
-                       scheds = adev->gfx.compute_sched;
-                       num_scheds = adev->gfx.num_compute_sched;
+                       if (priority > DRM_SCHED_PRIORITY_NORMAL &&
+                           adev->gfx.num_compute_sched_high) {
+                               scheds = adev->gfx.compute_sched_high;
+                               num_scheds = adev->gfx.num_compute_sched_high;
+                       } else {
+                               scheds = adev->gfx.compute_sched;
+                               num_scheds = adev->gfx.num_compute_sched;
+                       }
                        break;
                case AMDGPU_HW_IP_DMA:
                        scheds = adev->sdma.sdma_sched;
@@ -638,8 +644,13 @@ void amdgpu_ctx_init_sched(struct amdgpu_device *adev)
        }
 
        for (i = 0; i < adev->gfx.num_compute_rings; i++) {
-               adev->gfx.compute_sched[i] = &adev->gfx.compute_ring[i].sched;
-               adev->gfx.num_compute_sched++;
+               if (!adev->gfx.compute_ring[i].high_priority) {
+                       adev->gfx.compute_sched[adev->gfx.num_compute_sched++] =
+                               &adev->gfx.compute_ring[i].sched;
+               } else {
+                       adev->gfx.compute_sched_high[adev->gfx.num_compute_sched_high++] =
+                               &adev->gfx.compute_ring[i].sched;
+               }
        }
 
        for (i = 0; i < adev->sdma.num_instances; i++) {
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +14 -0
index 7403588684b3..bdea5d44edf4 100644
@@ -192,6 +192,20 @@ static bool amdgpu_gfx_is_multipipe_capable(struct amdgpu_device *adev)
        return adev->gfx.mec.num_mec > 1;
 }
 
+bool amdgpu_gfx_is_high_priority_compute_queue(struct amdgpu_device *adev,
+                                              int queue)
+{
+       bool multipipe_policy = amdgpu_gfx_is_multipipe_capable(adev);
+
+       /* only enable high priority queue if more than 1 MEC.
+        * When multipipe_policy is true amdgpu gets queue 0,1 from each pipe of
+        * 1st MEC. Policy: make queue 0 of each pipe as high priority compute queue */
+       if (multipipe_policy && queue == 0)
+               return true;
+
+       return false;
+}
+
 void amdgpu_gfx_compute_queue_acquire(struct amdgpu_device *adev)
 {
        int i, queue, pipe, mec;
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +12 -0
index 37ba05b63b2a..13ee0ea66c6f 100644
@@ -41,6 +41,14 @@
 #define AMDGPU_MAX_GFX_QUEUES KGD_MAX_QUEUES
 #define AMDGPU_MAX_COMPUTE_QUEUES KGD_MAX_QUEUES
 
+#define AMDGPU_GFX_PIPE_PRIO_LOW    0
+#define AMDGPU_GFX_PIPE_PRIO_NORMAL 1
+#define AMDGPU_GFX_PIPE_PRIO_HIGH   2
+
+#define AMDGPU_GFX_QUEUE_PRIORITY_MINIMUM  0
+#define AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM  15
+
+
 struct amdgpu_mec {
        struct amdgpu_bo        *hpd_eop_obj;
        u64                     hpd_eop_gpu_addr;
@@ -281,7 +289,9 @@ struct amdgpu_gfx {
        unsigned                        num_gfx_rings;
        struct amdgpu_ring              compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
        struct drm_gpu_scheduler        *compute_sched[AMDGPU_MAX_COMPUTE_RINGS];
+       struct drm_gpu_scheduler        *compute_sched_high[AMDGPU_MAX_COMPUTE_RINGS];
        uint32_t                        num_compute_sched;
+       uint32_t                        num_compute_sched_high;
        unsigned                        num_compute_rings;
        struct amdgpu_irq_src           eop_irq;
        struct amdgpu_irq_src           priv_reg_irq;
@@ -363,6 +373,8 @@ void amdgpu_gfx_bit_to_mec_queue(struct amdgpu_device *adev, int bit,
                                 int *mec, int *pipe, int *queue);
 bool amdgpu_gfx_is_mec_queue_enabled(struct amdgpu_device *adev, int mec,
                                     int pipe, int queue);
+bool amdgpu_gfx_is_high_priority_compute_queue(struct amdgpu_device *adev,
+                                              int queue);
 int amdgpu_gfx_me_queue_to_bit(struct amdgpu_device *adev, int me,
                               int pipe, int queue);
 void amdgpu_gfx_bit_to_me_queue(struct amdgpu_device *adev, int bit,
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -6
index d42be880a236..4981e443a884 100644
@@ -117,12 +117,10 @@ void amdgpu_job_free_resources(struct amdgpu_job *job)
 
 static void amdgpu_job_free_cb(struct drm_sched_job *s_job)
 {
-       struct amdgpu_ring *ring = to_amdgpu_ring(s_job->sched);
        struct amdgpu_job *job = to_amdgpu_job(s_job);
 
        drm_sched_job_cleanup(s_job);
 
-       amdgpu_ring_priority_put(ring, s_job->s_priority);
        dma_fence_put(job->fence);
        amdgpu_sync_free(&job->sync);
        amdgpu_sync_free(&job->sched_sync);
@@ -143,7 +141,6 @@ int amdgpu_job_submit(struct amdgpu_job *job, struct drm_sched_entity *entity,
                      void *owner, struct dma_fence **f)
 {
        enum drm_sched_priority priority;
-       struct amdgpu_ring *ring;
        int r;
 
        if (!f)
@@ -158,9 +155,6 @@ int amdgpu_job_submit(struct amdgpu_job *job, struct drm_sched_entity *entity,
        priority = job->base.s_priority;
        drm_sched_entity_push_job(&job->base, entity);
 
-       ring = to_amdgpu_ring(entity->rq->sched);
-       amdgpu_ring_priority_get(ring, priority);
-
        return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +1 -0
index 24caff085d00..34fcd467f18d 100644
@@ -222,6 +222,7 @@ struct amdgpu_ring {
        struct mutex            priority_mutex;
        /* protected by priority_mutex */
        int                     priority;
+       bool                    high_priority;
 
 #if defined(CONFIG_DEBUG_FS)
        struct dentry *ent;
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +1 -0
index e63f98b2d389..4260becd569b 100644
@@ -4426,6 +4426,23 @@ static int gfx_v8_0_deactivate_hqd(struct amdgpu_device *adev, u32 req)
        return r;
 }
 
+static void gfx_v8_0_mqd_set_priority(struct amdgpu_ring *ring, struct vi_mqd *mqd)

drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c static int gfx_v8_0_deactivate_hqd(struct amdgpu_device *adev, u32 req) · line 4439

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +10 -0
+{
+       struct amdgpu_device *adev = ring->adev;
+
+       if (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) {
+               if (amdgpu_gfx_is_high_priority_compute_queue(adev, ring->queue)) {
+                       mqd->cp_hqd_pipe_priority = AMDGPU_GFX_PIPE_PRIO_HIGH;
+                       ring->high_priority = true;
+                       mqd->cp_hqd_queue_priority =
+                               AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM;
+                       mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);

I think we can move this back to mqd_init(). It needs to be set up for both low and high priority queues.

Quoted 38 lines
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +9 -3
+               }
+               else
+                       ring->high_priority = false;
+       }
+}
+
 static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)
 {
        struct amdgpu_device *adev = ring->adev;
@@ -4549,9 +4566,6 @@ static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)
        /* defaults */
        mqd->cp_hqd_eop_rptr = RREG32(mmCP_HQD_EOP_RPTR);
        mqd->cp_hqd_eop_wptr = RREG32(mmCP_HQD_EOP_WPTR);
-       mqd->cp_hqd_pipe_priority = RREG32(mmCP_HQD_PIPE_PRIORITY);
-       mqd->cp_hqd_queue_priority = RREG32(mmCP_HQD_QUEUE_PRIORITY);
-       mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);
        mqd->cp_hqd_ctx_save_base_addr_lo = RREG32(mmCP_HQD_CTX_SAVE_BASE_ADDR_LO);
        mqd->cp_hqd_ctx_save_base_addr_hi = RREG32(mmCP_HQD_CTX_SAVE_BASE_ADDR_HI);
        mqd->cp_hqd_cntl_stack_offset = RREG32(mmCP_HQD_CNTL_STACK_OFFSET);
@@ -4563,6 +4577,9 @@ static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)
        mqd->cp_hqd_eop_wptr_mem = RREG32(mmCP_HQD_EOP_WPTR_MEM);
        mqd->cp_hqd_eop_dones = RREG32(mmCP_HQD_EOP_DONES);
 
+       /* set static priority for a queue/ring */
+       gfx_v8_0_mqd_set_priority(ring, mqd);
+
        /* map_queues packet doesn't need activate the queue,
         * so only kiq need set this field.
         */
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -0
index 4135e4126e82..85a54849abd1 100644
@@ -3310,6 +3310,23 @@ static void gfx_v9_0_kiq_setting(struct amdgpu_ring *ring)
        WREG32_SOC15_RLC(GC, 0, mmRLC_CP_SCHEDULERS, tmp);
 }
 
+static void gfx_v9_0_mqd_set_priority(struct amdgpu_ring *ring, struct v9_mqd *mqd)

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static void gfx_v9_0_kiq_setting(struct amdgpu_ring *ring) · line 3323

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +10 -0
+{
+       struct amdgpu_device *adev = ring->adev;
+
+       if (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) {
+               if (amdgpu_gfx_is_high_priority_compute_queue(adev, ring->queue)) {
+                       mqd->cp_hqd_pipe_priority = AMDGPU_GFX_PIPE_PRIO_HIGH;
+                       ring->high_priority = true;
+                       mqd->cp_hqd_queue_priority =
+                               AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM;
+                       mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);

Same comment here.

Alex

Quoted 22 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +9 -1
+               }
+               else
+                       ring->high_priority = false;
+       }
+}
+
 static int gfx_v9_0_mqd_init(struct amdgpu_ring *ring)
 {
        struct amdgpu_device *adev = ring->adev;
@@ -3446,6 +3463,9 @@ static int gfx_v9_0_mqd_init(struct amdgpu_ring *ring)
        tmp = REG_SET_FIELD(tmp, CP_HQD_IB_CONTROL, MIN_IB_AVAIL_SIZE, 3);
        mqd->cp_hqd_ib_control = tmp;
 
+       /* set static priority for a queue/ring */
+       gfx_v9_0_mqd_set_priority(ring, mqd);
+
        /* map_queues packet doesn't need activate the queue,
         * so only kiq need set this field.
         */
--

2.25.0

Quoted 4 lines

_______________________________________________
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

#13 lore raw
Quoted 7 lines · Alex Deucher
Quoted 5 lines · Nirmoy Das

We were changing compute ring priority while rings were being used before every job submission which is not recommended. This patch sets compute queue priority at mqd initialization for gfx8 and gfx9.

Quoted 22 lines
Quoted 2 lines

Policy: Enable high priority compute queues only if gpu has >1 MEC, if so PIPE0 and PIPE1 will be in high priority.

I think we still want high priority queues on even when there is only one MEC. It might work better on multi-MEC chips, but it should still work on single MEC chips.

Quoted 15 lines

high/normal priority compute sched list are generated from set of high/normal priority compute queues. At context creation, entity of compute queue get a sched list from high or normal priority depending on ctx->priority

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c   |  4 ----
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c  | 19 +++++++++++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c  | 14 ++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h  | 12 ++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c  |  6 ------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h |  1 +
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c    | 23 ++++++++++++++++++++---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 20 ++++++++++++++++++++

Also, can you add a patch for gfx_v10_0.c?

Alex

Quoted 269 lines
Quoted 180 lines
 8 files changed, 82 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -4
index f397ff97b4e4..8304d0c87899 100644
@@ -1205,7 +1205,6 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
        struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
        struct drm_sched_entity *entity = p->entity;
        enum drm_sched_priority priority;
-       struct amdgpu_ring *ring;
        struct amdgpu_bo_list_entry *e;
        struct amdgpu_job *job;
        uint64_t seq;
@@ -1258,9 +1257,6 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
        priority = job->base.s_priority;
        drm_sched_entity_push_job(&job->base, entity);
 
-       ring = to_amdgpu_ring(entity->rq->sched);
-       amdgpu_ring_priority_get(ring, priority);
-
        amdgpu_vm_move_to_lru_tail(p->adev, &fpriv->vm);
 
        ttm_eu_fence_buffer_objects(&p->ticket, &p->validated, p->fence);
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +15 -4
index 94a6c42f29ea..a1742b1d4f9c 100644
@@ -85,8 +85,14 @@ static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, const u32 hw_ip, const
                        num_scheds = 1;
                        break;
                case AMDGPU_HW_IP_COMPUTE:
-                       scheds = adev->gfx.compute_sched;
-                       num_scheds = adev->gfx.num_compute_sched;
+                       if (priority > DRM_SCHED_PRIORITY_NORMAL &&
+                           adev->gfx.num_compute_sched_high) {
+                               scheds = adev->gfx.compute_sched_high;
+                               num_scheds = adev->gfx.num_compute_sched_high;
+                       } else {
+                               scheds = adev->gfx.compute_sched;
+                               num_scheds = adev->gfx.num_compute_sched;
+                       }
                        break;
                case AMDGPU_HW_IP_DMA:
                        scheds = adev->sdma.sdma_sched;
@@ -638,8 +644,13 @@ void amdgpu_ctx_init_sched(struct amdgpu_device *adev)
        }
 
        for (i = 0; i < adev->gfx.num_compute_rings; i++) {
-               adev->gfx.compute_sched[i] = &adev->gfx.compute_ring[i].sched;
-               adev->gfx.num_compute_sched++;
+               if (!adev->gfx.compute_ring[i].high_priority) {
+                       adev->gfx.compute_sched[adev->gfx.num_compute_sched++] =
+                               &adev->gfx.compute_ring[i].sched;
+               } else {
+                       adev->gfx.compute_sched_high[adev->gfx.num_compute_sched_high++] =
+                               &adev->gfx.compute_ring[i].sched;
+               }
        }
 
        for (i = 0; i < adev->sdma.num_instances; i++) {
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +14 -0
index 7403588684b3..bdea5d44edf4 100644
@@ -192,6 +192,20 @@ static bool amdgpu_gfx_is_multipipe_capable(struct amdgpu_device *adev)
        return adev->gfx.mec.num_mec > 1;
 }
 
+bool amdgpu_gfx_is_high_priority_compute_queue(struct amdgpu_device *adev,
+                                              int queue)
+{
+       bool multipipe_policy = amdgpu_gfx_is_multipipe_capable(adev);
+
+       /* only enable high priority queue if more than 1 MEC.
+        * When multipipe_policy is true amdgpu gets queue 0,1 from each pipe of
+        * 1st MEC. Policy: make queue 0 of each pipe as high priority compute queue */
+       if (multipipe_policy && queue == 0)
+               return true;
+
+       return false;
+}
+
 void amdgpu_gfx_compute_queue_acquire(struct amdgpu_device *adev)
 {
        int i, queue, pipe, mec;
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +12 -0
index 37ba05b63b2a..13ee0ea66c6f 100644
@@ -41,6 +41,14 @@
 #define AMDGPU_MAX_GFX_QUEUES KGD_MAX_QUEUES
 #define AMDGPU_MAX_COMPUTE_QUEUES KGD_MAX_QUEUES
 
+#define AMDGPU_GFX_PIPE_PRIO_LOW    0
+#define AMDGPU_GFX_PIPE_PRIO_NORMAL 1
+#define AMDGPU_GFX_PIPE_PRIO_HIGH   2
+
+#define AMDGPU_GFX_QUEUE_PRIORITY_MINIMUM  0
+#define AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM  15
+
+
 struct amdgpu_mec {
        struct amdgpu_bo        *hpd_eop_obj;
        u64                     hpd_eop_gpu_addr;
@@ -281,7 +289,9 @@ struct amdgpu_gfx {
        unsigned                        num_gfx_rings;
        struct amdgpu_ring              compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
        struct drm_gpu_scheduler        *compute_sched[AMDGPU_MAX_COMPUTE_RINGS];
+       struct drm_gpu_scheduler        *compute_sched_high[AMDGPU_MAX_COMPUTE_RINGS];
        uint32_t                        num_compute_sched;
+       uint32_t                        num_compute_sched_high;
        unsigned                        num_compute_rings;
        struct amdgpu_irq_src           eop_irq;
        struct amdgpu_irq_src           priv_reg_irq;
@@ -363,6 +373,8 @@ void amdgpu_gfx_bit_to_mec_queue(struct amdgpu_device *adev, int bit,
                                 int *mec, int *pipe, int *queue);
 bool amdgpu_gfx_is_mec_queue_enabled(struct amdgpu_device *adev, int mec,
                                     int pipe, int queue);
+bool amdgpu_gfx_is_high_priority_compute_queue(struct amdgpu_device *adev,
+                                              int queue);
 int amdgpu_gfx_me_queue_to_bit(struct amdgpu_device *adev, int me,
                               int pipe, int queue);
 void amdgpu_gfx_bit_to_me_queue(struct amdgpu_device *adev, int bit,
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -6
index d42be880a236..4981e443a884 100644
@@ -117,12 +117,10 @@ void amdgpu_job_free_resources(struct amdgpu_job *job)
 
 static void amdgpu_job_free_cb(struct drm_sched_job *s_job)
 {
-       struct amdgpu_ring *ring = to_amdgpu_ring(s_job->sched);
        struct amdgpu_job *job = to_amdgpu_job(s_job);
 
        drm_sched_job_cleanup(s_job);
 
-       amdgpu_ring_priority_put(ring, s_job->s_priority);
        dma_fence_put(job->fence);
        amdgpu_sync_free(&job->sync);
        amdgpu_sync_free(&job->sched_sync);
@@ -143,7 +141,6 @@ int amdgpu_job_submit(struct amdgpu_job *job, struct drm_sched_entity *entity,
                      void *owner, struct dma_fence **f)
 {
        enum drm_sched_priority priority;
-       struct amdgpu_ring *ring;
        int r;
 
        if (!f)
@@ -158,9 +155,6 @@ int amdgpu_job_submit(struct amdgpu_job *job, struct drm_sched_entity *entity,
        priority = job->base.s_priority;
        drm_sched_entity_push_job(&job->base, entity);
 
-       ring = to_amdgpu_ring(entity->rq->sched);
-       amdgpu_ring_priority_get(ring, priority);
-
        return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +1 -0
index 24caff085d00..34fcd467f18d 100644
@@ -222,6 +222,7 @@ struct amdgpu_ring {
        struct mutex            priority_mutex;
        /* protected by priority_mutex */
        int                     priority;
+       bool                    high_priority;
 
 #if defined(CONFIG_DEBUG_FS)
        struct dentry *ent;
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +1 -0
index e63f98b2d389..4260becd569b 100644
@@ -4426,6 +4426,23 @@ static int gfx_v8_0_deactivate_hqd(struct amdgpu_device *adev, u32 req)
        return r;
 }
 
+static void gfx_v8_0_mqd_set_priority(struct amdgpu_ring *ring, struct vi_mqd *mqd)

drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c static int gfx_v8_0_deactivate_hqd(struct amdgpu_device *adev, u32 req) · line 4439

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +10 -0
+{
+       struct amdgpu_device *adev = ring->adev;
+
+       if (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) {
+               if (amdgpu_gfx_is_high_priority_compute_queue(adev, ring->queue)) {
+                       mqd->cp_hqd_pipe_priority = AMDGPU_GFX_PIPE_PRIO_HIGH;
+                       ring->high_priority = true;
+                       mqd->cp_hqd_queue_priority =
+                               AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM;
+                       mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);

I think we can move this back to mqd_init(). It needs to be set up for both low and high priority queues.

Quoted 38 lines
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +9 -3
+               }
+               else
+                       ring->high_priority = false;
+       }
+}
+
 static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)
 {
        struct amdgpu_device *adev = ring->adev;
@@ -4549,9 +4566,6 @@ static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)
        /* defaults */
        mqd->cp_hqd_eop_rptr = RREG32(mmCP_HQD_EOP_RPTR);
        mqd->cp_hqd_eop_wptr = RREG32(mmCP_HQD_EOP_WPTR);
-       mqd->cp_hqd_pipe_priority = RREG32(mmCP_HQD_PIPE_PRIORITY);
-       mqd->cp_hqd_queue_priority = RREG32(mmCP_HQD_QUEUE_PRIORITY);
-       mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);
        mqd->cp_hqd_ctx_save_base_addr_lo = RREG32(mmCP_HQD_CTX_SAVE_BASE_ADDR_LO);
        mqd->cp_hqd_ctx_save_base_addr_hi = RREG32(mmCP_HQD_CTX_SAVE_BASE_ADDR_HI);
        mqd->cp_hqd_cntl_stack_offset = RREG32(mmCP_HQD_CNTL_STACK_OFFSET);
@@ -4563,6 +4577,9 @@ static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)
        mqd->cp_hqd_eop_wptr_mem = RREG32(mmCP_HQD_EOP_WPTR_MEM);
        mqd->cp_hqd_eop_dones = RREG32(mmCP_HQD_EOP_DONES);
 
+       /* set static priority for a queue/ring */
+       gfx_v8_0_mqd_set_priority(ring, mqd);
+
        /* map_queues packet doesn't need activate the queue,
         * so only kiq need set this field.
         */
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -0
index 4135e4126e82..85a54849abd1 100644
@@ -3310,6 +3310,23 @@ static void gfx_v9_0_kiq_setting(struct amdgpu_ring *ring)
        WREG32_SOC15_RLC(GC, 0, mmRLC_CP_SCHEDULERS, tmp);
 }
 
+static void gfx_v9_0_mqd_set_priority(struct amdgpu_ring *ring, struct v9_mqd *mqd)

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static void gfx_v9_0_kiq_setting(struct amdgpu_ring *ring) · line 3323

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +10 -0
+{
+       struct amdgpu_device *adev = ring->adev;
+
+       if (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) {
+               if (amdgpu_gfx_is_high_priority_compute_queue(adev, ring->queue)) {
+                       mqd->cp_hqd_pipe_priority = AMDGPU_GFX_PIPE_PRIO_HIGH;
+                       ring->high_priority = true;
+                       mqd->cp_hqd_queue_priority =
+                               AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM;
+                       mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);

Same comment here.

Alex

Quoted 22 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +9 -1
+               }
+               else
+                       ring->high_priority = false;
+       }
+}
+
 static int gfx_v9_0_mqd_init(struct amdgpu_ring *ring)
 {
        struct amdgpu_device *adev = ring->adev;
@@ -3446,6 +3463,9 @@ static int gfx_v9_0_mqd_init(struct amdgpu_ring *ring)
        tmp = REG_SET_FIELD(tmp, CP_HQD_IB_CONTROL, MIN_IB_AVAIL_SIZE, 3);
        mqd->cp_hqd_ib_control = tmp;
 
+       /* set static priority for a queue/ring */
+       gfx_v9_0_mqd_set_priority(ring, mqd);
+
        /* map_queues packet doesn't need activate the queue,
         * so only kiq need set this field.
         */
--

2.25.0

Quoted 4 lines
Quoted 4 lines

_______________________________________________
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

#14 lore raw

[AMD Official Use Only - Internal Distribution Only]

Yes I missed gfx_v10_0.c. I will resend a updated one tomorrow.

Regards,
Nirmoy
Get Outlook for Android<https://aka.ms/ghei36>
________________________________
From: Alex Deucher <[email protected]>
Sent: Thursday, February 27, 2020 10:50:35 PM
To: Nirmoy Das <[email protected]>
Cc: amd-gfx list <[email protected]>; Deucher, Alexander <[email protected]>; Huang, Ray <[email protected]>; Das, Nirmoy <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [RFC PATCH 1/4] drm/amdgpu: set compute queue priority at mqd_init

Quoted 7 lines · Alex Deucher
Quoted 5 lines · Nirmoy Das

We were changing compute ring priority while rings were being used before every job submission which is not recommended. This patch sets compute queue priority at mqd initialization for gfx8 and gfx9.

Quoted 22 lines
Quoted 2 lines

Policy: Enable high priority compute queues only if gpu has >1 MEC, if so PIPE0 and PIPE1 will be in high priority.

I think we still want high priority queues on even when there is only one MEC. It might work better on multi-MEC chips, but it should still work on single MEC chips.

Quoted 15 lines

high/normal priority compute sched list are generated from set of high/normal priority compute queues. At context creation, entity of compute queue get a sched list from high or normal priority depending on ctx->priority

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c   |  4 ----
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c  | 19 +++++++++++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c  | 14 ++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h  | 12 ++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c  |  6 ------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h |  1 +
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c    | 23 ++++++++++++++++++++---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 20 ++++++++++++++++++++

Also, can you add a patch for gfx_v10_0.c?

Alex

Quoted 269 lines
Quoted 180 lines
 8 files changed, 82 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -4
index f397ff97b4e4..8304d0c87899 100644
@@ -1205,7 +1205,6 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
        struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
        struct drm_sched_entity *entity = p->entity;
        enum drm_sched_priority priority;
-       struct amdgpu_ring *ring;
        struct amdgpu_bo_list_entry *e;
        struct amdgpu_job *job;
        uint64_t seq;
@@ -1258,9 +1257,6 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
        priority = job->base.s_priority;
        drm_sched_entity_push_job(&job->base, entity);
 
-       ring = to_amdgpu_ring(entity->rq->sched);
-       amdgpu_ring_priority_get(ring, priority);
-
        amdgpu_vm_move_to_lru_tail(p->adev, &fpriv->vm);
 
        ttm_eu_fence_buffer_objects(&p->ticket, &p->validated, p->fence);
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +15 -4
index 94a6c42f29ea..a1742b1d4f9c 100644
@@ -85,8 +85,14 @@ static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, const u32 hw_ip, const
                        num_scheds = 1;
                        break;
                case AMDGPU_HW_IP_COMPUTE:
-                       scheds = adev->gfx.compute_sched;
-                       num_scheds = adev->gfx.num_compute_sched;
+                       if (priority > DRM_SCHED_PRIORITY_NORMAL &&
+                           adev->gfx.num_compute_sched_high) {
+                               scheds = adev->gfx.compute_sched_high;
+                               num_scheds = adev->gfx.num_compute_sched_high;
+                       } else {
+                               scheds = adev->gfx.compute_sched;
+                               num_scheds = adev->gfx.num_compute_sched;
+                       }
                        break;
                case AMDGPU_HW_IP_DMA:
                        scheds = adev->sdma.sdma_sched;
@@ -638,8 +644,13 @@ void amdgpu_ctx_init_sched(struct amdgpu_device *adev)
        }
 
        for (i = 0; i < adev->gfx.num_compute_rings; i++) {
-               adev->gfx.compute_sched[i] = &adev->gfx.compute_ring[i].sched;
-               adev->gfx.num_compute_sched++;
+               if (!adev->gfx.compute_ring[i].high_priority) {
+                       adev->gfx.compute_sched[adev->gfx.num_compute_sched++] =
+                               &adev->gfx.compute_ring[i].sched;
+               } else {
+                       adev->gfx.compute_sched_high[adev->gfx.num_compute_sched_high++] =
+                               &adev->gfx.compute_ring[i].sched;
+               }
        }
 
        for (i = 0; i < adev->sdma.num_instances; i++) {
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +14 -0
index 7403588684b3..bdea5d44edf4 100644
@@ -192,6 +192,20 @@ static bool amdgpu_gfx_is_multipipe_capable(struct amdgpu_device *adev)
        return adev->gfx.mec.num_mec > 1;
 }
 
+bool amdgpu_gfx_is_high_priority_compute_queue(struct amdgpu_device *adev,
+                                              int queue)
+{
+       bool multipipe_policy = amdgpu_gfx_is_multipipe_capable(adev);
+
+       /* only enable high priority queue if more than 1 MEC.
+        * When multipipe_policy is true amdgpu gets queue 0,1 from each pipe of
+        * 1st MEC. Policy: make queue 0 of each pipe as high priority compute queue */
+       if (multipipe_policy && queue == 0)
+               return true;
+
+       return false;
+}
+
 void amdgpu_gfx_compute_queue_acquire(struct amdgpu_device *adev)
 {
        int i, queue, pipe, mec;
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +12 -0
index 37ba05b63b2a..13ee0ea66c6f 100644
@@ -41,6 +41,14 @@
 #define AMDGPU_MAX_GFX_QUEUES KGD_MAX_QUEUES
 #define AMDGPU_MAX_COMPUTE_QUEUES KGD_MAX_QUEUES
 
+#define AMDGPU_GFX_PIPE_PRIO_LOW    0
+#define AMDGPU_GFX_PIPE_PRIO_NORMAL 1
+#define AMDGPU_GFX_PIPE_PRIO_HIGH   2
+
+#define AMDGPU_GFX_QUEUE_PRIORITY_MINIMUM  0
+#define AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM  15
+
+
 struct amdgpu_mec {
        struct amdgpu_bo        *hpd_eop_obj;
        u64                     hpd_eop_gpu_addr;
@@ -281,7 +289,9 @@ struct amdgpu_gfx {
        unsigned                        num_gfx_rings;
        struct amdgpu_ring              compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
        struct drm_gpu_scheduler        *compute_sched[AMDGPU_MAX_COMPUTE_RINGS];
+       struct drm_gpu_scheduler        *compute_sched_high[AMDGPU_MAX_COMPUTE_RINGS];
        uint32_t                        num_compute_sched;
+       uint32_t                        num_compute_sched_high;
        unsigned                        num_compute_rings;
        struct amdgpu_irq_src           eop_irq;
        struct amdgpu_irq_src           priv_reg_irq;
@@ -363,6 +373,8 @@ void amdgpu_gfx_bit_to_mec_queue(struct amdgpu_device *adev, int bit,
                                 int *mec, int *pipe, int *queue);
 bool amdgpu_gfx_is_mec_queue_enabled(struct amdgpu_device *adev, int mec,
                                     int pipe, int queue);
+bool amdgpu_gfx_is_high_priority_compute_queue(struct amdgpu_device *adev,
+                                              int queue);
 int amdgpu_gfx_me_queue_to_bit(struct amdgpu_device *adev, int me,
                               int pipe, int queue);
 void amdgpu_gfx_bit_to_me_queue(struct amdgpu_device *adev, int bit,
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -6
index d42be880a236..4981e443a884 100644
@@ -117,12 +117,10 @@ void amdgpu_job_free_resources(struct amdgpu_job *job)
 
 static void amdgpu_job_free_cb(struct drm_sched_job *s_job)
 {
-       struct amdgpu_ring *ring = to_amdgpu_ring(s_job->sched);
        struct amdgpu_job *job = to_amdgpu_job(s_job);
 
        drm_sched_job_cleanup(s_job);
 
-       amdgpu_ring_priority_put(ring, s_job->s_priority);
        dma_fence_put(job->fence);
        amdgpu_sync_free(&job->sync);
        amdgpu_sync_free(&job->sched_sync);
@@ -143,7 +141,6 @@ int amdgpu_job_submit(struct amdgpu_job *job, struct drm_sched_entity *entity,
                      void *owner, struct dma_fence **f)
 {
        enum drm_sched_priority priority;
-       struct amdgpu_ring *ring;
        int r;
 
        if (!f)
@@ -158,9 +155,6 @@ int amdgpu_job_submit(struct amdgpu_job *job, struct drm_sched_entity *entity,
        priority = job->base.s_priority;
        drm_sched_entity_push_job(&job->base, entity);
 
-       ring = to_amdgpu_ring(entity->rq->sched);
-       amdgpu_ring_priority_get(ring, priority);
-
        return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +1 -0
index 24caff085d00..34fcd467f18d 100644
@@ -222,6 +222,7 @@ struct amdgpu_ring {
        struct mutex            priority_mutex;
        /* protected by priority_mutex */
        int                     priority;
+       bool                    high_priority;
 
 #if defined(CONFIG_DEBUG_FS)
        struct dentry *ent;
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +1 -0
index e63f98b2d389..4260becd569b 100644
@@ -4426,6 +4426,23 @@ static int gfx_v8_0_deactivate_hqd(struct amdgpu_device *adev, u32 req)
        return r;
 }
 
+static void gfx_v8_0_mqd_set_priority(struct amdgpu_ring *ring, struct vi_mqd *mqd)

drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c static int gfx_v8_0_deactivate_hqd(struct amdgpu_device *adev, u32 req) · line 4439

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +10 -0
+{
+       struct amdgpu_device *adev = ring->adev;
+
+       if (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) {
+               if (amdgpu_gfx_is_high_priority_compute_queue(adev, ring->queue)) {
+                       mqd->cp_hqd_pipe_priority = AMDGPU_GFX_PIPE_PRIO_HIGH;
+                       ring->high_priority = true;
+                       mqd->cp_hqd_queue_priority =
+                               AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM;
+                       mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);

I think we can move this back to mqd_init(). It needs to be set up for both low and high priority queues.

Quoted 38 lines
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +9 -3
+               }
+               else
+                       ring->high_priority = false;
+       }
+}
+
 static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)
 {
        struct amdgpu_device *adev = ring->adev;
@@ -4549,9 +4566,6 @@ static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)
        /* defaults */
        mqd->cp_hqd_eop_rptr = RREG32(mmCP_HQD_EOP_RPTR);
        mqd->cp_hqd_eop_wptr = RREG32(mmCP_HQD_EOP_WPTR);
-       mqd->cp_hqd_pipe_priority = RREG32(mmCP_HQD_PIPE_PRIORITY);
-       mqd->cp_hqd_queue_priority = RREG32(mmCP_HQD_QUEUE_PRIORITY);
-       mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);
        mqd->cp_hqd_ctx_save_base_addr_lo = RREG32(mmCP_HQD_CTX_SAVE_BASE_ADDR_LO);
        mqd->cp_hqd_ctx_save_base_addr_hi = RREG32(mmCP_HQD_CTX_SAVE_BASE_ADDR_HI);
        mqd->cp_hqd_cntl_stack_offset = RREG32(mmCP_HQD_CNTL_STACK_OFFSET);
@@ -4563,6 +4577,9 @@ static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)
        mqd->cp_hqd_eop_wptr_mem = RREG32(mmCP_HQD_EOP_WPTR_MEM);
        mqd->cp_hqd_eop_dones = RREG32(mmCP_HQD_EOP_DONES);
 
+       /* set static priority for a queue/ring */
+       gfx_v8_0_mqd_set_priority(ring, mqd);
+
        /* map_queues packet doesn't need activate the queue,
         * so only kiq need set this field.
         */
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -0
index 4135e4126e82..85a54849abd1 100644
@@ -3310,6 +3310,23 @@ static void gfx_v9_0_kiq_setting(struct amdgpu_ring *ring)
        WREG32_SOC15_RLC(GC, 0, mmRLC_CP_SCHEDULERS, tmp);
 }
 
+static void gfx_v9_0_mqd_set_priority(struct amdgpu_ring *ring, struct v9_mqd *mqd)

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static void gfx_v9_0_kiq_setting(struct amdgpu_ring *ring) · line 3323

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +10 -0
+{
+       struct amdgpu_device *adev = ring->adev;
+
+       if (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) {
+               if (amdgpu_gfx_is_high_priority_compute_queue(adev, ring->queue)) {
+                       mqd->cp_hqd_pipe_priority = AMDGPU_GFX_PIPE_PRIO_HIGH;
+                       ring->high_priority = true;
+                       mqd->cp_hqd_queue_priority =
+                               AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM;
+                       mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);

Same comment here.

Alex

Quoted 22 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +9 -1
+               }
+               else
+                       ring->high_priority = false;
+       }
+}
+
 static int gfx_v9_0_mqd_init(struct amdgpu_ring *ring)
 {
        struct amdgpu_device *adev = ring->adev;
@@ -3446,6 +3463,9 @@ static int gfx_v9_0_mqd_init(struct amdgpu_ring *ring)
        tmp = REG_SET_FIELD(tmp, CP_HQD_IB_CONTROL, MIN_IB_AVAIL_SIZE, 3);
        mqd->cp_hqd_ib_control = tmp;
 
+       /* set static priority for a queue/ring */
+       gfx_v9_0_mqd_set_priority(ring, mqd);
+
        /* map_queues packet doesn't need activate the queue,
         * so only kiq need set this field.
         */
--

2.25.0

Quoted 4 lines
Quoted 4 lines

_______________________________________________
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%7Cnirmoy.das%40amd.com%7C9cd63275980e426c420808d7bbcf1b33%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637184370519368178&amp;sdata=qvENGcFENLfXkn3HiA0yeGwo1N0dU2meZm51kD%2FdjsE%3D&amp;reserved=0

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