Skip to contentSkip to conversation

drm/amdgpu: fix amdgpu_job_free_resources v2

PATCH In review Christian König 2 participants 5 messages Jan 16, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/amdgpu: fix amdgpu_job_free_resources v2

It can be that neither fence were initialized when we run out of UVD streams for example.

v2: fix typo breaking compile

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +8 -2
index f4a3122352de..6b73c074aa25 100644
@@ -154,8 +154,14 @@ void amdgpu_job_free_resources(struct amdgpu_job *job)
 	struct dma_fence *f;
 	unsigned i;
 
-	/* use sched fence if available */
-	f = job->base.s_fence ? &job->base.s_fence->finished :  &job->hw_fence;
+	/* Check if any fences where initialized */
+	if (job->base.s_fence && job->base.s_fence->finished.ops)
+		f = &job->base.s_fence->finished;
+	else if (job->hw_fence.ops)
+		f = &job->hw_fence;
+	else
+		f = NULL;
+
 	for (i = 0; i < job->num_ibs; ++i)
 		amdgpu_ib_free(ring->adev, &job->ibs[i], f);
 }
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 drm/amdgpu: simplify and cleanup amdgpu_uvd_send_msg

We only need one offset and not an array of it.

We have a wait in the amdgpu_bo_kmap() code for quite a while now, so waiting here isn't needed any more.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 38 +++++++------------------
 1 file changed, 10 insertions(+), 28 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +10 -28
index b67a5fb2ff3e..229419c0c031 100644
@@ -1118,30 +1118,26 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo,
 {
 	struct amdgpu_device *adev = ring->adev;
 	struct dma_fence *f = NULL;
+	uint32_t offset, data[4];
 	struct amdgpu_job *job;
 	struct amdgpu_ib *ib;
-	uint32_t data[4];
 	uint64_t addr;
-	long r;
-	int i;
-	unsigned offset_idx = 0;
-	unsigned offset[3] = { UVD_BASE_SI, 0, 0 };
+	int i, r;
 
 	r = amdgpu_job_alloc_with_ib(adev, 64, direct ? AMDGPU_IB_POOL_DIRECT :
 				     AMDGPU_IB_POOL_DELAYED, &job);
 	if (r)
 		return r;
 
-	if (adev->asic_type >= CHIP_VEGA10) {
-		offset_idx = 1 + ring->me;
-		offset[1] = adev->reg_offset[UVD_HWIP][0][1];
-		offset[2] = adev->reg_offset[UVD_HWIP][1][1];
-	}
+	if (adev->asic_type >= CHIP_VEGA10)
+		offset = adev->reg_offset[UVD_HWIP][ring->me][1];
+	else
+		offset = UVD_BASE_SI;
 
-	data[0] = PACKET0(offset[offset_idx] + UVD_GPCOM_VCPU_DATA0, 0);
-	data[1] = PACKET0(offset[offset_idx] + UVD_GPCOM_VCPU_DATA1, 0);
-	data[2] = PACKET0(offset[offset_idx] + UVD_GPCOM_VCPU_CMD, 0);
-	data[3] = PACKET0(offset[offset_idx] + UVD_NO_OP, 0);
+	data[0] = PACKET0(offset + UVD_GPCOM_VCPU_DATA0, 0);
+	data[1] = PACKET0(offset + UVD_GPCOM_VCPU_DATA1, 0);
+	data[2] = PACKET0(offset + UVD_GPCOM_VCPU_CMD, 0);
+	data[3] = PACKET0(offset + UVD_NO_OP, 0);
 
 	ib = &job->ibs[0];
 	addr = amdgpu_bo_gpu_offset(bo);
@@ -1158,24 +1154,10 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo,
 	ib->length_dw = 16;
 
 	if (direct) {
-		r = dma_resv_wait_timeout(bo->tbo.base.resv,
-					  DMA_RESV_USAGE_KERNEL, false,
-					  msecs_to_jiffies(10));
-		if (r == 0)
-			r = -ETIMEDOUT;
-		if (r < 0)
-			goto err_free;
-
 		r = amdgpu_job_submit_direct(job, ring, &f);
 		if (r)
 			goto err_free;
 	} else {
-		r = amdgpu_sync_resv(adev, &job->sync, bo->tbo.base.resv,
-				     AMDGPU_SYNC_ALWAYS,
-				     AMDGPU_FENCE_OWNER_UNDEFINED);
-		if (r)
-			goto err_free;
-
 		r = amdgpu_job_submit(job, &adev->uvd.entity,
 				      AMDGPU_FENCE_OWNER_UNDEFINED, &f);
 		if (r)
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 2/2] drm/amdgpu: simplify and cleanup amdgpu_uvd_send_msg

Quoted 5 lines · Christian König

We only need one offset and not an array of it.

We have a wait in the amdgpu_bo_kmap() code for quite a while now, so waiting here isn't needed any more.

This should probably be two patches, one to clean up the offsets and one to remove the syncs.

Alex

Quoted 79 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 38 +++++++------------------
 1 file changed, 10 insertions(+), 28 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +10 -29
index b67a5fb2ff3e..229419c0c031 100644
@@ -1118,30 +1118,26 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo,
 {
        struct amdgpu_device *adev = ring->adev;
        struct dma_fence *f = NULL;
+       uint32_t offset, data[4];
        struct amdgpu_job *job;
        struct amdgpu_ib *ib;
-       uint32_t data[4];
        uint64_t addr;
-       long r;
-       int i;
-       unsigned offset_idx = 0;
-       unsigned offset[3] = { UVD_BASE_SI, 0, 0 };
+       int i, r;
 
        r = amdgpu_job_alloc_with_ib(adev, 64, direct ? AMDGPU_IB_POOL_DIRECT :
                                     AMDGPU_IB_POOL_DELAYED, &job);
        if (r)
                return r;
 
-       if (adev->asic_type >= CHIP_VEGA10) {
-               offset_idx = 1 + ring->me;
-               offset[1] = adev->reg_offset[UVD_HWIP][0][1];
-               offset[2] = adev->reg_offset[UVD_HWIP][1][1];
-       }
+       if (adev->asic_type >= CHIP_VEGA10)
+               offset = adev->reg_offset[UVD_HWIP][ring->me][1];
+       else
+               offset = UVD_BASE_SI;
 
-       data[0] = PACKET0(offset[offset_idx] + UVD_GPCOM_VCPU_DATA0, 0);
-       data[1] = PACKET0(offset[offset_idx] + UVD_GPCOM_VCPU_DATA1, 0);
-       data[2] = PACKET0(offset[offset_idx] + UVD_GPCOM_VCPU_CMD, 0);
-       data[3] = PACKET0(offset[offset_idx] + UVD_NO_OP, 0);
+       data[0] = PACKET0(offset + UVD_GPCOM_VCPU_DATA0, 0);
+       data[1] = PACKET0(offset + UVD_GPCOM_VCPU_DATA1, 0);
+       data[2] = PACKET0(offset + UVD_GPCOM_VCPU_CMD, 0);
+       data[3] = PACKET0(offset + UVD_NO_OP, 0);
 
        ib = &job->ibs[0];
        addr = amdgpu_bo_gpu_offset(bo);
@@ -1158,24 +1154,10 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo,
        ib->length_dw = 16;
 
        if (direct) {
-               r = dma_resv_wait_timeout(bo->tbo.base.resv,
-                                         DMA_RESV_USAGE_KERNEL, false,
-                                         msecs_to_jiffies(10));
-               if (r == 0)
-                       r = -ETIMEDOUT;
-               if (r < 0)
-                       goto err_free;
-
                r = amdgpu_job_submit_direct(job, ring, &f);
                if (r)
                        goto err_free;
        } else {
-               r = amdgpu_sync_resv(adev, &job->sync, bo->tbo.base.resv,
-                                    AMDGPU_SYNC_ALWAYS,
-                                    AMDGPU_FENCE_OWNER_UNDEFINED);
-               if (r)
-                       goto err_free;
-
                r = amdgpu_job_submit(job, &adev->uvd.entity,
                                      AMDGPU_FENCE_OWNER_UNDEFINED, &f);
                if (r)
--

2.34.1

Reviewed-by on v1 1/2
#3 lore raw
In reply to Christian König
Quoted 7 lines · Christian König

It can be that neither fence were initialized when we run out of UVD streams for example.

v2: fix typo breaking compile

Quoted 28 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +8 -3
index f4a3122352de..6b73c074aa25 100644
@@ -154,8 +154,14 @@ void amdgpu_job_free_resources(struct amdgpu_job *job)
        struct dma_fence *f;
        unsigned i;
 
-       /* use sched fence if available */
-       f = job->base.s_fence ? &job->base.s_fence->finished :  &job->hw_fence;
+       /* Check if any fences where initialized */
+       if (job->base.s_fence && job->base.s_fence->finished.ops)
+               f = &job->base.s_fence->finished;
+       else if (job->hw_fence.ops)
+               f = &job->hw_fence;
+       else
+               f = NULL;
+
        for (i = 0; i < job->num_ibs; ++i)
                amdgpu_ib_free(ring->adev, &job->ibs[i], f);
 }
--

2.34.1

#4 lore raw
Quoted 4 lines · Alex Deucher
Quoted 1 line · Christian König
Quoted 8 lines
Quoted 6 lines

It can be that neither fence were initialized when we run out of UVD streams for example.

v2: fix typo breaking compile

Also add:

Alex

Quoted 29 lines
Quoted 29 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +8 -3
index f4a3122352de..6b73c074aa25 100644
@@ -154,8 +154,14 @@ void amdgpu_job_free_resources(struct amdgpu_job *job)
        struct dma_fence *f;
        unsigned i;
 
-       /* use sched fence if available */
-       f = job->base.s_fence ? &job->base.s_fence->finished :  &job->hw_fence;
+       /* Check if any fences where initialized */
+       if (job->base.s_fence && job->base.s_fence->finished.ops)
+               f = &job->base.s_fence->finished;
+       else if (job->hw_fence.ops)
+               f = &job->hw_fence;
+       else
+               f = NULL;
+
        for (i = 0; i < job->num_ibs; ++i)
                amdgpu_ib_free(ring->adev, &job->ibs[i], f);
 }
--

2.34.1