drm/amdgpu: Optimize a function called by every IB sheduling
authorAlex Xie <AlexBin.Xie@amd.com>
Tue, 30 May 2017 21:10:16 +0000 (17:10 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 31 May 2017 18:16:38 +0000 (14:16 -0400)
  Move several if statements and a loop statment from
  run time to initialization time.

Signed-off-by: Alex Xie <AlexBin.Xie@amd.com>
Reviewed-by: Chunming Zhou <david1.zhou@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

index 6a85db0c0bc3b82082f4ad5ff392e2b633ea3f78..7d95435fad1600ca92846485b71c1ce0adac4c16 100644 (file)
@@ -152,6 +152,36 @@ void amdgpu_ring_undo(struct amdgpu_ring *ring)
                ring->funcs->end_use(ring);
 }
 
+/**
+ * amdgpu_ring_check_compute_vm_bug - check whether this ring has compute vm bug
+ *
+ * @adev: amdgpu_device pointer
+ * @ring: amdgpu_ring structure holding ring information
+ */
+static void amdgpu_ring_check_compute_vm_bug(struct amdgpu_device *adev,
+                                       struct amdgpu_ring *ring)
+{
+       const struct amdgpu_ip_block *ip_block;
+
+       ring->has_compute_vm_bug = false;
+
+       if (ring->funcs->type != AMDGPU_RING_TYPE_COMPUTE)
+               /* only compute rings */
+               return;
+
+       ip_block = amdgpu_get_ip_block(adev, AMD_IP_BLOCK_TYPE_GFX);
+       if (!ip_block)
+               return;
+
+       /* Compute ring has a VM bug for GFX version < 7.
+           And compute ring has a VM bug for GFX 8 MEC firmware version < 673.*/
+       if (ip_block->version->major <= 7) {
+               ring->has_compute_vm_bug = true;
+       } else if (ip_block->version->major == 8)
+               if (adev->gfx.mec_fw_version < 673)
+                       ring->has_compute_vm_bug = true;
+}
+
 /**
  * amdgpu_ring_init - init driver ring struct.
  *
@@ -257,6 +287,9 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
        if (amdgpu_debugfs_ring_init(adev, ring)) {
                DRM_ERROR("Failed to register debugfs file for rings !\n");
        }
+
+       amdgpu_ring_check_compute_vm_bug(adev, ring);
+
        return 0;
 }
 
index a9223a8de8c290a8022c35046dbf338f3a397947..334307efac8b3e4663f3ba958076f84b33e5b43e 100644 (file)
@@ -185,6 +185,7 @@ struct amdgpu_ring {
        u64                     cond_exe_gpu_addr;
        volatile u32            *cond_exe_cpu_addr;
        unsigned                vm_inv_eng;
+       bool                    has_compute_vm_bug;
 #if defined(CONFIG_DEBUG_FS)
        struct dentry *ent;
 #endif
@@ -207,4 +208,9 @@ static inline void amdgpu_ring_clear_ring(struct amdgpu_ring *ring)
 
 }
 
+static inline bool amdgpu_ring_has_compute_vm_bug(struct amdgpu_ring *ring)
+{
+       return ring->has_compute_vm_bug;
+}
+
 #endif
index b2384b8536b9e852856fe48c0e9e21b0e772c723..7a323f91a10bceb03286235b326904a544627181 100644 (file)
@@ -656,32 +656,6 @@ unlock:
        return r;
 }
 
-static bool amdgpu_vm_ring_has_compute_vm_bug(struct amdgpu_ring *ring)
-{
-       struct amdgpu_device *adev = ring->adev;
-       const struct amdgpu_ip_block *ip_block;
-
-       if (ring->funcs->type != AMDGPU_RING_TYPE_COMPUTE)
-               /* only compute rings */
-               return false;
-
-       ip_block = amdgpu_get_ip_block(adev, AMD_IP_BLOCK_TYPE_GFX);
-       if (!ip_block)
-               return false;
-
-       if (ip_block->version->major <= 7) {
-               /* gfx7 has no workaround */
-               return true;
-       } else if (ip_block->version->major == 8) {
-               if (adev->gfx.mec_fw_version >= 673)
-                       /* gfx8 is fixed in MEC firmware 673 */
-                       return false;
-               else
-                       return true;
-       }
-       return false;
-}
-
 bool amdgpu_vm_need_pipeline_sync(struct amdgpu_ring *ring,
                                  struct amdgpu_job *job)
 {
@@ -691,7 +665,7 @@ bool amdgpu_vm_need_pipeline_sync(struct amdgpu_ring *ring,
        struct amdgpu_vm_id *id;
        bool gds_switch_needed;
        bool vm_flush_needed = job->vm_needs_flush ||
-               amdgpu_vm_ring_has_compute_vm_bug(ring);
+               amdgpu_ring_has_compute_vm_bug(ring);
 
        if (job->vm_id == 0)
                return false;