drm/amdgpu/gfx7: fix pipeline sync
Subsystems (2)
PATCH 1/1 drm/amdgpu/gfx7: fix pipeline sync
From: Chunming Zhou <[email protected]>
Need to wait on the fence as well.
--- drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +13 -12
@@ -3054,6 +3054,19 @@ static int gfx_v7_0_cp_resume(struct amdgpu_device *adev)static void gfx_v7_0_ring_emit_pipeline_sync (struct amdgpu_ring *ring) {int usepfp = (ring->type ==AMDGPU_RING_TYPE_GFX ); +uint32_t seq = ring->fence_drv.sync_seq; +uint64_t addr = ring->fence_drv.gpu_addr; + +amdgpu_ring_write (ring,PACKET3 (PACKET3_WAIT_REG_MEM ,5 )); +amdgpu_ring_write (ring, (WAIT_REG_MEM_MEM_SPACE (1 ) |/* memory */ +WAIT_REG_MEM_FUNCTION (3 ) |/* equal */ +WAIT_REG_MEM_ENGINE (usepfp)));/* pfp or me */ +amdgpu_ring_write (ring, addr &0xfffffffc ); +amdgpu_ring_write (ring,upper_32_bits (addr) &0xffffffff ); +amdgpu_ring_write (ring, seq); +amdgpu_ring_write (ring,0xffffffff ); +amdgpu_ring_write (ring,4 );/* poll interval */ +if (usepfp) {/* synce CE with ME to prevent CE fetch CEIB before context switch done */ amdgpu_ring_write (ring,PACKET3 (PACKET3_SWITCH_BUFFER ,0 ));
@@ -3081,18 +3094,6 @@ static void gfx_v7_0_ring_emit_vm_flush(struct amdgpu_ring *ring, unsigned vm_id, uint64_t pd_addr) { int usepfp = (ring->type == AMDGPU_RING_TYPE_GFX); -uint32_t seq = ring->fence_drv.sync_seq; -uint64_t addr = ring->fence_drv.gpu_addr; - -amdgpu_ring_write (ring,PACKET3 (PACKET3_WAIT_REG_MEM ,5 )); -amdgpu_ring_write (ring, (WAIT_REG_MEM_MEM_SPACE (1 ) |/* memory */ -WAIT_REG_MEM_FUNCTION (3 ) |/* equal */ -WAIT_REG_MEM_ENGINE (usepfp)));/* pfp or me */ -amdgpu_ring_write (ring, addr &0xfffffffc ); -amdgpu_ring_write (ring,upper_32_bits (addr) &0xffffffff ); -amdgpu_ring_write (ring, seq); -amdgpu_ring_write (ring,0xffffffff ); -amdgpu_ring_write (ring,4 );/* poll interval */ amdgpu_ring_write (ring,PACKET3 (PACKET3_WRITE_DATA ,3 )); amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
Signature · 6 lines
2.5.5 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 1/1 drm/amdgpu: move preamble IB handling into common code
From: Christian König <[email protected]>
This fixes the handling which was completely broken when you ad more than one preamble IB.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 8 +++++++- drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c | 4 ---- drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 4 ---- 3 files changed, 7 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +7 -1
@@ -125,6 +125,7 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,struct fence *hwf;struct amdgpu_vm *vm =NULL ;unsigned i, patch_offset = ~0 ; +bool skip_preamble;int r =0 ;
@@ -172,9 +173,14 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,/* always set cond_exec_polling to CONTINUE */ *ring->cond_exe_cpu_addr =1 ; + skip_preamble = ring->current_ctx == ctx; old_ctx = ring->current_ctx;for (i =0 ; i < num_ibs; ++i) { - ib = &ibs[i]; + +/* drop preamble IBs if we don't have a context switch */ +if ((ib->flags &AMDGPU_IB_FLAG_PREAMBLE ) && skip_preamble) +continue ; +amdgpu_ring_emit_ib (ring, ib); ring->current_ctx = ctx; }
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +0 -4
@@ -2036,10 +2036,6 @@ static void gfx_v7_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,u32 header, control =0 ;u32 next_rptr = ring->wptr +5 ; -/* drop the CE preamble IB for the same context */ -if ((ib->flags &AMDGPU_IB_FLAG_PREAMBLE ) && !need_ctx_switch) -return ; -if (need_ctx_switch) next_rptr +=2 ;
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +0 -4
@@ -5652,10 +5652,6 @@ static void gfx_v8_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,u32 header, control =0 ;u32 next_rptr = ring->wptr +5 ; -/* drop the CE preamble IB for the same context */ -if ((ib->flags &AMDGPU_IB_FLAG_PREAMBLE ) && !need_ctx_switch) -return ; -if (need_ctx_switch) next_rptr +=2 ;
Signature · 6 lines
2.5.5 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 1/1 drm/amdgpu: move context switch handling into common code v2
In reply to Alex DeucherFrom: Christian König <[email protected]>
It was a source of bugs to repeat that in each IP version.
v2: rename parameter
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 16 +++++++--------- drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h | 2 +- drivers/gpu/drm/amd/amdgpu/cik_sdma.c | 2 +- drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c | 9 ++++----- drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 9 ++++----- drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c | 2 +- drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c | 2 +- drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c | 2 +- 12 files changed, 25 insertions(+), 29 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -2
@@ -283,7 +283,7 @@ struct amdgpu_ring_funcs {int (*parse_cs)(struct amdgpu_cs_parser *p,uint32_t ib_idx);/* command emit functions */ void (*emit_ib)(struct amdgpu_ring *ring, -struct amdgpu_ib *ib); +struct amdgpu_ib *ib,bool ctx_switch);void (*emit_fence)(struct amdgpu_ring *ring,uint64_t addr,uint64_t seq,unsigned flags);void (*emit_pipeline_sync)(struct amdgpu_ring *ring);
@@ -2220,7 +2220,7 @@ amdgpu_get_sdma_instance(struct amdgpu_ring *ring)#define amdgpu_ring_get_rptr (r) (r)->funcs->get_rptr((r))#define amdgpu_ring_get_wptr (r) (r)->funcs->get_wptr((r))#define amdgpu_ring_set_wptr (r) (r)->funcs->set_wptr((r)) -#define amdgpu_ring_emit_ib (r, ib) (r)->funcs->emit_ib((r), (ib)) +#define amdgpu_ring_emit_ib (r, ib, c) (r)->funcs->emit_ib((r), (ib), (c))#define amdgpu_ring_emit_pipeline_sync (r) (r)->funcs->emit_pipeline_sync((r))#define amdgpu_ring_emit_vm_flush (r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))#define amdgpu_ring_emit_fence (r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +7 -9
@@ -121,18 +121,16 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs, {struct amdgpu_device *adev = ring->adev;struct amdgpu_ib *ib = &ibs[0 ]; -uint64_t ctx, old_ctx;struct fence *hwf;struct amdgpu_vm *vm =NULL ;unsigned i, patch_offset = ~0 ; -bool skip_preamble; +bool skip_preamble, need_ctx_switch;int r =0 ;if (num_ibs ==0 )return -EINVAL ; - ctx = ibs->ctx;if (job)/* for domain0 job like ring test, ibs->job is not assigned */ vm = job->vm;
@@ -156,7 +154,6 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs, patch_offset =amdgpu_ring_init_cond_exec (ring);if (vm) { -/* do context switch */ r = amdgpu_vm_flush(ring, ib->vm_id, ib->vm_pd_addr, ib->gds_base, ib->gds_size, ib->gws_base, ib->gws_size,
@@ -173,16 +170,17 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,/* always set cond_exec_polling to CONTINUE */ *ring->cond_exe_cpu_addr =1 ; - skip_preamble = ring->current_ctx == ctx; - old_ctx = ring->current_ctx; + skip_preamble = ring->current_ctx == ib->ctx; + need_ctx_switch = ring->current_ctx != ib->ctx;for (i =0 ; i < num_ibs; ++i) { + ib = &ibs[i];/* drop preamble IBs if we don't have a context switch */ if ((ib->flags &AMDGPU_IB_FLAG_PREAMBLE ) && skip_preamble)continue ; -amdgpu_ring_emit_ib (ring, ib); - ring->current_ctx = ctx; +amdgpu_ring_emit_ib (ring, ib, need_ctx_switch); + need_ctx_switch = false; }if (ring->funcs->emit_hdp_invalidate)
@@ -191,7 +189,6 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs, r =amdgpu_fence_emit (ring, &hwf);if (r) {dev_err (adev->dev,"failed to emit fence (%d)\n" , r); - ring->current_ctx = old_ctx;if (ib->vm_id)amdgpu_vm_reset_id (adev, ib->vm_id);amdgpu_ring_undo (ring);
@@ -212,6 +209,7 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,if (patch_offset != ~0 && ring->funcs->patch_cond_exec)amdgpu_ring_patch_cond_exec (ring, patch_offset); + ring->current_ctx = ibs->ctx;amdgpu_ring_commit (ring);return 0 ; }
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +1 -1
@@ -761,7 +761,7 @@ out:* @ib: the IB to execute * */ -void amdgpu_vce_ring_emit_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib) +void amdgpu_vce_ring_emit_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib,bool ctx_switch) {amdgpu_ring_write (ring,VCE_CMD_IB );amdgpu_ring_write (ring,lower_32_bits (ib->gpu_addr));
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h +1 -1
@@ -34,7 +34,7 @@ int amdgpu_vce_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle, bool direct, struct fence **fence);void amdgpu_vce_free_handles (struct amdgpu_device *adev,struct drm_file *filp);int amdgpu_vce_ring_parse_cs (struct amdgpu_cs_parser *p,uint32_t ib_idx); -void amdgpu_vce_ring_emit_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib); +void amdgpu_vce_ring_emit_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib,bool ctx_switch);void amdgpu_vce_ring_emit_fence (struct amdgpu_ring *ring,u64 addr,u64 seq,unsigned flags);int amdgpu_vce_ring_test_ring (struct amdgpu_ring *ring);
drivers/gpu/drm/amd/amdgpu/cik_sdma.c +1 -1
@@ -210,7 +210,7 @@ static void cik_sdma_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count)* Schedule an IB in the DMA ring (CIK). */ static void cik_sdma_ring_emit_ib (struct amdgpu_ring *ring, -struct amdgpu_ib *ib) +struct amdgpu_ib *ib,bool ctx_switch) {u32 extra_bits = ib->vm_id &0xf ;u32 next_rptr = ring->wptr +5 ;
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +4 -5
@@ -2030,13 +2030,12 @@ static void gfx_v7_0_ring_emit_fence_compute(struct amdgpu_ring *ring,* on the gfx ring for execution by the GPU. */ static void gfx_v7_0_ring_emit_ib_gfx (struct amdgpu_ring *ring, -struct amdgpu_ib *ib) +struct amdgpu_ib *ib,bool ctx_switch) { -bool need_ctx_switch = ring->current_ctx != ib->ctx;u32 header, control =0 ;u32 next_rptr = ring->wptr +5 ; -if (need_ctx_switch) +if (ctx_switch) next_rptr +=2 ; next_rptr +=4 ;
@@ -2047,7 +2046,7 @@ static void gfx_v7_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,amdgpu_ring_write (ring, next_rptr);/* insert SWITCH_BUFFER packet before first IB in the ring frame */ -if (need_ctx_switch) { +if (ctx_switch) {amdgpu_ring_write (ring,PACKET3 (PACKET3_SWITCH_BUFFER ,0 ));amdgpu_ring_write (ring,0 ); }
@@ -2070,7 +2069,7 @@ static void gfx_v7_0_ring_emit_ib_gfx(struct amdgpu_ring *ring, }static void gfx_v7_0_ring_emit_ib_compute (struct amdgpu_ring *ring, -struct amdgpu_ib *ib) +struct amdgpu_ib *ib,bool ctx_switch) {u32 header, control =0 ;u32 next_rptr = ring->wptr +5 ;
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +4 -5
@@ -5646,13 +5646,12 @@ static void gfx_v8_0_ring_emit_hdp_invalidate(struct amdgpu_ring *ring) }static void gfx_v8_0_ring_emit_ib_gfx (struct amdgpu_ring *ring, -struct amdgpu_ib *ib) +struct amdgpu_ib *ib,bool ctx_switch) { -bool need_ctx_switch = ring->current_ctx != ib->ctx;u32 header, control =0 ;u32 next_rptr = ring->wptr +5 ; -if (need_ctx_switch) +if (ctx_switch) next_rptr +=2 ; next_rptr +=4 ;
@@ -5663,7 +5662,7 @@ static void gfx_v8_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,amdgpu_ring_write (ring, next_rptr);/* insert SWITCH_BUFFER packet before first IB in the ring frame */ -if (need_ctx_switch) { +if (ctx_switch) {amdgpu_ring_write (ring,PACKET3 (PACKET3_SWITCH_BUFFER ,0 ));amdgpu_ring_write (ring,0 ); }
@@ -5686,7 +5685,7 @@ static void gfx_v8_0_ring_emit_ib_gfx(struct amdgpu_ring *ring, }static void gfx_v8_0_ring_emit_ib_compute (struct amdgpu_ring *ring, -struct amdgpu_ib *ib) +struct amdgpu_ib *ib,bool ctx_switch) {u32 header, control =0 ;u32 next_rptr = ring->wptr +5 ;
drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c +1 -1
@@ -242,7 +242,7 @@ static void sdma_v2_4_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count)* Schedule an IB in the DMA ring (VI). */ static void sdma_v2_4_ring_emit_ib (struct amdgpu_ring *ring, -struct amdgpu_ib *ib) +struct amdgpu_ib *ib,bool ctx_switch) {u32 vmid = ib->vm_id &0xf ;u32 next_rptr = ring->wptr +5 ;
drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +1 -1
@@ -400,7 +400,7 @@ static void sdma_v3_0_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count)* Schedule an IB in the DMA ring (VI). */ static void sdma_v3_0_ring_emit_ib (struct amdgpu_ring *ring, -struct amdgpu_ib *ib) +struct amdgpu_ib *ib,bool ctx_switch) {u32 vmid = ib->vm_id &0xf ;u32 next_rptr = ring->wptr +5 ;
drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c +1 -1
@@ -489,7 +489,7 @@ static int uvd_v4_2_ring_test_ring(struct amdgpu_ring *ring)* Write ring commands to execute the indirect buffer */ static void uvd_v4_2_ring_emit_ib (struct amdgpu_ring *ring, -struct amdgpu_ib *ib) +struct amdgpu_ib *ib,bool ctx_switch) {amdgpu_ring_write (ring,PACKET0 (mmUVD_RBC_IB_BASE,0 ));amdgpu_ring_write (ring, ib->gpu_addr);
drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c +1 -1
@@ -539,7 +539,7 @@ static int uvd_v5_0_ring_test_ring(struct amdgpu_ring *ring)* Write ring commands to execute the indirect buffer */ static void uvd_v5_0_ring_emit_ib (struct amdgpu_ring *ring, -struct amdgpu_ib *ib) +struct amdgpu_ib *ib,bool ctx_switch) {amdgpu_ring_write (ring,PACKET0 (mmUVD_LMI_RBC_IB_64BIT_BAR_LOW,0 ));amdgpu_ring_write (ring,lower_32_bits (ib->gpu_addr));
drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c +1 -1
@@ -631,7 +631,7 @@ static int uvd_v6_0_ring_test_ring(struct amdgpu_ring *ring)* Write ring commands to execute the indirect buffer */ static void uvd_v6_0_ring_emit_ib (struct amdgpu_ring *ring, -struct amdgpu_ib *ib) +struct amdgpu_ib *ib,bool ctx_switch) {amdgpu_ring_write (ring,PACKET0 (mmUVD_LMI_RBC_IB_64BIT_BAR_LOW,0 ));amdgpu_ring_write (ring,lower_32_bits (ib->gpu_addr));
Signature · 6 lines
2.5.5 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 1/1 drm/amdgpu: move the context from the IBs into the job
In reply to Alex DeucherFrom: Christian König <[email protected]>
We only have one context for all IBs.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 10 +++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 22 +++++++++++++++------- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 7 +++---- 4 files changed, 24 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -1
@@ -743,7 +743,6 @@ struct amdgpu_ib {struct amdgpu_user_fence *user;unsigned vm_id;uint64_t vm_pd_addr; -uint64_t ctx;uint32_t gds_base, gds_size;uint32_t gws_base, gws_size;uint32_t oa_base, oa_size;
@@ -1262,6 +1261,7 @@ struct amdgpu_job {struct fence *fence;/* the hw fence */ uint32_t num_ibs;void *owner; +uint64_t ctx;struct amdgpu_user_fence uf; };#define to_amdgpu_job (sched_job) \
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +5 -5
@@ -741,7 +741,6 @@ static int amdgpu_cs_ib_fill(struct amdgpu_device *adev, ib->length_dw = chunk_ib->ib_bytes /4 ; ib->flags = chunk_ib->flags; - ib->ctx = parser->ctx->rings[ring->idx].entity.fence_context; j++; }
@@ -840,6 +839,7 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p, union drm_amdgpu_cs *cs) {struct amdgpu_ring *ring = p->job->ring; +struct amd_sched_entity *entity = &p->ctx->rings[ring->idx].entity;struct fence *fence;struct amdgpu_job *job;int r;
@@ -848,16 +848,16 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p, p->job =NULL ; r =amd_sched_job_init (&job->base, &ring->sched, - &p->ctx->rings[ring->idx].entity, - amdgpu_job_timeout_func, - amdgpu_job_free_func, - p->filp, &fence); + entity, amdgpu_job_timeout_func, + amdgpu_job_free_func, + p->filp, &fence);if (r) {amdgpu_job_free (job);return r; } job->owner = p->filp; + job->ctx = entity->fence_context; p->fence =fence_get (fence); cs->out.handle =amdgpu_ctx_add_fence (p->ctx, ring, fence); job->ibs[job->num_ibs -1 ].sequence = cs->out.handle;
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +15 -7
@@ -121,18 +121,26 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs, {struct amdgpu_device *adev = ring->adev;struct amdgpu_ib *ib = &ibs[0 ]; -struct fence *hwf; -struct amdgpu_vm *vm =NULL ; -unsigned i, patch_offset = ~0 ;bool skip_preamble, need_ctx_switch; +unsigned patch_offset = ~0 ; +struct amdgpu_vm *vm; +struct fence *hwf; +uint64_t ctx; +unsigned i;int r =0 ;if (num_ibs ==0 )return -EINVAL ; -if (job)/* for domain0 job like ring test, ibs->job is not assigned */ +/* ring tests don't use a job */ +if (job) { vm = job->vm; + ctx = job->ctx; + }else { + vm =NULL ; + ctx =0 ; + }if (!ring->ready) {dev_err (adev->dev,"couldn't schedule ib\n" );
@@ -170,8 +178,8 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,/* always set cond_exec_polling to CONTINUE */ *ring->cond_exe_cpu_addr =1 ; - skip_preamble = ring->current_ctx == ib->ctx; - need_ctx_switch = ring->current_ctx != ib->ctx; + skip_preamble = ring->current_ctx == ctx; + need_ctx_switch = ring->current_ctx != ctx;for (i =0 ; i < num_ibs; ++i) { ib = &ibs[i];
@@ -209,7 +217,7 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,if (patch_offset != ~0 && ring->funcs->patch_cond_exec)amdgpu_ring_patch_cond_exec (ring, patch_offset); - ring->current_ctx = ibs->ctx; + ring->current_ctx = ctx;amdgpu_ring_commit (ring);return 0 ; }
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +3 -4
@@ -122,14 +122,13 @@ int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,return -EINVAL ; r =amd_sched_job_init (&job->base, &ring->sched, - entity, - amdgpu_job_timeout_func, - amdgpu_job_free_func, - owner, &fence); + entity, amdgpu_job_timeout_func, + amdgpu_job_free_func, owner, &fence);if (r)return r; job->owner = owner; + job->ctx = entity->fence_context; *f =fence_get (fence);amd_sched_entity_push_job (&job->base);
Signature · 6 lines
2.5.5 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 1/1 drm/amdgpu: move VM fields into job
In reply to Alex DeucherFrom: Christian König <[email protected]>
They are the same for all IBs.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 15 +++++++------- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 36 +++++++++++++++------------------ drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 19 +++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 12 ++--------- drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h | 3 ++- drivers/gpu/drm/amd/amdgpu/cik_sdma.c | 5 +++-- drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c | 10 +++++---- drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 10 +++++---- drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c | 5 +++-- drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 5 +++-- drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c | 3 ++- drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c | 3 ++- drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c | 3 ++- 14 files changed, 66 insertions(+), 66 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +8 -7
@@ -283,7 +283,8 @@ struct amdgpu_ring_funcs {int (*parse_cs)(struct amdgpu_cs_parser *p,uint32_t ib_idx);/* command emit functions */ void (*emit_ib)(struct amdgpu_ring *ring, -struct amdgpu_ib *ib,bool ctx_switch); +struct amdgpu_ib *ib, +unsigned vm_id,bool ctx_switch);void (*emit_fence)(struct amdgpu_ring *ring,uint64_t addr,uint64_t seq,unsigned flags);void (*emit_pipeline_sync)(struct amdgpu_ring *ring);
@@ -741,11 +742,6 @@ struct amdgpu_ib {uint64_t gpu_addr;uint32_t *ptr;struct amdgpu_user_fence *user; -unsigned vm_id; -uint64_t vm_pd_addr; -uint32_t gds_base, gds_size; -uint32_t gws_base, gws_size; -uint32_t oa_base, oa_size;uint32_t flags;/* resulting sequence number */ uint64_t sequence;
@@ -1262,6 +1258,11 @@ struct amdgpu_job {uint32_t num_ibs;void *owner;uint64_t ctx; +unsigned vm_id; +uint64_t vm_pd_addr; +uint32_t gds_base, gds_size; +uint32_t gws_base, gws_size; +uint32_t oa_base, oa_size;struct amdgpu_user_fence uf; };#define to_amdgpu_job (sched_job) \
@@ -2220,7 +2221,7 @@ amdgpu_get_sdma_instance(struct amdgpu_ring *ring)#define amdgpu_ring_get_rptr (r) (r)->funcs->get_rptr((r))#define amdgpu_ring_get_wptr (r) (r)->funcs->get_wptr((r))#define amdgpu_ring_set_wptr (r) (r)->funcs->set_wptr((r)) -#define amdgpu_ring_emit_ib (r, ib, c) (r)->funcs->emit_ib((r), (ib), (c)) +#define amdgpu_ring_emit_ib (r, ib, vm_id, c) (r)->funcs->emit_ib((r), (ib), (vm_id), (c))#define amdgpu_ring_emit_pipeline_sync (r) (r)->funcs->emit_pipeline_sync((r))#define amdgpu_ring_emit_vm_flush (r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))#define amdgpu_ring_emit_fence (r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +16 -20
@@ -473,6 +473,9 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, goto error_validate;if (p->bo_list) { +struct amdgpu_bo *gds = p->bo_list->gds_obj; +struct amdgpu_bo *gws = p->bo_list->gws_obj; +struct amdgpu_bo *oa = p->bo_list->oa_obj;struct amdgpu_vm *vm = &fpriv->vm;unsigned i;
@@ -481,6 +484,19 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, p->bo_list->array[i].bo_va =amdgpu_vm_bo_find (vm, bo); } + +if (gds) { + p->job->gds_base =amdgpu_bo_gpu_offset (gds); + p->job->gds_size =amdgpu_bo_size (gds); + } +if (gws) { + p->job->gws_base =amdgpu_bo_gpu_offset (gws); + p->job->gws_size =amdgpu_bo_size (gws); + } +if (oa) { + p->job->oa_base =amdgpu_bo_gpu_offset (oa); + p->job->oa_size =amdgpu_bo_size (oa); + } } error_validate:
@@ -744,26 +760,6 @@ static int amdgpu_cs_ib_fill(struct amdgpu_device *adev, j++; } -/* add GDS resources to first IB */ -if (parser->bo_list) { -struct amdgpu_bo *gds = parser->bo_list->gds_obj; -struct amdgpu_bo *gws = parser->bo_list->gws_obj; -struct amdgpu_bo *oa = parser->bo_list->oa_obj; -struct amdgpu_ib *ib = &parser->job->ibs[0 ]; - -if (gds) { - ib->gds_base =amdgpu_bo_gpu_offset (gds); - ib->gds_size =amdgpu_bo_size (gds); - } -if (gws) { - ib->gws_base =amdgpu_bo_gpu_offset (gws); - ib->gws_size =amdgpu_bo_size (gws); - } -if (oa) { - ib->oa_base =amdgpu_bo_gpu_offset (oa); - ib->oa_size =amdgpu_bo_size (oa); - } - }/* wrap the last IB with user fence */ if (parser->job->uf.bo) {struct amdgpu_ib *ib = &parser->job->ibs[parser->job->num_ibs -1 ];
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +9 -10
@@ -74,8 +74,6 @@ int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm, ib->gpu_addr =amdgpu_sa_bo_gpu_addr (ib->sa_bo); } - ib->vm_id =0 ; -return 0 ; }
@@ -147,7 +145,7 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,return -EINVAL ; } -if (vm && !ibs->vm_id) { +if (vm && !job->vm_id) {dev_err (adev->dev,"VM IB without ID\n" );return -EINVAL ; }
@@ -162,10 +160,10 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs, patch_offset =amdgpu_ring_init_cond_exec (ring);if (vm) { - r =amdgpu_vm_flush (ring, ib->vm_id, ib->vm_pd_addr, - ib->gds_base, ib->gds_size, - ib->gws_base, ib->gws_size, - ib->oa_base, ib->oa_size); + r =amdgpu_vm_flush (ring, job->vm_id, job->vm_pd_addr, + job->gds_base, job->gds_size, + job->gws_base, job->gws_size, + job->oa_base, job->oa_size);if (r) {amdgpu_ring_undo (ring);return r;
@@ -187,7 +185,8 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,if ((ib->flags &AMDGPU_IB_FLAG_PREAMBLE ) && skip_preamble)continue ; -amdgpu_ring_emit_ib (ring, ib, need_ctx_switch); +amdgpu_ring_emit_ib (ring, ib, job ? job->vm_id :0 , + need_ctx_switch); need_ctx_switch = false; }
@@ -197,8 +196,8 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs, r =amdgpu_fence_emit (ring, &hwf);if (r) {dev_err (adev->dev,"failed to emit fence (%d)\n" , r); -if (ib->vm_id) -amdgpu_vm_reset_id (adev, ib->vm_id); +if (job && job->vm_id) +amdgpu_vm_reset_id (adev, job->vm_id);amdgpu_ring_undo (ring);return r; }
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +2 -10
@@ -142,23 +142,15 @@ static struct fence *amdgpu_job_dependency(struct amd_sched_job *sched_job)struct fence *fence =amdgpu_sync_get_fence (&job->sync); -if (fence ==NULL && vm && !job->ibs->vm_id) { +if (fence ==NULL && vm && !job->vm_id) {struct amdgpu_ring *ring = job->ring; -unsigned i, vm_id; -uint64_t vm_pd_addr;int r; r =amdgpu_vm_grab_id (vm, ring, &job->sync, &job->base.s_fence->base, - &vm_id, &vm_pd_addr); + &job->vm_id, &job->vm_pd_addr);if (r)DRM_ERROR ("Error getting VM ID (%d)\n" , r); -else { -for (i =0 ; i < job->num_ibs; ++i) { - job->ibs[i].vm_id = vm_id; - job->ibs[i].vm_pd_addr = vm_pd_addr; - } - } fence =amdgpu_sync_get_fence (&job->sync); }
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +2 -1
@@ -761,7 +761,8 @@ out:* @ib: the IB to execute * */ -void amdgpu_vce_ring_emit_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib,bool ctx_switch) +void amdgpu_vce_ring_emit_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib, +unsigned vm_id,bool ctx_switch) {amdgpu_ring_write (ring,VCE_CMD_IB );amdgpu_ring_write (ring,lower_32_bits (ib->gpu_addr));
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h +2 -1
@@ -34,7 +34,8 @@ int amdgpu_vce_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle, bool direct, struct fence **fence);void amdgpu_vce_free_handles (struct amdgpu_device *adev,struct drm_file *filp);int amdgpu_vce_ring_parse_cs (struct amdgpu_cs_parser *p,uint32_t ib_idx); -void amdgpu_vce_ring_emit_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib,bool ctx_switch); +void amdgpu_vce_ring_emit_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib, +unsigned vm_id,bool ctx_switch);void amdgpu_vce_ring_emit_fence (struct amdgpu_ring *ring,u64 addr,u64 seq,unsigned flags);int amdgpu_vce_ring_test_ring (struct amdgpu_ring *ring);
drivers/gpu/drm/amd/amdgpu/cik_sdma.c +3 -2
@@ -210,9 +210,10 @@ static void cik_sdma_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count)* Schedule an IB in the DMA ring (CIK). */ static void cik_sdma_ring_emit_ib (struct amdgpu_ring *ring, -struct amdgpu_ib *ib,bool ctx_switch) +struct amdgpu_ib *ib, +unsigned vm_id,bool ctx_switch) { -u32 extra_bits = ib->vm_id &0xf ; +u32 extra_bits = vm_id &0xf ;u32 next_rptr = ring->wptr +5 ;while ((next_rptr &7 ) !=4 )
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +6 -4
@@ -2030,7 +2030,8 @@ static void gfx_v7_0_ring_emit_fence_compute(struct amdgpu_ring *ring,* on the gfx ring for execution by the GPU. */ static void gfx_v7_0_ring_emit_ib_gfx (struct amdgpu_ring *ring, -struct amdgpu_ib *ib,bool ctx_switch) +struct amdgpu_ib *ib, +unsigned vm_id,bool ctx_switch) {u32 header, control =0 ;u32 next_rptr = ring->wptr +5 ;
@@ -2056,7 +2057,7 @@ static void gfx_v7_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,else header =PACKET3 (PACKET3_INDIRECT_BUFFER ,2 ); - control |= ib->length_dw | (ib->vm_id <<24 ); + control |= ib->length_dw | (vm_id <<24 );amdgpu_ring_write (ring, header); amdgpu_ring_write(ring,
@@ -2069,7 +2070,8 @@ static void gfx_v7_0_ring_emit_ib_gfx(struct amdgpu_ring *ring, }static void gfx_v7_0_ring_emit_ib_compute (struct amdgpu_ring *ring, -struct amdgpu_ib *ib,bool ctx_switch) +struct amdgpu_ib *ib, +unsigned vm_id,bool ctx_switch) {u32 header, control =0 ;u32 next_rptr = ring->wptr +5 ;
@@ -2084,7 +2086,7 @@ static void gfx_v7_0_ring_emit_ib_compute(struct amdgpu_ring *ring, header =PACKET3 (PACKET3_INDIRECT_BUFFER ,2 ); - control |= ib->length_dw | (ib->vm_id <<24 ); + control |= ib->length_dw | (vm_id <<24 );amdgpu_ring_write (ring, header); amdgpu_ring_write(ring,
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +6 -4
@@ -5646,7 +5646,8 @@ static void gfx_v8_0_ring_emit_hdp_invalidate(struct amdgpu_ring *ring) }static void gfx_v8_0_ring_emit_ib_gfx (struct amdgpu_ring *ring, -struct amdgpu_ib *ib,bool ctx_switch) +struct amdgpu_ib *ib, +unsigned vm_id,bool ctx_switch) {u32 header, control =0 ;u32 next_rptr = ring->wptr +5 ;
@@ -5672,7 +5673,7 @@ static void gfx_v8_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,else header =PACKET3 (PACKET3_INDIRECT_BUFFER ,2 ); - control |= ib->length_dw | (ib->vm_id <<24 ); + control |= ib->length_dw | (vm_id <<24 );amdgpu_ring_write (ring, header); amdgpu_ring_write(ring,
@@ -5685,7 +5686,8 @@ static void gfx_v8_0_ring_emit_ib_gfx(struct amdgpu_ring *ring, }static void gfx_v8_0_ring_emit_ib_compute (struct amdgpu_ring *ring, -struct amdgpu_ib *ib,bool ctx_switch) +struct amdgpu_ib *ib, +unsigned vm_id,bool ctx_switch) {u32 header, control =0 ;u32 next_rptr = ring->wptr +5 ;
@@ -5701,7 +5703,7 @@ static void gfx_v8_0_ring_emit_ib_compute(struct amdgpu_ring *ring, header =PACKET3 (PACKET3_INDIRECT_BUFFER ,2 ); - control |= ib->length_dw | (ib->vm_id <<24 ); + control |= ib->length_dw | (vm_id <<24 );amdgpu_ring_write (ring, header); amdgpu_ring_write(ring,
drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c +3 -2
@@ -242,9 +242,10 @@ static void sdma_v2_4_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count)* Schedule an IB in the DMA ring (VI). */ static void sdma_v2_4_ring_emit_ib (struct amdgpu_ring *ring, -struct amdgpu_ib *ib,bool ctx_switch) +struct amdgpu_ib *ib, +unsigned vm_id,bool ctx_switch) { -u32 vmid = ib->vm_id &0xf ; +u32 vmid = vm_id &0xf ;u32 next_rptr = ring->wptr +5 ;while ((next_rptr &7 ) !=2 )
drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +3 -2
@@ -400,9 +400,10 @@ static void sdma_v3_0_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count)* Schedule an IB in the DMA ring (VI). */ static void sdma_v3_0_ring_emit_ib (struct amdgpu_ring *ring, -struct amdgpu_ib *ib,bool ctx_switch) +struct amdgpu_ib *ib, +unsigned vm_id,bool ctx_switch) { -u32 vmid = ib->vm_id &0xf ; +u32 vmid = vm_id &0xf ;u32 next_rptr = ring->wptr +5 ;while ((next_rptr &7 ) !=2 )
drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c +2 -1
@@ -489,7 +489,8 @@ static int uvd_v4_2_ring_test_ring(struct amdgpu_ring *ring)* Write ring commands to execute the indirect buffer */ static void uvd_v4_2_ring_emit_ib (struct amdgpu_ring *ring, -struct amdgpu_ib *ib,bool ctx_switch) +struct amdgpu_ib *ib, +unsigned vm_id,bool ctx_switch) {amdgpu_ring_write (ring,PACKET0 (mmUVD_RBC_IB_BASE,0 ));amdgpu_ring_write (ring, ib->gpu_addr);
drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c +2 -1
@@ -539,7 +539,8 @@ static int uvd_v5_0_ring_test_ring(struct amdgpu_ring *ring)* Write ring commands to execute the indirect buffer */ static void uvd_v5_0_ring_emit_ib (struct amdgpu_ring *ring, -struct amdgpu_ib *ib,bool ctx_switch) +struct amdgpu_ib *ib, +unsigned vm_id,bool ctx_switch) {amdgpu_ring_write (ring,PACKET0 (mmUVD_LMI_RBC_IB_64BIT_BAR_LOW,0 ));amdgpu_ring_write (ring,lower_32_bits (ib->gpu_addr));
drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c +2 -1
@@ -631,7 +631,8 @@ static int uvd_v6_0_ring_test_ring(struct amdgpu_ring *ring)* Write ring commands to execute the indirect buffer */ static void uvd_v6_0_ring_emit_ib (struct amdgpu_ring *ring, -struct amdgpu_ib *ib,bool ctx_switch) +struct amdgpu_ib *ib, +unsigned vm_id,bool ctx_switch) {amdgpu_ring_write (ring,PACKET0 (mmUVD_LMI_RBC_IB_64BIT_BAR_LOW,0 ));amdgpu_ring_write (ring,lower_32_bits (ib->gpu_addr));
Signature · 6 lines
2.5.5 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 1/1 drm/amdgpu: fix and cleanup user fence handling v2
In reply to Alex DeucherFrom: Christian König <[email protected]>
We leaked the BO in the error pass, additional to that we only have one user fence for all IBs in a job.
v2: remove white space changes
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 19 +++++------- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 55 +++++++++++++++------------------ drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 9 +++--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 2 +- 4 files changed, 38 insertions(+), 47 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +7 -12
@@ -368,13 +368,6 @@ struct amdgpu_fence_driver {#define AMDGPU_FENCE_FLAG_64BIT (1 << 0)#define AMDGPU_FENCE_FLAG_INT (1 << 1) -struct amdgpu_user_fence { -/* write-back bo */ -struct amdgpu_bo *bo; -/* write-back address offset to bo start */ -uint32_t offset; -}; -int amdgpu_fence_driver_init (struct amdgpu_device *adev);void amdgpu_fence_driver_fini (struct amdgpu_device *adev);void amdgpu_fence_driver_force_completion (struct amdgpu_device *adev);
@@ -741,10 +734,7 @@ struct amdgpu_ib {uint32_t length_dw;uint64_t gpu_addr;uint32_t *ptr; -struct amdgpu_user_fence *user;uint32_t flags; -/* resulting sequence number */ -uint64_t sequence; };enum amdgpu_ring_type {
@@ -1219,7 +1209,7 @@ void amdgpu_ring_fini(struct amdgpu_ring *ring);struct amdgpu_cs_chunk {uint32_t chunk_id;uint32_t length_dw; -uint32_t *kdata; +void *kdata; };struct amdgpu_cs_parser {
@@ -1263,7 +1253,12 @@ struct amdgpu_job {uint32_t gds_base, gds_size;uint32_t gws_base, gws_size;uint32_t oa_base, oa_size; -struct amdgpu_user_fence uf; + +/* user fence handling */ +struct amdgpu_bo *uf_bo; +uint32_t uf_offset; +uint64_t uf_sequence; + };#define to_amdgpu_job (sched_job) \ container_of((sched_job), struct amdgpu_job, base)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +25 -30
111 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +5 -4
@@ -203,10 +203,11 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs, }/* wrap the last IB with fence */ -if (ib->user) { -uint64_t addr =amdgpu_bo_gpu_offset (ib->user->bo); - addr += ib->user->offset; -amdgpu_ring_emit_fence (ring, addr, ib->sequence, +if (job && job->uf_bo) { +uint64_t addr =amdgpu_bo_gpu_offset (job->uf_bo); + + addr += job->uf_offset; +amdgpu_ring_emit_fence (ring, addr, job->uf_sequence,AMDGPU_FENCE_FLAG_64BIT ); }
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1 -1
@@ -97,7 +97,7 @@ void amdgpu_job_free(struct amdgpu_job *job)amdgpu_sa_bo_free (job->adev, &job->ibs[i].sa_bo, f);fence_put (job->fence); -amdgpu_bo_unref (&job->uf.bo); +amdgpu_bo_unref (&job->uf_bo);amdgpu_sync_free (&job->sync);if (!job->base.use_sched)
Signature · 6 lines
2.5.5 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel