Skip to contentSkip to conversation

drm/amdgpu: set compute queue priority at mqd_init

PATCH Superseded Nirmoy Das 4 participants 7 messages Feb 28, 2020

Subsystems (4)

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Nirmoy Das

author
#0 lore raw

PATCH v2 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, gfx9 and gfx10.

Policy: make queue 0 of each pipe as high priority compute queue

High/normal priority compute sched lists 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  | 40 +++++++++++++++++++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c  |  8 +++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h  | 13 +++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c  |  6 ----
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h |  1 +
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c   | 19 +++++++++++
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c    | 23 ++++++++++++--
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 20 ++++++++++++
 9 files changed, 113 insertions(+), 21 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 +33 -7
index 94a6c42f29ea..b21771b37300 100644
@@ -85,8 +85,8 @@ 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;
+			scheds = adev->gfx.compute_prio_sched[priority];
+			num_scheds = adev->gfx.num_compute_sched[priority];
 			break;
 		case AMDGPU_HW_IP_DMA:
 			scheds = adev->sdma.sdma_sched;
@@ -628,20 +628,46 @@ void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr)
 	mutex_destroy(&mgr->lock);
 }
 
+
+static void amdgpu_ctx_init_compute_sched(struct amdgpu_device *adev)
+{
+	int num_compute_sched_normal = 0;
+	int num_compute_sched_high = AMDGPU_MAX_COMPUTE_RINGS - 1;
+	int i;
+
+
+	for (i = 0; i < adev->gfx.num_compute_rings; i++) {
+		if (adev->gfx.compute_ring[i].high_priority)
+			adev->gfx.compute_sched[num_compute_sched_normal++] =
+				&adev->gfx.compute_ring[i].sched;
+		else
+			adev->gfx.compute_sched[num_compute_sched_high--] =
+				&adev->gfx.compute_ring[i].sched;
+	}
+
+	for (i = DRM_SCHED_PRIORITY_MIN; i <= DRM_SCHED_PRIORITY_NORMAL; i++) {
+		adev->gfx.compute_prio_sched[i] = &adev->gfx.compute_sched[0];
+		adev->gfx.num_compute_sched[i] = num_compute_sched_normal;
+	}
+
+	for (i = DRM_SCHED_PRIORITY_NORMAL + 1; i < DRM_SCHED_PRIORITY_MAX; i++) {
+		adev->gfx.compute_prio_sched[i] =
+			&adev->gfx.compute_sched[num_compute_sched_high - 1];
+		adev->gfx.num_compute_sched[i] =
+			adev->gfx.num_compute_rings - num_compute_sched_normal;
+	}
+}
+
 void amdgpu_ctx_init_sched(struct amdgpu_device *adev)
 {
 	int i, j;
 
+	amdgpu_ctx_init_compute_sched(adev);
 	for (i = 0; i < adev->gfx.num_gfx_rings; i++) {
 		adev->gfx.gfx_sched[i] = &adev->gfx.gfx_ring[i].sched;
 		adev->gfx.num_gfx_sched++;
 	}
 
-	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++;
-	}
-
 	for (i = 0; i < adev->sdma.num_instances; i++) {
 		adev->sdma.sdma_sched[i] = &adev->sdma.instance[i].ring.sched;
 		adev->sdma.num_sdma_sched++;
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +8 -0
index 7403588684b3..952725e7243c 100644
@@ -192,6 +192,14 @@ 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)
+{
+	/* Policy: make queue 0 of each pipe as high priority compute queue */
+	return (queue == 0);
+
+}
+
 void amdgpu_gfx_compute_queue_acquire(struct amdgpu_device *adev)
 {
 	int i, queue, pipe, mec;
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +12 -1
index 37ba05b63b2a..f87b6df67694 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;
@@ -280,8 +288,9 @@ struct amdgpu_gfx {
 	uint32_t			num_gfx_sched;
 	unsigned			num_gfx_rings;
 	struct amdgpu_ring		compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
+	struct drm_gpu_scheduler        **compute_prio_sched[DRM_SCHED_PRIORITY_MAX];
 	struct drm_gpu_scheduler	*compute_sched[AMDGPU_MAX_COMPUTE_RINGS];
-	uint32_t			num_compute_sched;
+	uint32_t                        num_compute_sched[DRM_SCHED_PRIORITY_MAX];
 	unsigned			num_compute_rings;
 	struct amdgpu_irq_src		eop_irq;
 	struct amdgpu_irq_src		priv_reg_irq;
@@ -363,6 +372,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_v10_0.c +19 -0
index 94ca9ffa0ccb..0e6ce65e1e54 100644
@@ -3211,6 +3211,22 @@ static int gfx_v10_0_cp_async_gfx_ring_resume(struct amdgpu_device *adev)
 	return r;
 }
 
+static void gfx_v10_0_compute_mqd_set_priority(struct amdgpu_ring *ring, struct v10_compute_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;
+		}
+		else
+			ring->high_priority = false;
+	}
+}
+
 static int gfx_v10_0_compute_mqd_init(struct amdgpu_ring *ring)
 {
 	struct amdgpu_device *adev = ring->adev;
@@ -3336,6 +3352,9 @@ static int gfx_v10_0_compute_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_v10_0_compute_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_v8_0.c +20 -3
index 393a1324daa9..6c4b7e49f97f 100644
@@ -4430,6 +4430,22 @@ 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;
+		}
+		else
+			ring->high_priority = false;
+	}
+}
+
 static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)
 {
 	struct amdgpu_device *adev = ring->adev;
@@ -4553,9 +4569,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);
@@ -4567,6 +4580,10 @@ 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);
+	mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);
+
 	/* 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 015647959d69..ff5e913f244d 100644
@@ -3314,6 +3314,22 @@ 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;
+		}
+		else
+			ring->high_priority = false;
+	}
+}
+
 static int gfx_v9_0_mqd_init(struct amdgpu_ring *ring)
 {
 	struct amdgpu_device *adev = ring->adev;
@@ -3450,6 +3466,10 @@ 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);
+	mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);
+
 	/* map_queues packet doesn't need activate the queue,
 	 * so only kiq need set this field.
 	 */

--
2.25.0

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

author
#1 lore raw

PATCH v2 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 | 19 +++++++++++++++++++
 include/drm/gpu_scheduler.h              |  4 ++++
 2 files changed, 23 insertions(+)
drivers/gpu/drm/scheduler/sched_entity.c +19 -0
index 63bccd201b97..b94312154e56 100644
@@ -83,6 +83,25 @@ 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
+ */
+void drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
+				  struct drm_gpu_scheduler **sched_list,
+				  unsigned int num_sched_list)
+{
+	WARN_ON(!num_sched_list || !sched_list);
+
+	entity->sched_list = sched_list;
+	entity->num_sched_list = num_sched_list;
+}
+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..f70a84aaaf7a 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);
+void 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);

--
2.25.0

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

author
#2 lore raw

PATCH v2 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 | 27 +++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +23 -4
index b21771b37300..3744c689affc 100644
@@ -502,6 +502,27 @@ struct dma_fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
 	return fence;
 }
 
+static void amdgpu_ctx_set_entity_priority(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:
+		scheds = adev->gfx.compute_prio_sched[priority];
+		num_scheds = adev->gfx.num_compute_sched[priority];
+		break;
+	default:
+		return;
+	}
+
+	drm_sched_entity_modify_sched(&aentity->entity, scheds, num_scheds);
+	drm_sched_entity_set_priority(&aentity->entity, priority);
+}
+
 void amdgpu_ctx_priority_override(struct amdgpu_ctx *ctx,
 				  enum drm_sched_priority priority)
 {
@@ -514,13 +535,11 @@ void amdgpu_ctx_priority_override(struct amdgpu_ctx *ctx,
 			ctx->init_priority : ctx->override_priority;
 	for (i = 0; i < AMDGPU_HW_IP_NUM; ++i) {
 		for (j = 0; j < amdgpu_ctx_num_entities[i]; ++j) {
-			struct drm_sched_entity *entity;
-
 			if (!ctx->entities[i][j])
 				continue;
 
-			entity = &ctx->entities[i][j]->entity;
-			drm_sched_entity_set_priority(entity, ctx_prio);
+			amdgpu_ctx_set_entity_priority(ctx, ctx->entities[i][j],
+						       i, ctx_prio);
 		}
 	}
 }

--
2.25.0

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

author
#3 lore raw

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 ca6b52054b4b..a7e1d0425ed0 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
maintainer
#4 lore raw
In reply to Nirmoy Das

Am 28.02.20 um 15:39 schrieb Nirmoy Das:

Quoted 152 lines

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, gfx9 and gfx10.

Policy: make queue 0 of each pipe as high priority compute queue

High/normal priority compute sched lists 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  | 40 +++++++++++++++++++-----
  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c  |  8 +++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h  | 13 +++++++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.c  |  6 ----
  drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h |  1 +
  drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c   | 19 +++++++++++
  drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c    | 23 ++++++++++++--
  drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 20 ++++++++++++
  9 files changed, 113 insertions(+), 21 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 +33 -7
index 94a6c42f29ea..b21771b37300 100644
@@ -85,8 +85,8 @@ 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;
+			scheds = adev->gfx.compute_prio_sched[priority];
+			num_scheds = adev->gfx.num_compute_sched[priority];
  			break;
  		case AMDGPU_HW_IP_DMA:
  			scheds = adev->sdma.sdma_sched;
@@ -628,20 +628,46 @@ void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr)
  	mutex_destroy(&mgr->lock);
  }
 
+
+static void amdgpu_ctx_init_compute_sched(struct amdgpu_device *adev)
+{
+	int num_compute_sched_normal = 0;
+	int num_compute_sched_high = AMDGPU_MAX_COMPUTE_RINGS - 1;
+	int i;
+
+
+	for (i = 0; i < adev->gfx.num_compute_rings; i++) {
+		if (adev->gfx.compute_ring[i].high_priority)
+			adev->gfx.compute_sched[num_compute_sched_normal++] =
+				&adev->gfx.compute_ring[i].sched;
+		else
+			adev->gfx.compute_sched[num_compute_sched_high--] =
+				&adev->gfx.compute_ring[i].sched;
+	}
+
+	for (i = DRM_SCHED_PRIORITY_MIN; i <= DRM_SCHED_PRIORITY_NORMAL; i++) {
+		adev->gfx.compute_prio_sched[i] = &adev->gfx.compute_sched[0];
+		adev->gfx.num_compute_sched[i] = num_compute_sched_normal;
+	}
+
+	for (i = DRM_SCHED_PRIORITY_NORMAL + 1; i < DRM_SCHED_PRIORITY_MAX; i++) {
+		adev->gfx.compute_prio_sched[i] =
+			&adev->gfx.compute_sched[num_compute_sched_high - 1];
+		adev->gfx.num_compute_sched[i] =
+			adev->gfx.num_compute_rings - num_compute_sched_normal;
+	}
+}
+
  void amdgpu_ctx_init_sched(struct amdgpu_device *adev)
  {
  	int i, j;
 
+	amdgpu_ctx_init_compute_sched(adev);
  	for (i = 0; i < adev->gfx.num_gfx_rings; i++) {
  		adev->gfx.gfx_sched[i] = &adev->gfx.gfx_ring[i].sched;
  		adev->gfx.num_gfx_sched++;
  	}
 
-	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++;
-	}
-
  	for (i = 0; i < adev->sdma.num_instances; i++) {
  		adev->sdma.sdma_sched[i] = &adev->sdma.instance[i].ring.sched;
  		adev->sdma.num_sdma_sched++;
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +8 -0
index 7403588684b3..952725e7243c 100644
@@ -192,6 +192,14 @@ 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)
+{
+	/* Policy: make queue 0 of each pipe as high priority compute queue */
+	return (queue == 0);
+
+}
+
  void amdgpu_gfx_compute_queue_acquire(struct amdgpu_device *adev)
  {
  	int i, queue, pipe, mec;
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +8 -0
index 37ba05b63b2a..f87b6df67694 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;

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h struct amdgpu_gfx { · line 291

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +1 -0
@@ -280,8 +288,9 @@ struct amdgpu_gfx {
  	uint32_t			num_gfx_sched;
  	unsigned			num_gfx_rings;
  	struct amdgpu_ring		compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
+	struct drm_gpu_scheduler        **compute_prio_sched[DRM_SCHED_PRIORITY_MAX];

Mhm, that mixes the middle layer implementation with the hardware backend.

Can you instead use an enum for AMDGPU_GFX_PIPE_PRIO_* and a switch to map the scheduler priority to the hardware priority?

Alternatively using something like compute_lo, compute, compute_high should work as well.

Regards,
Christian.

Quoted 186 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +3 -1
  	struct drm_gpu_scheduler	*compute_sched[AMDGPU_MAX_COMPUTE_RINGS];
-	uint32_t			num_compute_sched;
+	uint32_t                        num_compute_sched[DRM_SCHED_PRIORITY_MAX];
  	unsigned			num_compute_rings;
  	struct amdgpu_irq_src		eop_irq;
  	struct amdgpu_irq_src		priv_reg_irq;
@@ -363,6 +372,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_v10_0.c +19 -0
index 94ca9ffa0ccb..0e6ce65e1e54 100644
@@ -3211,6 +3211,22 @@ static int gfx_v10_0_cp_async_gfx_ring_resume(struct amdgpu_device *adev)
  	return r;
  }
 
+static void gfx_v10_0_compute_mqd_set_priority(struct amdgpu_ring *ring, struct v10_compute_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;
+		}
+		else
+			ring->high_priority = false;
+	}
+}
+
  static int gfx_v10_0_compute_mqd_init(struct amdgpu_ring *ring)
  {
  	struct amdgpu_device *adev = ring->adev;
@@ -3336,6 +3352,9 @@ static int gfx_v10_0_compute_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_v10_0_compute_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_v8_0.c +20 -3
index 393a1324daa9..6c4b7e49f97f 100644
@@ -4430,6 +4430,22 @@ 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;
+		}
+		else
+			ring->high_priority = false;
+	}
+}
+
  static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)
  {
  	struct amdgpu_device *adev = ring->adev;
@@ -4553,9 +4569,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);
@@ -4567,6 +4580,10 @@ 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);
+	mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);
+
  	/* 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 -1
index 015647959d69..ff5e913f244d 100644
@@ -3314,6 +3314,22 @@ 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;
+		}
+		else
+			ring->high_priority = false;
+	}
+}
+
  static int gfx_v9_0_mqd_init(struct amdgpu_ring *ring)
  {
  	struct amdgpu_device *adev = ring->adev;
@@ -3450,6 +3466,10 @@ 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);
+	mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);
+
  	/* map_queues packet doesn't need activate the queue,
  	 * so only kiq need set this field.
  	 */
--
Quoted 2 lines

2.25.0

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

#5 lore raw

Thanks Christian, I will send a updated one soon.

Quoted 373 lines · Christian König

Am 28.02.20 um 15:39 schrieb Nirmoy Das:

Quoted 161 lines

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, gfx9 and gfx10.

Policy: make queue 0 of each pipe as high priority compute queue

High/normal priority compute sched lists 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  | 40 +++++++++++++++++++-----
  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c  |  8 +++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h  | 13 +++++++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.c  |  6 ----

  drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h |  1 + drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c   | 19 +++++++++++ drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c    | 23 ++++++++++++-- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 20 ++++++++++++

  9 files changed, 113 insertions(+), 21 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -1
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;

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -3
@@ -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 +0 -0
index 94a6c42f29ea..b21771b37300 100644
@@ -85,8 +85,8 @@ 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; +            scheds = adev->gfx.compute_prio_sched[priority]; +            num_scheds = adev->gfx.num_compute_sched[priority]; break;
          case AMDGPU_HW_IP_DMA:
              scheds = adev->sdma.sdma_sched;

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +31 -5
@@ -628,20 +628,46 @@ void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr 
 *mgr)
       mutex_destroy(&mgr->lock);
   }
 
+
+static void amdgpu_ctx_init_compute_sched(struct amdgpu_device *adev)
+{
+    int num_compute_sched_normal = 0;
+    int num_compute_sched_high = AMDGPU_MAX_COMPUTE_RINGS - 1;
+    int i;
+
+
+    for (i = 0; i < adev->gfx.num_compute_rings; i++) {
+        if (adev->gfx.compute_ring[i].high_priority)
+ adev->gfx.compute_sched[num_compute_sched_normal++] =
+                &adev->gfx.compute_ring[i].sched;
+        else
+ adev->gfx.compute_sched[num_compute_sched_high--] =
+                &adev->gfx.compute_ring[i].sched;
+    }
+
+    for (i = DRM_SCHED_PRIORITY_MIN; i <= DRM_SCHED_PRIORITY_NORMAL; 
 i++) {
+        adev->gfx.compute_prio_sched[i] = &adev->gfx.compute_sched[0];
+        adev->gfx.num_compute_sched[i] = num_compute_sched_normal;
+    }
+
+    for (i = DRM_SCHED_PRIORITY_NORMAL + 1; i < 
 DRM_SCHED_PRIORITY_MAX; i++) {
+        adev->gfx.compute_prio_sched[i] =
+ &adev->gfx.compute_sched[num_compute_sched_high - 1];
+        adev->gfx.num_compute_sched[i] =
+            adev->gfx.num_compute_rings - num_compute_sched_normal;
+    }
+}
+
   void amdgpu_ctx_init_sched(struct amdgpu_device *adev)
   {
       int i, j;
 
+    amdgpu_ctx_init_compute_sched(adev);
       for (i = 0; i < adev->gfx.num_gfx_rings; i++) {
           adev->gfx.gfx_sched[i] = &adev->gfx.gfx_ring[i].sched;
           adev->gfx.num_gfx_sched++;
       }
 
-    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++;
-    }
-

      for (i = 0; i < adev->sdma.num_instances; i++) { adev->sdma.sdma_sched[i] = &adev->sdma.instance[i].ring.sched; adev->sdma.num_sdma_sched++;

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +4 -0
index 7403588684b3..952725e7243c 100644
@@ -192,6 +192,14 @@ 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)
+{
+    /* Policy: make queue 0 of each pipe as high priority compute 

queue */
+    return (queue == 0);

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +3 -0
+
+}
+

  void amdgpu_gfx_compute_queue_acquire(struct amdgpu_device *adev) {
      int i, queue, pipe, mec;

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +8 -0
index 37ba05b63b2a..f87b6df67694 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;

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h struct amdgpu_gfx { · line 292

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +1 -0
@@ -280,8 +288,9 @@ struct amdgpu_gfx {
       uint32_t            num_gfx_sched;
       unsigned            num_gfx_rings;
       struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
+    struct drm_gpu_scheduler 
 **compute_prio_sched[DRM_SCHED_PRIORITY_MAX];

Mhm, that mixes the middle layer implementation with the hardware backend.

Can you instead use an enum for AMDGPU_GFX_PIPE_PRIO_* and a switch to map the scheduler priority to the hardware priority?

Alternatively using something like compute_lo, compute, compute_high should work as well.

Regards,
Christian.

Quoted 196 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +1 -1
       struct drm_gpu_scheduler *compute_sched[AMDGPU_MAX_COMPUTE_RINGS];
-    uint32_t            num_compute_sched;
+    uint32_t num_compute_sched[DRM_SCHED_PRIORITY_MAX];
       unsigned            num_compute_rings;
       struct amdgpu_irq_src        eop_irq;

      struct amdgpu_irq_src        priv_reg_irq;

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +2 -0
@@ -363,6 +372,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 -2
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);

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -1
@@ -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)

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -3
@@ -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_v10_0.c +16 -0
index 94ca9ffa0ccb..0e6ce65e1e54 100644
@@ -3211,6 +3211,22 @@ static int 
 gfx_v10_0_cp_async_gfx_ring_resume(struct amdgpu_device *adev)
       return r;
   }
 
+static void gfx_v10_0_compute_mqd_set_priority(struct amdgpu_ring 
 *ring, struct v10_compute_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;
+        }
+        else
+            ring->high_priority = false;
+    }
+}
+

  static int gfx_v10_0_compute_mqd_init(struct amdgpu_ring *ring) {
      struct amdgpu_device *adev = ring->adev;

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +3 -0
@@ -3336,6 +3352,9 @@ static int gfx_v10_0_compute_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_v10_0_compute_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_v8_0.c +16 -0
index 393a1324daa9..6c4b7e49f97f 100644
@@ -4430,6 +4430,22 @@ 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;
+        }
+        else
+            ring->high_priority = false;
+    }
+}
+

  static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring) {
      struct amdgpu_device *adev = ring->adev;

drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +0 -3
@@ -4553,9 +4569,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);

drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +4 -0
@@ -4567,6 +4580,10 @@ 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);
+    mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);
+
       /* 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 +16 -0
index 015647959d69..ff5e913f244d 100644
@@ -3314,6 +3314,22 @@ 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;
+        }
+        else
+            ring->high_priority = false;
+    }
+}
+

  static int gfx_v9_0_mqd_init(struct amdgpu_ring *ring) {
      struct amdgpu_device *adev = ring->adev;

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +0 -0
@@ -3450,6 +3466,10 @@ 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;
 
Quoted 11 lines
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +4 -0
+    /* set static priority for a queue/ring */
+    gfx_v9_0_mqd_set_priority(ring, mqd);
+    mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);
+
       /* map_queues packet doesn't need activate the queue,
        * so only kiq need set this field.

       */

Signature · 1 line
2.25.0

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

#6 lore raw
In reply to Nirmoy Das
Quoted 230 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, gfx9 and gfx10.

Policy: make queue 0 of each pipe as high priority compute queue

High/normal priority compute sched lists 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  | 40 +++++++++++++++++++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c  |  8 +++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h  | 13 +++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c  |  6 ----
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h |  1 +
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c   | 19 +++++++++++
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c    | 23 ++++++++++++--
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 20 ++++++++++++
 9 files changed, 113 insertions(+), 21 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 +33 -7
index 94a6c42f29ea..b21771b37300 100644
@@ -85,8 +85,8 @@ 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;
+                       scheds = adev->gfx.compute_prio_sched[priority];
+                       num_scheds = adev->gfx.num_compute_sched[priority];
                        break;
                case AMDGPU_HW_IP_DMA:
                        scheds = adev->sdma.sdma_sched;
@@ -628,20 +628,46 @@ void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr)
        mutex_destroy(&mgr->lock);
 }
 
+
+static void amdgpu_ctx_init_compute_sched(struct amdgpu_device *adev)
+{
+       int num_compute_sched_normal = 0;
+       int num_compute_sched_high = AMDGPU_MAX_COMPUTE_RINGS - 1;
+       int i;
+
+
+       for (i = 0; i < adev->gfx.num_compute_rings; i++) {
+               if (adev->gfx.compute_ring[i].high_priority)
+                       adev->gfx.compute_sched[num_compute_sched_normal++] =
+                               &adev->gfx.compute_ring[i].sched;
+               else
+                       adev->gfx.compute_sched[num_compute_sched_high--] =
+                               &adev->gfx.compute_ring[i].sched;
+       }
+
+       for (i = DRM_SCHED_PRIORITY_MIN; i <= DRM_SCHED_PRIORITY_NORMAL; i++) {
+               adev->gfx.compute_prio_sched[i] = &adev->gfx.compute_sched[0];
+               adev->gfx.num_compute_sched[i] = num_compute_sched_normal;
+       }
+
+       for (i = DRM_SCHED_PRIORITY_NORMAL + 1; i < DRM_SCHED_PRIORITY_MAX; i++) {
+               adev->gfx.compute_prio_sched[i] =
+                       &adev->gfx.compute_sched[num_compute_sched_high - 1];
+               adev->gfx.num_compute_sched[i] =
+                       adev->gfx.num_compute_rings - num_compute_sched_normal;
+       }
+}
+
 void amdgpu_ctx_init_sched(struct amdgpu_device *adev)
 {
        int i, j;
 
+       amdgpu_ctx_init_compute_sched(adev);
        for (i = 0; i < adev->gfx.num_gfx_rings; i++) {
                adev->gfx.gfx_sched[i] = &adev->gfx.gfx_ring[i].sched;
                adev->gfx.num_gfx_sched++;
        }
 
-       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++;
-       }
-
        for (i = 0; i < adev->sdma.num_instances; i++) {
                adev->sdma.sdma_sched[i] = &adev->sdma.instance[i].ring.sched;
                adev->sdma.num_sdma_sched++;
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +8 -0
index 7403588684b3..952725e7243c 100644
@@ -192,6 +192,14 @@ 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)
+{
+       /* Policy: make queue 0 of each pipe as high priority compute queue */
+       return (queue == 0);
+
+}
+
 void amdgpu_gfx_compute_queue_acquire(struct amdgpu_device *adev)
 {
        int i, queue, pipe, mec;
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +12 -1
index 37ba05b63b2a..f87b6df67694 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;
@@ -280,8 +288,9 @@ struct amdgpu_gfx {
        uint32_t                        num_gfx_sched;
        unsigned                        num_gfx_rings;
        struct amdgpu_ring              compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
+       struct drm_gpu_scheduler        **compute_prio_sched[DRM_SCHED_PRIORITY_MAX];
        struct drm_gpu_scheduler        *compute_sched[AMDGPU_MAX_COMPUTE_RINGS];
-       uint32_t                        num_compute_sched;
+       uint32_t                        num_compute_sched[DRM_SCHED_PRIORITY_MAX];
        unsigned                        num_compute_rings;
        struct amdgpu_irq_src           eop_irq;
        struct amdgpu_irq_src           priv_reg_irq;
@@ -363,6 +372,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_v10_0.c +3 -0
index 94ca9ffa0ccb..0e6ce65e1e54 100644
@@ -3211,6 +3211,22 @@ static int gfx_v10_0_cp_async_gfx_ring_resume(struct amdgpu_device *adev)
        return r;
 }
 
+static void gfx_v10_0_compute_mqd_set_priority(struct amdgpu_ring *ring, struct v10_compute_mqd *mqd)
+{
+       struct amdgpu_device *adev = ring->adev;

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static int gfx_v10_0_cp_async_gfx_ring_resume(struct amdgpu_device *adev) · line 3226

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +10 -0
+
+       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;
+               }
+               else
+                       ring->high_priority = false;

Coding style. If any clause has parens, the whole thing should have them. Also conditions should be on the same line as the parens. E.g.,

if () {
    ...
} else {
    ...
}

Same comment on the other gfx* functions below.

Alex

Quoted 105 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +6 -0
+       }
+}
+
 static int gfx_v10_0_compute_mqd_init(struct amdgpu_ring *ring)
 {
        struct amdgpu_device *adev = ring->adev;
@@ -3336,6 +3352,9 @@ static int gfx_v10_0_compute_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_v10_0_compute_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_v8_0.c +20 -3
index 393a1324daa9..6c4b7e49f97f 100644
@@ -4430,6 +4430,22 @@ 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;
+               }
+               else
+                       ring->high_priority = false;
+       }
+}
+
 static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)
 {
        struct amdgpu_device *adev = ring->adev;
@@ -4553,9 +4569,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);
@@ -4567,6 +4580,10 @@ 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);
+       mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);
+
        /* 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 -1
index 015647959d69..ff5e913f244d 100644
@@ -3314,6 +3314,22 @@ 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;
+               }
+               else
+                       ring->high_priority = false;
+       }
+}
+
 static int gfx_v9_0_mqd_init(struct amdgpu_ring *ring)
 {
        struct amdgpu_device *adev = ring->adev;
@@ -3450,6 +3466,10 @@ 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);
+       mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);
+
        /* 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