Skip to contentSkip to conversation

RFC: Removal of some mutexes from the radeon driver

PATCH In review Christian König 3 participants 12 messages May 11, 2012 – May 14, 2012

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

Hi everybody,

well the following patches remove the cs and vram mutex from the radeon driver and so are something very experimental. The first three just move what I know to be still critical into the protection of the ring mutex, and the other two actually remove the mutexs.

Interestingly it still survives a couple of hours running the following script:

while true
do

        for (( x = 10, y = 45, i = 0; $i < 144; i = $i + 1 ))
        do
                glxgears -geometry 100x100+$x+$y > /dev/null 2>&1 &
                x=$(expr $x + 120)
                if [ $x -gt 1920 ]
                then
                        x=10
                        y=$(expr $y + 110)
                fi
        done

        sleep 30

        killall glxgears

done

So the mutexes doesn't seem to protected something so critical and I'm wondering why we still have them so widely locked.

Cheers,
Christian.

PS: I'm away for the next week or so don't expect any response soon.

#1 lore raw

PATCH 1/5 drm/radeon: remove radeon_fence_create

It is completely unnecessary to create fences
before they are emitted, so remove it and a bunch
of checks if fences are emitted or not.

---
 drivers/gpu/drm/radeon/evergreen.c        |    2 +-
 drivers/gpu/drm/radeon/ni.c               |    2 +-
 drivers/gpu/drm/radeon/r100.c             |    4 +-
 drivers/gpu/drm/radeon/r200.c             |    4 +-
 drivers/gpu/drm/radeon/r600.c             |    4 +-
 drivers/gpu/drm/radeon/r600_blit_kms.c    |    6 +--
 drivers/gpu/drm/radeon/radeon.h           |   11 +++--
 drivers/gpu/drm/radeon/radeon_asic.h      |    8 ++--
 drivers/gpu/drm/radeon/radeon_benchmark.c |   10 +----
 drivers/gpu/drm/radeon/radeon_fence.c     |   42 ++++++------------
 drivers/gpu/drm/radeon/radeon_ring.c      |   19 +++++----
 drivers/gpu/drm/radeon/radeon_sa.c        |    2 +-
 drivers/gpu/drm/radeon/radeon_test.c      |   66 ++++++++++++-----------------
 drivers/gpu/drm/radeon/radeon_ttm.c       |   30 +++++--------
 drivers/gpu/drm/radeon/si.c               |    6 +--
 15 files changed, 86 insertions(+), 130 deletions(-)
drivers/gpu/drm/radeon/evergreen.c +1 -1
index 7e7ac3d..81678be 100644
@@ -1366,7 +1366,7 @@ void evergreen_mc_program(struct radeon_device *rdev)
  */
 void evergreen_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
 {
-	struct radeon_ring *ring = &rdev->ring[ib->fence->ring];
+	struct radeon_ring *ring = &rdev->ring[ib->ring];
 
 	/* set to DX10/11 mode */
 	radeon_ring_write(ring, PACKET3(PACKET3_MODE_CONTROL, 0));
drivers/gpu/drm/radeon/ni.c +1 -1
index 107b217..4c2758d 100644
@@ -1127,7 +1127,7 @@ void cayman_fence_ring_emit(struct radeon_device *rdev,
 
 void cayman_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
 {
-	struct radeon_ring *ring = &rdev->ring[ib->fence->ring];
+	struct radeon_ring *ring = &rdev->ring[ib->ring];
 
 	/* set to DX10/11 mode */
 	radeon_ring_write(ring, PACKET3(PACKET3_MODE_CONTROL, 0));
drivers/gpu/drm/radeon/r100.c +2 -2
index 0874a6d..1e3518d 100644
@@ -883,7 +883,7 @@ int r100_copy_blit(struct radeon_device *rdev,
 		   uint64_t src_offset,
 		   uint64_t dst_offset,
 		   unsigned num_gpu_pages,
-		   struct radeon_fence *fence)
+		   struct radeon_fence **fence)
 {
 	struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
 	uint32_t cur_pages;
@@ -947,7 +947,7 @@ int r100_copy_blit(struct radeon_device *rdev,
 			  RADEON_WAIT_HOST_IDLECLEAN |
 			  RADEON_WAIT_DMA_GUI_IDLE);
 	if (fence) {
-		r = radeon_fence_emit(rdev, fence);
+		r = radeon_fence_emit(rdev, fence, RADEON_RING_TYPE_GFX_INDEX);
 	}
 	radeon_ring_unlock_commit(rdev, ring);
 	return r;
drivers/gpu/drm/radeon/r200.c +2 -2
index a26144d..f088925 100644
@@ -85,7 +85,7 @@ int r200_copy_dma(struct radeon_device *rdev,
 		  uint64_t src_offset,
 		  uint64_t dst_offset,
 		  unsigned num_gpu_pages,
-		  struct radeon_fence *fence)
+		  struct radeon_fence **fence)
 {
 	struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
 	uint32_t size;
@@ -120,7 +120,7 @@ int r200_copy_dma(struct radeon_device *rdev,
 	radeon_ring_write(ring, PACKET0(RADEON_WAIT_UNTIL, 0));
 	radeon_ring_write(ring, RADEON_WAIT_DMA_GUI_IDLE);
 	if (fence) {
-		r = radeon_fence_emit(rdev, fence);
+		r = radeon_fence_emit(rdev, fence, RADEON_RING_TYPE_GFX_INDEX);
 	}
 	radeon_ring_unlock_commit(rdev, ring);
 	return r;
drivers/gpu/drm/radeon/r600.c +2 -2
index 4c0d8c9..b680cc4 100644
@@ -2361,7 +2361,7 @@ int r600_copy_blit(struct radeon_device *rdev,
 		   uint64_t src_offset,
 		   uint64_t dst_offset,
 		   unsigned num_gpu_pages,
-		   struct radeon_fence *fence)
+		   struct radeon_fence **fence)
 {
 	struct radeon_sa_bo *vb = NULL;
 	int r;
@@ -2666,7 +2666,7 @@ void r600_fini(struct radeon_device *rdev)
  */
 void r600_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
 {
-	struct radeon_ring *ring = &rdev->ring[ib->fence->ring];
+	struct radeon_ring *ring = &rdev->ring[ib->ring];
 
 	/* FIXME: implement */
 	radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
drivers/gpu/drm/radeon/r600_blit_kms.c +3 -3
index ef20822..5d1f1c0 100644
@@ -703,20 +703,20 @@ int r600_blit_prepare_copy(struct radeon_device *rdev, unsigned num_gpu_pages,
 	return 0;
 }
 
-void r600_blit_done_copy(struct radeon_device *rdev, struct radeon_fence *fence,
+void r600_blit_done_copy(struct radeon_device *rdev, struct radeon_fence **fence,
 			 struct radeon_sa_bo *vb)
 {
 	struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
 	int r;
 
-	r = radeon_fence_emit(rdev, fence);
+	r = radeon_fence_emit(rdev, fence, RADEON_RING_TYPE_GFX_INDEX);
 	if (r) {
 		radeon_ring_unlock_undo(rdev, ring);
 		return;
 	}
 
 	radeon_ring_unlock_commit(rdev, ring);
-	radeon_sa_bo_free(rdev, &vb, fence);
+	radeon_sa_bo_free(rdev, &vb, *fence);
 }
 
 void r600_kms_blit_copy(struct radeon_device *rdev,
drivers/gpu/drm/radeon/radeon.h +5 -6
index 60233d7..cd2d10f 100644
@@ -113,7 +113,6 @@ extern int radeon_lockup_timeout;
 
 /* fence seq are set to this number when signaled */
 #define RADEON_FENCE_SIGNALED_SEQ		0LL
-#define RADEON_FENCE_NOTEMITED_SEQ		(~0LL)
 
 /* internal ring indices */
 /* r1xx+ has gfx CP ring */
@@ -277,8 +276,7 @@ struct radeon_fence {
 int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring);
 int radeon_fence_driver_init(struct radeon_device *rdev);
 void radeon_fence_driver_fini(struct radeon_device *rdev);
-int radeon_fence_create(struct radeon_device *rdev, struct radeon_fence **fence, int ring);
-int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence);
+int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence **fence, int ring);
 void radeon_fence_process(struct radeon_device *rdev, int ring);
 bool radeon_fence_signaled(struct radeon_fence *fence);
 int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
@@ -627,6 +625,7 @@ struct radeon_ib {
 	uint32_t			length_dw;
 	uint64_t			gpu_addr;
 	uint32_t			*ptr;
+	int				ring;
 	struct radeon_fence		*fence;
 	unsigned			vm_id;
 	bool				is_const_ib;
@@ -1191,20 +1190,20 @@ struct radeon_asic {
 			    uint64_t src_offset,
 			    uint64_t dst_offset,
 			    unsigned num_gpu_pages,
-			    struct radeon_fence *fence);
+			    struct radeon_fence **fence);
 		u32 blit_ring_index;
 		int (*dma)(struct radeon_device *rdev,
 			   uint64_t src_offset,
 			   uint64_t dst_offset,
 			   unsigned num_gpu_pages,
-			   struct radeon_fence *fence);
+			   struct radeon_fence **fence);
 		u32 dma_ring_index;
 		/* method used for bo copy */
 		int (*copy)(struct radeon_device *rdev,
 			    uint64_t src_offset,
 			    uint64_t dst_offset,
 			    unsigned num_gpu_pages,
-			    struct radeon_fence *fence);
+			    struct radeon_fence **fence);
 		/* ring used for bo copies */
 		u32 copy_ring_index;
 	} copy;
drivers/gpu/drm/radeon/radeon_asic.h +4 -4
index 05a4e15..6d0beaf 100644
@@ -79,7 +79,7 @@ int r100_copy_blit(struct radeon_device *rdev,
 		   uint64_t src_offset,
 		   uint64_t dst_offset,
 		   unsigned num_gpu_pages,
-		   struct radeon_fence *fence);
+		   struct radeon_fence **fence);
 int r100_set_surface_reg(struct radeon_device *rdev, int reg,
 			 uint32_t tiling_flags, uint32_t pitch,
 			 uint32_t offset, uint32_t obj_size);
@@ -144,7 +144,7 @@ extern int r200_copy_dma(struct radeon_device *rdev,
 			 uint64_t src_offset,
 			 uint64_t dst_offset,
 			 unsigned num_gpu_pages,
-			 struct radeon_fence *fence);
+			 struct radeon_fence **fence);
 void r200_set_safe_registers(struct radeon_device *rdev);
 
 /*
@@ -318,7 +318,7 @@ void r600_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib);
 int r600_ring_test(struct radeon_device *rdev, struct radeon_ring *cp);
 int r600_copy_blit(struct radeon_device *rdev,
 		   uint64_t src_offset, uint64_t dst_offset,
-		   unsigned num_gpu_pages, struct radeon_fence *fence);
+		   unsigned num_gpu_pages, struct radeon_fence **fence);
 void r600_hpd_init(struct radeon_device *rdev);
 void r600_hpd_fini(struct radeon_device *rdev);
 bool r600_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd);
@@ -370,7 +370,7 @@ void r600_hdmi_update_audio_settings(struct drm_encoder *encoder);
 /* r600 blit */
 int r600_blit_prepare_copy(struct radeon_device *rdev, unsigned num_gpu_pages,
 			   struct radeon_sa_bo **vb);
-void r600_blit_done_copy(struct radeon_device *rdev, struct radeon_fence *fence,
+void r600_blit_done_copy(struct radeon_device *rdev, struct radeon_fence **fence,
 			 struct radeon_sa_bo *vb);
 void r600_kms_blit_copy(struct radeon_device *rdev,
 			u64 src_gpu_addr, u64 dst_gpu_addr,
drivers/gpu/drm/radeon/radeon_benchmark.c +2 -8
index fef7b72..61019e7 100644
@@ -45,20 +45,14 @@ static int radeon_benchmark_do_move(struct radeon_device *rdev, unsigned size,
 	for (i = 0; i < n; i++) {
 		switch (flag) {
 		case RADEON_BENCHMARK_COPY_DMA:
-			r = radeon_fence_create(rdev, &fence, radeon_copy_dma_ring_index(rdev));
-			if (r)
-				return r;
 			r = radeon_copy_dma(rdev, saddr, daddr,
 					    size / RADEON_GPU_PAGE_SIZE,
-					    fence);
+					    &fence);
 			break;
 		case RADEON_BENCHMARK_COPY_BLIT:
-			r = radeon_fence_create(rdev, &fence, radeon_copy_blit_ring_index(rdev));
-			if (r)
-				return r;
 			r = radeon_copy_blit(rdev, saddr, daddr,
 					     size / RADEON_GPU_PAGE_SIZE,
-					     fence);
+					     &fence);
 			break;
 		default:
 			DRM_ERROR("Unknown copy method\n");
drivers/gpu/drm/radeon/radeon_fence.c +13 -29

72 lines not on this page · raw message

drivers/gpu/drm/radeon/radeon_ring.c +10 -9
index a5dee76..2d91bbb 100644
@@ -74,13 +74,9 @@ int radeon_ib_get(struct radeon_device *rdev, int ring,
 		dev_err(rdev->dev, "failed to get a new IB (%d)\n", r);
 		return r;
 	}
-	r = radeon_fence_create(rdev, &ib->fence, ring);
-	if (r) {
-		dev_err(rdev->dev, "failed to create fence for new IB (%d)\n", r);
-		radeon_sa_bo_free(rdev, &ib->sa_bo, NULL);
-		return r;
-	}
 
+	ib->ring = ring;
+	ib->fence = NULL;
 	ib->ptr = radeon_sa_bo_cpu_addr(ib->sa_bo);
 	ib->gpu_addr = radeon_sa_bo_gpu_addr(ib->sa_bo);
 	ib->vm_id = 0;
@@ -99,7 +95,7 @@ void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib *ib)
 
 int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib)
 {
-	struct radeon_ring *ring = &rdev->ring[ib->fence->ring];
+	struct radeon_ring *ring = &rdev->ring[ib->ring];
 	int r = 0;
 
 	if (!ib->length_dw || !ring->ready) {
@@ -114,8 +110,13 @@ int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib)
 		dev_err(rdev->dev, "scheduling IB failed (%d).\n", r);
 		return r;
 	}
-	radeon_ring_ib_execute(rdev, ib->fence->ring, ib);
-	radeon_fence_emit(rdev, ib->fence);
+	radeon_ring_ib_execute(rdev, ib->ring, ib);
+	r = radeon_fence_emit(rdev, &ib->fence, ib->ring);
+	if (r) {
+		dev_err(rdev->dev, "failed to emit fence for new IB (%d)\n", r);
+		radeon_ring_unlock_undo(rdev, ring);
+		return r;
+	}
 	radeon_ring_unlock_commit(rdev, ring);
 	return 0;
 }
drivers/gpu/drm/radeon/radeon_sa.c +1 -1
index c3ac7f4..0619ee2 100644
@@ -349,7 +349,7 @@ void radeon_sa_bo_free(struct radeon_device *rdev, struct radeon_sa_bo **sa_bo,
 
 	sa_manager = (*sa_bo)->manager;
 	spin_lock(&sa_manager->lock);
-	if (fence && fence->seq && fence->seq < RADEON_FENCE_NOTEMITED_SEQ) {
+	if (fence && !radeon_fence_signaled(fence)) {
 		(*sa_bo)->fence = radeon_fence_ref(fence);
 		list_add_tail(&(*sa_bo)->flist,
 			      &sa_manager->flist[fence->ring]);
drivers/gpu/drm/radeon/radeon_test.c +26 -40

109 lines not on this page · raw message

drivers/gpu/drm/radeon/radeon_ttm.c +11 -19
index 0f6aee8..860e730 100644
@@ -222,15 +222,12 @@ static int radeon_move_blit(struct ttm_buffer_object *bo,
 {
 	struct radeon_device *rdev;
 	uint64_t old_start, new_start;
-	struct radeon_fence *fence, *old_fence;
+	struct radeon_fence *fence;
 	struct radeon_semaphore *sem = NULL;
-	int r;
+	int r, ridx;
 
 	rdev = radeon_get_rdev(bo->bdev);
-	r = radeon_fence_create(rdev, &fence, radeon_copy_ring_index(rdev));
-	if (unlikely(r)) {
-		return r;
-	}
+	ridx = radeon_copy_ring_index(rdev);
 	old_start = old_mem->start << PAGE_SHIFT;
 	new_start = new_mem->start << PAGE_SHIFT;
 
@@ -243,7 +240,6 @@ static int radeon_move_blit(struct ttm_buffer_object *bo,
 		break;
 	default:
 		DRM_ERROR("Unknown placement %d\n", old_mem->mem_type);
-		radeon_fence_unref(&fence);
 		return -EINVAL;
 	}
 	switch (new_mem->mem_type) {
@@ -255,42 +251,38 @@ static int radeon_move_blit(struct ttm_buffer_object *bo,
 		break;
 	default:
 		DRM_ERROR("Unknown placement %d\n", old_mem->mem_type);
-		radeon_fence_unref(&fence);
 		return -EINVAL;
 	}
-	if (!rdev->ring[radeon_copy_ring_index(rdev)].ready) {
+	if (!rdev->ring[ridx].ready) {
 		DRM_ERROR("Trying to move memory with ring turned off.\n");
-		radeon_fence_unref(&fence);
 		return -EINVAL;
 	}
 
 	BUILD_BUG_ON((PAGE_SIZE % RADEON_GPU_PAGE_SIZE) != 0);
 
 	/* sync other rings */
-	old_fence = bo->sync_obj;
-	if (old_fence && old_fence->ring != fence->ring
-	    && !radeon_fence_signaled(old_fence)) {
+	fence = bo->sync_obj;
+	if (fence && fence->ring != ridx
+	    && !radeon_fence_signaled(fence)) {
 		bool sync_to_ring[RADEON_NUM_RINGS] = { };
-		sync_to_ring[old_fence->ring] = true;
+		sync_to_ring[fence->ring] = true;
 
 		r = radeon_semaphore_create(rdev, &sem);
 		if (r) {
-			radeon_fence_unref(&fence);
 			return r;
 		}
 
-		r = radeon_semaphore_sync_rings(rdev, sem,
-						sync_to_ring, fence->ring);
+		r = radeon_semaphore_sync_rings(rdev, sem, sync_to_ring, ridx);
 		if (r) {
 			radeon_semaphore_free(rdev, sem, NULL);
-			radeon_fence_unref(&fence);
 			return r;
 		}
 	}
 
+	fence = NULL;
 	r = radeon_copy(rdev, old_start, new_start,
 			new_mem->num_pages * (PAGE_SIZE / RADEON_GPU_PAGE_SIZE), /* GPU pages */
-			fence);
+			&fence);
 	/* FIXME: handle copy error */
 	r = ttm_bo_move_accel_cleanup(bo, (void *)fence, NULL,
 				      evict, no_wait_reserve, no_wait_gpu, new_mem);
drivers/gpu/drm/radeon/si.c +3 -3
index be3b9fd..099dae4 100644
@@ -1915,7 +1915,7 @@ void si_fence_ring_emit(struct radeon_device *rdev,
  */
 void si_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
 {
-	struct radeon_ring *ring = &rdev->ring[ib->fence->ring];
+	struct radeon_ring *ring = &rdev->ring[ib->ring];
 	u32 header;
 
 	if (ib->is_const_ib)
@@ -2854,7 +2854,7 @@ int si_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)
 			if (ib->is_const_ib)
 				ret = si_vm_packet3_ce_check(rdev, ib->ptr, &pkt);
 			else {
-				switch (ib->fence->ring) {
+				switch (ib->ring) {
 				case RADEON_RING_TYPE_GFX_INDEX:
 					ret = si_vm_packet3_gfx_check(rdev, ib->ptr, &pkt);
 					break;
@@ -2863,7 +2863,7 @@ int si_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)
 					ret = si_vm_packet3_compute_check(rdev, ib->ptr, &pkt);
 					break;
 				default:
-					dev_err(rdev->dev, "Non-PM4 ring %d !\n", ib->fence->ring);
+					dev_err(rdev->dev, "Non-PM4 ring %d !\n", ib->ring);
 					ret = -EINVAL;
 					break;
 				}
Signature · 6 lines
1.7.9.5

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

PATCH 2/5 drm/radeon: add infrastructure for advanced ring synchronization

In reply to Christian König
---
 drivers/gpu/drm/radeon/radeon.h       |   23 ++++++++++-
 drivers/gpu/drm/radeon/radeon_fence.c |   73 +++++++++++++++++++++++++++++----
 2 files changed, 85 insertions(+), 11 deletions(-)
drivers/gpu/drm/radeon/radeon.h +21 -2
index cd2d10f..b02e36b 100644
@@ -257,8 +257,8 @@ struct radeon_fence_driver {
 	uint32_t			scratch_reg;
 	uint64_t			gpu_addr;
 	volatile uint32_t		*cpu_addr;
-	/* seq is protected by ring emission lock */
-	uint64_t			seq;
+	/* sync_seq is protected by ring emission lock */
+	uint64_t			sync_seq[RADEON_NUM_RINGS];
 	atomic64_t			last_seq;
 	unsigned long			last_activity;
 	bool				initialized;
@@ -288,6 +288,25 @@ int radeon_fence_wait_any(struct radeon_device *rdev,
 struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence);
 void radeon_fence_unref(struct radeon_fence **fence);
 unsigned radeon_fence_count_emitted(struct radeon_device *rdev, int ring);
+bool radeon_fence_need_sync(struct radeon_fence *fence, int ring);
+void radeon_fence_note_sync(struct radeon_fence *fence, int ring);
+static inline struct radeon_fence *radeon_fence_later(struct radeon_fence *a,
+						      struct radeon_fence *b)
+{
+	if (!a) {
+		return b;
+	}
+
+	if (!b) {
+		return a;
+	}
+
+	if (a->seq > b->seq) {
+		return a;
+	} else {
+		return b;
+	}
+}
 
 /*
  * Tiling registers
drivers/gpu/drm/radeon/radeon_fence.c +64 -9

130 lines not on this page · raw message

Signature · 6 lines
1.7.9.5

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw

PATCH 3/5 drm/radeon: rework ring syncing code

In reply to Christian König

Move inter ring syncing with semaphores into the
existing ring allocations, with that we need to
lock the ring mutex only once.

---
 drivers/gpu/drm/radeon/evergreen_blit_kms.c |    3 +-
 drivers/gpu/drm/radeon/r600.c               |    5 +-
 drivers/gpu/drm/radeon/r600_blit_kms.c      |   24 +++++++--
 drivers/gpu/drm/radeon/radeon.h             |    6 +--
 drivers/gpu/drm/radeon/radeon_asic.h        |    5 +-
 drivers/gpu/drm/radeon/radeon_cs.c          |   38 +++-----------
 drivers/gpu/drm/radeon/radeon_ring.c        |   30 +++++++++--
 drivers/gpu/drm/radeon/radeon_semaphore.c   |   71 ++++++++++-----------------
 drivers/gpu/drm/radeon/radeon_test.c        |    6 +--
 drivers/gpu/drm/radeon/radeon_ttm.c         |   20 --------
 10 files changed, 92 insertions(+), 116 deletions(-)
drivers/gpu/drm/radeon/evergreen_blit_kms.c +2 -1
index 30f0480..4bbf83c 100644
@@ -622,7 +622,8 @@ int evergreen_blit_init(struct radeon_device *rdev)
 	rdev->r600_blit.primitives.draw_auto = draw_auto;
 	rdev->r600_blit.primitives.set_default_state = set_default_state;
 
-	rdev->r600_blit.ring_size_common = 55; /* shaders + def state */
+	rdev->r600_blit.ring_size_common = 8; /* sync semaphore */
+	rdev->r600_blit.ring_size_common += 55; /* shaders + def state */
 	rdev->r600_blit.ring_size_common += 16; /* fence emit for VB IB */
 	rdev->r600_blit.ring_size_common += 5; /* done copy */
 	rdev->r600_blit.ring_size_common += 16; /* fence emit for done copy */
drivers/gpu/drm/radeon/r600.c +3 -2
index b680cc4..b12687b 100644
@@ -2363,15 +2363,16 @@ int r600_copy_blit(struct radeon_device *rdev,
 		   unsigned num_gpu_pages,
 		   struct radeon_fence **fence)
 {
+	struct radeon_semaphore *sem = NULL;
 	struct radeon_sa_bo *vb = NULL;
 	int r;
 
-	r = r600_blit_prepare_copy(rdev, num_gpu_pages, &vb);
+	r = r600_blit_prepare_copy(rdev, num_gpu_pages, fence, &vb, &sem);
 	if (r) {
 		return r;
 	}
 	r600_kms_blit_copy(rdev, src_offset, dst_offset, num_gpu_pages, vb);
-	r600_blit_done_copy(rdev, fence, vb);
+	r600_blit_done_copy(rdev, fence, vb, sem);
 	return 0;
 }
 
drivers/gpu/drm/radeon/r600_blit_kms.c +21 -3
index 5d1f1c0..b683221 100644
@@ -512,7 +512,8 @@ int r600_blit_init(struct radeon_device *rdev)
 	rdev->r600_blit.primitives.draw_auto = draw_auto;
 	rdev->r600_blit.primitives.set_default_state = set_default_state;
 
-	rdev->r600_blit.ring_size_common = 40; /* shaders + def state */
+	rdev->r600_blit.ring_size_common = 8; /* sync semaphore */
+	rdev->r600_blit.ring_size_common += 40; /* shaders + def state */
 	rdev->r600_blit.ring_size_common += 5; /* done copy */
 	rdev->r600_blit.ring_size_common += 16; /* fence emit for done copy */
 
@@ -666,7 +667,8 @@ static unsigned r600_blit_create_rect(unsigned num_gpu_pages,
 
 
 int r600_blit_prepare_copy(struct radeon_device *rdev, unsigned num_gpu_pages,
-			   struct radeon_sa_bo **vb)
+			   struct radeon_fence **fence, struct radeon_sa_bo **vb,
+			   struct radeon_semaphore **sem)
 {
 	struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
 	int r;
@@ -689,22 +691,37 @@ int r600_blit_prepare_copy(struct radeon_device *rdev, unsigned num_gpu_pages,
 		return r;
 	}
 
+	r = radeon_semaphore_create(rdev, sem);
+	if (r) {
+		radeon_sa_bo_free(rdev, vb, NULL);
+		return r;
+	}
+
 	/* calculate number of loops correctly */
 	ring_size = num_loops * dwords_per_loop;
 	ring_size += rdev->r600_blit.ring_size_common;
 	r = radeon_ring_lock(rdev, ring, ring_size);
 	if (r) {
 		radeon_sa_bo_free(rdev, vb, NULL);
+		radeon_semaphore_free(rdev, sem, NULL);
 		return r;
 	}
 
+	if (radeon_fence_need_sync(*fence, RADEON_RING_TYPE_GFX_INDEX)) {
+		radeon_semaphore_sync_rings(rdev, *sem, (*fence)->ring,
+					    RADEON_RING_TYPE_GFX_INDEX);
+		radeon_fence_note_sync(*fence, RADEON_RING_TYPE_GFX_INDEX);
+	} else {
+		radeon_semaphore_free(rdev, sem, NULL);
+	}
+
 	rdev->r600_blit.primitives.set_default_state(rdev);
 	rdev->r600_blit.primitives.set_shaders(rdev);
 	return 0;
 }
 
 void r600_blit_done_copy(struct radeon_device *rdev, struct radeon_fence **fence,
-			 struct radeon_sa_bo *vb)
+			 struct radeon_sa_bo *vb, struct radeon_semaphore *sem)
 {
 	struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
 	int r;
@@ -717,6 +734,7 @@ void r600_blit_done_copy(struct radeon_device *rdev, struct radeon_fence **fence
 
 	radeon_ring_unlock_commit(rdev, ring);
 	radeon_sa_bo_free(rdev, &vb, *fence);
+	radeon_semaphore_free(rdev, &sem, *fence);
 }
 
 void r600_kms_blit_copy(struct radeon_device *rdev,
drivers/gpu/drm/radeon/radeon.h +3 -3
index b02e36b..e00c50d 100644
@@ -465,10 +465,9 @@ void radeon_semaphore_emit_wait(struct radeon_device *rdev, int ring,
 				struct radeon_semaphore *semaphore);
 int radeon_semaphore_sync_rings(struct radeon_device *rdev,
 				struct radeon_semaphore *semaphore,
-				bool sync_to[RADEON_NUM_RINGS],
-				int dst_ring);
+				int signaler, int waiter);
 void radeon_semaphore_free(struct radeon_device *rdev,
-			   struct radeon_semaphore *semaphore,
+			   struct radeon_semaphore **semaphore,
 			   struct radeon_fence *fence);
 
 /*
@@ -648,6 +647,7 @@ struct radeon_ib {
 	struct radeon_fence		*fence;
 	unsigned			vm_id;
 	bool				is_const_ib;
+	struct radeon_fence		*sync_to[RADEON_NUM_RINGS];
 	struct radeon_semaphore		*semaphore;
 };
 
drivers/gpu/drm/radeon/radeon_asic.h +3 -2
index 6d0beaf..fe18f51 100644
@@ -369,9 +369,10 @@ int r600_hdmi_buffer_status_changed(struct drm_encoder *encoder);
 void r600_hdmi_update_audio_settings(struct drm_encoder *encoder);
 /* r600 blit */
 int r600_blit_prepare_copy(struct radeon_device *rdev, unsigned num_gpu_pages,
-			   struct radeon_sa_bo **vb);
+			   struct radeon_fence **fence, struct radeon_sa_bo **vb,
+			   struct radeon_semaphore **sem);
 void r600_blit_done_copy(struct radeon_device *rdev, struct radeon_fence **fence,
-			 struct radeon_sa_bo *vb);
+			 struct radeon_sa_bo *vb, struct radeon_semaphore *sem);
 void r600_kms_blit_copy(struct radeon_device *rdev,
 			u64 src_gpu_addr, u64 dst_gpu_addr,
 			unsigned num_gpu_pages,
drivers/gpu/drm/radeon/radeon_cs.c +8 -30
index c7d64a7..d295821 100644
@@ -115,36 +115,20 @@ static int radeon_cs_get_ring(struct radeon_cs_parser *p, u32 ring, s32 priority
 	return 0;
 }
 
-static int radeon_cs_sync_rings(struct radeon_cs_parser *p)
+static void radeon_cs_sync_rings(struct radeon_cs_parser *p)
 {
-	bool sync_to_ring[RADEON_NUM_RINGS] = { };
-	bool need_sync = false;
-	int i, r;
+	int i;
 
 	for (i = 0; i < p->nrelocs; i++) {
-		struct radeon_fence *fence;
+		struct radeon_fence *a, *b;
 
 		if (!p->relocs[i].robj || !p->relocs[i].robj->tbo.sync_obj)
 			continue;
 
-		fence = p->relocs[i].robj->tbo.sync_obj;
-		if (fence->ring != p->ring && !radeon_fence_signaled(fence)) {
-			sync_to_ring[fence->ring] = true;
-			need_sync = true;
-		}
-	}
-
-	if (!need_sync) {
-		return 0;
-	}
-
-	r = radeon_semaphore_create(p->rdev, &p->ib.semaphore);
-	if (r) {
-		return r;
+		a = p->relocs[i].robj->tbo.sync_obj;
+		b = p->ib.sync_to[a->ring];
+		p->ib.sync_to[a->ring] = radeon_fence_later(a, b);
 	}
-
-	return radeon_semaphore_sync_rings(p->rdev, p->ib.semaphore,
-					   sync_to_ring, p->ring);
 }
 
 int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data)
@@ -365,10 +349,7 @@ static int radeon_cs_ib_chunk(struct radeon_device *rdev,
 		DRM_ERROR("Invalid command stream !\n");
 		return r;
 	}
-	r = radeon_cs_sync_rings(parser);
-	if (r) {
-		DRM_ERROR("Failed to synchronize rings !\n");
-	}
+	radeon_cs_sync_rings(parser);
 	parser->ib.vm_id = 0;
 	r = radeon_ib_schedule(rdev, &parser->ib);
 	if (r) {
@@ -465,10 +446,7 @@ static int radeon_cs_ib_vm_chunk(struct radeon_device *rdev,
 	if (r) {
 		goto out;
 	}
-	r = radeon_cs_sync_rings(parser);
-	if (r) {
-		DRM_ERROR("Failed to synchronize rings !\n");
-	}
+	radeon_cs_sync_rings(parser);
 
 	if ((rdev->family >= CHIP_TAHITI) &&
 	    (parser->chunk_const_ib_idx != -1)) {
drivers/gpu/drm/radeon/radeon_ring.c +25 -5
index 2d91bbb..cf70c2c 100644
@@ -67,7 +67,7 @@ u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx)
 int radeon_ib_get(struct radeon_device *rdev, int ring,
 		  struct radeon_ib *ib, unsigned size)
 {
-	int r;
+	int i, r;
 
 	r = radeon_sa_bo_new(rdev, &rdev->ring_tmp_bo, &ib->sa_bo, size, 256, true);
 	if (r) {
@@ -75,20 +75,26 @@ int radeon_ib_get(struct radeon_device *rdev, int ring,
 		return r;
 	}
 
+	r = radeon_semaphore_create(rdev, &ib->semaphore);
+	if (r) {
+		return r;
+	}
+
 	ib->ring = ring;
 	ib->fence = NULL;
 	ib->ptr = radeon_sa_bo_cpu_addr(ib->sa_bo);
 	ib->gpu_addr = radeon_sa_bo_gpu_addr(ib->sa_bo);
 	ib->vm_id = 0;
 	ib->is_const_ib = false;
-	ib->semaphore = NULL;
+	for (i = 0; i < RADEON_NUM_RINGS; ++i)
+		ib->sync_to[i] = NULL;
 
 	return 0;
 }
 
 void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib *ib)
 {
-	radeon_semaphore_free(rdev, ib->semaphore, ib->fence);
+	radeon_semaphore_free(rdev, &ib->semaphore, ib->fence);
 	radeon_sa_bo_free(rdev, &ib->sa_bo, ib->fence);
 	radeon_fence_unref(&ib->fence);
 }
@@ -96,7 +102,8 @@ void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib *ib)
 int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib)
 {
 	struct radeon_ring *ring = &rdev->ring[ib->ring];
-	int r = 0;
+	bool need_sync = false;
+	int i, r = 0;
 
 	if (!ib->length_dw || !ring->ready) {
 		/* TODO: Nothings in the ib we should report. */
@@ -105,11 +112,24 @@ int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib)
 	}
 
 	/* 64 dwords should be enough for fence too */
-	r = radeon_ring_lock(rdev, ring, 64);
+	r = radeon_ring_lock(rdev, ring, 64 + RADEON_NUM_RINGS * 8);
 	if (r) {
 		dev_err(rdev->dev, "scheduling IB failed (%d).\n", r);
 		return r;
 	}
+	for (i = 0; i < RADEON_NUM_RINGS; ++i) {
+		struct radeon_fence *fence = ib->sync_to[i];
+		if (radeon_fence_need_sync(fence, ib->ring)) {
+			need_sync = true;
+			radeon_semaphore_sync_rings(rdev, ib->semaphore,
+						    fence->ring, ib->ring);
+			radeon_fence_note_sync(fence, ib->ring);
+		}
+	}
+	/* immediately free semaphore when we don't need to sync */
+	if (!need_sync) {
+		radeon_semaphore_free(rdev, &ib->semaphore, NULL);
+	}
 	radeon_ring_ib_execute(rdev, ib->ring, ib);
 	r = radeon_fence_emit(rdev, &ib->fence, ib->ring);
 	if (r) {
drivers/gpu/drm/radeon/radeon_semaphore.c +25 -46

95 lines not on this page · raw message

drivers/gpu/drm/radeon/radeon_test.c +2 -4
index eace3a5..ff6ac4b 100644
@@ -303,8 +303,7 @@ void radeon_test_ring_sync(struct radeon_device *rdev,
 	}
 
 out_cleanup:
-	if (semaphore)
-		radeon_semaphore_free(rdev, semaphore, NULL);
+	radeon_semaphore_free(rdev, &semaphore, NULL);
 
 	if (fence1)
 		radeon_fence_unref(&fence1);
@@ -422,8 +421,7 @@ void radeon_test_ring_sync2(struct radeon_device *rdev,
 	}
 
 out_cleanup:
-	if (semaphore)
-		radeon_semaphore_free(rdev, semaphore, NULL);
+	radeon_semaphore_free(rdev, &semaphore, NULL);
 
 	if (fenceA)
 		radeon_fence_unref(&fenceA);
drivers/gpu/drm/radeon/radeon_ttm.c +0 -20
index 860e730..a7f9007 100644
@@ -223,7 +223,6 @@ static int radeon_move_blit(struct ttm_buffer_object *bo,
 	struct radeon_device *rdev;
 	uint64_t old_start, new_start;
 	struct radeon_fence *fence;
-	struct radeon_semaphore *sem = NULL;
 	int r, ridx;
 
 	rdev = radeon_get_rdev(bo->bdev);
@@ -262,31 +261,12 @@ static int radeon_move_blit(struct ttm_buffer_object *bo,
 
 	/* sync other rings */
 	fence = bo->sync_obj;
-	if (fence && fence->ring != ridx
-	    && !radeon_fence_signaled(fence)) {
-		bool sync_to_ring[RADEON_NUM_RINGS] = { };
-		sync_to_ring[fence->ring] = true;
-
-		r = radeon_semaphore_create(rdev, &sem);
-		if (r) {
-			return r;
-		}
-
-		r = radeon_semaphore_sync_rings(rdev, sem, sync_to_ring, ridx);
-		if (r) {
-			radeon_semaphore_free(rdev, sem, NULL);
-			return r;
-		}
-	}
-
-	fence = NULL;
 	r = radeon_copy(rdev, old_start, new_start,
 			new_mem->num_pages * (PAGE_SIZE / RADEON_GPU_PAGE_SIZE), /* GPU pages */
 			&fence);
 	/* FIXME: handle copy error */
 	r = ttm_bo_move_accel_cleanup(bo, (void *)fence, NULL,
 				      evict, no_wait_reserve, no_wait_gpu, new_mem);
-	radeon_semaphore_free(rdev, sem, fence);
 	radeon_fence_unref(&fence);
 	return r;
 }
Signature · 6 lines
1.7.9.5

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw

PATCH 4/5 drm/radeon: WIP remove cs_mutex

In reply to Christian König

There are probably some missed corner cases, but at least try to remove or replace it with a vm mutex where it is still needed.

---
 drivers/gpu/drm/radeon/radeon.h        |   44 +-------------------------------
 drivers/gpu/drm/radeon/radeon_cs.c     |    7 ++---
 drivers/gpu/drm/radeon/radeon_device.c |    2 +-
 drivers/gpu/drm/radeon/radeon_gart.c   |   16 ++++++------
 drivers/gpu/drm/radeon/radeon_gem.c    |    2 --
 5 files changed, 12 insertions(+), 59 deletions(-)
drivers/gpu/drm/radeon/radeon.h +1 -43
index e00c50d..8769217 100644
@@ -159,48 +159,6 @@ static inline int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len)
 #endif
 bool radeon_get_bios(struct radeon_device *rdev);
 
-
-/*
- * Mutex which allows recursive locking from the same process.
- */
-struct radeon_mutex {
-	struct mutex		mutex;
-	struct task_struct	*owner;
-	int			level;
-};
-
-static inline void radeon_mutex_init(struct radeon_mutex *mutex)
-{
-	mutex_init(&mutex->mutex);
-	mutex->owner = NULL;
-	mutex->level = 0;
-}
-
-static inline void radeon_mutex_lock(struct radeon_mutex *mutex)
-{
-	if (mutex_trylock(&mutex->mutex)) {
-		/* The mutex was unlocked before, so it's ours now */
-		mutex->owner = current;
-	} else if (mutex->owner != current) {
-		/* Another process locked the mutex, take it */
-		mutex_lock(&mutex->mutex);
-		mutex->owner = current;
-	}
-	/* Otherwise the mutex was already locked by this process */
-
-	mutex->level++;
-}
-
-static inline void radeon_mutex_unlock(struct radeon_mutex *mutex)
-{
-	if (--mutex->level > 0)
-		return;
-
-	mutex->owner = NULL;
-	mutex_unlock(&mutex->mutex);
-}
-
-
 /*
  * Dummy page
  */
@@ -1530,7 +1488,6 @@ struct radeon_device {
 	struct radeon_gem		gem;
 	struct radeon_pm		pm;
 	uint32_t			bios_scratch[RADEON_BIOS_NUM_SCRATCH];
-	struct radeon_mutex		cs_mutex;
 	struct radeon_wb		wb;
 	struct radeon_dummy_page	dummy_page;
 	bool				shutdown;
@@ -1564,6 +1521,7 @@ struct radeon_device {
 	struct radeon_debugfs	debugfs[RADEON_DEBUGFS_MAX_COMPONENTS];
 	unsigned 		debugfs_count;
 	/* virtual memory */
+	struct mutex			vm_mutex;
 	struct radeon_vm_manager	vm_manager;
 };
 
drivers/gpu/drm/radeon/radeon_cs.c +2 -5
index d295821..d1ead9c 100644
@@ -438,6 +438,7 @@ static int radeon_cs_ib_vm_chunk(struct radeon_device *rdev,
 	}
 
 	mutex_lock(&vm->mutex);
+	mutex_lock(&rdev->vm_mutex);
 	r = radeon_vm_bind(rdev, vm);
 	if (r) {
 		goto out;
@@ -474,6 +475,7 @@ out:
 		}
 		vm->fence = radeon_fence_ref(parser->ib.fence);
 	}
+	mutex_unlock(&rdev->vm_mutex);
 	mutex_unlock(&fpriv->vm.mutex);
 	return r;
 }
@@ -494,9 +496,7 @@ int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 	struct radeon_cs_parser parser;
 	int r;
 
-	radeon_mutex_lock(&rdev->cs_mutex);
 	if (!rdev->accel_working) {
-		radeon_mutex_unlock(&rdev->cs_mutex);
 		return -EBUSY;
 	}
 	/* initialize parser */
@@ -510,7 +510,6 @@ int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 		DRM_ERROR("Failed to initialize parser !\n");
 		radeon_cs_parser_fini(&parser, r);
 		r = radeon_cs_handle_lockup(rdev, r);
-		radeon_mutex_unlock(&rdev->cs_mutex);
 		return r;
 	}
 	r = radeon_cs_parser_relocs(&parser);
@@ -519,7 +518,6 @@ int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 			DRM_ERROR("Failed to parse relocation %d!\n", r);
 		radeon_cs_parser_fini(&parser, r);
 		r = radeon_cs_handle_lockup(rdev, r);
-		radeon_mutex_unlock(&rdev->cs_mutex);
 		return r;
 	}
 	r = radeon_cs_ib_chunk(rdev, &parser);
@@ -533,7 +531,6 @@ int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 out:
 	radeon_cs_parser_fini(&parser, r);
 	r = radeon_cs_handle_lockup(rdev, r);
-	radeon_mutex_unlock(&rdev->cs_mutex);
 	return r;
 }
 
drivers/gpu/drm/radeon/radeon_device.c +1 -1
index e1bc7e9..7ddab8b 100644
@@ -723,7 +723,6 @@ int radeon_device_init(struct radeon_device *rdev,
 
 	/* mutex initialization are all done here so we
 	 * can recall function without having locking issues */
-	radeon_mutex_init(&rdev->cs_mutex);
 	mutex_init(&rdev->ring_lock);
 	mutex_init(&rdev->dc_hw_i2c_mutex);
 	if (rdev->family >= CHIP_R600)
@@ -735,6 +734,7 @@ int radeon_device_init(struct radeon_device *rdev,
 	init_waitqueue_head(&rdev->irq.vblank_queue);
 	init_waitqueue_head(&rdev->irq.idle_queue);
 	/* initialize vm here */
+	mutex_init(&rdev->vm_mutex);
 	rdev->vm_manager.use_bitmap = 1;
 	rdev->vm_manager.max_pfn = 1 << 20;
 	INIT_LIST_HEAD(&rdev->vm_manager.lru_vm);
drivers/gpu/drm/radeon/radeon_gart.c +8 -8
index 8e9ef34..8076794 100644
@@ -356,13 +356,13 @@ int radeon_vm_manager_suspend(struct radeon_device *rdev)
 {
 	struct radeon_vm *vm, *tmp;
 
-	radeon_mutex_lock(&rdev->cs_mutex);
+	mutex_lock(&rdev->vm_mutex);
 	/* unbind all active vm */
 	list_for_each_entry_safe(vm, tmp, &rdev->vm_manager.lru_vm, list) {
 		radeon_vm_unbind_locked(rdev, vm);
 	}
 	rdev->vm_manager.funcs->fini(rdev);
-	radeon_mutex_unlock(&rdev->cs_mutex);
+	mutex_unlock(&rdev->vm_mutex);
 	return radeon_sa_bo_manager_suspend(rdev, &rdev->vm_manager.sa_manager);
 }
 
@@ -478,9 +478,9 @@ int radeon_vm_bo_add(struct radeon_device *rdev,
 	if (last_pfn > vm->last_pfn) {
 		/* grow va space 32M by 32M */
 		unsigned align = ((32 << 20) >> 12) - 1;
-		radeon_mutex_lock(&rdev->cs_mutex);
+		mutex_lock(&rdev->vm_mutex);
 		radeon_vm_unbind_locked(rdev, vm);
-		radeon_mutex_unlock(&rdev->cs_mutex);
+		mutex_unlock(&rdev->vm_mutex);
 		vm->last_pfn = (last_pfn + align) & ~align;
 	}
 	head = &vm->va;
@@ -596,9 +596,9 @@ int radeon_vm_bo_rmv(struct radeon_device *rdev,
 		return 0;
 
 	mutex_lock(&vm->mutex);
-	radeon_mutex_lock(&rdev->cs_mutex);
+	mutex_lock(&rdev->vm_mutex);
 	radeon_vm_bo_update_pte(rdev, vm, bo, NULL);
-	radeon_mutex_unlock(&rdev->cs_mutex);
+	mutex_unlock(&rdev->vm_mutex);
 	list_del(&bo_va->vm_list);
 	mutex_unlock(&vm->mutex);
 	list_del(&bo_va->bo_list);
@@ -643,9 +643,9 @@ void radeon_vm_fini(struct radeon_device *rdev, struct radeon_vm *vm)
 
 	mutex_lock(&vm->mutex);
 
-	radeon_mutex_lock(&rdev->cs_mutex);
+	mutex_lock(&rdev->vm_mutex);
 	radeon_vm_unbind_locked(rdev, vm);
-	radeon_mutex_unlock(&rdev->cs_mutex);
+	mutex_unlock(&rdev->vm_mutex);
 
 	/* remove all bo */
 	r = radeon_bo_reserve(rdev->ring_tmp_bo.bo, false);
drivers/gpu/drm/radeon/radeon_gem.c +0 -2
index e15cb1f..bc5ad73 100644
@@ -157,11 +157,9 @@ void radeon_gem_object_close(struct drm_gem_object *obj,
 static int radeon_gem_handle_lockup(struct radeon_device *rdev, int r)
 {
 	if (r == -EDEADLK) {
-		radeon_mutex_lock(&rdev->cs_mutex);
 		r = radeon_gpu_reset(rdev);
 		if (!r)
 			r = -EAGAIN;
-		radeon_mutex_unlock(&rdev->cs_mutex);
 	}
 	return r;
 }
Signature · 6 lines
1.7.9.5

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw

PATCH 5/5 drm/radeon: WIP remove vmram_mutex

In reply to Christian König

Even more heretic than the last one. The mutex is probably good for something, I just can't see what that is at the moment.

---
 drivers/gpu/drm/radeon/radeon.h        |    1 -
 drivers/gpu/drm/radeon/radeon_device.c |    1 -
 drivers/gpu/drm/radeon/radeon_object.c |    4 ----
 drivers/gpu/drm/radeon/radeon_pm.c     |    2 --
 drivers/gpu/drm/radeon/radeon_ttm.c    |   26 --------------------------
 5 files changed, 34 deletions(-)
drivers/gpu/drm/radeon/radeon.h +0 -1
index 8769217..c2753e7 100644
@@ -1509,7 +1509,6 @@ struct radeon_device {
 	struct work_struct audio_work;
 	int num_crtc; /* number of crtcs */
 	struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
-	struct mutex vram_mutex;
 	struct r600_audio audio; /* audio stuff */
 	struct notifier_block acpi_nb;
 	/* only one userspace can use Hyperz features or CMASK at a time */
drivers/gpu/drm/radeon/radeon_device.c +0 -1
index 7ddab8b..24e185c 100644
@@ -729,7 +729,6 @@ int radeon_device_init(struct radeon_device *rdev,
 		spin_lock_init(&rdev->ih.lock);
 	mutex_init(&rdev->gem.mutex);
 	mutex_init(&rdev->pm.mutex);
-	mutex_init(&rdev->vram_mutex);
 	INIT_LIST_HEAD(&rdev->gem.objects);
 	init_waitqueue_head(&rdev->irq.vblank_queue);
 	init_waitqueue_head(&rdev->irq.idle_queue);
drivers/gpu/drm/radeon/radeon_object.c +0 -4
index df6a4db..5fa2b1b 100644
@@ -152,11 +152,9 @@ retry:
 	INIT_LIST_HEAD(&bo->va);
 	radeon_ttm_placement_from_domain(bo, domain);
 	/* Kernel allocation are uninterruptible */
-	mutex_lock(&rdev->vram_mutex);
 	r = ttm_bo_init(&rdev->mman.bdev, &bo->tbo, size, type,
 			&bo->placement, page_align, 0, !kernel, NULL,
 			acc_size, &radeon_ttm_bo_destroy);
-	mutex_unlock(&rdev->vram_mutex);
 	if (unlikely(r != 0)) {
 		if (r != -ERESTARTSYS) {
 			if (domain == RADEON_GEM_DOMAIN_VRAM) {
@@ -217,9 +215,7 @@ void radeon_bo_unref(struct radeon_bo **bo)
 		return;
 	rdev = (*bo)->rdev;
 	tbo = &((*bo)->tbo);
-	mutex_lock(&rdev->vram_mutex);
 	ttm_bo_unref(&tbo);
-	mutex_unlock(&rdev->vram_mutex);
 	if (tbo == NULL)
 		*bo = NULL;
 }
drivers/gpu/drm/radeon/radeon_pm.c +0 -2
index 0882554..e8fba26 100644
@@ -251,7 +251,6 @@ static void radeon_pm_set_clocks(struct radeon_device *rdev)
 		return;
 
 	mutex_lock(&rdev->ddev->struct_mutex);
-	mutex_lock(&rdev->vram_mutex);
 	mutex_lock(&rdev->ring_lock);
 
 	/* gui idle int has issues on older chips it seems */
@@ -303,7 +302,6 @@ static void radeon_pm_set_clocks(struct radeon_device *rdev)
 	rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE;
 
 	mutex_unlock(&rdev->ring_lock);
-	mutex_unlock(&rdev->vram_mutex);
 	mutex_unlock(&rdev->ddev->struct_mutex);
 }
 
drivers/gpu/drm/radeon/radeon_ttm.c +0 -26
index a7f9007..c0a8647 100644
@@ -771,26 +771,6 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
 	man->size = size >> PAGE_SHIFT;
 }
 
-static struct vm_operations_struct radeon_ttm_vm_ops;
-static const struct vm_operations_struct *ttm_vm_ops = NULL;
-
-static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
-{
-	struct ttm_buffer_object *bo;
-	struct radeon_device *rdev;
-	int r;
-
-	bo = (struct ttm_buffer_object *)vma->vm_private_data;	
-	if (bo == NULL) {
-		return VM_FAULT_NOPAGE;
-	}
-	rdev = radeon_get_rdev(bo->bdev);
-	mutex_lock(&rdev->vram_mutex);
-	r = ttm_vm_ops->fault(vma, vmf);
-	mutex_unlock(&rdev->vram_mutex);
-	return r;
-}
-
 int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
 {
 	struct drm_file *file_priv;
@@ -810,12 +790,6 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
 	if (unlikely(r != 0)) {
 		return r;
 	}
-	if (unlikely(ttm_vm_ops == NULL)) {
-		ttm_vm_ops = vma->vm_ops;
-		radeon_ttm_vm_ops = *ttm_vm_ops;
-		radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
-	}
-	vma->vm_ops = &radeon_ttm_vm_ops;
 	return 0;
 }
 
Signature · 6 lines
1.7.9.5

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#6 lore raw

Re: [PATCH 5/5] drm/radeon: WIP remove vmram_mutex

Quoted 117 lines · Christian König

Even more heretic than the last one. The mutex is probably good for something, I just can't see what that is at the moment.

---
 drivers/gpu/drm/radeon/radeon.h        |    1 - drivers/gpu/drm/radeon/radeon_device.c |    1 - drivers/gpu/drm/radeon/radeon_object.c |    4 ---- drivers/gpu/drm/radeon/radeon_pm.c     |    2 -- drivers/gpu/drm/radeon/radeon_ttm.c    |   26 --------------------------

 5 files changed, 34 deletions(-)
drivers/gpu/drm/radeon/radeon.h +0 -0
index 8769217..c2753e7 100644
@@ -1509,7 +1509,6 @@ struct radeon_device {
        struct work_struct audio_work;

       int num_crtc; /* number of crtcs */
       struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
-       struct mutex vram_mutex;
       struct r600_audio audio; /* audio stuff */
       struct notifier_block acpi_nb;
       /* only one userspace can use Hyperz features or CMASK at a time */

drivers/gpu/drm/radeon/radeon_device.c +0 -1
index 7ddab8b..24e185c 100644
@@ -729,7 +729,6 @@ int radeon_device_init(struct radeon_device *rdev,
                spin_lock_init(&rdev->ih.lock);
        mutex_init(&rdev->gem.mutex);
        mutex_init(&rdev->pm.mutex);
-       mutex_init(&rdev->vram_mutex);
        INIT_LIST_HEAD(&rdev->gem.objects);
        init_waitqueue_head(&rdev->irq.vblank_queue);
        init_waitqueue_head(&rdev->irq.idle_queue);
drivers/gpu/drm/radeon/radeon_object.c +0 -4
index df6a4db..5fa2b1b 100644
@@ -152,11 +152,9 @@ retry:
        INIT_LIST_HEAD(&bo->va);
        radeon_ttm_placement_from_domain(bo, domain);
        /* Kernel allocation are uninterruptible */
-       mutex_lock(&rdev->vram_mutex);
        r = ttm_bo_init(&rdev->mman.bdev, &bo->tbo, size, type,
                        &bo->placement, page_align, 0, !kernel, NULL,
                        acc_size, &radeon_ttm_bo_destroy);
-       mutex_unlock(&rdev->vram_mutex);
        if (unlikely(r != 0)) {
                if (r != -ERESTARTSYS) {
                        if (domain == RADEON_GEM_DOMAIN_VRAM) {
@@ -217,9 +215,7 @@ void radeon_bo_unref(struct radeon_bo **bo)
                return;
        rdev = (*bo)->rdev;
        tbo = &((*bo)->tbo);
-       mutex_lock(&rdev->vram_mutex);
        ttm_bo_unref(&tbo);
-       mutex_unlock(&rdev->vram_mutex);
        if (tbo == NULL)
                *bo = NULL;
  }
drivers/gpu/drm/radeon/radeon_pm.c +0 -2
index 0882554..e8fba26 100644
@@ -251,7 +251,6 @@ static void radeon_pm_set_clocks(struct radeon_device *rdev)
                return;
 
        mutex_lock(&rdev->ddev->struct_mutex);
-       mutex_lock(&rdev->vram_mutex);
        mutex_lock(&rdev->ring_lock);
 
        /* gui idle int has issues on older chips it seems */
@@ -303,7 +302,6 @@ static void radeon_pm_set_clocks(struct radeon_device *rdev)
        rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE;
 
        mutex_unlock(&rdev->ring_lock);
-       mutex_unlock(&rdev->vram_mutex);
        mutex_unlock(&rdev->ddev->struct_mutex);
  }
 
drivers/gpu/drm/radeon/radeon_ttm.c +0 -20
index a7f9007..c0a8647 100644
@@ -771,26 +771,6 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
        man->size = size >> PAGE_SHIFT;
  }
 
-static struct vm_operations_struct radeon_ttm_vm_ops;
-static const struct vm_operations_struct *ttm_vm_ops = NULL;
-
-static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
-{
-       struct ttm_buffer_object *bo;
-       struct radeon_device *rdev;
-       int r;
-
-       bo = (struct ttm_buffer_object *)vma->vm_private_data;
-       if (bo == NULL) {
-               return VM_FAULT_NOPAGE;
-       }
-       rdev = radeon_get_rdev(bo->bdev);
-       mutex_lock(&rdev->vram_mutex);
-       r = ttm_vm_ops->fault(vma, vmf);
-       mutex_unlock(&rdev->vram_mutex);
-       return r;
-}
-
  int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
  {
        struct drm_file *file_priv;
@@ -810,12 +790,6 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
        if (unlikely(r != 0)) {
                return r;

drivers/gpu/drm/radeon/radeon_ttm.c int radeon_mmap(struct file *filp, struct vm_area_struct *vma) · line 795

Quoted 10 lines
drivers/gpu/drm/radeon/radeon_ttm.c +0 -6
        }
-       if (unlikely(ttm_vm_ops == NULL)) {
-               ttm_vm_ops = vma->vm_ops;
-               radeon_ttm_vm_ops = *ttm_vm_ops;
-               radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
-       }
-       vma->vm_ops = &radeon_ttm_vm_ops;
        return 0;
  }
 

Why are you removing the ttm fault stuff ? And does the driver keep working without this ? I would be surprise.

Cheers,
Jerome

#7 lore raw

Re: [PATCH 5/5] drm/radeon: WIP remove vmram_mutex

Quoted 133 lines · Jerome Glisse
Quoted 117 lines · Christian König

Even more heretic than the last one. The mutex is probably good for something, I just can't see what that is at the moment.

---
 drivers/gpu/drm/radeon/radeon.h        |    1 - drivers/gpu/drm/radeon/radeon_device.c |    1 - drivers/gpu/drm/radeon/radeon_object.c |    4 ---- drivers/gpu/drm/radeon/radeon_pm.c     |    2 -- drivers/gpu/drm/radeon/radeon_ttm.c    |   26 --------------------------

 5 files changed, 34 deletions(-)
drivers/gpu/drm/radeon/radeon.h +0 -0
index 8769217..c2753e7 100644
@@ -1509,7 +1509,6 @@ struct radeon_device {
        struct work_struct audio_work;

       int num_crtc; /* number of crtcs */
       struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
-       struct mutex vram_mutex;
       struct r600_audio audio; /* audio stuff */
       struct notifier_block acpi_nb;
       /* only one userspace can use Hyperz features or CMASK at a time */

drivers/gpu/drm/radeon/radeon_device.c +0 -1
index 7ddab8b..24e185c 100644
@@ -729,7 +729,6 @@ int radeon_device_init(struct radeon_device *rdev,
                spin_lock_init(&rdev->ih.lock);
        mutex_init(&rdev->gem.mutex);
        mutex_init(&rdev->pm.mutex);
-       mutex_init(&rdev->vram_mutex);
        INIT_LIST_HEAD(&rdev->gem.objects);
        init_waitqueue_head(&rdev->irq.vblank_queue);
        init_waitqueue_head(&rdev->irq.idle_queue);
drivers/gpu/drm/radeon/radeon_object.c +0 -4
index df6a4db..5fa2b1b 100644
@@ -152,11 +152,9 @@ retry:
        INIT_LIST_HEAD(&bo->va);
        radeon_ttm_placement_from_domain(bo, domain);
        /* Kernel allocation are uninterruptible */
-       mutex_lock(&rdev->vram_mutex);
        r = ttm_bo_init(&rdev->mman.bdev, &bo->tbo, size, type,
                        &bo->placement, page_align, 0, !kernel, NULL,
                        acc_size, &radeon_ttm_bo_destroy);
-       mutex_unlock(&rdev->vram_mutex);
        if (unlikely(r != 0)) {
                if (r != -ERESTARTSYS) {
                        if (domain == RADEON_GEM_DOMAIN_VRAM) {
@@ -217,9 +215,7 @@ void radeon_bo_unref(struct radeon_bo **bo)
                return;
        rdev = (*bo)->rdev;
        tbo = &((*bo)->tbo);
-       mutex_lock(&rdev->vram_mutex);
        ttm_bo_unref(&tbo);
-       mutex_unlock(&rdev->vram_mutex);
        if (tbo == NULL)
                *bo = NULL;
  }
drivers/gpu/drm/radeon/radeon_pm.c +0 -2
index 0882554..e8fba26 100644
@@ -251,7 +251,6 @@ static void radeon_pm_set_clocks(struct radeon_device *rdev)
                return;
 
        mutex_lock(&rdev->ddev->struct_mutex);
-       mutex_lock(&rdev->vram_mutex);
        mutex_lock(&rdev->ring_lock);
 
        /* gui idle int has issues on older chips it seems */
@@ -303,7 +302,6 @@ static void radeon_pm_set_clocks(struct radeon_device *rdev)
        rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE;
 
        mutex_unlock(&rdev->ring_lock);
-       mutex_unlock(&rdev->vram_mutex);
        mutex_unlock(&rdev->ddev->struct_mutex);
  }
 
drivers/gpu/drm/radeon/radeon_ttm.c +0 -20
index a7f9007..c0a8647 100644
@@ -771,26 +771,6 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
        man->size = size >> PAGE_SHIFT;
  }
 
-static struct vm_operations_struct radeon_ttm_vm_ops;
-static const struct vm_operations_struct *ttm_vm_ops = NULL;
-
-static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
-{
-       struct ttm_buffer_object *bo;
-       struct radeon_device *rdev;
-       int r;
-
-       bo = (struct ttm_buffer_object *)vma->vm_private_data;
-       if (bo == NULL) {
-               return VM_FAULT_NOPAGE;
-       }
-       rdev = radeon_get_rdev(bo->bdev);
-       mutex_lock(&rdev->vram_mutex);
-       r = ttm_vm_ops->fault(vma, vmf);
-       mutex_unlock(&rdev->vram_mutex);
-       return r;
-}
-
  int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
  {
        struct drm_file *file_priv;
@@ -810,12 +790,6 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
        if (unlikely(r != 0)) {
                return r;

drivers/gpu/drm/radeon/radeon_ttm.c int radeon_mmap(struct file *filp, struct vm_area_struct *vma) · line 795

Quoted 10 lines
drivers/gpu/drm/radeon/radeon_ttm.c +0 -6
        }
-       if (unlikely(ttm_vm_ops == NULL)) {
-               ttm_vm_ops = vma->vm_ops;
-               radeon_ttm_vm_ops = *ttm_vm_ops;
-               radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
-       }
-       vma->vm_ops = &radeon_ttm_vm_ops;
        return 0;
  }
 

Why are you removing the ttm fault stuff ? And does the driver keep working without this ? I would be surprise.

Quoted 2 lines

Cheers,
Jerome

Oh i forgot ttm already fill the vma with its own callback.

Cheers,
Jerome

#8 lore raw

Re: [PATCH 5/5] drm/radeon: WIP remove vmram_mutex

Quoted 133 lines · Jerome Glisse
Quoted 132 lines · Jerome Glisse
Quoted 117 lines · Christian König

Even more heretic than the last one. The mutex is probably good for something, I just can't see what that is at the moment.

---
  drivers/gpu/drm/radeon/radeon.h        |    1 -
  drivers/gpu/drm/radeon/radeon_device.c |    1 -
  drivers/gpu/drm/radeon/radeon_object.c |    4 ----
  drivers/gpu/drm/radeon/radeon_pm.c     |    2 --
  drivers/gpu/drm/radeon/radeon_ttm.c    |   26 --------------------------
  5 files changed, 34 deletions(-)
drivers/gpu/drm/radeon/radeon.h +0 -1
index 8769217..c2753e7 100644
@@ -1509,7 +1509,6 @@ struct radeon_device {
        struct work_struct audio_work;
        int num_crtc; /* number of crtcs */
        struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
-       struct mutex vram_mutex;
        struct r600_audio audio; /* audio stuff */
        struct notifier_block acpi_nb;
        /* only one userspace can use Hyperz features or CMASK at a time */
drivers/gpu/drm/radeon/radeon_device.c +0 -1
index 7ddab8b..24e185c 100644
@@ -729,7 +729,6 @@ int radeon_device_init(struct radeon_device *rdev,
                spin_lock_init(&rdev->ih.lock);
        mutex_init(&rdev->gem.mutex);
        mutex_init(&rdev->pm.mutex);
-       mutex_init(&rdev->vram_mutex);
        INIT_LIST_HEAD(&rdev->gem.objects);
        init_waitqueue_head(&rdev->irq.vblank_queue);
        init_waitqueue_head(&rdev->irq.idle_queue);
drivers/gpu/drm/radeon/radeon_object.c +0 -4
index df6a4db..5fa2b1b 100644
@@ -152,11 +152,9 @@ retry:
        INIT_LIST_HEAD(&bo->va);
        radeon_ttm_placement_from_domain(bo, domain);
        /* Kernel allocation are uninterruptible */
-       mutex_lock(&rdev->vram_mutex);
        r = ttm_bo_init(&rdev->mman.bdev,&bo->tbo, size, type,
                        &bo->placement, page_align, 0, !kernel, NULL,
                        acc_size,&radeon_ttm_bo_destroy);
-       mutex_unlock(&rdev->vram_mutex);
        if (unlikely(r != 0)) {
                if (r != -ERESTARTSYS) {
                        if (domain == RADEON_GEM_DOMAIN_VRAM) {
@@ -217,9 +215,7 @@ void radeon_bo_unref(struct radeon_bo **bo)
                return;
        rdev = (*bo)->rdev;
        tbo =&((*bo)->tbo);
-       mutex_lock(&rdev->vram_mutex);
        ttm_bo_unref(&tbo);
-       mutex_unlock(&rdev->vram_mutex);
        if (tbo == NULL)
                *bo = NULL;
  }
drivers/gpu/drm/radeon/radeon_pm.c +0 -2
index 0882554..e8fba26 100644
@@ -251,7 +251,6 @@ static void radeon_pm_set_clocks(struct radeon_device *rdev)
                return;
 
        mutex_lock(&rdev->ddev->struct_mutex);
-       mutex_lock(&rdev->vram_mutex);
        mutex_lock(&rdev->ring_lock);
 
        /* gui idle int has issues on older chips it seems */
@@ -303,7 +302,6 @@ static void radeon_pm_set_clocks(struct radeon_device *rdev)
        rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE;
 
        mutex_unlock(&rdev->ring_lock);
-       mutex_unlock(&rdev->vram_mutex);
        mutex_unlock(&rdev->ddev->struct_mutex);
  }
 
drivers/gpu/drm/radeon/radeon_ttm.c +0 -20
index a7f9007..c0a8647 100644
@@ -771,26 +771,6 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
        man->size = size>>  PAGE_SHIFT;
  }
 
-static struct vm_operations_struct radeon_ttm_vm_ops;
-static const struct vm_operations_struct *ttm_vm_ops = NULL;
-
-static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
-{
-       struct ttm_buffer_object *bo;
-       struct radeon_device *rdev;
-       int r;
-
-       bo = (struct ttm_buffer_object *)vma->vm_private_data;
-       if (bo == NULL) {
-               return VM_FAULT_NOPAGE;
-       }
-       rdev = radeon_get_rdev(bo->bdev);
-       mutex_lock(&rdev->vram_mutex);
-       r = ttm_vm_ops->fault(vma, vmf);
-       mutex_unlock(&rdev->vram_mutex);
-       return r;
-}
-
  int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
  {
        struct drm_file *file_priv;
@@ -810,12 +790,6 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
        if (unlikely(r != 0)) {
                return r;

drivers/gpu/drm/radeon/radeon_ttm.c int radeon_mmap(struct file *filp, struct vm_area_struct *vma) · line 795

Quoted 10 lines
drivers/gpu/drm/radeon/radeon_ttm.c +0 -6
        }
-       if (unlikely(ttm_vm_ops == NULL)) {
-               ttm_vm_ops = vma->vm_ops;
-               radeon_ttm_vm_ops = *ttm_vm_ops;
-               radeon_ttm_vm_ops.fault =&radeon_ttm_fault;
-       }
-       vma->vm_ops =&radeon_ttm_vm_ops;
        return 0;
  }
 

Why are you removing the ttm fault stuff ? And does the driver keep working without this ? I would be surprise.

Quoted 7 lines
Quoted 2 lines

Cheers,
Jerome

Oh i forgot ttm already fill the vma with its own callback.

Cheers,
Jerome

Removed it to just figure out why it is there in the first place, Dave already explained it as a protection for accessing VRAM while we change the memory clock. Currently just trying to look into all the parts of the driver I still doesn't understand completely.

Anyway, I would suggest to change it to a rw_semaphore and read lock it in most cases, and just write lock it while changing the memory clock, see the attached patch for this.

Cheers,
Christian.

Quoted 1 line

From 2f8068d07e8dec198b61f096f5300a477a67a5b1 Mon Sep 17 00:00:00 2001

From: =?UTF-8?q?Christian=20K=C3=B6nig?= <[email protected]>
Date: Fri, 11 May 2012 14:57:18 +0200
Subject: [PATCH 1/2] drm/radeon: replace vmram_mutex with mclk_lock
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

It is a rw_semaphore now and only write locked while changing the clock. Also the lock is renamed to better reflect what it is protecting.

---
 drivers/gpu/drm/radeon/radeon.h        |    3 ++-
 drivers/gpu/drm/radeon/radeon_device.c |    2 +-
 drivers/gpu/drm/radeon/radeon_object.c |    8 ++++----
 drivers/gpu/drm/radeon/radeon_pm.c     |    4 ++--
 drivers/gpu/drm/radeon/radeon_ttm.c    |    6 +++---
 5 files changed, 12 insertions(+), 11 deletions(-)
drivers/gpu/drm/radeon/radeon.h +2 -1
index e00c50d..2417327 100644
@@ -1055,6 +1055,8 @@ struct radeon_power_state {
 
 struct radeon_pm {
 	struct mutex		mutex;
+	/* write locked while reprogramming mclk */
+	struct rw_semaphore	mclk_lock;
 	u32			active_crtcs;
 	int			active_crtc_count;
 	int			req_vblank;
@@ -1552,7 +1554,6 @@ struct radeon_device {
 	struct work_struct audio_work;
 	int num_crtc; /* number of crtcs */
 	struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
-	struct mutex vram_mutex;
 	struct r600_audio audio; /* audio stuff */
 	struct notifier_block acpi_nb;
 	/* only one userspace can use Hyperz features or CMASK at a time */
drivers/gpu/drm/radeon/radeon_device.c +1 -1
index e1bc7e9..c74f770 100644
@@ -730,7 +730,7 @@ int radeon_device_init(struct radeon_device *rdev,
 		spin_lock_init(&rdev->ih.lock);
 	mutex_init(&rdev->gem.mutex);
 	mutex_init(&rdev->pm.mutex);
-	mutex_init(&rdev->vram_mutex);
+	init_rwsem(&rdev->pm.mclk_lock);
 	INIT_LIST_HEAD(&rdev->gem.objects);
 	init_waitqueue_head(&rdev->irq.vblank_queue);
 	init_waitqueue_head(&rdev->irq.idle_queue);
drivers/gpu/drm/radeon/radeon_object.c +4 -4
index df6a4db..bc814e7 100644
@@ -152,11 +152,11 @@ retry:
 	INIT_LIST_HEAD(&bo->va);
 	radeon_ttm_placement_from_domain(bo, domain);
 	/* Kernel allocation are uninterruptible */
-	mutex_lock(&rdev->vram_mutex);
+	down_read(&rdev->pm.mclk_lock);
 	r = ttm_bo_init(&rdev->mman.bdev, &bo->tbo, size, type,
 			&bo->placement, page_align, 0, !kernel, NULL,
 			acc_size, &radeon_ttm_bo_destroy);
-	mutex_unlock(&rdev->vram_mutex);
+	up_read(&rdev->pm.mclk_lock);
 	if (unlikely(r != 0)) {
 		if (r != -ERESTARTSYS) {
 			if (domain == RADEON_GEM_DOMAIN_VRAM) {
@@ -217,9 +217,9 @@ void radeon_bo_unref(struct radeon_bo **bo)
 		return;
 	rdev = (*bo)->rdev;
 	tbo = &((*bo)->tbo);
-	mutex_lock(&rdev->vram_mutex);
+	down_read(&rdev->pm.mclk_lock);
 	ttm_bo_unref(&tbo);
-	mutex_unlock(&rdev->vram_mutex);
+	up_read(&rdev->pm.mclk_lock);
 	if (tbo == NULL)
 		*bo = NULL;
 }
drivers/gpu/drm/radeon/radeon_pm.c +2 -2
index 0882554..d13b6ae 100644
@@ -251,7 +251,7 @@ static void radeon_pm_set_clocks(struct radeon_device *rdev)
 		return;
 
 	mutex_lock(&rdev->ddev->struct_mutex);
-	mutex_lock(&rdev->vram_mutex);
+	down_write(&rdev->pm.mclk_lock);
 	mutex_lock(&rdev->ring_lock);
 
 	/* gui idle int has issues on older chips it seems */
@@ -303,7 +303,7 @@ static void radeon_pm_set_clocks(struct radeon_device *rdev)
 	rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE;
 
 	mutex_unlock(&rdev->ring_lock);
-	mutex_unlock(&rdev->vram_mutex);
+	up_write(&rdev->pm.mclk_lock);
 	mutex_unlock(&rdev->ddev->struct_mutex);
 }
 
drivers/gpu/drm/radeon/radeon_ttm.c +3 -3
index a7f9007..fc05ae3 100644
@@ -785,9 +785,9 @@ static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 		return VM_FAULT_NOPAGE;
 	}
 	rdev = radeon_get_rdev(bo->bdev);
-	mutex_lock(&rdev->vram_mutex);
+	down_read(&rdev->pm.mclk_lock);
 	r = ttm_vm_ops->fault(vma, vmf);
-	mutex_unlock(&rdev->vram_mutex);
+	up_read(&rdev->pm.mclk_lock);
 	return r;
 }
 
@@ -810,7 +810,7 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
 	if (unlikely(r != 0)) {
 		return r;
 	}
-	if (unlikely(ttm_vm_ops == NULL)) {
+	if (unlikely(ttm_vm_ops == NULL && !(rdev->flags & RADEON_IS_IGP))) {
 		ttm_vm_ops = vma->vm_ops;
 		radeon_ttm_vm_ops = *ttm_vm_ops;
 		radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
Signature · 1 line
1.7.9.5

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer
#9 lore raw
In reply to Christian König
Quoted 27 lines · Christian König

Hi everybody,

well the following patches remove the cs and vram mutex from the radeon driver and so are something very experimental. The first three just move what I know to be still critical into the protection of the ring mutex, and the other two actually remove the mutexs.

Interestingly it still survives a couple of hours running the following script:

while true
do
       for (( x = 10, y = 45, i = 0; $i < 144; i = $i + 1 )) do
               glxgears -geometry 100x100+$x+$y > /dev/null 2>&1 & x=$(expr $x + 120)
               if [ $x -gt 1920 ]
               then
                       x=10
                       y=$(expr $y + 110)
               fi
       done

       sleep 30

       killall glxgears
done

Quoted 7 lines

So the mutexes doesn't seem to protected something so critical and I'm wondering why we still have them so widely locked.

Cheers,
Christian.

PS: I'm away for the next week or so don't expect any response soon.

The vram mutex is to block access to the VRAM during reclocking.

So if you reclocks a lot while running stuff you might notice.

Dave.

#10 lore raw
Quoted 32 lines · Dave Airlie
Quoted 30 lines · Christian König

Hi everybody,

well the following patches remove the cs and vram mutex from the radeon driver and so are something very experimental. The first three just move what I know to be still critical into the protection of the ring mutex, and the other two actually remove the mutexs.

Interestingly it still survives a couple of hours running the following script:

while true
do

        for (( x = 10, y = 45, i = 0; $i<  144; i = $i + 1 ))
        do
                glxgears -geometry 100x100+$x+$y>  /dev/null 2>&1&
                x=$(expr $x + 120)
                if [ $x -gt 1920 ]
                then
                        x=10
                        y=$(expr $y + 110)
                fi
        done

        sleep 30

        killall glxgears

done

So the mutexes doesn't seem to protected something so critical and I'm wondering why we still have them so widely locked.

Quoted 7 lines
Quoted 4 lines

Cheers,
Christian.

PS: I'm away for the next week or so don't expect any response soon.

The vram mutex is to block access to the VRAM during reclocking.

So if you reclocks a lot while running stuff you might notice.

Ah, thx for that info it suddenly starts to make sense. Also not using an APU for testing might also help triggering the problem, but in turn that means we can avoid taking that lock on APUs.

Cheers,
Christian.

#11 lore raw
Quoted 49 lines · Christian König
Quoted 38 lines · Dave Airlie
Quoted 35 lines · Christian König

Hi everybody,

well the following patches remove the cs and vram mutex from the radeon driver
and so are something very experimental. The first three just move what I know
to be still critical into the protection of the ring mutex, and the other two
actually remove the mutexs.

Interestingly it still survives a couple of hours running the following script:

while true
do
       for (( x = 10, y = 45, i = 0; $i<  144; i = $i + 1 )) do
               glxgears -geometry 100x100+$x+$y>  /dev/null 2>&1& x=$(expr $x + 120)
               if [ $x -gt 1920 ]
               then
                       x=10
                       y=$(expr $y + 110)
               fi
       done

       sleep 30

       killall glxgears
done

So the mutexes doesn't seem to protected something so critical and I'm wondering why we still have them so widely locked.

Quoted 8 lines
Quoted 4 lines

Cheers,
Christian.

PS: I'm away for the next week or so don't expect any response soon.

The vram mutex is to block access to the VRAM during reclocking.

So if you reclocks a lot while running stuff you might notice.

Quoted 7 lines

Ah, thx for that info it suddenly starts to make sense. Also not using an APU for testing might also help triggering the problem, but in turn that means we can avoid taking that lock on APUs.

Cheers,
Christian.

The first 3 looks good, i need to test and read more carefully the cs -> vm mutex one but it looks good too.

Cheers,
Jerome