Skip to content

Commit 33abcb1

Browse files
Nirmoy Dasalexdeucher
authored andcommitted
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 Signed-off-by: Nirmoy Das <[email protected]> Acked-by: Alex Deucher <[email protected]> Acked-by: Christian König <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent c1b6921 commit 33abcb1

File tree

9 files changed

+127
-21
lines changed

9 files changed

+127
-21
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,6 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
12051205
struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
12061206
struct drm_sched_entity *entity = p->entity;
12071207
enum drm_sched_priority priority;
1208-
struct amdgpu_ring *ring;
12091208
struct amdgpu_bo_list_entry *e;
12101209
struct amdgpu_job *job;
12111210
uint64_t seq;
@@ -1258,9 +1257,6 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
12581257
priority = job->base.s_priority;
12591258
drm_sched_entity_push_job(&job->base, entity);
12601259

1261-
ring = to_amdgpu_ring(entity->rq->sched);
1262-
amdgpu_ring_priority_get(ring, priority);
1263-
12641260
amdgpu_vm_move_to_lru_tail(p->adev, &fpriv->vm);
12651261

12661262
ttm_eu_fence_buffer_objects(&p->ticket, &p->validated, p->fence);

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,24 @@ static int amdgpu_ctx_priority_permit(struct drm_file *filp,
6161
return -EACCES;
6262
}
6363

64+
static enum gfx_pipe_priority amdgpu_ctx_sched_prio_to_compute_prio(enum drm_sched_priority prio)
65+
{
66+
switch (prio) {
67+
case DRM_SCHED_PRIORITY_HIGH_HW:
68+
case DRM_SCHED_PRIORITY_KERNEL:
69+
return AMDGPU_GFX_PIPE_PRIO_HIGH;
70+
default:
71+
return AMDGPU_GFX_PIPE_PRIO_NORMAL;
72+
}
73+
}
74+
6475
static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, const u32 hw_ip, const u32 ring)
6576
{
6677
struct amdgpu_device *adev = ctx->adev;
6778
struct amdgpu_ctx_entity *entity;
6879
struct drm_gpu_scheduler **scheds = NULL, *sched = NULL;
6980
unsigned num_scheds = 0;
81+
enum gfx_pipe_priority hw_prio;
7082
enum drm_sched_priority priority;
7183
int r;
7284

@@ -85,8 +97,9 @@ static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, const u32 hw_ip, const
8597
num_scheds = 1;
8698
break;
8799
case AMDGPU_HW_IP_COMPUTE:
88-
scheds = adev->gfx.compute_sched;
89-
num_scheds = adev->gfx.num_compute_sched;
100+
hw_prio = amdgpu_ctx_sched_prio_to_compute_prio(priority);
101+
scheds = adev->gfx.compute_prio_sched[hw_prio];
102+
num_scheds = adev->gfx.num_compute_sched[hw_prio];
90103
break;
91104
case AMDGPU_HW_IP_DMA:
92105
scheds = adev->sdma.sdma_sched;
@@ -628,20 +641,46 @@ void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr)
628641
mutex_destroy(&mgr->lock);
629642
}
630643

644+
645+
static void amdgpu_ctx_init_compute_sched(struct amdgpu_device *adev)
646+
{
647+
int num_compute_sched_normal = 0;
648+
int num_compute_sched_high = AMDGPU_MAX_COMPUTE_RINGS - 1;
649+
int i;
650+
651+
/* use one drm sched array, gfx.compute_sched to store both high and
652+
* normal priority drm compute schedulers */
653+
for (i = 0; i < adev->gfx.num_compute_rings; i++) {
654+
if (!adev->gfx.compute_ring[i].has_high_prio)
655+
adev->gfx.compute_sched[num_compute_sched_normal++] =
656+
&adev->gfx.compute_ring[i].sched;
657+
else
658+
adev->gfx.compute_sched[num_compute_sched_high--] =
659+
&adev->gfx.compute_ring[i].sched;
660+
}
661+
662+
/* compute ring only has two priority for now */
663+
i = AMDGPU_GFX_PIPE_PRIO_NORMAL;
664+
adev->gfx.compute_prio_sched[i] = &adev->gfx.compute_sched[0];
665+
adev->gfx.num_compute_sched[i] = num_compute_sched_normal;
666+
667+
i = AMDGPU_GFX_PIPE_PRIO_HIGH;
668+
adev->gfx.compute_prio_sched[i] =
669+
&adev->gfx.compute_sched[num_compute_sched_high - 1];
670+
adev->gfx.num_compute_sched[i] =
671+
adev->gfx.num_compute_rings - num_compute_sched_normal;
672+
}
673+
631674
void amdgpu_ctx_init_sched(struct amdgpu_device *adev)
632675
{
633676
int i, j;
634677

678+
amdgpu_ctx_init_compute_sched(adev);
635679
for (i = 0; i < adev->gfx.num_gfx_rings; i++) {
636680
adev->gfx.gfx_sched[i] = &adev->gfx.gfx_ring[i].sched;
637681
adev->gfx.num_gfx_sched++;
638682
}
639683

640-
for (i = 0; i < adev->gfx.num_compute_rings; i++) {
641-
adev->gfx.compute_sched[i] = &adev->gfx.compute_ring[i].sched;
642-
adev->gfx.num_compute_sched++;
643-
}
644-
645684
for (i = 0; i < adev->sdma.num_instances; i++) {
646685
adev->sdma.sdma_sched[i] = &adev->sdma.instance[i].ring.sched;
647686
adev->sdma.num_sdma_sched++;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ static bool amdgpu_gfx_is_multipipe_capable(struct amdgpu_device *adev)
192192
return adev->gfx.mec.num_mec > 1;
193193
}
194194

195+
bool amdgpu_gfx_is_high_priority_compute_queue(struct amdgpu_device *adev,
196+
int queue)
197+
{
198+
/* Policy: make queue 0 of each pipe as high priority compute queue */
199+
return (queue == 0);
200+
201+
}
202+
195203
void amdgpu_gfx_compute_queue_acquire(struct amdgpu_device *adev)
196204
{
197205
int i, queue, pipe, mec;

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@
4141
#define AMDGPU_MAX_GFX_QUEUES KGD_MAX_QUEUES
4242
#define AMDGPU_MAX_COMPUTE_QUEUES KGD_MAX_QUEUES
4343

44+
enum gfx_pipe_priority {
45+
AMDGPU_GFX_PIPE_PRIO_NORMAL = 1,
46+
AMDGPU_GFX_PIPE_PRIO_HIGH,
47+
AMDGPU_GFX_PIPE_PRIO_MAX
48+
};
49+
50+
#define AMDGPU_GFX_QUEUE_PRIORITY_MINIMUM 0
51+
#define AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM 15
52+
4453
struct amdgpu_mec {
4554
struct amdgpu_bo *hpd_eop_obj;
4655
u64 hpd_eop_gpu_addr;
@@ -281,8 +290,9 @@ struct amdgpu_gfx {
281290
uint32_t num_gfx_sched;
282291
unsigned num_gfx_rings;
283292
struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
293+
struct drm_gpu_scheduler **compute_prio_sched[AMDGPU_GFX_PIPE_PRIO_MAX];
284294
struct drm_gpu_scheduler *compute_sched[AMDGPU_MAX_COMPUTE_RINGS];
285-
uint32_t num_compute_sched;
295+
uint32_t num_compute_sched[AMDGPU_GFX_PIPE_PRIO_MAX];
286296
unsigned num_compute_rings;
287297
struct amdgpu_irq_src eop_irq;
288298
struct amdgpu_irq_src priv_reg_irq;
@@ -364,6 +374,8 @@ void amdgpu_gfx_bit_to_mec_queue(struct amdgpu_device *adev, int bit,
364374
int *mec, int *pipe, int *queue);
365375
bool amdgpu_gfx_is_mec_queue_enabled(struct amdgpu_device *adev, int mec,
366376
int pipe, int queue);
377+
bool amdgpu_gfx_is_high_priority_compute_queue(struct amdgpu_device *adev,
378+
int queue);
367379
int amdgpu_gfx_me_queue_to_bit(struct amdgpu_device *adev, int me,
368380
int pipe, int queue);
369381
void amdgpu_gfx_bit_to_me_queue(struct amdgpu_device *adev, int bit,

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,10 @@ void amdgpu_job_free_resources(struct amdgpu_job *job)
117117

118118
static void amdgpu_job_free_cb(struct drm_sched_job *s_job)
119119
{
120-
struct amdgpu_ring *ring = to_amdgpu_ring(s_job->sched);
121120
struct amdgpu_job *job = to_amdgpu_job(s_job);
122121

123122
drm_sched_job_cleanup(s_job);
124123

125-
amdgpu_ring_priority_put(ring, s_job->s_priority);
126124
dma_fence_put(job->fence);
127125
amdgpu_sync_free(&job->sync);
128126
amdgpu_sync_free(&job->sched_sync);
@@ -143,7 +141,6 @@ int amdgpu_job_submit(struct amdgpu_job *job, struct drm_sched_entity *entity,
143141
void *owner, struct dma_fence **f)
144142
{
145143
enum drm_sched_priority priority;
146-
struct amdgpu_ring *ring;
147144
int r;
148145

149146
if (!f)
@@ -158,9 +155,6 @@ int amdgpu_job_submit(struct amdgpu_job *job, struct drm_sched_entity *entity,
158155
priority = job->base.s_priority;
159156
drm_sched_entity_push_job(&job->base, entity);
160157

161-
ring = to_amdgpu_ring(entity->rq->sched);
162-
amdgpu_ring_priority_get(ring, priority);
163-
164158
return 0;
165159
}
166160

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ struct amdgpu_ring {
222222
struct mutex priority_mutex;
223223
/* protected by priority_mutex */
224224
int priority;
225+
bool has_high_prio;
225226

226227
#if defined(CONFIG_DEBUG_FS)
227228
struct dentry *ent;

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3213,6 +3213,22 @@ static int gfx_v10_0_cp_async_gfx_ring_resume(struct amdgpu_device *adev)
32133213
return r;
32143214
}
32153215

3216+
static void gfx_v10_0_compute_mqd_set_priority(struct amdgpu_ring *ring, struct v10_compute_mqd *mqd)
3217+
{
3218+
struct amdgpu_device *adev = ring->adev;
3219+
3220+
if (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) {
3221+
if (amdgpu_gfx_is_high_priority_compute_queue(adev, ring->queue)) {
3222+
mqd->cp_hqd_pipe_priority = AMDGPU_GFX_PIPE_PRIO_HIGH;
3223+
ring->has_high_prio = true;
3224+
mqd->cp_hqd_queue_priority =
3225+
AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM;
3226+
} else {
3227+
ring->has_high_prio = false;
3228+
}
3229+
}
3230+
}
3231+
32163232
static int gfx_v10_0_compute_mqd_init(struct amdgpu_ring *ring)
32173233
{
32183234
struct amdgpu_device *adev = ring->adev;
@@ -3338,6 +3354,9 @@ static int gfx_v10_0_compute_mqd_init(struct amdgpu_ring *ring)
33383354
tmp = REG_SET_FIELD(tmp, CP_HQD_IB_CONTROL, MIN_IB_AVAIL_SIZE, 3);
33393355
mqd->cp_hqd_ib_control = tmp;
33403356

3357+
/* set static priority for a compute queue/ring */
3358+
gfx_v10_0_compute_mqd_set_priority(ring, mqd);
3359+
33413360
/* map_queues packet doesn't need activate the queue,
33423361
* so only kiq need set this field.
33433362
*/

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4430,6 +4430,22 @@ static int gfx_v8_0_deactivate_hqd(struct amdgpu_device *adev, u32 req)
44304430
return r;
44314431
}
44324432

4433+
static void gfx_v8_0_mqd_set_priority(struct amdgpu_ring *ring, struct vi_mqd *mqd)
4434+
{
4435+
struct amdgpu_device *adev = ring->adev;
4436+
4437+
if (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) {
4438+
if (amdgpu_gfx_is_high_priority_compute_queue(adev, ring->queue)) {
4439+
mqd->cp_hqd_pipe_priority = AMDGPU_GFX_PIPE_PRIO_HIGH;
4440+
ring->has_high_prio = true;
4441+
mqd->cp_hqd_queue_priority =
4442+
AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM;
4443+
} else {
4444+
ring->has_high_prio = false;
4445+
}
4446+
}
4447+
}
4448+
44334449
static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)
44344450
{
44354451
struct amdgpu_device *adev = ring->adev;
@@ -4553,9 +4569,6 @@ static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)
45534569
/* defaults */
45544570
mqd->cp_hqd_eop_rptr = RREG32(mmCP_HQD_EOP_RPTR);
45554571
mqd->cp_hqd_eop_wptr = RREG32(mmCP_HQD_EOP_WPTR);
4556-
mqd->cp_hqd_pipe_priority = RREG32(mmCP_HQD_PIPE_PRIORITY);
4557-
mqd->cp_hqd_queue_priority = RREG32(mmCP_HQD_QUEUE_PRIORITY);
4558-
mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);
45594572
mqd->cp_hqd_ctx_save_base_addr_lo = RREG32(mmCP_HQD_CTX_SAVE_BASE_ADDR_LO);
45604573
mqd->cp_hqd_ctx_save_base_addr_hi = RREG32(mmCP_HQD_CTX_SAVE_BASE_ADDR_HI);
45614574
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)
45674580
mqd->cp_hqd_eop_wptr_mem = RREG32(mmCP_HQD_EOP_WPTR_MEM);
45684581
mqd->cp_hqd_eop_dones = RREG32(mmCP_HQD_EOP_DONES);
45694582

4583+
/* set static priority for a queue/ring */
4584+
gfx_v8_0_mqd_set_priority(ring, mqd);
4585+
mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);
4586+
45704587
/* map_queues packet doesn't need activate the queue,
45714588
* so only kiq need set this field.
45724589
*/

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3316,6 +3316,22 @@ static void gfx_v9_0_kiq_setting(struct amdgpu_ring *ring)
33163316
WREG32_SOC15_RLC(GC, 0, mmRLC_CP_SCHEDULERS, tmp);
33173317
}
33183318

3319+
static void gfx_v9_0_mqd_set_priority(struct amdgpu_ring *ring, struct v9_mqd *mqd)
3320+
{
3321+
struct amdgpu_device *adev = ring->adev;
3322+
3323+
if (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) {
3324+
if (amdgpu_gfx_is_high_priority_compute_queue(adev, ring->queue)) {
3325+
mqd->cp_hqd_pipe_priority = AMDGPU_GFX_PIPE_PRIO_HIGH;
3326+
ring->has_high_prio = true;
3327+
mqd->cp_hqd_queue_priority =
3328+
AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM;
3329+
} else {
3330+
ring->has_high_prio = false;
3331+
}
3332+
}
3333+
}
3334+
33193335
static int gfx_v9_0_mqd_init(struct amdgpu_ring *ring)
33203336
{
33213337
struct amdgpu_device *adev = ring->adev;
@@ -3452,6 +3468,10 @@ static int gfx_v9_0_mqd_init(struct amdgpu_ring *ring)
34523468
tmp = REG_SET_FIELD(tmp, CP_HQD_IB_CONTROL, MIN_IB_AVAIL_SIZE, 3);
34533469
mqd->cp_hqd_ib_control = tmp;
34543470

3471+
/* set static priority for a queue/ring */
3472+
gfx_v9_0_mqd_set_priority(ring, mqd);
3473+
mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);
3474+
34553475
/* map_queues packet doesn't need activate the queue,
34563476
* so only kiq need set this field.
34573477
*/

0 commit comments

Comments
 (0)