Skip to contentSkip to conversation

Reworking of GPU reset logic

PATCH In review Christian König 6 participants 35 messages Apr 19, 2012 – Apr 25, 2012

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

This includes mostly fixes for multi ring lockups and GPU resets, but it should general improve the behavior of the kernel mode driver in case something goes badly wrong.

On the other hand it completely rewrites the IB pool and semaphore handling, so I think there are still a couple of problems in it.

The first four patches were already send to the list, but the current set depends on them so I resend them again.

Cheers,
Christian.

#1 lore raw

PATCH 1/13 drm/radeon: make radeon_gpu_is_lockup a per ring function

Different rings have different criteria to test
if they are stuck.

v2: rebased on current drm-next

---
 drivers/gpu/drm/radeon/radeon.h       |    4 +-
 drivers/gpu/drm/radeon/radeon_asic.c  |   44 ++++++++++++++++++--------------
 drivers/gpu/drm/radeon/radeon_fence.c |    2 +-
 3 files changed, 28 insertions(+), 22 deletions(-)
drivers/gpu/drm/radeon/radeon.h +2 -2
index 138b952..bea99e3 100644
@@ -1144,7 +1144,6 @@ struct radeon_asic {
 	int (*resume)(struct radeon_device *rdev);
 	int (*suspend)(struct radeon_device *rdev);
 	void (*vga_set_state)(struct radeon_device *rdev, bool state);
-	bool (*gpu_is_lockup)(struct radeon_device *rdev, struct radeon_ring *cp);
 	int (*asic_reset)(struct radeon_device *rdev);
 	/* ioctl hw specific callback. Some hw might want to perform special
 	 * operation on specific ioctl. For instance on wait idle some hw
@@ -1173,6 +1172,7 @@ struct radeon_asic {
 		void (*ring_start)(struct radeon_device *rdev, struct radeon_ring *cp);
 		int (*ring_test)(struct radeon_device *rdev, struct radeon_ring *cp);
 		int (*ib_test)(struct radeon_device *rdev, struct radeon_ring *cp);
+		bool (*is_lockup)(struct radeon_device *rdev, struct radeon_ring *cp);
 	} ring[RADEON_NUM_RINGS];
 	/* irqs */
 	struct {
@@ -1730,7 +1730,6 @@ void radeon_ring_write(struct radeon_ring *ring, uint32_t v);
 #define radeon_suspend(rdev) (rdev)->asic->suspend((rdev))
 #define radeon_cs_parse(rdev, r, p) (rdev)->asic->ring[(r)].cs_parse((p))
 #define radeon_vga_set_state(rdev, state) (rdev)->asic->vga_set_state((rdev), (state))
-#define radeon_gpu_is_lockup(rdev, cp) (rdev)->asic->gpu_is_lockup((rdev), (cp))
 #define radeon_asic_reset(rdev) (rdev)->asic->asic_reset((rdev))
 #define radeon_gart_tlb_flush(rdev) (rdev)->asic->gart.tlb_flush((rdev))
 #define radeon_gart_set_page(rdev, i, p) (rdev)->asic->gart.set_page((rdev), (i), (p))
@@ -1739,6 +1738,7 @@ void radeon_ring_write(struct radeon_ring *ring, uint32_t v);
 #define radeon_ib_test(rdev, r, cp) (rdev)->asic->ring[(r)].ib_test((rdev), (cp))
 #define radeon_ring_ib_execute(rdev, r, ib) (rdev)->asic->ring[(r)].ib_execute((rdev), (ib))
 #define radeon_ring_ib_parse(rdev, r, ib) (rdev)->asic->ring[(r)].ib_parse((rdev), (ib))
+#define radeon_ring_is_lockup(rdev, r, cp) (rdev)->asic->ring[(r)].is_lockup((rdev), (cp))
 #define radeon_irq_set(rdev) (rdev)->asic->irq.set((rdev))
 #define radeon_irq_process(rdev) (rdev)->asic->irq.process((rdev))
 #define radeon_get_vblank_counter(rdev, crtc) (rdev)->asic->display.get_vblank_counter((rdev), (crtc))
drivers/gpu/drm/radeon/radeon_asic.c +25 -19

308 lines not on this page · raw message

drivers/gpu/drm/radeon/radeon_fence.c +1 -1
index 4bd36a3..66b2229 100644
@@ -259,7 +259,7 @@ retry:
 		 * if we experiencing a lockup the value doesn't change
 		 */
 		if (seq == rdev->fence_drv[fence->ring].last_seq &&
-		    radeon_gpu_is_lockup(rdev, &rdev->ring[fence->ring])) {
+		    radeon_ring_is_lockup(rdev, fence->ring, &rdev->ring[fence->ring])) {
 			/* good news we believe it's a lockup */
 			printk(KERN_WARNING "GPU lockup (waiting for 0x%08X last fence id 0x%08X)\n",
 			     fence->seq, seq);
Signature · 6 lines
1.7.5.4

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

PATCH 2/13 drm/radeon: replace gpu_lockup with ring->ready flag

In reply to Christian König

It makes no sense at all to have more than one flag.

---
 drivers/gpu/drm/radeon/r100.c          |    1 -
 drivers/gpu/drm/radeon/r300.c          |    1 -
 drivers/gpu/drm/radeon/radeon.h        |    1 -
 drivers/gpu/drm/radeon/radeon_device.c |    1 -
 drivers/gpu/drm/radeon/radeon_fence.c  |   36 +++++++++++--------------------
 drivers/gpu/drm/radeon/rs600.c         |    1 -
 6 files changed, 13 insertions(+), 28 deletions(-)
drivers/gpu/drm/radeon/r100.c +0 -1
index e11df77..4b677fc 100644
@@ -2300,7 +2300,6 @@ int r100_asic_reset(struct radeon_device *rdev)
 	if (G_000E40_SE_BUSY(status) || G_000E40_RE_BUSY(status) ||
 		G_000E40_TAM_BUSY(status) || G_000E40_PB_BUSY(status)) {
 		dev_err(rdev->dev, "failed to reset GPU\n");
-		rdev->gpu_lockup = true;
 		ret = -1;
 	} else
 		dev_info(rdev->dev, "GPU reset succeed\n");
drivers/gpu/drm/radeon/r300.c +0 -1
index fa14383..a63f432 100644
@@ -449,7 +449,6 @@ int r300_asic_reset(struct radeon_device *rdev)
 	/* Check if GPU is idle */
 	if (G_000E40_GA_BUSY(status) || G_000E40_VAP_BUSY(status)) {
 		dev_err(rdev->dev, "failed to reset GPU\n");
-		rdev->gpu_lockup = true;
 		ret = -1;
 	} else
 		dev_info(rdev->dev, "GPU reset succeed\n");
drivers/gpu/drm/radeon/radeon.h +0 -1
index bea99e3..365334b 100644
@@ -1529,7 +1529,6 @@ struct radeon_device {
 	struct radeon_mutex		cs_mutex;
 	struct radeon_wb		wb;
 	struct radeon_dummy_page	dummy_page;
-	bool				gpu_lockup;
 	bool				shutdown;
 	bool				suspend;
 	bool				need_dma32;
drivers/gpu/drm/radeon/radeon_device.c +0 -1
index 0fb4f89..dedb398 100644
@@ -714,7 +714,6 @@ int radeon_device_init(struct radeon_device *rdev,
 	rdev->is_atom_bios = false;
 	rdev->usec_timeout = RADEON_MAX_USEC_TIMEOUT;
 	rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024;
-	rdev->gpu_lockup = false;
 	rdev->accel_working = false;
 
 	DRM_INFO("initializing kernel modesetting (%s 0x%04X:0x%04X 0x%04X:0x%04X).\n",
drivers/gpu/drm/radeon/radeon_fence.c +13 -23
index 66b2229..36c411f 100644
@@ -71,14 +71,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
 		return 0;
 	}
 	fence->seq = atomic_add_return(1, &rdev->fence_drv[fence->ring].seq);
-	if (!rdev->ring[fence->ring].ready)
-		/* FIXME: cp is not running assume everythings is done right
-		 * away
-		 */
-		radeon_fence_write(rdev, fence->seq, fence->ring);
-	else
-		radeon_fence_ring_emit(rdev, fence->ring, fence);
-
+	radeon_fence_ring_emit(rdev, fence->ring, fence);
 	trace_radeon_fence_emit(rdev->ddev, fence->seq);
 	fence->emitted = true;
 	list_move_tail(&fence->list, &rdev->fence_drv[fence->ring].emitted);
@@ -191,9 +184,6 @@ bool radeon_fence_signaled(struct radeon_fence *fence)
 	if (!fence)
 		return true;
 
-	if (fence->rdev->gpu_lockup)
-		return true;
-
 	write_lock_irqsave(&fence->rdev->fence_lock, irq_flags);
 	signaled = fence->signaled;
 	/* if we are shuting down report all fence as signaled */
@@ -260,18 +250,16 @@ retry:
 		 */
 		if (seq == rdev->fence_drv[fence->ring].last_seq &&
 		    radeon_ring_is_lockup(rdev, fence->ring, &rdev->ring[fence->ring])) {
+
 			/* good news we believe it's a lockup */
 			printk(KERN_WARNING "GPU lockup (waiting for 0x%08X last fence id 0x%08X)\n",
 			     fence->seq, seq);
-			/* FIXME: what should we do ? marking everyone
-			 * as signaled for now
-			 */
-			rdev->gpu_lockup = true;
+
+			/* mark the ring as not ready any more */
+			rdev->ring[fence->ring].ready = false;
 			r = radeon_gpu_reset(rdev);
 			if (r)
 				return r;
-			radeon_fence_write(rdev, fence->seq, fence->ring);
-			rdev->gpu_lockup = false;
 		}
 		timeout = RADEON_FENCE_JIFFIES_TIMEOUT;
 		write_lock_irqsave(&rdev->fence_lock, irq_flags);
@@ -289,10 +277,11 @@ int radeon_fence_wait_next(struct radeon_device *rdev, int ring)
 	struct radeon_fence *fence;
 	int r;
 
-	if (rdev->gpu_lockup) {
-		return 0;
-	}
 	write_lock_irqsave(&rdev->fence_lock, irq_flags);
+	if (!rdev->ring[ring].ready) {
+		write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
+		return -EBUSY;
+	}
 	if (list_empty(&rdev->fence_drv[ring].emitted)) {
 		write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
 		return 0;
@@ -312,10 +301,11 @@ int radeon_fence_wait_last(struct radeon_device *rdev, int ring)
 	struct radeon_fence *fence;
 	int r;
 
-	if (rdev->gpu_lockup) {
-		return 0;
-	}
 	write_lock_irqsave(&rdev->fence_lock, irq_flags);
+	if (!rdev->ring[ring].ready) {
+		write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
+		return -EBUSY;
+	}
 	if (list_empty(&rdev->fence_drv[ring].emitted)) {
 		write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
 		return 0;
drivers/gpu/drm/radeon/rs600.c +0 -1
index d25cf86..f709fe8 100644
@@ -396,7 +396,6 @@ int rs600_asic_reset(struct radeon_device *rdev)
 	/* Check if GPU is idle */
 	if (G_000E40_GA_BUSY(status) || G_000E40_VAP_BUSY(status)) {
 		dev_err(rdev->dev, "failed to reset GPU\n");
-		rdev->gpu_lockup = true;
 		ret = -1;
 	} else
 		dev_info(rdev->dev, "GPU reset succeed\n");
Signature · 6 lines
1.7.5.4

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

PATCH 3/13 drm/radeon: register ring debugfs handlers on init

In reply to Christian König

Just register the debugfs files on init instead of checking the chipset type multiple times.

---
 drivers/gpu/drm/radeon/radeon_ring.c |   31 +++++++++++++++++++------------
 1 files changed, 19 insertions(+), 12 deletions(-)
drivers/gpu/drm/radeon/radeon_ring.c +19 -12
index cc33b3d..b6eb1d2 100644
@@ -34,7 +34,7 @@
 #include "atom.h"
 
 int radeon_debugfs_ib_init(struct radeon_device *rdev);
-int radeon_debugfs_ring_init(struct radeon_device *rdev);
+int radeon_debugfs_ring_init(struct radeon_device *rdev, struct radeon_ring *ring);
 
 u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx)
 {
@@ -237,9 +237,6 @@ int radeon_ib_pool_init(struct radeon_device *rdev)
 	if (radeon_debugfs_ib_init(rdev)) {
 		DRM_ERROR("Failed to register debugfs file for IB !\n");
 	}
-	if (radeon_debugfs_ring_init(rdev)) {
-		DRM_ERROR("Failed to register debugfs file for rings !\n");
-	}
 	radeon_mutex_unlock(&rdev->ib_pool.mutex);
 	return 0;
 }
@@ -411,6 +408,9 @@ int radeon_ring_init(struct radeon_device *rdev, struct radeon_ring *ring, unsig
 	}
 	ring->ptr_mask = (ring->ring_size / 4) - 1;
 	ring->ring_free_dw = ring->ring_size / 4;
+	if (radeon_debugfs_ring_init(rdev, ring)) {
+		DRM_ERROR("Failed to register debugfs file for rings !\n");
+	}
 	return 0;
 }
 
@@ -501,17 +501,24 @@ static char radeon_debugfs_ib_names[RADEON_IB_POOL_SIZE][32];
 static unsigned radeon_debugfs_ib_idx[RADEON_IB_POOL_SIZE];
 #endif
 
-int radeon_debugfs_ring_init(struct radeon_device *rdev)
+int radeon_debugfs_ring_init(struct radeon_device *rdev, struct radeon_ring *ring)
 {
 #if defined(CONFIG_DEBUG_FS)
-	if (rdev->family >= CHIP_CAYMAN)
-		return radeon_debugfs_add_files(rdev, radeon_debugfs_ring_info_list,
-						ARRAY_SIZE(radeon_debugfs_ring_info_list));
-	else
-		return radeon_debugfs_add_files(rdev, radeon_debugfs_ring_info_list, 1);
-#else
-	return 0;
+	unsigned i;
+	for (i = 0; i < ARRAY_SIZE(radeon_debugfs_ring_info_list); ++i) {
+		struct drm_info_list *info = &radeon_debugfs_ring_info_list[i];
+		int ridx = *(int*)radeon_debugfs_ring_info_list[i].data;
+		unsigned r;
+
+		if (&rdev->ring[ridx] != ring)
+			continue;
+
+		r = radeon_debugfs_add_files(rdev, info, 1);
+		if (r)
+			return r;
+	}
 #endif
+	return 0;
 }
 
 int radeon_debugfs_ib_init(struct radeon_device *rdev)
Signature · 6 lines
1.7.5.4

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

PATCH 4/13 drm/radeon: use central function for IB testing

In reply to Christian König

Removing all the different error messages and
having just one standard behaviour over all
chipset generations.

---
 drivers/gpu/drm/radeon/evergreen.c   |    7 ++-----
 drivers/gpu/drm/radeon/ni.c          |    7 ++-----
 drivers/gpu/drm/radeon/r100.c        |    7 ++-----
 drivers/gpu/drm/radeon/r300.c        |    7 ++-----
 drivers/gpu/drm/radeon/r420.c        |    7 ++-----
 drivers/gpu/drm/radeon/r520.c        |    8 +++-----
 drivers/gpu/drm/radeon/r600.c        |    7 ++-----
 drivers/gpu/drm/radeon/radeon.h      |    1 +
 drivers/gpu/drm/radeon/radeon_ring.c |   30 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/radeon/rs400.c       |    7 ++-----
 drivers/gpu/drm/radeon/rs600.c       |    7 ++-----
 drivers/gpu/drm/radeon/rs690.c       |    7 ++-----
 drivers/gpu/drm/radeon/rv515.c       |    8 +++-----
 drivers/gpu/drm/radeon/rv770.c       |    7 ++-----
 14 files changed, 57 insertions(+), 60 deletions(-)
drivers/gpu/drm/radeon/evergreen.c +2 -5
index cfa372c..ca47f52 100644
@@ -3248,12 +3248,9 @@ static int evergreen_startup(struct radeon_device *rdev)
 	if (r)
 		return r;
 
-	r = radeon_ib_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
-	if (r) {
-		DRM_ERROR("radeon: failed testing IB (%d).\n", r);
-		rdev->accel_working = false;
+	r = radeon_ib_ring_tests(rdev);
+	if (r)
 		return r;
-	}
 
 	r = r600_audio_init(rdev);
 	if (r) {
drivers/gpu/drm/radeon/ni.c +2 -5
index a48ca53..0146428 100644
@@ -1601,12 +1601,9 @@ static int cayman_startup(struct radeon_device *rdev)
 	if (r)
 		return r;
 
-	r = radeon_ib_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
-	if (r) {
-		DRM_ERROR("radeon: failed testing IB (%d).\n", r);
-		rdev->accel_working = false;
+	r = radeon_ib_ring_tests(rdev);
+	if (r)
 		return r;
-	}
 
 	r = radeon_vm_manager_start(rdev);
 	if (r)
drivers/gpu/drm/radeon/r100.c +2 -5
index 4b677fc..62f9dab 100644
@@ -3968,12 +3968,9 @@ static int r100_startup(struct radeon_device *rdev)
 	if (r)
 		return r;
 
-	r = radeon_ib_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
-	if (r) {
-		dev_err(rdev->dev, "failed testing IB (%d).\n", r);
-		rdev->accel_working = false;
+	r = radeon_ib_ring_tests(rdev);
+	if (r)
 		return r;
-	}
 
 	return 0;
 }
drivers/gpu/drm/radeon/r300.c +2 -5
index a63f432..26e0db8 100644
@@ -1417,12 +1417,9 @@ static int r300_startup(struct radeon_device *rdev)
 	if (r)
 		return r;
 
-	r = radeon_ib_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
-	if (r) {
-		dev_err(rdev->dev, "failed testing IB (%d).\n", r);
-		rdev->accel_working = false;
+	r = radeon_ib_ring_tests(rdev);
+	if (r)
 		return r;
-	}
 
 	return 0;
 }
drivers/gpu/drm/radeon/r420.c +2 -5
index f3fcaac..99137be 100644
@@ -279,12 +279,9 @@ static int r420_startup(struct radeon_device *rdev)
 	if (r)
 		return r;
 
-	r = radeon_ib_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
-	if (r) {
-		dev_err(rdev->dev, "failed testing IB (%d).\n", r);
-		rdev->accel_working = false;
+	r = radeon_ib_ring_tests(rdev);
+	if (r)
 		return r;
-	}
 
 	return 0;
 }
drivers/gpu/drm/radeon/r520.c +3 -5
index ebcc15b..b5cf837 100644
@@ -207,12 +207,10 @@ static int r520_startup(struct radeon_device *rdev)
 	if (r)
 		return r;
 
-	r = radeon_ib_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
-	if (r) {
-		dev_err(rdev->dev, "failed testing IB (%d).\n", r);
-		rdev->accel_working = false;
+	r = radeon_ib_ring_tests(rdev);
+	if (r)
 		return r;
-	}
+
 	return 0;
 }
 
drivers/gpu/drm/radeon/r600.c +2 -5
index 4added1..c749e00 100644
@@ -2494,12 +2494,9 @@ int r600_startup(struct radeon_device *rdev)
 	if (r)
 		return r;
 
-	r = radeon_ib_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
-	if (r) {
-		DRM_ERROR("radeon: failed testing IB (%d).\n", r);
-		rdev->accel_working = false;
+	r = radeon_ib_ring_tests(rdev);
+	if (r)
 		return r;
-	}
 
 	return 0;
 }
drivers/gpu/drm/radeon/radeon.h +1 -0
index 365334b..8801657 100644
@@ -793,6 +793,7 @@ int radeon_ib_pool_init(struct radeon_device *rdev);
 void radeon_ib_pool_fini(struct radeon_device *rdev);
 int radeon_ib_pool_start(struct radeon_device *rdev);
 int radeon_ib_pool_suspend(struct radeon_device *rdev);
+int radeon_ib_ring_tests(struct radeon_device *rdev);
 /* Ring access between begin & end cannot sleep */
 int radeon_ring_index(struct radeon_device *rdev, struct radeon_ring *cp);
 void radeon_ring_free_size(struct radeon_device *rdev, struct radeon_ring *cp);
drivers/gpu/drm/radeon/radeon_ring.c +30 -0
index b6eb1d2..1b020ef 100644
@@ -267,6 +267,36 @@ int radeon_ib_pool_suspend(struct radeon_device *rdev)
 	return radeon_sa_bo_manager_suspend(rdev, &rdev->ib_pool.sa_manager);
 }
 
+int radeon_ib_ring_tests(struct radeon_device *rdev)
+{
+	unsigned i;
+	int r;
+
+	for (i = 0; i < RADEON_NUM_RINGS; ++i) {
+		struct radeon_ring *ring = &rdev->ring[i];
+
+		if (!ring->ready)
+			continue;
+
+		r = radeon_ib_test(rdev, i, ring);
+		if (r) {
+			ring->ready = false;
+
+			if (i == RADEON_RING_TYPE_GFX_INDEX) {
+				/* oh, oh, that's really bad */
+				DRM_ERROR("radeon: failed testing IB on GFX ring (%d).\n", r);
+		                rdev->accel_working = false;
+				return r;
+
+			} else {
+				/* still not good, but we can live with it */
+				DRM_ERROR("radeon: failed testing IB on ring %d (%d).\n", i, r);
+			}
+		}
+	}
+	return 0;
+}
+
 /*
  * Ring.
  */
drivers/gpu/drm/radeon/rs400.c +2 -5
index 4cf381b..a464eb5 100644
@@ -430,12 +430,9 @@ static int rs400_startup(struct radeon_device *rdev)
 	if (r)
 		return r;
 
-	r = radeon_ib_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
-	if (r) {
-		dev_err(rdev->dev, "failed testing IB (%d).\n", r);
-		rdev->accel_working = false;
+	r = radeon_ib_ring_tests(rdev);
+	if (r)
 		return r;
-	}
 
 	return 0;
 }
drivers/gpu/drm/radeon/rs600.c +2 -5
index f709fe8..a286dea 100644
@@ -882,12 +882,9 @@ static int rs600_startup(struct radeon_device *rdev)
 	if (r)
 		return r;
 
-	r = radeon_ib_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
-	if (r) {
-		dev_err(rdev->dev, "failed testing IB (%d).\n", r);
-		rdev->accel_working = false;
+	r = radeon_ib_ring_tests(rdev);
+	if (r)
 		return r;
-	}
 
 	return 0;
 }
drivers/gpu/drm/radeon/rs690.c +2 -5
index f2c3b9d..3277dde 100644
@@ -647,12 +647,9 @@ static int rs690_startup(struct radeon_device *rdev)
 	if (r)
 		return r;
 
-	r = radeon_ib_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
-	if (r) {
-		dev_err(rdev->dev, "failed testing IB (%d).\n", r);
-		rdev->accel_working = false;
+	r = radeon_ib_ring_tests(rdev);
+	if (r)
 		return r;
-	}
 
 	return 0;
 }
drivers/gpu/drm/radeon/rv515.c +3 -5
index d8d78fe..7f08ced 100644
@@ -412,12 +412,10 @@ static int rv515_startup(struct radeon_device *rdev)
 	if (r)
 		return r;
 
-	r = radeon_ib_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
-	if (r) {
-		dev_err(rdev->dev, "failed testing IB (%d).\n", r);
-		rdev->accel_working = false;
+	r = radeon_ib_ring_tests(rdev);
+	if (r)
 		return r;
-	}
+
 	return 0;
 }
 
drivers/gpu/drm/radeon/rv770.c +2 -5
index c62ae4b..cacec0e 100644
@@ -1114,12 +1114,9 @@ static int rv770_startup(struct radeon_device *rdev)
 	if (r)
 		return r;
 
-	r = radeon_ib_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
-	if (r) {
-		dev_err(rdev->dev, "IB test failed (%d).\n", r);
-		rdev->accel_working = false;
+	r = radeon_ib_ring_tests(rdev);
+	if (r)
 		return r;
-	}
 
 	return 0;
 }
Signature · 6 lines
1.7.5.4

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

PATCH 5/13 drm/radeon: rework gpu lockup detection and processing

In reply to Christian König

Previusly multiple ring could trigger multiple GPU resets at the same time.

---
 drivers/gpu/drm/radeon/radeon.h       |    3 +-
 drivers/gpu/drm/radeon/radeon_fence.c |  146 +++++++++++++++++----------------
 2 files changed, 75 insertions(+), 74 deletions(-)
drivers/gpu/drm/radeon/radeon.h +1 -2
index 8801657..85a3aa9 100644
@@ -255,8 +255,7 @@ struct radeon_fence_driver {
 	volatile uint32_t		*cpu_addr;
 	atomic_t			seq;
 	uint32_t			last_seq;
-	unsigned long			last_jiffies;
-	unsigned long			last_timeout;
+	unsigned long			last_activity;
 	wait_queue_head_t		queue;
 	struct list_head		created;
 	struct list_head		emitted;
drivers/gpu/drm/radeon/radeon_fence.c +76 -74

182 lines not on this page · raw message

Signature · 6 lines
1.7.5.4

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

PATCH 6/13 drm/radeon: improve sub allocator

In reply to Christian König

Make the suballocator self containing to locking
and fix a overrun bug which happens with
allocations of different alignments.

---
 drivers/gpu/drm/radeon/radeon.h    |    1 +
 drivers/gpu/drm/radeon/radeon_sa.c |   19 ++++++++++++-------
 2 files changed, 13 insertions(+), 7 deletions(-)
drivers/gpu/drm/radeon/radeon.h +1 -0
index 85a3aa9..1aefbd9 100644
@@ -381,6 +381,7 @@ struct radeon_bo_list {
  * alignment).
  */
 struct radeon_sa_manager {
+	spinlock_t		lock;
 	struct radeon_bo	*bo;
 	struct list_head	sa_bo;
 	unsigned		size;
drivers/gpu/drm/radeon/radeon_sa.c +12 -7
index 4cce47e..4ce5c51 100644
@@ -37,6 +37,7 @@ int radeon_sa_bo_manager_init(struct radeon_device *rdev,
 {
 	int r;
 
+	spin_lock_init(&sa_manager->lock);
 	sa_manager->bo = NULL;
 	sa_manager->size = size;
 	sa_manager->domain = domain;
@@ -136,30 +137,30 @@ int radeon_sa_bo_new(struct radeon_device *rdev,
 	struct radeon_sa_bo *tmp;
 	struct list_head *head;
 	unsigned offset = 0, wasted = 0;
+	unsigned long flags;
 
 	BUG_ON(align > RADEON_GPU_PAGE_SIZE);
 	BUG_ON(size > sa_manager->size);
+	spin_lock_irqsave(&sa_manager->lock, flags);
 
 	/* no one ? */
-	head = sa_manager->sa_bo.prev;
 	if (list_empty(&sa_manager->sa_bo)) {
+		head = &sa_manager->sa_bo;
 		goto out;
 	}
 
 	/* look for a hole big enough */
-	offset = 0;
 	list_for_each_entry(tmp, &sa_manager->sa_bo, list) {
 		/* room before this object ? */
-		if ((tmp->offset - offset) >= size) {
+		if (offset < tmp->offset && (tmp->offset - offset) >= size) {
 			head = tmp->list.prev;
 			goto out;
 		}
 		offset = tmp->offset + tmp->size;
 		wasted = offset % align;
 		if (wasted) {
-			wasted = align - wasted;
+			offset += align - wasted;
 		}
-		offset += wasted;
 	}
 	/* room at the end ? */
 	head = sa_manager->sa_bo.prev;
@@ -167,11 +168,11 @@ int radeon_sa_bo_new(struct radeon_device *rdev,
 	offset = tmp->offset + tmp->size;
 	wasted = offset % align;
 	if (wasted) {
-		wasted = align - wasted;
+		offset += wasted = align - wasted;
 	}
-	offset += wasted;
 	if ((sa_manager->size - offset) < size) {
 		/* failed to find somethings big enough */
+		spin_unlock_irqrestore(&sa_manager->lock, flags);
 		return -ENOMEM;
 	}
 
@@ -180,10 +181,14 @@ out:
 	sa_bo->offset = offset;
 	sa_bo->size = size;
 	list_add(&sa_bo->list, head);
+	spin_unlock_irqrestore(&sa_manager->lock, flags);
 	return 0;
 }
 
 void radeon_sa_bo_free(struct radeon_device *rdev, struct radeon_sa_bo *sa_bo)
 {
+	unsigned long flags;
+	spin_lock_irqsave(&sa_bo->manager->lock, flags);
 	list_del_init(&sa_bo->list);
+	spin_unlock_irqrestore(&sa_bo->manager->lock, flags);
 }
Signature · 6 lines
1.7.5.4

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

Re: [PATCH 06/13] drm/radeon: improve sub allocator

Quoted 3 lines · Christian König

Make the suballocator self containing to locking
and fix a overrun bug which happens with
allocations of different alignments.

Sounds like this should be split up into two changes. :)

Signature · 6 lines
Earthling Michel Dänzer           |                   http://www.amd.com
Libre software enthusiast         |          Debian, X and DRI developer
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#8 lore raw

Re: [PATCH 06/13] drm/radeon: improve sub allocator

Quoted 5 lines · Michel Dänzer
Quoted 3 lines · Christian König

Make the suballocator self containing to locking
and fix a overrun bug which happens with
allocations of different alignments.

Sounds like this should be split up into two changes. :)

Yeah you are probably right.

But wait a moment, thinking about it some more the overrun bug is actually a quite critical bug in mainline, cause it quickly leads to memory corruption if two users of the SA have different alignment restrictions. And hell, there currently is at least the IB pool (256 bytes) and the VM code (4096 bytes alignment) using it, so this could be responsible for some of the VM corruptions we are seeing!!!

Going to write a patch immediately,
Christian.
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#9 lore raw

PATCH 7/13 drm/radeon: add sub allocator debugfs file

In reply to Christian König

Dumping the current allocations.

---
 drivers/gpu/drm/radeon/radeon_object.h |    5 +++++
 drivers/gpu/drm/radeon/radeon_ring.c   |   22 ++++++++++++++++++++++
 drivers/gpu/drm/radeon/radeon_sa.c     |   15 +++++++++++++++
 3 files changed, 42 insertions(+), 0 deletions(-)
drivers/gpu/drm/radeon/radeon_object.h +5 -0
index f9104be..d9b9333 100644
@@ -161,5 +161,10 @@ extern int radeon_sa_bo_new(struct radeon_device *rdev,
 			    unsigned size, unsigned align);
 extern void radeon_sa_bo_free(struct radeon_device *rdev,
 			      struct radeon_sa_bo *sa_bo);
+#if defined(CONFIG_DEBUG_FS)
+extern void radeon_sa_bo_dump_debug_info(struct radeon_sa_manager *sa_manager,
+					 struct seq_file *m);
+#endif
+
 
 #endif
drivers/gpu/drm/radeon/radeon_ring.c +22 -0
index 1b020ef..1d9bce9 100644
@@ -529,6 +529,23 @@ static int radeon_debugfs_ib_info(struct seq_file *m, void *data)
 static struct drm_info_list radeon_debugfs_ib_list[RADEON_IB_POOL_SIZE];
 static char radeon_debugfs_ib_names[RADEON_IB_POOL_SIZE][32];
 static unsigned radeon_debugfs_ib_idx[RADEON_IB_POOL_SIZE];
+
+static int radeon_debugfs_sa_info(struct seq_file *m, void *data)
+{
+	struct drm_info_node *node = (struct drm_info_node *) m->private;
+	struct drm_device *dev = node->minor->dev;
+	struct radeon_device *rdev = dev->dev_private;
+
+	radeon_sa_bo_dump_debug_info(&rdev->ib_pool.sa_manager, m);
+
+	return 0;
+
+}
+
+static struct drm_info_list radeon_debugfs_sa_list[] = {
+        {"radeon_sa_info", &radeon_debugfs_sa_info, 0, NULL},
+};
+
 #endif
 
 int radeon_debugfs_ring_init(struct radeon_device *rdev, struct radeon_ring *ring)
@@ -555,6 +572,11 @@ int radeon_debugfs_ib_init(struct radeon_device *rdev)
 {
 #if defined(CONFIG_DEBUG_FS)
 	unsigned i;
+	int r;
+
+	r = radeon_debugfs_add_files(rdev, radeon_debugfs_sa_list, 1);
+	if (r)
+		return r;
 
 	for (i = 0; i < RADEON_IB_POOL_SIZE; i++) {
 		sprintf(radeon_debugfs_ib_names[i], "radeon_ib_%04u", i);
drivers/gpu/drm/radeon/radeon_sa.c +15 -0
index 4ce5c51..013a787 100644
@@ -192,3 +192,18 @@ void radeon_sa_bo_free(struct radeon_device *rdev, struct radeon_sa_bo *sa_bo)
 	list_del_init(&sa_bo->list);
 	spin_unlock_irqrestore(&sa_bo->manager->lock, flags);
 }
+
+#if defined(CONFIG_DEBUG_FS)
+void radeon_sa_bo_dump_debug_info(struct radeon_sa_manager *sa_manager,
+				  struct seq_file *m)
+{
+	struct radeon_sa_bo *i;
+	unsigned long flags;
+
+	spin_lock_irqsave(&sa_manager->lock, flags);
+	list_for_each_entry(i, &sa_manager->sa_bo, list) {
+		seq_printf(m, "offset %08d: size %4d\n", i->offset, i->size);
+	}
+	spin_unlock_irqrestore(&sa_manager->lock, flags);
+}
+#endif
Signature · 6 lines
1.7.5.4

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

PATCH 8/13 drm/radeon: add biggest hole tracking and wakequeue to the sa

In reply to Christian König

With that in place clients are automatically blocking until their memory request can be handled.

---
 drivers/gpu/drm/radeon/radeon.h      |    5 +-
 drivers/gpu/drm/radeon/radeon_ring.c |   18 ++--
 drivers/gpu/drm/radeon/radeon_sa.c   |  192 +++++++++++++++++++++++++---------
 3 files changed, 153 insertions(+), 62 deletions(-)
drivers/gpu/drm/radeon/radeon.h +2 -3
index 1aefbd9..415a496 100644
@@ -381,17 +381,16 @@ struct radeon_bo_list {
  * alignment).
  */
 struct radeon_sa_manager {
-	spinlock_t		lock;
+	wait_queue_head_t	queue;
 	struct radeon_bo	*bo;
 	struct list_head	sa_bo;
 	unsigned		size;
+	struct list_head	*biggest_hole;
 	uint64_t		gpu_addr;
 	void			*cpu_ptr;
 	uint32_t		domain;
 };
 
-struct radeon_sa_bo;
-
 /* sub-allocation buffer */
 struct radeon_sa_bo {
 	struct list_head		list;
drivers/gpu/drm/radeon/radeon_ring.c +8 -10
index 1d9bce9..5942769 100644
@@ -205,10 +205,16 @@ int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib)
 
 int radeon_ib_pool_init(struct radeon_device *rdev)
 {
-	struct radeon_sa_manager tmp;
 	int i, r;
 
-	r = radeon_sa_bo_manager_init(rdev, &tmp,
+	radeon_mutex_lock(&rdev->ib_pool.mutex);
+	if (rdev->ib_pool.ready) {
+		return 0;
+	}
+	rdev->ib_pool.ready = true;
+	radeon_mutex_unlock(&rdev->ib_pool.mutex);
+
+	r = radeon_sa_bo_manager_init(rdev, &rdev->ib_pool.sa_manager,
 				      RADEON_IB_POOL_SIZE*64*1024,
 				      RADEON_GEM_DOMAIN_GTT);
 	if (r) {
@@ -216,14 +222,6 @@ int radeon_ib_pool_init(struct radeon_device *rdev)
 	}
 
 	radeon_mutex_lock(&rdev->ib_pool.mutex);
-	if (rdev->ib_pool.ready) {
-		radeon_mutex_unlock(&rdev->ib_pool.mutex);
-		radeon_sa_bo_manager_fini(rdev, &tmp);
-		return 0;
-	}
-
-	rdev->ib_pool.sa_manager = tmp;
-	INIT_LIST_HEAD(&rdev->ib_pool.sa_manager.sa_bo);
 	for (i = 0; i < RADEON_IB_POOL_SIZE; i++) {
 		rdev->ib_pool.ibs[i].fence = NULL;
 		rdev->ib_pool.ibs[i].idx = i;
drivers/gpu/drm/radeon/radeon_sa.c +143 -49

245 lines not on this page · raw message

Signature · 6 lines
1.7.5.4

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

PATCH 9/13 drm/radeon: simplify semaphore handling

In reply to Christian König

Directly use the suballocator to get small chunks of memory. It's equally fast and doesn't crash when we encounter a GPU reset.

---
 drivers/gpu/drm/radeon/evergreen.c        |    1 -
 drivers/gpu/drm/radeon/ni.c               |    1 -
 drivers/gpu/drm/radeon/r600.c             |    1 -
 drivers/gpu/drm/radeon/radeon.h           |   29 +------
 drivers/gpu/drm/radeon/radeon_device.c    |    2 -
 drivers/gpu/drm/radeon/radeon_semaphore.c |  137 +++++------------------------
 drivers/gpu/drm/radeon/rv770.c            |    1 -
 drivers/gpu/drm/radeon/si.c               |    1 -
 8 files changed, 26 insertions(+), 147 deletions(-)
drivers/gpu/drm/radeon/evergreen.c +0 -1
index ca47f52..a76389c 100644
@@ -3431,7 +3431,6 @@ void evergreen_fini(struct radeon_device *rdev)
 	evergreen_pcie_gart_fini(rdev);
 	r600_vram_scratch_fini(rdev);
 	radeon_gem_fini(rdev);
-	radeon_semaphore_driver_fini(rdev);
 	radeon_fence_driver_fini(rdev);
 	radeon_agp_fini(rdev);
 	radeon_bo_fini(rdev);
drivers/gpu/drm/radeon/ni.c +0 -1
index 0146428..c0b0956 100644
@@ -1773,7 +1773,6 @@ void cayman_fini(struct radeon_device *rdev)
 	cayman_pcie_gart_fini(rdev);
 	r600_vram_scratch_fini(rdev);
 	radeon_gem_fini(rdev);
-	radeon_semaphore_driver_fini(rdev);
 	radeon_fence_driver_fini(rdev);
 	radeon_bo_fini(rdev);
 	radeon_atombios_fini(rdev);
drivers/gpu/drm/radeon/r600.c +0 -1
index c749e00..b8d9335 100644
@@ -2672,7 +2672,6 @@ void r600_fini(struct radeon_device *rdev)
 	r600_vram_scratch_fini(rdev);
 	radeon_agp_fini(rdev);
 	radeon_gem_fini(rdev);
-	radeon_semaphore_driver_fini(rdev);
 	radeon_fence_driver_fini(rdev);
 	radeon_bo_fini(rdev);
 	radeon_atombios_fini(rdev);
drivers/gpu/drm/radeon/radeon.h +3 -26
index 415a496..222939f 100644
@@ -427,34 +427,12 @@ int radeon_mode_dumb_destroy(struct drm_file *file_priv,
 /*
  * Semaphores.
  */
-struct radeon_ring;
-
-#define	RADEON_SEMAPHORE_BO_SIZE	256
-
-struct radeon_semaphore_driver {
-	rwlock_t			lock;
-	struct list_head		bo;
-};
-
-struct radeon_semaphore_bo;
-
-/* everything here is constant */
 struct radeon_semaphore {
-	struct list_head		list;
-	uint64_t			gpu_addr;
-	uint32_t			*cpu_ptr;
-	struct radeon_semaphore_bo	*bo;
-};
-
-struct radeon_semaphore_bo {
-	struct list_head		list;
-	struct radeon_ib		*ib;
-	struct list_head		free;
-	struct radeon_semaphore		semaphores[RADEON_SEMAPHORE_BO_SIZE/8];
-	unsigned			nused;
+	struct radeon_sa_bo	sa_bo;
+	signed			waiters;
+	uint64_t		gpu_addr;
 };
 
-void radeon_semaphore_driver_fini(struct radeon_device *rdev);
 int radeon_semaphore_create(struct radeon_device *rdev,
 			    struct radeon_semaphore **semaphore);
 void radeon_semaphore_emit_signal(struct radeon_device *rdev, int ring,
@@ -1518,7 +1496,6 @@ struct radeon_device {
 	struct radeon_mman		mman;
 	rwlock_t			fence_lock;
 	struct radeon_fence_driver	fence_drv[RADEON_NUM_RINGS];
-	struct radeon_semaphore_driver	semaphore_drv;
 	struct radeon_ring		ring[RADEON_NUM_RINGS];
 	struct radeon_ib_pool		ib_pool;
 	struct radeon_irq		irq;
drivers/gpu/drm/radeon/radeon_device.c +0 -2
index dedb398..8c49990 100644
@@ -733,11 +733,9 @@ int radeon_device_init(struct radeon_device *rdev,
 	mutex_init(&rdev->pm.mutex);
 	mutex_init(&rdev->vram_mutex);
 	rwlock_init(&rdev->fence_lock);
-	rwlock_init(&rdev->semaphore_drv.lock);
 	INIT_LIST_HEAD(&rdev->gem.objects);
 	init_waitqueue_head(&rdev->irq.vblank_queue);
 	init_waitqueue_head(&rdev->irq.idle_queue);
-	INIT_LIST_HEAD(&rdev->semaphore_drv.bo);
 	/* initialize vm here */
 	rdev->vm_manager.use_bitmap = 1;
 	rdev->vm_manager.max_pfn = 1 << 20;
drivers/gpu/drm/radeon/radeon_semaphore.c +23 -114

170 lines not on this page · raw message

drivers/gpu/drm/radeon/rv770.c +0 -1
index cacec0e..c6ee54e 100644
@@ -1278,7 +1278,6 @@ void rv770_fini(struct radeon_device *rdev)
 	rv770_pcie_gart_fini(rdev);
 	r600_vram_scratch_fini(rdev);
 	radeon_gem_fini(rdev);
-	radeon_semaphore_driver_fini(rdev);
 	radeon_fence_driver_fini(rdev);
 	radeon_agp_fini(rdev);
 	radeon_bo_fini(rdev);
drivers/gpu/drm/radeon/si.c +0 -1
index 14919e1..7c0110d 100644
@@ -4120,7 +4120,6 @@ void si_fini(struct radeon_device *rdev)
 	si_pcie_gart_fini(rdev);
 	r600_vram_scratch_fini(rdev);
 	radeon_gem_fini(rdev);
-	radeon_semaphore_driver_fini(rdev);
 	radeon_fence_driver_fini(rdev);
 	radeon_bo_fini(rdev);
 	radeon_atombios_fini(rdev);
Signature · 6 lines
1.7.5.4

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

PATCH 10/13 drm/radeon: return -ENOENT in fence_wait_*

In reply to Christian König
---
 drivers/gpu/drm/radeon/radeon_fence.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_fence.c +2 -2
index 1a9765a..764ab7e 100644
@@ -286,7 +286,7 @@ int radeon_fence_wait_next(struct radeon_device *rdev, int ring)
 	}
 	if (list_empty(&rdev->fence_drv[ring].emitted)) {
 		write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
-		return 0;
+		return -ENOENT;
 	}
 	fence = list_entry(rdev->fence_drv[ring].emitted.next,
 			   struct radeon_fence, list);
@@ -310,7 +310,7 @@ int radeon_fence_wait_last(struct radeon_device *rdev, int ring)
 	}
 	if (list_empty(&rdev->fence_drv[ring].emitted)) {
 		write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
-		return 0;
+		return -ENOENT;
 	}
 	fence = list_entry(rdev->fence_drv[ring].emitted.prev,
 			   struct radeon_fence, list);
Signature · 6 lines
1.7.5.4

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

Re: [PATCH 10/13] drm/radeon: return -ENOENT in fence_wait_*

Quoted 19 lines · Christian König
---
 drivers/gpu/drm/radeon/radeon_fence.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_fence.c +1 -1
index 1a9765a..764ab7e 100644
@@ -286,7 +286,7 @@ int radeon_fence_wait_next(struct radeon_device *rdev, int ring)
 	}
 	if (list_empty(&rdev->fence_drv[ring].emitted)) {
 		write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
-		return 0;
+		return -ENOENT;
 	}
 	fence = list_entry(rdev->fence_drv[ring].emitted.next,
 			   struct radeon_fence, list);

drivers/gpu/drm/radeon/radeon_fence.c int radeon_fence_wait_last(struct radeon_device *rdev, int ring) · line 316

Quoted 8 lines
drivers/gpu/drm/radeon/radeon_fence.c +1 -1
@@ -310,7 +310,7 @@ int radeon_fence_wait_last(struct radeon_device *rdev, int ring)
 	}
 	if (list_empty(&rdev->fence_drv[ring].emitted)) {
 		write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
-		return 0;
+		return -ENOENT;
 	}
 	fence = list_entry(rdev->fence_drv[ring].emitted.prev,
 			   struct radeon_fence, list);

It seems weird to declare a fence wait as failed when there are no outstanding fences in the first place. If there are callers which require outstanding fences, they should probably handle that themselves.

Signature · 6 lines
Earthling Michel Dänzer           |                   http://www.amd.com
Libre software enthusiast         |          Debian, X and DRI developer
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#14 lore raw

Re: [PATCH 10/13] drm/radeon: return -ENOENT in fence_wait_*

Quoted 23 lines · Michel Dänzer
Quoted 22 lines · Christian König
---
  drivers/gpu/drm/radeon/radeon_fence.c |    4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_fence.c +1 -1
index 1a9765a..764ab7e 100644
@@ -286,7 +286,7 @@ int radeon_fence_wait_next(struct radeon_device *rdev, int ring)
  	}
  	if (list_empty(&rdev->fence_drv[ring].emitted)) {
  		write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
-		return 0;
+		return -ENOENT;
  	}
  	fence = list_entry(rdev->fence_drv[ring].emitted.next,
  			   struct radeon_fence, list);
@@ -310,7 +310,7 @@ int radeon_fence_wait_last(struct radeon_device *rdev, int ring)
  	}
  	if (list_empty(&rdev->fence_drv[ring].emitted)) {
  		write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
Quoted 8 lines

drivers/gpu/drm/radeon/radeon_fence.c int radeon_fence_wait_last(struct radeon_device *rdev, int ring) · line 316

Quoted 5 lines
drivers/gpu/drm/radeon/radeon_fence.c +1 -1
-		return 0;
+		return -ENOENT;
  	}
  	fence = list_entry(rdev->fence_drv[ring].emitted.prev,
  			   struct radeon_fence, list);

It seems weird to declare a fence wait as failed when there are no outstanding fences in the first place. If there are callers which require outstanding fences, they should probably handle that themselves.

Why that sounds so weird? Ok, maybe for radeon_fence_wait_last that's questionable, but for radeon_fence_wait_next it's quite clear to me that we should signal the caller that there is no fence to wait for.

The problem I wanted to fix with that is the usage of radeon_fence_wait_next in radeon_ring_alloc (for example):

Quoted 13 lines

int radeon_ring_alloc(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ndw)

{
        int r;

        /* Align requested size with padding so unlock_commit can
         * pad safely */
        ndw = (ndw + ring->align_mask) & ~ring->align_mask;
        while (ndw > (ring->ring_free_dw - 1)) {
                radeon_ring_free_size(rdev, ring);
                if (ndw < ring->ring_free_dw) {
                        break;
                }
                r = radeon_fence_wait_next(rdev, 
Quoted 8 lines
radeon_ring_index(rdev, ring));
                if (r)
                        return r;
        }
        ring->count_dw = ndw;
        ring->wptr_old = ring->wptr;
        return 0;
}

If the ring is full, but actually has no more fences in it (which in my case was caused by my stupidity and actually shouldn't happen otherwise) this loop will just busy wait with a critical mutex locked for something that never happens.

It actually shouldn't make any difference for real world applications, but it just prevents the users of those functions from doing something stupid.

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

#15 lore raw

Re: [PATCH 10/13] drm/radeon: return -ENOENT in fence_wait_*

Quoted 33 lines · Christian König
Quoted 23 lines · Michel Dänzer
Quoted 22 lines · Christian König
---
  drivers/gpu/drm/radeon/radeon_fence.c |    4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_fence.c +1 -1
index 1a9765a..764ab7e 100644
@@ -286,7 +286,7 @@ int radeon_fence_wait_next(struct radeon_device *rdev, int ring)
  	}
  	if (list_empty(&rdev->fence_drv[ring].emitted)) {
  		write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
-		return 0;
+		return -ENOENT;
  	}
  	fence = list_entry(rdev->fence_drv[ring].emitted.next,
  			   struct radeon_fence, list);
@@ -310,7 +310,7 @@ int radeon_fence_wait_last(struct radeon_device *rdev, int ring)
  	}
  	if (list_empty(&rdev->fence_drv[ring].emitted)) {
  		write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
Quoted 8 lines

drivers/gpu/drm/radeon/radeon_fence.c int radeon_fence_wait_last(struct radeon_device *rdev, int ring) · line 316

Quoted 5 lines
drivers/gpu/drm/radeon/radeon_fence.c +1 -1
-		return 0;
+		return -ENOENT;
  	}
  	fence = list_entry(rdev->fence_drv[ring].emitted.prev,
  			   struct radeon_fence, list);

It seems weird to declare a fence wait as failed when there are no outstanding fences in the first place. If there are callers which require outstanding fences, they should probably handle that themselves.

Quoted 2 lines

Why that sounds so weird? Ok, maybe for radeon_fence_wait_last that's questionable,

Indeed. It happens not to break radeon_suspend_kms because it doesn't check the return value, but otherwise it would fail spuriously.

Quoted 27 lines

but for radeon_fence_wait_next it's quite clear to me that we should signal the caller that there is no fence to wait for.

The problem I wanted to fix with that is the usage of radeon_fence_wait_next in radeon_ring_alloc (for example):

Quoted 14 lines

int radeon_ring_alloc(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ndw)

{
        int r;

        /* Align requested size with padding so unlock_commit can
         * pad safely */
        ndw = (ndw + ring->align_mask) & ~ring->align_mask;
        while (ndw > (ring->ring_free_dw - 1)) {
                radeon_ring_free_size(rdev, ring);
                if (ndw < ring->ring_free_dw) {
                        break;
                }
                r = radeon_fence_wait_next(rdev, 
Quoted 8 lines
radeon_ring_index(rdev, ring));
                if (r)
                        return r;
        }
        ring->count_dw = ndw;
        ring->wptr_old = ring->wptr;
        return 0;
}
Quoted 4 lines

If the ring is full, but actually has no more fences in it (which in my case was caused by my stupidity and actually shouldn't happen otherwise) this loop will just busy wait with a critical mutex locked for something that never happens.

My suggestion was to explicitly check for that in radeon_ring_alloc. But I guess right now it doesn't really matter, as it's the only caller. :)

Signature · 6 lines
Earthling Michel Dänzer           |                   http://www.amd.com
Libre software enthusiast         |          Debian, X and DRI developer
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#16 lore raw

Re: [PATCH 10/13] drm/radeon: return -ENOENT in fence_wait_*

Quoted 66 lines · Michel Dänzer
Quoted 32 lines · Christian König
Quoted 23 lines · Michel Dänzer
Quoted 22 lines · Christian König
---
   drivers/gpu/drm/radeon/radeon_fence.c |    4 ++--
   1 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_fence.c +1 -1
index 1a9765a..764ab7e 100644
@@ -286,7 +286,7 @@ int radeon_fence_wait_next(struct radeon_device *rdev, int ring)
   	}
   	if (list_empty(&rdev->fence_drv[ring].emitted)) {
   		write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
-		return 0;
+		return -ENOENT;
   	}
   	fence = list_entry(rdev->fence_drv[ring].emitted.next,
   			   struct radeon_fence, list);
@@ -310,7 +310,7 @@ int radeon_fence_wait_last(struct radeon_device *rdev, int ring)
   	}
   	if (list_empty(&rdev->fence_drv[ring].emitted)) {
   		write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
Quoted 8 lines

drivers/gpu/drm/radeon/radeon_fence.c int radeon_fence_wait_last(struct radeon_device *rdev, int ring) · line 316

Quoted 5 lines
drivers/gpu/drm/radeon/radeon_fence.c +1 -1
-		return 0;
+		return -ENOENT;
   	}
   	fence = list_entry(rdev->fence_drv[ring].emitted.prev,
   			   struct radeon_fence, list);

It seems weird to declare a fence wait as failed when there are no outstanding fences in the first place. If there are callers which require outstanding fences, they should probably handle that themselves..

Quoted 2 lines

Why that sounds so weird? Ok, maybe for radeon_fence_wait_last that's questionable,

Indeed. It happens not to break radeon_suspend_kms because it doesn't check the return value, but otherwise it would fail spuriously.

Quoted 27 lines

but for radeon_fence_wait_next it's quite clear to me that we should signal the caller that there is no fence to wait for.

The problem I wanted to fix with that is the usage of radeon_fence_wait_next in radeon_ring_alloc (for example):

Quoted 22 lines

int radeon_ring_alloc(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ndw)

{
         int r;

         /* Align requested size with padding so unlock_commit can
          * pad safely */
         ndw = (ndw + ring->align_mask)&  ~ring->align_mask;
         while (ndw>  (ring->ring_free_dw - 1)) {
                 radeon_ring_free_size(rdev, ring);
                 if (ndw<  ring->ring_free_dw) {
                         break;
                 }
                 r = radeon_fence_wait_next(rdev,
radeon_ring_index(rdev, ring));
                 if (r)
                         return r;
         }
         ring->count_dw = ndw;
         ring->wptr_old = ring->wptr;
         return 0;
}
Quoted 6 lines
Quoted 4 lines

If the ring is full, but actually has no more fences in it (which in my case was caused by my stupidity and actually shouldn't happen otherwise) this loop will just busy wait with a critical mutex locked for something that never happens.

My suggestion was to explicitly check for that in radeon_ring_alloc. But I guess right now it doesn't really matter, as it's the only caller. :)

Yeah, but when we check that explicitly we need to call into the fence code twice, without locking in between, so the result of the first call could change before the second call happens etc... well that's just crap.

So what do you think of this: Just add the -ENOENT to fence_wait_next and rename fence_wait_last to fence_wait_empty instead?

Well I'm just trying to program defensively here, making it as robust as possible to both technically and human errors.

Christian.

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

#17 lore raw

Re: [PATCH 10/13] drm/radeon: return -ENOENT in fence_wait_*

Quoted 71 lines · Christian König
Quoted 70 lines · Michel Dänzer
Quoted 32 lines · Christian König
Quoted 23 lines · Michel Dänzer
Quoted 22 lines · Christian König
---
   drivers/gpu/drm/radeon/radeon_fence.c |    4 ++--
   1 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_fence.c +1 -1
index 1a9765a..764ab7e 100644
@@ -286,7 +286,7 @@ int radeon_fence_wait_next(struct radeon_device *rdev, int ring)
   	}
   	if (list_empty(&rdev->fence_drv[ring].emitted)) {
   		write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
-		return 0;
+		return -ENOENT;
   	}
   	fence = list_entry(rdev->fence_drv[ring].emitted.next,
   			   struct radeon_fence, list);
@@ -310,7 +310,7 @@ int radeon_fence_wait_last(struct radeon_device *rdev, int ring)
   	}
   	if (list_empty(&rdev->fence_drv[ring].emitted)) {
   		write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
Quoted 8 lines

drivers/gpu/drm/radeon/radeon_fence.c int radeon_fence_wait_last(struct radeon_device *rdev, int ring) · line 316

Quoted 5 lines
drivers/gpu/drm/radeon/radeon_fence.c +1 -1
-		return 0;
+		return -ENOENT;
   	}
   	fence = list_entry(rdev->fence_drv[ring].emitted.prev,
   			   struct radeon_fence, list);

It seems weird to declare a fence wait as failed when there are no outstanding fences in the first place. If there are callers which require outstanding fences, they should probably handle that themselves..

Quoted 2 lines

Why that sounds so weird? Ok, maybe for radeon_fence_wait_last that's questionable,

Indeed. It happens not to break radeon_suspend_kms because it doesn't check the return value, but otherwise it would fail spuriously.

Quoted 31 lines

but for radeon_fence_wait_next it's quite clear to me that we should signal the caller that there is no fence to wait for.

The problem I wanted to fix with that is the usage of radeon_fence_wait_next in radeon_ring_alloc (for example):

Quoted 14 lines

int radeon_ring_alloc(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ndw)

{
         int r;

         /* Align requested size with padding so unlock_commit can
          * pad safely */
         ndw = (ndw + ring->align_mask)&  ~ring->align_mask;
         while (ndw>  (ring->ring_free_dw - 1)) {
                 radeon_ring_free_size(rdev, ring);
                 if (ndw<  ring->ring_free_dw) {
                         break;
                 }
                 r = radeon_fence_wait_next(rdev,
Quoted 8 lines
radeon_ring_index(rdev, ring));
                 if (r)
                         return r;
         }
         ring->count_dw = ndw;
         ring->wptr_old = ring->wptr;
         return 0;
}

If the ring is full, but actually has no more fences in it (which in my case was caused by my stupidity and actually shouldn't happen otherwise) this loop will just busy wait with a critical mutex locked for something that never happens.

Quoted 8 lines
Quoted 2 lines

My suggestion was to explicitly check for that in radeon_ring_alloc. But I guess right now it doesn't really matter, as it's the only caller. :)

Yeah, but when we check that explicitly we need to call into the fence code twice, without locking in between, so the result of the first call could change before the second call happens etc... well that's just crap.

So what do you think of this: Just add the -ENOENT to fence_wait_next and rename fence_wait_last to fence_wait_empty instead?

Sounds good.

Signature · 6 lines
Earthling Michel Dänzer           |                   http://www.amd.com
Libre software enthusiast         |          Debian, X and DRI developer
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#18 lore raw

PATCH 11/13 drm/radeon: rip out the ib pool

In reply to Christian König

It isn't necessary any more and the suballocator
seems to perform even better.

---
 drivers/gpu/drm/radeon/radeon.h           |   22 +--
 drivers/gpu/drm/radeon/radeon_device.c    |    1 -
 drivers/gpu/drm/radeon/radeon_fence.c     |   44 +++++-
 drivers/gpu/drm/radeon/radeon_gart.c      |   12 +-
 drivers/gpu/drm/radeon/radeon_ring.c      |  240 ++++++++--------------------
 drivers/gpu/drm/radeon/radeon_semaphore.c |    6 +-
 6 files changed, 123 insertions(+), 202 deletions(-)
drivers/gpu/drm/radeon/radeon.h +6 -16
index 222939f..d46d5ac 100644
@@ -249,6 +249,8 @@ extern void evergreen_tiling_fields(unsigned tiling_flags, unsigned *bankw,
 /*
  * Fences.
  */
+struct radeon_ib;
+
 struct radeon_fence_driver {
 	uint32_t			scratch_reg;
 	uint64_t			gpu_addr;
@@ -259,7 +261,6 @@ struct radeon_fence_driver {
 	wait_queue_head_t		queue;
 	struct list_head		created;
 	struct list_head		emitted;
-	struct list_head		signaled;
 	bool				initialized;
 };
 
@@ -274,6 +275,7 @@ struct radeon_fence {
 	/* RB, DMA, etc. */
 	int				ring;
 	struct radeon_semaphore		*semaphore;
+	struct radeon_ib		*ib;
 };
 
 int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring);
@@ -289,6 +291,7 @@ int radeon_fence_wait_last(struct radeon_device *rdev, int ring);
 struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence);
 void radeon_fence_unref(struct radeon_fence **fence);
 int radeon_fence_count_emitted(struct radeon_device *rdev, int ring);
+bool radeon_fence_set_associated_ib(struct radeon_fence *fence, struct radeon_ib *ib);
 
 /*
  * Tiling registers
@@ -603,7 +606,6 @@ void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc);
 
 struct radeon_ib {
 	struct radeon_sa_bo	sa_bo;
-	unsigned		idx;
 	uint32_t		length_dw;
 	uint64_t		gpu_addr;
 	uint32_t		*ptr;
@@ -612,18 +614,6 @@ struct radeon_ib {
 	bool			is_const_ib;
 };
 
-/*
- * locking -
- * mutex protects scheduled_ibs, ready, alloc_bm
- */
-struct radeon_ib_pool {
-	struct radeon_mutex		mutex;
-	struct radeon_sa_manager	sa_manager;
-	struct radeon_ib		ibs[RADEON_IB_POOL_SIZE];
-	bool				ready;
-	unsigned			head_id;
-};
-
 struct radeon_ring {
 	struct radeon_bo	*ring_obj;
 	volatile uint32_t	*ring;
@@ -764,7 +754,6 @@ struct si_rlc {
 int radeon_ib_get(struct radeon_device *rdev, int ring,
 		  struct radeon_ib **ib, unsigned size);
 void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib);
-bool radeon_ib_try_free(struct radeon_device *rdev, struct radeon_ib *ib);
 int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib);
 int radeon_ib_pool_init(struct radeon_device *rdev);
 void radeon_ib_pool_fini(struct radeon_device *rdev);
@@ -1497,7 +1486,8 @@ struct radeon_device {
 	rwlock_t			fence_lock;
 	struct radeon_fence_driver	fence_drv[RADEON_NUM_RINGS];
 	struct radeon_ring		ring[RADEON_NUM_RINGS];
-	struct radeon_ib_pool		ib_pool;
+	bool				ib_pool_ready;
+	struct radeon_sa_manager	sa_manager;
 	struct radeon_irq		irq;
 	struct radeon_asic		*asic;
 	struct radeon_gem		gem;
drivers/gpu/drm/radeon/radeon_device.c +0 -1
index 8c49990..9189f8d 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);
-	radeon_mutex_init(&rdev->ib_pool.mutex);
 	for (i = 0; i < RADEON_NUM_RINGS; ++i)
 		mutex_init(&rdev->ring[i].mutex);
 	mutex_init(&rdev->dc_hw_i2c_mutex);
drivers/gpu/drm/radeon/radeon_fence.c +39 -5

104 lines not on this page · raw message

drivers/gpu/drm/radeon/radeon_gart.c +6 -6
index c58a036..0ab3277 100644
@@ -434,8 +434,8 @@ retry_id:
 	rdev->vm_manager.use_bitmap |= 1 << id;
 	vm->id = id;
 	list_add_tail(&vm->list, &rdev->vm_manager.lru_vm);
-	return radeon_vm_bo_update_pte(rdev, vm, rdev->ib_pool.sa_manager.bo,
-				       &rdev->ib_pool.sa_manager.bo->tbo.mem);
+	return radeon_vm_bo_update_pte(rdev, vm, rdev->sa_manager.bo,
+				       &rdev->sa_manager.bo->tbo.mem);
 }
 
 /* object have to be reserved */
@@ -633,7 +633,7 @@ int radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm)
 	/* map the ib pool buffer at 0 in virtual address space, set
 	 * read only
 	 */
-	r = radeon_vm_bo_add(rdev, vm, rdev->ib_pool.sa_manager.bo, 0,
+	r = radeon_vm_bo_add(rdev, vm, rdev->sa_manager.bo, 0,
 			     RADEON_VM_PAGE_READABLE | RADEON_VM_PAGE_SNOOPED);
 	return r;
 }
@@ -650,12 +650,12 @@ void radeon_vm_fini(struct radeon_device *rdev, struct radeon_vm *vm)
 	radeon_mutex_unlock(&rdev->cs_mutex);
 
 	/* remove all bo */
-	r = radeon_bo_reserve(rdev->ib_pool.sa_manager.bo, false);
+	r = radeon_bo_reserve(rdev->sa_manager.bo, false);
 	if (!r) {
-		bo_va = radeon_bo_va(rdev->ib_pool.sa_manager.bo, vm);
+		bo_va = radeon_bo_va(rdev->sa_manager.bo, vm);
 		list_del_init(&bo_va->bo_list);
 		list_del_init(&bo_va->vm_list);
-		radeon_bo_unreserve(rdev->ib_pool.sa_manager.bo);
+		radeon_bo_unreserve(rdev->sa_manager.bo);
 		kfree(bo_va);
 	}
 	if (!list_empty(&vm->va)) {
drivers/gpu/drm/radeon/radeon_ring.c +69 -171

346 lines not on this page · raw message

drivers/gpu/drm/radeon/radeon_semaphore.c +3 -3
index 4603fab..a09cc05 100644
@@ -42,7 +42,7 @@ int radeon_semaphore_create(struct radeon_device *rdev,
 		return -ENOMEM;
 	}
 
-	r = radeon_sa_bo_new(rdev, &rdev->ib_pool.sa_manager, 
+	r = radeon_sa_bo_new(rdev, &rdev->sa_manager, 
 			     &(*semaphore)->sa_bo, 8, 8);
 	if (r) {
 		kfree(*semaphore);
@@ -51,10 +51,10 @@ int radeon_semaphore_create(struct radeon_device *rdev,
 	}
 
 	(*semaphore)->waiters = 0;	
-	(*semaphore)->gpu_addr = rdev->ib_pool.sa_manager.gpu_addr;
+	(*semaphore)->gpu_addr = rdev->sa_manager.gpu_addr;
 	(*semaphore)->gpu_addr += (*semaphore)->sa_bo.offset;
 
-	cpu_ptr = rdev->ib_pool.sa_manager.cpu_ptr;
+	cpu_ptr = rdev->sa_manager.cpu_ptr;
 	cpu_ptr += (*semaphore)->sa_bo.offset;
 	*((uint64_t*)cpu_ptr) = 0;
 
Signature · 6 lines
1.7.5.4

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

PATCH 12/13 drm/radeon: fix a bug with the ring syncing code

In reply to Christian König

Rings need to lock in order, otherwise
the ring subsystem can deadlock.

---
 drivers/gpu/drm/radeon/radeon.h           |    4 ++
 drivers/gpu/drm/radeon/radeon_cs.c        |   33 ++++++------------
 drivers/gpu/drm/radeon/radeon_semaphore.c |   53 +++++++++++++++++++++++++++++
 drivers/gpu/drm/radeon/radeon_ttm.c       |   46 +++++++++++--------------
 4 files changed, 88 insertions(+), 48 deletions(-)
drivers/gpu/drm/radeon/radeon.h +4 -0
index d46d5ac..5912cab 100644
@@ -442,6 +442,10 @@ void radeon_semaphore_emit_signal(struct radeon_device *rdev, int ring,
 				  struct radeon_semaphore *semaphore);
 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);
 void radeon_semaphore_free(struct radeon_device *rdev,
 			   struct radeon_semaphore *semaphore);
 
drivers/gpu/drm/radeon/radeon_cs.c +11 -22
index e7b0b5d..de40d33 100644
@@ -118,6 +118,7 @@ static int radeon_cs_get_ring(struct radeon_cs_parser *p, u32 ring, s32 priority
 static int radeon_cs_sync_rings(struct radeon_cs_parser *p)
 {
 	bool sync_to_ring[RADEON_NUM_RINGS] = { };
+	bool need_sync = false;
 	int i, r;
 
 	for (i = 0; i < p->nrelocs; i++) {
@@ -128,34 +129,22 @@ static int radeon_cs_sync_rings(struct radeon_cs_parser *p)
 			struct radeon_fence *fence = p->relocs[i].robj->tbo.sync_obj;
 			if (!radeon_fence_signaled(fence)) {
 				sync_to_ring[fence->ring] = true;
+				need_sync = true;
 			}
 		}
 	}
 
-	for (i = 0; i < RADEON_NUM_RINGS; ++i) {
-		/* no need to sync to our own or unused rings */
-		if (i == p->ring || !sync_to_ring[i] || !p->rdev->ring[i].ready)
-			continue;
-
-		if (!p->ib->fence->semaphore) {
-			r = radeon_semaphore_create(p->rdev, &p->ib->fence->semaphore);
-			if (r)
-				return r;
-		}
-
-		r = radeon_ring_lock(p->rdev, &p->rdev->ring[i], 3);
-		if (r)
-			return r;
-		radeon_semaphore_emit_signal(p->rdev, i, p->ib->fence->semaphore);
-		radeon_ring_unlock_commit(p->rdev, &p->rdev->ring[i]);
+	if (!need_sync) {
+		return 0;
+	}
 
-		r = radeon_ring_lock(p->rdev, &p->rdev->ring[p->ring], 3);
-		if (r)
-			return r;
-		radeon_semaphore_emit_wait(p->rdev, p->ring, p->ib->fence->semaphore);
-		radeon_ring_unlock_commit(p->rdev, &p->rdev->ring[p->ring]);
+	r = radeon_semaphore_create(p->rdev, &p->ib->fence->semaphore);
+	if (r) {
+		return r;
 	}
-	return 0;
+
+	return radeon_semaphore_sync_rings(p->rdev, p->ib->fence->semaphore,
+					   sync_to_ring, p->ring);
 }
 
 int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data)
drivers/gpu/drm/radeon/radeon_semaphore.c +53 -0

59 lines not on this page · raw message

drivers/gpu/drm/radeon/radeon_ttm.c +21 -27

77 lines not on this page · raw message

Signature · 6 lines
1.7.5.4

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

Re: [PATCH 12/13] drm/radeon: fix a bug with the ring syncing code

2012/4/19 Christian König <[email protected]>:

Quoted 2 lines

Rings need to lock in order, otherwise
the ring subsystem can deadlock.

No sure if its the commit or not but I was profiling on an r700 and saw it create a semaphore for ring syncing.

surely the r700 would have no need?

Dave.

#21 lore raw

Re: [PATCH 12/13] drm/radeon: fix a bug with the ring syncing code

Quoted 8 lines · Dave Airlie

2012/4/19 Christian König<[email protected]>:

Quoted 2 lines

Rings need to lock in order, otherwise
the ring subsystem can deadlock.

No sure if its the commit or not but I was profiling on an r700 and saw it create a semaphore for ring syncing.

surely the r700 would have no need?

In theory the first hardware with more than a gfx ring was some r6xx (but of course we haven't released any code/documentation for that yet), so it's ok that the code generally checks for inter ring synchronization needs on r7xx cards.

But with the current mainline it should just boil down to an not taken "if" branch, witch it currently doesn't (*crap*). Just tested with my RV710 and I can confirm that it unnecessarily allocates a semaphore. Another bug on my todo list for this patchset, going to send out an v2 soon, but going to test it through first.

Thanks for the comment,
Christian.

#22 lore raw

PATCH 13/13 drm/radeon: rework recursive gpu reset handling

In reply to Christian König

Instead of all this humpy pumpy with recursive mutex (which also fixes only halve of the problem) move the actual gpu reset out of the fence code, return -EDEADLK and then reset the gpu in the calling ioctl function.

---
 drivers/gpu/drm/radeon/radeon.h        |   44 +-------------------------------
 drivers/gpu/drm/radeon/radeon_cs.c     |   21 +++++++++++---
 drivers/gpu/drm/radeon/radeon_device.c |    7 +----
 drivers/gpu/drm/radeon/radeon_fence.c  |   10 ++-----
 drivers/gpu/drm/radeon/radeon_gart.c   |   16 ++++++------
 drivers/gpu/drm/radeon/radeon_gem.c    |   14 ++++++++++
 6 files changed, 43 insertions(+), 69 deletions(-)
drivers/gpu/drm/radeon/radeon.h +1 -43
index 5912cab..aadc334 100644
@@ -155,48 +155,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
  */
@@ -1497,7 +1455,7 @@ 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 mutex			cs_mutex;
 	struct radeon_wb		wb;
 	struct radeon_dummy_page	dummy_page;
 	bool				shutdown;
drivers/gpu/drm/radeon/radeon_cs.c +16 -5
index de40d33..2486b21 100644
@@ -496,15 +496,23 @@ out:
 	return r;
 }
 
+static int radeon_cs_handle_lockup(struct radeon_device *rdev, int r)
+{
+	if (r == -EDEADLK) {
+		r = radeon_gpu_reset(rdev);
+	}
+	return r;
+}
+
 int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 {
 	struct radeon_device *rdev = dev->dev_private;
 	struct radeon_cs_parser parser;
 	int r;
 
-	radeon_mutex_lock(&rdev->cs_mutex);
+	mutex_lock(&rdev->cs_mutex);
 	if (!rdev->accel_working) {
-		radeon_mutex_unlock(&rdev->cs_mutex);
+		mutex_unlock(&rdev->cs_mutex);
 		return -EBUSY;
 	}
 	/* initialize parser */
@@ -517,7 +525,8 @@ int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 	if (r) {
 		DRM_ERROR("Failed to initialize parser !\n");
 		radeon_cs_parser_fini(&parser, r);
-		radeon_mutex_unlock(&rdev->cs_mutex);
+		r = radeon_cs_handle_lockup(rdev, r);
+		mutex_unlock(&rdev->cs_mutex);
 		return r;
 	}
 	r = radeon_cs_parser_relocs(&parser);
@@ -525,7 +534,8 @@ int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 		if (r != -ERESTARTSYS)
 			DRM_ERROR("Failed to parse relocation %d!\n", r);
 		radeon_cs_parser_fini(&parser, r);
-		radeon_mutex_unlock(&rdev->cs_mutex);
+		r = radeon_cs_handle_lockup(rdev, r);
+		mutex_unlock(&rdev->cs_mutex);
 		return r;
 	}
 	r = radeon_cs_ib_chunk(rdev, &parser);
@@ -538,7 +548,8 @@ int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 	}
 out:
 	radeon_cs_parser_fini(&parser, r);
-	radeon_mutex_unlock(&rdev->cs_mutex);
+	r = radeon_cs_handle_lockup(rdev, r);
+	mutex_unlock(&rdev->cs_mutex);
 	return r;
 }
 
drivers/gpu/drm/radeon/radeon_device.c +1 -6
index 9189f8d..04f3f40 100644
@@ -722,7 +722,7 @@ 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->cs_mutex);
 	for (i = 0; i < RADEON_NUM_RINGS; ++i)
 		mutex_init(&rdev->ring[i].mutex);
 	mutex_init(&rdev->dc_hw_i2c_mutex);
@@ -983,9 +983,6 @@ int radeon_gpu_reset(struct radeon_device *rdev)
 	int r;
 	int resched;
 
-	/* Prevent CS ioctl from interfering */
-	radeon_mutex_lock(&rdev->cs_mutex);
-
 	radeon_save_bios_scratch_regs(rdev);
 	/* block TTM */
 	resched = ttm_bo_lock_delayed_workqueue(&rdev->mman.bdev);
@@ -1000,8 +997,6 @@ int radeon_gpu_reset(struct radeon_device *rdev)
 		ttm_bo_unlock_delayed_workqueue(&rdev->mman.bdev, resched);
 	}
 
-	radeon_mutex_unlock(&rdev->cs_mutex);
-
 	if (r) {
 		/* bad news, how to tell it to userspace ? */
 		dev_info(rdev->dev, "GPU reset failed\n");
drivers/gpu/drm/radeon/radeon_fence.c +3 -7
index 0e8ac35..ea7aee3 100644
@@ -267,6 +267,8 @@ int radeon_fence_wait(struct radeon_fence *fence, bool intr)
 			/* change sequence value on all rings, so nobody else things there is a lockup */
 			for (i = 0; i < RADEON_NUM_RINGS; ++i)
 				rdev->fence_drv[i].last_seq -= 0x10000;
+
+			rdev->fence_drv[fence->ring].last_activity = jiffies;
 			write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
 
 			if (radeon_ring_is_lockup(rdev, fence->ring, &rdev->ring[fence->ring])) {
@@ -277,13 +279,7 @@ int radeon_fence_wait(struct radeon_fence *fence, bool intr)
 
 				/* mark the ring as not ready any more */
 				rdev->ring[fence->ring].ready = false;
-				r = radeon_gpu_reset(rdev);
-				if (r)
-					return r;
-
-				write_lock_irqsave(&rdev->fence_lock, irq_flags);
-				rdev->fence_drv[fence->ring].last_activity = jiffies;
-				write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
+				return -EDEADLK;
 			}
 		}
 	}
drivers/gpu/drm/radeon/radeon_gart.c +8 -8
index 0ab3277..450ae77 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->cs_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->cs_mutex);
 	return radeon_sa_bo_manager_suspend(rdev, &rdev->vm_manager.sa_manager);
 }
 
@@ -480,9 +480,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->cs_mutex);
 		radeon_vm_unbind_locked(rdev, vm);
-		radeon_mutex_unlock(&rdev->cs_mutex);
+		mutex_unlock(&rdev->cs_mutex);
 		vm->last_pfn = (last_pfn + align) & ~align;
 	}
 	head = &vm->va;
@@ -598,9 +598,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->cs_mutex);
 	radeon_vm_bo_update_pte(rdev, vm, bo, NULL);
-	radeon_mutex_unlock(&rdev->cs_mutex);
+	mutex_unlock(&rdev->cs_mutex);
 	list_del(&bo_va->vm_list);
 	mutex_unlock(&vm->mutex);
 	list_del(&bo_va->bo_list);
@@ -645,9 +645,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->cs_mutex);
 	radeon_vm_unbind_locked(rdev, vm);
-	radeon_mutex_unlock(&rdev->cs_mutex);
+	mutex_unlock(&rdev->cs_mutex);
 
 	/* remove all bo */
 	r = radeon_bo_reserve(rdev->sa_manager.bo, false);
drivers/gpu/drm/radeon/radeon_gem.c +14 -0
index c7008b5..f65377f 100644
@@ -154,6 +154,15 @@ void radeon_gem_object_close(struct drm_gem_object *obj,
 	radeon_bo_unreserve(rbo);
 }
 
+static int radeon_gem_handle_lockup(struct radeon_device *rdev, int r)
+{
+	if (r == -EDEADLK) {
+		mutex_lock(&rdev->cs_mutex);
+		r = radeon_gpu_reset(rdev);
+		mutex_unlock(&rdev->cs_mutex);
+	}
+	return r;
+}
 
 /*
  * GEM ioctls.
@@ -210,12 +219,14 @@ int radeon_gem_create_ioctl(struct drm_device *dev, void *data,
 					args->initial_domain, false,
 					false, &gobj);
 	if (r) {
+		r = radeon_gem_handle_lockup(rdev, r);
 		return r;
 	}
 	r = drm_gem_handle_create(filp, gobj, &handle);
 	/* drop reference from allocate - handle holds it now */
 	drm_gem_object_unreference_unlocked(gobj);
 	if (r) {
+		r = radeon_gem_handle_lockup(rdev, r);
 		return r;
 	}
 	args->handle = handle;
@@ -245,6 +256,7 @@ int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
 	r = radeon_gem_set_domain(gobj, args->read_domains, args->write_domain);
 
 	drm_gem_object_unreference_unlocked(gobj);
+	r = radeon_gem_handle_lockup(robj->rdev, r);
 	return r;
 }
 
@@ -301,6 +313,7 @@ int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
 		break;
 	}
 	drm_gem_object_unreference_unlocked(gobj);
+	r = radeon_gem_handle_lockup(robj->rdev, r);
 	return r;
 }
 
@@ -322,6 +335,7 @@ int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
 	if (robj->rdev->asic->ioctl_wait_idle)
 		robj->rdev->asic->ioctl_wait_idle(robj->rdev, robj);
 	drm_gem_object_unreference_unlocked(gobj);
+	r = radeon_gem_handle_lockup(robj->rdev, r);
 	return r;
 }
 
Signature · 6 lines
1.7.5.4

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

Re: [PATCH 13/13] drm/radeon: rework recursive gpu reset handling

2012/4/19 Christian König <[email protected]>:

Quoted 5 lines

Instead of all this humpy pumpy with recursive mutex (which also fixes only halve of the problem) move the actual gpu reset out of the fence code, return -EDEADLK and then reset the gpu in the calling ioctl function.

I'm trying to figure out if this has any disadvantages over doing what I proposed before and just kicking a thread to reset the gpu.

It seems like this should also avoid the locking problems, I'd like to make sure we don't return -EDEADLK to userspace by accident anywhere, since I don't think it prepared for it and it would be an ABI change.

Dave.

#24 lore raw

Re: [PATCH 13/13] drm/radeon: rework recursive gpu reset handling

Quoted 7 lines · Dave Airlie

2012/4/19 Christian König <[email protected]>:

Quoted 5 lines

Instead of all this humpy pumpy with recursive mutex (which also fixes only halve of the problem) move the actual gpu reset out of the fence code, return -EDEADLK and then reset the gpu in the calling ioctl function.

Quoted 6 lines

I'm trying to figure out if this has any disadvantages over doing what I proposed before and just kicking a thread to reset the gpu.

It seems like this should also avoid the locking problems, I'd like to make sure we don't return -EDEADLK to userspace by accident anywhere, since I don't think it prepared for it and it would be an ABI change.

Fyi, the trick i915 uses to solve the reset problem is to bail out with -EAGAIN and rely on drmIOCtl restarting the ioctl. This way we use the same codepaths we use to bail out when getting a signal, and thanks to X these are rather well-tested. The hangcheck code also fires of a work item to do all the reset magic. In all the ioctls that might wait for the gpu we have a fancy piece of code which checks whether a gpu reset is pending, and if so waits for that to complete. It also checks whether the reset succeeded and if not bails out with -EIO.
-Daniel

Signature · 3 lines
Daniel Vetter
Mail: [email protected]
Mobile: +41 (0)79 365 57 48
#25 lore raw

Re: [PATCH 13/13] drm/radeon: rework recursive gpu reset handling

Quoted 13 lines · Daniel Vetter
Quoted 6 lines · Dave Airlie

2012/4/19 Christian König<[email protected]>:

Quoted 5 lines

Instead of all this humpy pumpy with recursive mutex (which also fixes only halve of the problem) move the actual gpu reset out of the fence code, return -EDEADLK and then reset the gpu in the calling ioctl function.

Quoted 6 lines

I'm trying to figure out if this has any disadvantages over doing what I proposed before and just kicking a thread to reset the gpu.

It seems like this should also avoid the locking problems, I'd like to make sure we don't return -EDEADLK to userspace by accident anywhere, since I don't think it prepared for it and it would be an ABI change.

Quoted 9 lines

Fyi, the trick i915 uses to solve the reset problem is to bail out with -EAGAIN and rely on drmIOCtl restarting the ioctl. This way we use the same codepaths we use to bail out when getting a signal, and thanks to X these are rather well-tested. The hangcheck code also fires of a work item to do all the reset magic. In all the ioctls that might wait for the gpu we have a fancy piece of code which checks whether a gpu reset is pending, and if so waits for that to complete. It also checks whether the reset succeeded and if not bails out with -EIO.
-Daniel

Well I considered using an asynchronous work item also, but didn't know how to probably prevent multiple GPU resets at the same time, signaling the result back to the ioctls, etc.. It just seemed to be more complicated without any real benefit (maybe except that you don't have to check every ioctl result separately, but there are not so many).

Also I didn't know what to tell userspace to retry the current operation, but if it's already prepared for -EAGAIN than this sounds like the proper solution here.

And regarding returning -EDEADLK to userspace: I think I handle every ioctl that could cause the lockup detection to run, but checking that again won't hurt.

Christian.

#26 lore raw
In reply to Christian König

2012/4/19 Christian König <[email protected]>:

Quoted 8 lines

This includes mostly fixes for multi ring lockups and GPU resets, but it should general improve the behavior of the kernel mode driver in case something goes badly wrong.

On the other hand it completely rewrites the IB pool and semaphore handling, so I think there are still a couple of problems in it.

The first four patches were already send to the list, but the current set depends on them so I resend them again.

Cheers,
Christian.

I did a quick review, it looks mostly good, but as it's sensitive code i would like to spend sometime on
it. Probably next week. Note that i had some work on this area too, i mostly want to drop all the debugfs
related to this and add some new more usefull (basicly something that allow you to read all the data
needed to replay a locking up ib). I also was looking into Dave reset thread and your solution of moving
reset in ioctl return path sounds good too but i need to convince my self that it encompass all possible
case.

Cheers,
Jerome

#27 lore raw
Quoted 21 lines · Jerome Glisse

2012/4/19 Christian König<[email protected]>:

Quoted 8 lines

This includes mostly fixes for multi ring lockups and GPU resets, but it should general improve the behavior of the kernel mode driver in case something goes badly wrong.

On the other hand it completely rewrites the IB pool and semaphore handling, so I think there are still a couple of problems in it.

The first four patches were already send to the list, but the current set depends on them so I resend them again.

Cheers,
Christian.

I did a quick review, it looks mostly good, but as it's sensitive code i would like to spend sometime on
it. Probably next week. Note that i had some work on this area too, i mostly want to drop all the debugfs
related to this and add some new more usefull (basicly something that allow you to read all the data
needed to replay a locking up ib). I also was looking into Dave reset thread and your solution of moving
reset in ioctl return path sounds good too but i need to convince my self that it encompass all possible
case.

Quoted 3 lines

Cheers,
Jerome

After sleeping a night over it I already reworked the patch for improving the SA performance, so please wait at least for v2 before taking a look at it :)

Regarding the debugging of lockups I had the following on my "in mind todo" list:
1. Rework the chip specific lockup detection code a bit more and probably clean it up a bit.
2. Make the timeout a module parameter, cause compute task sometimes block a ring for more than 10 seconds.
3. Keep track of the actually RPTR offset a fence is emitted to
3. Keep track of all the BOs a IB is touching.
4. Now if a lockup happens start with the last successfully signaled fence and dump the ring content after that RPTR offset till the first not signaled fence.
5. Then if this fence references to an IB dump it's content and the BOs it is touching.
6. Dump everything on the ring after that fence until you reach the RPTR of the next fence or the WPTR of the ring.
7. If there is a next fence repeat the whole thing at number 5.

If I'm not completely wrong that should give you practically every information available, and we probably should put that behind another module option, cause we are going to spam syslog pretty much here. Feel free to add/modify the ideas on this list.

Christian.

#28 lore raw

2012/4/21 Christian König <[email protected]>:

Quoted 53 lines · Jerome Glisse
Quoted 28 lines

2012/4/19 Christian König<[email protected]>:

Quoted 5 lines

This includes mostly fixes for multi ring lockups and GPU resets, but it should general improve the behavior of the kernel mode driver in case something goes badly wrong.

Quoted 8 lines

On the other hand it completely rewrites the IB pool and semaphore handling, so I think there are still a couple of problems in it.

The first four patches were already send to the list, but the current set depends on them so I resend them again.

Cheers,
Christian.

I did a quick review, it looks mostly good, but as it's sensitive code i would like to spend sometime on
it. Probably next week. Note that i had some work on this area too, i mostly want to drop all the debugfs
related to this and add some new more usefull (basicly something that allow you to read all the data
needed to replay a locking up ib). I also was looking into Dave reset thread and your solution of moving
reset in ioctl return path sounds good too but i need to convince my self that it encompass all possible
case.

Quoted 3 lines

Cheers,
Jerome

After sleeping a night over it I already reworked the patch for improving the SA performance, so please wait at least for v2 before taking a look at it :)

Regarding the debugging of lockups I had the following on my "in mind todo" list:
1. Rework the chip specific lockup detection code a bit more and probably clean it up a bit.
2. Make the timeout a module parameter, cause compute task sometimes block a ring for more than 10 seconds.
3. Keep track of the actually RPTR offset a fence is emitted to
3. Keep track of all the BOs a IB is touching.
4. Now if a lockup happens start with the last successfully signaled fence and dump the ring content after that RPTR offset till the first not signaled fence.
5. Then if this fence references to an IB dump it's content and the BOs it is touching.
6. Dump everything on the ring after that fence until you reach the RPTR of the next fence or the WPTR of the ring.
7. If there is a next fence repeat the whole thing at number 5.

Quoted 6 lines

If I'm not completely wrong that should give you practically every information available, and we probably should put that behind another module option, cause we are going to spam syslog pretty much here. Feel free to add/modify the ideas on this list.

Christian.

What i have is similar, i am assuming only ib trigger lockup, before each ib emit to scratch reg ib offset in sa and ib size. For each ib keep bo list. On lockup allocate big memory to copy the whole ib and all the bo referenced by the ib (i am using my bof format as i already have userspace tools).

Remove all the debugfs file. Just add a new one that gave you the first faulty ib. On read of this file kernel free the memory. Kernel should also free the memory after a while or better would be to enable the lockup copy only if some kernel radeon option is enabled.

Cheers,
Jerome

#29 lore raw
Quoted 62 lines · Jerome Glisse

2012/4/21 Christian König<[email protected]>:

Quoted 50 lines · Jerome Glisse
Quoted 25 lines

2012/4/19 Christian König<[email protected]>:

Quoted 4 lines

This includes mostly fixes for multi ring lockups and GPU resets, but it should general improve the behavior of the kernel mode driver in case something goes badly wrong.

Quoted 8 lines

On the other hand it completely rewrites the IB pool and semaphore handling, so I think there are still a couple of problems in it.

The first four patches were already send to the list, but the current set depends on them so I resend them again.

Cheers,
Christian.

I did a quick review, it looks mostly good, but as it's sensitive code i would like to spend sometime on
it. Probably next week. Note that i had some work on this area too, i mostly want to drop all the debugfs
related to this and add some new more usefull (basicly something that allow you to read all the data
needed to replay a locking up ib). I also was looking into Dave reset thread and your solution of moving
reset in ioctl return path sounds good too but i need to convince my self that it encompass all possible
case.

Quoted 3 lines

Cheers,
Jerome

After sleeping a night over it I already reworked the patch for improving the SA performance, so please wait at least for v2 before taking a look at it :)

Regarding the debugging of lockups I had the following on my "in mind todo" list:
1. Rework the chip specific lockup detection code a bit more and probably clean it up a bit.
2. Make the timeout a module parameter, cause compute task sometimes block a ring for more than 10 seconds.
3. Keep track of the actually RPTR offset a fence is emitted to
3. Keep track of all the BOs a IB is touching.
4. Now if a lockup happens start with the last successfully signaled fence and dump the ring content after that RPTR offset till the first not signaled fence.
5. Then if this fence references to an IB dump it's content and the BOs it is touching.
6. Dump everything on the ring after that fence until you reach the RPTR of the next fence or the WPTR of the ring.
7. If there is a next fence repeat the whole thing at number 5.

Quoted 6 lines

If I'm not completely wrong that should give you practically every information available, and we probably should put that behind another module option, cause we are going to spam syslog pretty much here. Feel free to add/modify the ideas on this list.

Christian.

What i have is similar, i am assuming only ib trigger lockup, before each ib emit to scratch reg ib offset in sa and ib size. For each ib keep bo list. On lockup allocate big memory to copy the whole ib and all the bo referenced by the ib (i am using my bof format as i already have userspace tools).

Quoted 4 lines

Remove all the debugfs file. Just add a new one that gave you the first faulty ib. On read of this file kernel free the memory. Kernel should also free the memory after a while or better would be to enable the lockup copy only if some kernel radeon option is enabled.

Just resent my current patchset to the mailing list, it's not as complete as your solution, but seems to be a step into the right direction. So please take a look at them.

Being able to generate something like a "GPU crash dump" on lockup sounds like something very valuable to me, but I'm not sure if debugfs files are the right direction to go. Maybe something more like a module parameter containing a directory, and if set we dump all informations (including bo content) available in binary form (instead of the current human readable form of the debugfs files).

Anyway, the just send patchset solves the problem I'm currently looking into, and I'm running a bit out of time (again). So I don't know if I can complete that solution....

Cheers,
Christian.

maintainer
#30 lore raw

2012/4/25 Christian König <[email protected]>:

Quoted 93 lines · Jerome Glisse
Quoted 80 lines

2012/4/21 Christian König<[email protected]>:

Quoted 63 lines · Jerome Glisse
Quoted 30 lines

2012/4/19 Christian König<[email protected]>:

Quoted 9 lines

This includes mostly fixes for multi ring lockups and GPU resets, but it
should general improve the behavior of the kernel mode driver in case something goes badly wrong.

On the other hand it completely rewrites the IB pool and semaphore handling, so I think there are still a couple of problems in it.

Quoted 6 lines

The first four patches were already send to the list, but the current set
depends on them so I resend them again.

Cheers,
Christian.

I did a quick review, it looks mostly good, but as it's sensitive code i would like to spend sometime on
it. Probably next week. Note that i had some work on this area too, i mostly want to drop all the debugfs
related to this and add some new more usefull (basicly something that allow you to read all the data
needed to replay a locking up ib). I also was looking into Dave reset thread and your solution of moving
reset in ioctl return path sounds good too but i need to convince my self that it encompass all possible
case.

Quoted 3 lines

Cheers,
Jerome

After sleeping a night over it I already reworked the patch for improving the SA performance, so please wait at least for v2 before taking a look at
it :)

Regarding the debugging of lockups I had the following on my "in mind todo"
list:
1. Rework the chip specific lockup detection code a bit more and probably clean it up a bit.
2. Make the timeout a module parameter, cause compute task sometimes block a
ring for more than 10 seconds.
3. Keep track of the actually RPTR offset a fence is emitted to
3. Keep track of all the BOs a IB is touching.
4. Now if a lockup happens start with the last successfully signaled fence
and dump the ring content after that RPTR offset till the first not signaled
fence.
5. Then if this fence references to an IB dump it's content and the BOs it
is touching.
6. Dump everything on the ring after that fence until you reach the RPTR of
the next fence or the WPTR of the ring.
7. If there is a next fence repeat the whole thing at number 5.

Quoted 7 lines

If I'm not completely wrong that should give you practically every information available, and we probably should put that behind another module
option, cause we are going to spam syslog pretty much here. Feel free to add/modify the ideas on this list.

Christian.

What i have is similar, i am assuming only ib trigger lockup, before each ib
emit to scratch reg ib offset in sa and ib size. For each ib keep bo list. On
lockup allocate big memory to copy the whole ib and all the bo referenced by the ib (i am using my bof format as i already have userspace tools).

Quoted 6 lines

Remove all the debugfs file. Just add a new one that gave you the first faulty
ib. On read of this file kernel free the memory. Kernel should also free the
memory after a while or better would be to enable the lockup copy only if some kernel radeon option is enabled.

Just resent my current patchset to the mailing list, it's not as complete as your solution, but seems to be a step into the right direction. So please take a look at them.

Quoted 6 lines

Being able to generate something like a "GPU crash dump" on lockup sounds like something very valuable to me, but I'm not sure if debugfs files are the right direction to go. Maybe something more like a module parameter containing a directory, and if set we dump all informations (including bo content) available in binary form (instead of the current human readable form of the debugfs files).

Do what intel driver does, create a versioned binary debugfs file with all the error state in it for a lockup,
store only one of these at a time, run a userspace tool to dump it out into something you can
upload or just cat the file and upload it.

You don't want the kernel writing to dirs on disk under any circumstances

Dave.

#31 lore raw

2012/4/25 Dave Airlie <[email protected]>:

Quoted 101 lines

2012/4/25 Christian König <[email protected]>:

Quoted 93 lines · Jerome Glisse
Quoted 80 lines

2012/4/21 Christian König<[email protected]>:

Quoted 63 lines · Jerome Glisse
Quoted 30 lines

2012/4/19 Christian König<[email protected]>:

Quoted 9 lines

This includes mostly fixes for multi ring lockups and GPU resets, but it
should general improve the behavior of the kernel mode driver in case something goes badly wrong.

On the other hand it completely rewrites the IB pool and semaphore handling, so I think there are still a couple of problems in it.

Quoted 6 lines

The first four patches were already send to the list, but the current set
depends on them so I resend them again.

Cheers,
Christian.

I did a quick review, it looks mostly good, but as it's sensitive code i would like to spend sometime on
it. Probably next week. Note that i had some work on this area too, i mostly want to drop all the debugfs
related to this and add some new more usefull (basicly something that allow you to read all the data
needed to replay a locking up ib). I also was looking into Dave reset thread and your solution of moving
reset in ioctl return path sounds good too but i need to convince my self that it encompass all possible
case.

Quoted 3 lines

Cheers,
Jerome

After sleeping a night over it I already reworked the patch for improving the SA performance, so please wait at least for v2 before taking a look at
it :)

Regarding the debugging of lockups I had the following on my "in mind todo"
list:
1. Rework the chip specific lockup detection code a bit more and probably clean it up a bit.
2. Make the timeout a module parameter, cause compute task sometimes block a
ring for more than 10 seconds.
3. Keep track of the actually RPTR offset a fence is emitted to
3. Keep track of all the BOs a IB is touching.
4. Now if a lockup happens start with the last successfully signaled fence
and dump the ring content after that RPTR offset till the first not signaled
fence.
5. Then if this fence references to an IB dump it's content and the BOs it
is touching.
6. Dump everything on the ring after that fence until you reach the RPTR of
the next fence or the WPTR of the ring.
7. If there is a next fence repeat the whole thing at number 5.

Quoted 7 lines

If I'm not completely wrong that should give you practically every information available, and we probably should put that behind another module
option, cause we are going to spam syslog pretty much here. Feel free to add/modify the ideas on this list.

Christian.

What i have is similar, i am assuming only ib trigger lockup, before each ib
emit to scratch reg ib offset in sa and ib size. For each ib keep bo list. On
lockup allocate big memory to copy the whole ib and all the bo referenced by the ib (i am using my bof format as i already have userspace tools).

Quoted 6 lines

Remove all the debugfs file. Just add a new one that gave you the first faulty
ib. On read of this file kernel free the memory. Kernel should also free the
memory after a while or better would be to enable the lockup copy only if some kernel radeon option is enabled.

Just resent my current patchset to the mailing list, it's not as complete as your solution, but seems to be a step into the right direction. So please take a look at them.

Quoted 6 lines

Being able to generate something like a "GPU crash dump" on lockup sounds like something very valuable to me, but I'm not sure if debugfs files are the right direction to go. Maybe something more like a module parameter containing a directory, and if set we dump all informations (including bo content) available in binary form (instead of the current human readable form of the debugfs files).

Quoted 8 lines

Do what intel driver does, create a versioned binary debugfs file with all the error state in it for a lockup,
store only one of these at a time, run a userspace tool to dump it out into something you can
upload or just cat the file and upload it.

You don't want the kernel writing to dirs on disk under any circumstances

We have an internal binary format for dumping command streams and associated buffers, we should probably use that so that we can better take advantage of existing internal tools.

Alex

Quoted 5 lines

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

#32 lore raw
Quoted 108 lines · Alex Deucher

2012/4/25 Dave Airlie <[email protected]>:

Quoted 107 lines

2012/4/25 Christian König <[email protected]>:

Quoted 93 lines · Jerome Glisse
Quoted 80 lines

2012/4/21 Christian König<[email protected]>:

Quoted 63 lines · Jerome Glisse
Quoted 30 lines

2012/4/19 Christian König<[email protected]>:

Quoted 9 lines

This includes mostly fixes for multi ring lockups and GPU resets, but it
should general improve the behavior of the kernel mode driver in case something goes badly wrong.

On the other hand it completely rewrites the IB pool and semaphore handling, so I think there are still a couple of problems in it.

Quoted 6 lines

The first four patches were already send to the list, but the current set
depends on them so I resend them again.

Cheers,
Christian.

I did a quick review, it looks mostly good, but as it's sensitive code i would like to spend sometime on
it. Probably next week. Note that i had some work on this area too, i mostly want to drop all the debugfs
related to this and add some new more usefull (basicly something that allow you to read all the data
needed to replay a locking up ib). I also was looking into Dave reset thread and your solution of moving
reset in ioctl return path sounds good too but i need to convince my self that it encompass all possible
case.

Quoted 3 lines

Cheers,
Jerome

After sleeping a night over it I already reworked the patch for improving the SA performance, so please wait at least for v2 before taking a look at
it :)

Regarding the debugging of lockups I had the following on my "in mind todo"
list:
1. Rework the chip specific lockup detection code a bit more and probably clean it up a bit.
2. Make the timeout a module parameter, cause compute task sometimes block a
ring for more than 10 seconds.
3. Keep track of the actually RPTR offset a fence is emitted to
3. Keep track of all the BOs a IB is touching.
4. Now if a lockup happens start with the last successfully signaled fence
and dump the ring content after that RPTR offset till the first not signaled
fence.
5. Then if this fence references to an IB dump it's content and the BOs it
is touching.
6. Dump everything on the ring after that fence until you reach the RPTR of
the next fence or the WPTR of the ring.
7. If there is a next fence repeat the whole thing at number 5.

Quoted 7 lines

If I'm not completely wrong that should give you practically every information available, and we probably should put that behind another module
option, cause we are going to spam syslog pretty much here. Feel free to add/modify the ideas on this list.

Christian.

What i have is similar, i am assuming only ib trigger lockup, before each ib
emit to scratch reg ib offset in sa and ib size. For each ib keep bo list. On
lockup allocate big memory to copy the whole ib and all the bo referenced by the ib (i am using my bof format as i already have userspace tools).

Quoted 6 lines

Remove all the debugfs file. Just add a new one that gave you the first faulty
ib. On read of this file kernel free the memory. Kernel should also free the
memory after a while or better would be to enable the lockup copy only if some kernel radeon option is enabled.

Just resent my current patchset to the mailing list, it's not as complete as your solution, but seems to be a step into the right direction. So please take a look at them.

Quoted 6 lines

Being able to generate something like a "GPU crash dump" on lockup sounds like something very valuable to me, but I'm not sure if debugfs files are the right direction to go. Maybe something more like a module parameter containing a directory, and if set we dump all informations (including bo content) available in binary form (instead of the current human readable form of the debugfs files).

Do what intel driver does, create a versioned binary debugfs file with all the error state in it for a lockup,
store only one of these at a time, run a userspace tool to dump it out into something you can
upload or just cat the file and upload it.

Quoted 9 lines
Quoted 2 lines

You don't want the kernel writing to dirs on disk under any circumstances

We have an internal binary format for dumping command streams and associated buffers, we should probably use that so that we can better take advantage of existing internal tools.

Alex

I really would like to drop all the debugfs file related to ib/ring with this patchset. Note that i also have a binary format to replay command stream the blob format. It has all the information needed to replay on the open driver and tools are their (my joujou repo on fdo).

Cheers,
Jerome

#33 lore raw
In reply to Christian König
Quoted 7 lines · Christian König

Regarding the debugging of lockups I had the following on my "in mind todo" list:
1. Rework the chip specific lockup detection code a bit more and probably clean it up a bit.
2. Make the timeout a module parameter, cause compute task sometimes block a ring for more than 10 seconds.

A better solution for that would be to improve the detection of the GPU making progress, also for graphics operations. We should try to reduce the timeout rather than making it even larger.

Signature · 6 lines
Earthling Michel Dänzer           |                   http://www.amd.com
Libre software enthusiast         |          Debian, X and DRI developer
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#34 lore raw
Quoted 10 lines · Michel Dänzer
Quoted 6 lines · Christian König

Regarding the debugging of lockups I had the following on my "in mind todo" list:
1. Rework the chip specific lockup detection code a bit more and probably clean it up a bit.
2. Make the timeout a module parameter, cause compute task sometimes block a ring for more than 10 seconds.

A better solution for that would be to improve the detection of the GPU making progress, also for graphics operations. We should try to reduce the timeout rather than making it even larger.

Well, let's call it a more complete solution.

Since making the parameter configurable don't necessary means we are going to increase it. I usually set it to zero now, since that disables lockup detection at all and enables me to dig into the reason for something getting stuck.

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