[PATCH] drm/amdgpu: Add back ring lock

Rex Zhu Rex.Zhu at amd.com
Wed Dec 26 11:13:35 UTC 2018


lock ring from alloc to commit.

Signed-off-by: Rex Zhu <Rex.Zhu at amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 10 +++++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h |  1 +
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
index 5b75bdc..39172d1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
@@ -73,12 +73,13 @@ int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw)
 	if (WARN_ON_ONCE(ndw > ring->max_dw))
 		return -ENOMEM;
 
-	ring->count_dw = ndw;
-	ring->wptr_old = ring->wptr;
-
 	if (ring->funcs->begin_use)
 		ring->funcs->begin_use(ring);
 
+	mutex_lock(&ring->ring_lock);
+	ring->count_dw = ndw;
+	ring->wptr_old = ring->wptr;
+
 	return 0;
 }
 
@@ -133,6 +134,8 @@ void amdgpu_ring_commit(struct amdgpu_ring *ring)
 	mb();
 	amdgpu_ring_set_wptr(ring);
 
+	mutex_unlock(&ring->ring_lock);
+
 	if (ring->funcs->end_use)
 		ring->funcs->end_use(ring);
 }
@@ -317,6 +320,7 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
 	ring->max_dw = max_dw;
 	ring->priority = DRM_SCHED_PRIORITY_NORMAL;
 	mutex_init(&ring->priority_mutex);
+	mutex_init(&ring->ring_lock);
 
 	for (i = 0; i < DRM_SCHED_PRIORITY_MAX; ++i)
 		atomic_set(&ring->num_jobs[i], 0);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h
index 0beb01f..25976b6 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h
@@ -214,6 +214,7 @@ struct amdgpu_ring {
 
 	atomic_t		num_jobs[DRM_SCHED_PRIORITY_MAX];
 	struct mutex		priority_mutex;
+	struct mutex		ring_lock;
 	/* protected by priority_mutex */
 	int			priority;
 
-- 
1.9.1



More information about the amd-gfx mailing list