drm/amdgpu: move UVD and VCE sched entity init after sched init
authorAlex Deucher <alexander.deucher@amd.com>
Wed, 8 Nov 2023 14:40:44 +0000 (09:40 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 10 Nov 2023 16:33:08 +0000 (11:33 -0500)
We need kernel scheduling entities to deal with handle clean up
if apps are not cleaned up properly.  With commit 56e449603f0ac5
("drm/sched: Convert the GPU scheduler to variable number of run-queues")
the scheduler entities have to be created after scheduler init, so
change the ordering to fix this.

v2: Leave logic in UVD and VCE code

Fixes: 56e449603f0a ("drm/sched: Convert the GPU scheduler to variable number of run-queues")
Reviewed-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Luben Tuikov <ltuikov89@gmail.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Cc: ltuikov89@gmail.com
13 files changed:
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.h
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h
drivers/gpu/drm/amd/amdgpu/uvd_v3_1.c
drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c
drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c
drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c
drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c
drivers/gpu/drm/amd/amdgpu/vce_v2_0.c
drivers/gpu/drm/amd/amdgpu/vce_v3_0.c
drivers/gpu/drm/amd/amdgpu/vce_v4_0.c

index e8a2685..7eeaf0a 100644 (file)
@@ -2584,6 +2584,18 @@ static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)
                                  ring->name);
                        return r;
                }
+               r = amdgpu_uvd_entity_init(adev, ring);
+               if (r) {
+                       DRM_ERROR("Failed to create UVD scheduling entity on ring %s.\n",
+                                 ring->name);
+                       return r;
+               }
+               r = amdgpu_vce_entity_init(adev, ring);
+               if (r) {
+                       DRM_ERROR("Failed to create VCE scheduling entity on ring %s.\n",
+                                 ring->name);
+                       return r;
+               }
        }
 
        amdgpu_xcp_update_partition_sched_list(adev);
index 815b7c3..65949cc 100644 (file)
@@ -399,20 +399,20 @@ int amdgpu_uvd_sw_fini(struct amdgpu_device *adev)
  *
  * @adev: amdgpu_device pointer
  *
+ * Initialize the entity used for handle management in the kernel driver.
  */
-int amdgpu_uvd_entity_init(struct amdgpu_device *adev)
+int amdgpu_uvd_entity_init(struct amdgpu_device *adev, struct amdgpu_ring *ring)
 {
-       struct amdgpu_ring *ring;
-       struct drm_gpu_scheduler *sched;
-       int r;
+       if (ring == &adev->uvd.inst[0].ring) {
+               struct drm_gpu_scheduler *sched = &ring->sched;
+               int r;
 
-       ring = &adev->uvd.inst[0].ring;
-       sched = &ring->sched;
-       r = drm_sched_entity_init(&adev->uvd.entity, DRM_SCHED_PRIORITY_NORMAL,
-                                 &sched, 1, NULL);
-       if (r) {
-               DRM_ERROR("Failed setting up UVD kernel entity.\n");
-               return r;
+               r = drm_sched_entity_init(&adev->uvd.entity, DRM_SCHED_PRIORITY_NORMAL,
+                                         &sched, 1, NULL);
+               if (r) {
+                       DRM_ERROR("Failed setting up UVD kernel entity.\n");
+                       return r;
+               }
        }
 
        return 0;
index a9f3425..9dfad2f 100644 (file)
@@ -73,7 +73,7 @@ struct amdgpu_uvd {
 
 int amdgpu_uvd_sw_init(struct amdgpu_device *adev);
 int amdgpu_uvd_sw_fini(struct amdgpu_device *adev);
-int amdgpu_uvd_entity_init(struct amdgpu_device *adev);
+int amdgpu_uvd_entity_init(struct amdgpu_device *adev, struct amdgpu_ring *ring);
 int amdgpu_uvd_prepare_suspend(struct amdgpu_device *adev);
 int amdgpu_uvd_suspend(struct amdgpu_device *adev);
 int amdgpu_uvd_resume(struct amdgpu_device *adev);
index 1904edf..0954447 100644 (file)
@@ -231,20 +231,20 @@ int amdgpu_vce_sw_fini(struct amdgpu_device *adev)
  *
  * @adev: amdgpu_device pointer
  *
+ * Initialize the entity used for handle management in the kernel driver.
  */
-int amdgpu_vce_entity_init(struct amdgpu_device *adev)
+int amdgpu_vce_entity_init(struct amdgpu_device *adev, struct amdgpu_ring *ring)
 {
-       struct amdgpu_ring *ring;
-       struct drm_gpu_scheduler *sched;
-       int r;
-
-       ring = &adev->vce.ring[0];
-       sched = &ring->sched;
-       r = drm_sched_entity_init(&adev->vce.entity, DRM_SCHED_PRIORITY_NORMAL,
-                                 &sched, 1, NULL);
-       if (r != 0) {
-               DRM_ERROR("Failed setting up VCE run queue.\n");
-               return r;
+       if (ring == &adev->vce.ring[0]) {
+               struct drm_gpu_scheduler *sched = &ring->sched;
+               int r;
+
+               r = drm_sched_entity_init(&adev->vce.entity, DRM_SCHED_PRIORITY_NORMAL,
+                                         &sched, 1, NULL);
+               if (r != 0) {
+                       DRM_ERROR("Failed setting up VCE run queue.\n");
+                       return r;
+               }
        }
 
        return 0;
index ea680fc..6e53f87 100644 (file)
@@ -55,7 +55,7 @@ struct amdgpu_vce {
 
 int amdgpu_vce_sw_init(struct amdgpu_device *adev, unsigned long size);
 int amdgpu_vce_sw_fini(struct amdgpu_device *adev);
-int amdgpu_vce_entity_init(struct amdgpu_device *adev);
+int amdgpu_vce_entity_init(struct amdgpu_device *adev, struct amdgpu_ring *ring);
 int amdgpu_vce_suspend(struct amdgpu_device *adev);
 int amdgpu_vce_resume(struct amdgpu_device *adev);
 void amdgpu_vce_free_handles(struct amdgpu_device *adev, struct drm_file *filp);
index 58a8f78..a6006f2 100644 (file)
@@ -577,8 +577,6 @@ static int uvd_v3_1_sw_init(void *handle)
        ptr += ucode_len;
        memcpy(&adev->uvd.keyselect, ptr, 4);
 
-       r = amdgpu_uvd_entity_init(adev);
-
        return r;
 }
 
index d3b1e31..1aa09ad 100644 (file)
@@ -127,8 +127,6 @@ static int uvd_v4_2_sw_init(void *handle)
        if (r)
                return r;
 
-       r = amdgpu_uvd_entity_init(adev);
-
        return r;
 }
 
index 5a81164..f8b229b 100644 (file)
@@ -125,8 +125,6 @@ static int uvd_v5_0_sw_init(void *handle)
        if (r)
                return r;
 
-       r = amdgpu_uvd_entity_init(adev);
-
        return r;
 }
 
index 74c0923..a9a6880 100644 (file)
@@ -432,8 +432,6 @@ static int uvd_v6_0_sw_init(void *handle)
                }
        }
 
-       r = amdgpu_uvd_entity_init(adev);
-
        return r;
 }
 
index 1c42cf1..6068b78 100644 (file)
@@ -480,10 +480,6 @@ static int uvd_v7_0_sw_init(void *handle)
        if (r)
                return r;
 
-       r = amdgpu_uvd_entity_init(adev);
-       if (r)
-               return r;
-
        r = amdgpu_virt_alloc_mm_table(adev);
        if (r)
                return r;
index 67eb01f..a08e7ab 100644 (file)
@@ -441,8 +441,6 @@ static int vce_v2_0_sw_init(void *handle)
                        return r;
        }
 
-       r = amdgpu_vce_entity_init(adev);
-
        return r;
 }
 
index 18f6e62..f476074 100644 (file)
@@ -450,8 +450,6 @@ static int vce_v3_0_sw_init(void *handle)
                        return r;
        }
 
-       r = amdgpu_vce_entity_init(adev);
-
        return r;
 }
 
index e0b70cd..06d7873 100644 (file)
@@ -486,11 +486,6 @@ static int vce_v4_0_sw_init(void *handle)
                        return r;
        }
 
-
-       r = amdgpu_vce_entity_init(adev);
-       if (r)
-               return r;
-
        r = amdgpu_virt_alloc_mm_table(adev);
        if (r)
                return r;