Skip to contentSkip to conversation

SA and other Patches.

PATCH In review Christian König 2 participants 35 messages May 7, 2012 – May 9, 2012 1 message not in the archive

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

Hi Jerome & everybody on the list,

this gathers together every patch we developed over the last week or so and which is not already in drm-next.

I've run quite some tests with them yesterday and today and as far as I can see hammered out every known bug. For the SA allocator I reverted to tracking the hole pointer instead of just the last allocation, cause otherwise we will never release the first allocation on the list. Glxgears now even keeps happily running if I deadlock on the not GFX rings on purpose.

Please take a second look at them and if nobody objects any more we should commit them to drm-next.

Cheers,
Christian.

#1 lore raw

PATCH 1/20 drm/radeon: fix possible lack of synchronization btw ttm and other ring

From: Jerome Glisse <[email protected]>

We need to sync with the GFX ring as ttm might have schedule bo move on it and new command scheduled for other ring need to wait for bo data to be in place.

Reviewed by: Christian König <[email protected]>

---
 drivers/gpu/drm/radeon/radeon_cs.c |   12 ++++++------
 include/drm/radeon_drm.h           |    1 -
 2 files changed, 6 insertions(+), 7 deletions(-)
drivers/gpu/drm/radeon/radeon_cs.c +6 -6
index c66beb1..289b0d7 100644
@@ -122,15 +122,15 @@ static int radeon_cs_sync_rings(struct radeon_cs_parser *p)
 	int i, r;
 
 	for (i = 0; i < p->nrelocs; i++) {
+		struct radeon_fence *fence;
+
 		if (!p->relocs[i].robj || !p->relocs[i].robj->tbo.sync_obj)
 			continue;
 
-		if (!(p->relocs[i].flags & RADEON_RELOC_DONT_SYNC)) {
-			struct radeon_fence *fence = p->relocs[i].robj->tbo.sync_obj;
-			if (fence->ring != p->ring && !radeon_fence_signaled(fence)) {
-				sync_to_ring[fence->ring] = true;
-				need_sync = true;
-			}
+		fence = p->relocs[i].robj->tbo.sync_obj;
+		if (fence->ring != p->ring && !radeon_fence_signaled(fence)) {
+			sync_to_ring[fence->ring] = true;
+			need_sync = true;
 		}
 	}
 
include/drm/radeon_drm.h +0 -1
index 7c491b4..5805686 100644
@@ -926,7 +926,6 @@ struct drm_radeon_cs_chunk {
 };
 
 /* drm_radeon_cs_reloc.flags */
-#define RADEON_RELOC_DONT_SYNC		0x01
 
 struct drm_radeon_cs_reloc {
 	uint32_t		handle;
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/20 drm/radeon: clarify and extend wb setup on APUs and NI+ asics

In reply to Christian König

From: Alex Deucher <[email protected]>

Use family rather than DCE check for clarity, also always use wb on APUs, there will never be AGP variants.

Reviewed by: Christian König <[email protected]>

---
 drivers/gpu/drm/radeon/radeon_device.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_device.c +2 -2
index d18f0c4..ff28210 100644
@@ -241,8 +241,8 @@ int radeon_wb_init(struct radeon_device *rdev)
 				rdev->wb.use_event = true;
 		}
 	}
-	/* always use writeback/events on NI */
-	if (ASIC_IS_DCE5(rdev)) {
+	/* always use writeback/events on NI, APUs */
+	if (rdev->family >= CHIP_PALM) {
 		rdev->wb.enabled = true;
 		rdev->wb.use_event = true;
 	}
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/20 drm/radeon: replace the per ring mutex with a global one

In reply to Christian König

A single global mutex for ring submissions seems sufficient.

---
 drivers/gpu/drm/radeon/radeon.h           |    3 +-
 drivers/gpu/drm/radeon/radeon_device.c    |    3 +-
 drivers/gpu/drm/radeon/radeon_pm.c        |   10 +-----
 drivers/gpu/drm/radeon/radeon_ring.c      |   28 +++++++++++-------
 drivers/gpu/drm/radeon/radeon_semaphore.c |   42 +++++++++++++----------------
 5 files changed, 41 insertions(+), 45 deletions(-)
drivers/gpu/drm/radeon/radeon.h +2 -1
index 82ffa6a..e99ea81 100644
@@ -676,7 +676,6 @@ struct radeon_ring {
 	uint64_t		gpu_addr;
 	uint32_t		align_mask;
 	uint32_t		ptr_mask;
-	struct mutex		mutex;
 	bool			ready;
 	u32			ptr_reg_shift;
 	u32			ptr_reg_mask;
@@ -815,6 +814,7 @@ int radeon_ring_alloc(struct radeon_device *rdev, struct radeon_ring *cp, unsign
 int radeon_ring_lock(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ndw);
 void radeon_ring_commit(struct radeon_device *rdev, struct radeon_ring *cp);
 void radeon_ring_unlock_commit(struct radeon_device *rdev, struct radeon_ring *cp);
+void radeon_ring_undo(struct radeon_ring *ring);
 void radeon_ring_unlock_undo(struct radeon_device *rdev, struct radeon_ring *cp);
 int radeon_ring_test(struct radeon_device *rdev, struct radeon_ring *cp);
 void radeon_ring_force_activity(struct radeon_device *rdev, struct radeon_ring *ring);
@@ -1534,6 +1534,7 @@ struct radeon_device {
 	rwlock_t			fence_lock;
 	struct radeon_fence_driver	fence_drv[RADEON_NUM_RINGS];
 	struct radeon_semaphore_driver	semaphore_drv;
+	struct mutex			ring_lock;
 	struct radeon_ring		ring[RADEON_NUM_RINGS];
 	struct radeon_ib_pool		ib_pool;
 	struct radeon_irq		irq;
drivers/gpu/drm/radeon/radeon_device.c +1 -2
index ff28210..3f6ff2a 100644
@@ -724,8 +724,7 @@ int radeon_device_init(struct radeon_device *rdev,
 	 * 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->ring_lock);
 	mutex_init(&rdev->dc_hw_i2c_mutex);
 	if (rdev->family >= CHIP_R600)
 		spin_lock_init(&rdev->ih.lock);
drivers/gpu/drm/radeon/radeon_pm.c +2 -8
index caa55d6..7c38745 100644
@@ -252,10 +252,7 @@ static void radeon_pm_set_clocks(struct radeon_device *rdev)
 
 	mutex_lock(&rdev->ddev->struct_mutex);
 	mutex_lock(&rdev->vram_mutex);
-	for (i = 0; i < RADEON_NUM_RINGS; ++i) {
-		if (rdev->ring[i].ring_obj)
-			mutex_lock(&rdev->ring[i].mutex);
-	}
+	mutex_lock(&rdev->ring_lock);
 
 	/* gui idle int has issues on older chips it seems */
 	if (rdev->family >= CHIP_R600) {
@@ -311,10 +308,7 @@ static void radeon_pm_set_clocks(struct radeon_device *rdev)
 
 	rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE;
 
-	for (i = 0; i < RADEON_NUM_RINGS; ++i) {
-		if (rdev->ring[i].ring_obj)
-			mutex_unlock(&rdev->ring[i].mutex);
-	}
+	mutex_unlock(&rdev->ring_lock);
 	mutex_unlock(&rdev->vram_mutex);
 	mutex_unlock(&rdev->ddev->struct_mutex);
 }
drivers/gpu/drm/radeon/radeon_ring.c +17 -11
index 2eb4c6e..a4d60ae 100644
@@ -346,9 +346,9 @@ int radeon_ring_alloc(struct radeon_device *rdev, struct radeon_ring *ring, unsi
 		if (ndw < ring->ring_free_dw) {
 			break;
 		}
-		mutex_unlock(&ring->mutex);
+		mutex_unlock(&rdev->ring_lock);
 		r = radeon_fence_wait_next(rdev, radeon_ring_index(rdev, ring));
-		mutex_lock(&ring->mutex);
+		mutex_lock(&rdev->ring_lock);
 		if (r)
 			return r;
 	}
@@ -361,10 +361,10 @@ int radeon_ring_lock(struct radeon_device *rdev, struct radeon_ring *ring, unsig
 {
 	int r;
 
-	mutex_lock(&ring->mutex);
+	mutex_lock(&rdev->ring_lock);
 	r = radeon_ring_alloc(rdev, ring, ndw);
 	if (r) {
-		mutex_unlock(&ring->mutex);
+		mutex_unlock(&rdev->ring_lock);
 		return r;
 	}
 	return 0;
@@ -389,20 +389,25 @@ void radeon_ring_commit(struct radeon_device *rdev, struct radeon_ring *ring)
 void radeon_ring_unlock_commit(struct radeon_device *rdev, struct radeon_ring *ring)
 {
 	radeon_ring_commit(rdev, ring);
-	mutex_unlock(&ring->mutex);
+	mutex_unlock(&rdev->ring_lock);
 }
 
-void radeon_ring_unlock_undo(struct radeon_device *rdev, struct radeon_ring *ring)
+void radeon_ring_undo(struct radeon_ring *ring)
 {
 	ring->wptr = ring->wptr_old;
-	mutex_unlock(&ring->mutex);
+}
+
+void radeon_ring_unlock_undo(struct radeon_device *rdev, struct radeon_ring *ring)
+{
+	radeon_ring_undo(ring);
+	mutex_unlock(&rdev->ring_lock);
 }
 
 void radeon_ring_force_activity(struct radeon_device *rdev, struct radeon_ring *ring)
 {
 	int r;
 
-	mutex_lock(&ring->mutex);
+	mutex_lock(&rdev->ring_lock);
 	radeon_ring_free_size(rdev, ring);
 	if (ring->rptr == ring->wptr) {
 		r = radeon_ring_alloc(rdev, ring, 1);
@@ -411,7 +416,7 @@ void radeon_ring_force_activity(struct radeon_device *rdev, struct radeon_ring *
 			radeon_ring_commit(rdev, ring);
 		}
 	}
-	mutex_unlock(&ring->mutex);
+	mutex_unlock(&rdev->ring_lock);
 }
 
 void radeon_ring_lockup_update(struct radeon_ring *ring)
@@ -520,11 +525,12 @@ void radeon_ring_fini(struct radeon_device *rdev, struct radeon_ring *ring)
 	int r;
 	struct radeon_bo *ring_obj;
 
-	mutex_lock(&ring->mutex);
+	mutex_lock(&rdev->ring_lock);
 	ring_obj = ring->ring_obj;
+	ring->ready = false;
 	ring->ring = NULL;
 	ring->ring_obj = NULL;
-	mutex_unlock(&ring->mutex);
+	mutex_unlock(&rdev->ring_lock);
 
 	if (ring_obj) {
 		r = radeon_bo_reserve(ring_obj, false);
drivers/gpu/drm/radeon/radeon_semaphore.c +19 -23

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
#4 lore raw

PATCH 4/20 drm/radeon: convert fence to uint64_t v4

In reply to Christian König

From: Jerome Glisse <[email protected]>

This convert fence to use uint64_t sequence number intention is to use the fact that uin64_t is big enough that we don't need to care about wrap around.

Tested with and without writeback using 0xFFFFF000 as initial fence sequence and thus allowing to test the wrap around from 32bits to 64bits.

v2: Add comment about possible race btw CPU & GPU, add comment
stressing that we need 2 dword aligned for R600_WB_EVENT_OFFSET Read fence sequenc in reverse order of GPU write them so we mitigate the race btw CPU and GPU.

v3: Drop the need for ring to emit the 64bits fence, and just have
each ring emit the lower 32bits of the fence sequence. We handle the wrap over 32bits in fence_process.

v4: Just a small optimization: Don't reread the last_seq value
if loop restarts, since we already know its value anyway. Also start at zero not one for seq value and use pre instead of post increment in emmit, otherwise wait_empty will deadlock.

---
 drivers/gpu/drm/radeon/radeon.h       |   39 ++++++-----
 drivers/gpu/drm/radeon/radeon_fence.c |  116 +++++++++++++++++++++++----------
 drivers/gpu/drm/radeon/radeon_ring.c  |    9 ++-
 3 files changed, 107 insertions(+), 57 deletions(-)
drivers/gpu/drm/radeon/radeon.h +21 -18
index e99ea81..cdf46bc 100644
@@ -100,28 +100,32 @@ extern int radeon_lockup_timeout;
  * Copy from radeon_drv.h so we don't have to include both and have conflicting
  * symbol;
  */
-#define RADEON_MAX_USEC_TIMEOUT		100000	/* 100 ms */
-#define RADEON_FENCE_JIFFIES_TIMEOUT	(HZ / 2)
+#define RADEON_MAX_USEC_TIMEOUT			100000	/* 100 ms */
+#define RADEON_FENCE_JIFFIES_TIMEOUT		(HZ / 2)
 /* RADEON_IB_POOL_SIZE must be a power of 2 */
-#define RADEON_IB_POOL_SIZE		16
-#define RADEON_DEBUGFS_MAX_COMPONENTS	32
-#define RADEONFB_CONN_LIMIT		4
-#define RADEON_BIOS_NUM_SCRATCH		8
+#define RADEON_IB_POOL_SIZE			16
+#define RADEON_DEBUGFS_MAX_COMPONENTS		32
+#define RADEONFB_CONN_LIMIT			4
+#define RADEON_BIOS_NUM_SCRATCH			8
 
 /* max number of rings */
-#define RADEON_NUM_RINGS 3
+#define RADEON_NUM_RINGS			3
+
+/* fence seq are set to this number when signaled */
+#define RADEON_FENCE_SIGNALED_SEQ		0LL
+#define RADEON_FENCE_NOTEMITED_SEQ		(~0LL)
 
 /* internal ring indices */
 /* r1xx+ has gfx CP ring */
-#define RADEON_RING_TYPE_GFX_INDEX  0
+#define RADEON_RING_TYPE_GFX_INDEX		0
 
 /* cayman has 2 compute CP rings */
-#define CAYMAN_RING_TYPE_CP1_INDEX 1
-#define CAYMAN_RING_TYPE_CP2_INDEX 2
+#define CAYMAN_RING_TYPE_CP1_INDEX		1
+#define CAYMAN_RING_TYPE_CP2_INDEX		2
 
 /* hardcode those limit for now */
-#define RADEON_VA_RESERVED_SIZE		(8 << 20)
-#define RADEON_IB_VM_MAX_SIZE		(64 << 10)
+#define RADEON_VA_RESERVED_SIZE			(8 << 20)
+#define RADEON_IB_VM_MAX_SIZE			(64 << 10)
 
 /*
  * Errata workarounds.
@@ -254,8 +258,9 @@ struct radeon_fence_driver {
 	uint32_t			scratch_reg;
 	uint64_t			gpu_addr;
 	volatile uint32_t		*cpu_addr;
-	atomic_t			seq;
-	uint32_t			last_seq;
+	/* seq is protected by ring emission lock */
+	uint64_t			seq;
+	atomic64_t			last_seq;
 	unsigned long			last_activity;
 	wait_queue_head_t		queue;
 	struct list_head		emitted;
@@ -268,11 +273,9 @@ struct radeon_fence {
 	struct kref			kref;
 	struct list_head		list;
 	/* protected by radeon_fence.lock */
-	uint32_t			seq;
-	bool				emitted;
-	bool				signaled;
+	uint64_t			seq;
 	/* RB, DMA, etc. */
-	int				ring;
+	unsigned			ring;
 	struct radeon_semaphore		*semaphore;
 };
 
drivers/gpu/drm/radeon/radeon_fence.c +81 -35

217 lines not on this page · raw message

drivers/gpu/drm/radeon/radeon_ring.c +5 -4
index a4d60ae..4ae222b 100644
@@ -82,7 +82,7 @@ bool radeon_ib_try_free(struct radeon_device *rdev, struct radeon_ib *ib)
 	bool done = false;
 
 	/* only free ib which have been emited */
-	if (ib->fence && ib->fence->emitted) {
+	if (ib->fence && ib->fence->seq < RADEON_FENCE_NOTEMITED_SEQ) {
 		if (radeon_fence_signaled(ib->fence)) {
 			radeon_fence_unref(&ib->fence);
 			radeon_sa_bo_free(rdev, &ib->sa_bo);
@@ -149,8 +149,9 @@ retry:
 	/* this should be rare event, ie all ib scheduled none signaled yet.
 	 */
 	for (i = 0; i < RADEON_IB_POOL_SIZE; i++) {
-		if (rdev->ib_pool.ibs[idx].fence && rdev->ib_pool.ibs[idx].fence->emitted) {
-			r = radeon_fence_wait(rdev->ib_pool.ibs[idx].fence, false);
+		struct radeon_fence *fence = rdev->ib_pool.ibs[idx].fence;
+		if (fence && fence->seq < RADEON_FENCE_NOTEMITED_SEQ) {
+			r = radeon_fence_wait(fence, false);
 			if (!r) {
 				goto retry;
 			}
@@ -173,7 +174,7 @@ void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib)
 		return;
 	}
 	radeon_mutex_lock(&rdev->ib_pool.mutex);
-	if (tmp->fence && !tmp->fence->emitted) {
+	if (tmp->fence && tmp->fence->seq == RADEON_FENCE_NOTEMITED_SEQ) {
 		radeon_sa_bo_free(rdev, &tmp->sa_bo);
 		radeon_fence_unref(&tmp->fence);
 	}
Signature · 6 lines
1.7.5.4

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

Re: [PATCH 04/20] drm/radeon: convert fence to uint64_t v4

Quoted 15 lines · Christian König

From: Jerome Glisse <[email protected]>

This convert fence to use uint64_t sequence number intention is to use the fact that uin64_t is big enough that we don't need to care about wrap around.

Tested with and without writeback using 0xFFFFF000 as initial fence sequence and thus allowing to test the wrap around from 32bits to 64bits.

v2: Add comment about possible race btw CPU & GPU, add comment stressing that we need 2 dword aligned for R600_WB_EVENT_OFFSET Read fence sequenc in reverse order of GPU write them so we mitigate the race btw CPU and GPU.

Quoted 8 lines

v3: Drop the need for ring to emit the 64bits fence, and just have each ring emit the lower 32bits of the fence sequence. We handle the wrap over 32bits in fence_process.

v4: Just a small optimization: Don't reread the last_seq value if loop restarts, since we already know its value anyway. Also start at zero not one for seq value and use pre instead of post increment in emmit, otherwise wait_empty will deadlock.

Why changing that v3 was already good no deadlock. I started at 1 especialy for that, a signaled fence is set to 0 so it always compare as signaled. Just using preincrement is exactly like starting at one. I don't see the need for this change but if it makes you happy.

Cheers,
Jerome

Quoted 354 lines

---
 drivers/gpu/drm/radeon/radeon.h       |   39 ++++++----- drivers/gpu/drm/radeon/radeon_fence.c |  116 +++++++++++++++++++++++---------- drivers/gpu/drm/radeon/radeon_ring.c  |    9 ++-

 3 files changed, 107 insertions(+), 57 deletions(-)
drivers/gpu/drm/radeon/radeon.h +21 -18
index e99ea81..cdf46bc 100644
@@ -100,28 +100,32 @@ extern int radeon_lockup_timeout;
  * Copy from radeon_drv.h so we don't have to include both and have conflicting
  * symbol;
  */
-#define RADEON_MAX_USEC_TIMEOUT                100000  /* 100 ms */
-#define RADEON_FENCE_JIFFIES_TIMEOUT   (HZ / 2)
+#define RADEON_MAX_USEC_TIMEOUT                        100000  /* 100 ms */
+#define RADEON_FENCE_JIFFIES_TIMEOUT           (HZ / 2)
  /* RADEON_IB_POOL_SIZE must be a power of 2 */
-#define RADEON_IB_POOL_SIZE            16
-#define RADEON_DEBUGFS_MAX_COMPONENTS  32
-#define RADEONFB_CONN_LIMIT            4
-#define RADEON_BIOS_NUM_SCRATCH                8
+#define RADEON_IB_POOL_SIZE                    16
+#define RADEON_DEBUGFS_MAX_COMPONENTS          32
+#define RADEONFB_CONN_LIMIT                    4
+#define RADEON_BIOS_NUM_SCRATCH                        8
 
  /* max number of rings */
-#define RADEON_NUM_RINGS 3
+#define RADEON_NUM_RINGS                       3
+
+/* fence seq are set to this number when signaled */
+#define RADEON_FENCE_SIGNALED_SEQ              0LL
+#define RADEON_FENCE_NOTEMITED_SEQ             (~0LL)
 
  /* internal ring indices */
  /* r1xx+ has gfx CP ring */
-#define RADEON_RING_TYPE_GFX_INDEX  0
+#define RADEON_RING_TYPE_GFX_INDEX             0
 
  /* cayman has 2 compute CP rings */
-#define CAYMAN_RING_TYPE_CP1_INDEX 1
-#define CAYMAN_RING_TYPE_CP2_INDEX 2
+#define CAYMAN_RING_TYPE_CP1_INDEX             1
+#define CAYMAN_RING_TYPE_CP2_INDEX             2
 
  /* hardcode those limit for now */
-#define RADEON_VA_RESERVED_SIZE                (8 << 20)
-#define RADEON_IB_VM_MAX_SIZE          (64 << 10)
+#define RADEON_VA_RESERVED_SIZE                        (8 << 20)
+#define RADEON_IB_VM_MAX_SIZE                  (64 << 10)
 
  /*
  * Errata workarounds.
@@ -254,8 +258,9 @@ struct radeon_fence_driver {
        uint32_t                        scratch_reg;
        uint64_t                        gpu_addr;
        volatile uint32_t               *cpu_addr;
-       atomic_t                        seq;
-       uint32_t                        last_seq;
+       /* seq is protected by ring emission lock */
+       uint64_t                        seq;
+       atomic64_t                      last_seq;
        unsigned long                   last_activity;
        wait_queue_head_t               queue;
        struct list_head                emitted;
@@ -268,11 +273,9 @@ struct radeon_fence {
        struct kref                     kref;
        struct list_head                list;
        /* protected by radeon_fence.lock */
-       uint32_t                        seq;
-       bool                            emitted;
-       bool                            signaled;
+       uint64_t                        seq;
        /* RB, DMA, etc. */
-       int                             ring;
+       unsigned                        ring;
        struct radeon_semaphore         *semaphore;
  };
 
drivers/gpu/drm/radeon/radeon_fence.c +81 -35
index 5bb78bf..feb2bbc 100644
@@ -66,14 +66,14 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
        unsigned long irq_flags;
 
        write_lock_irqsave(&rdev->fence_lock, irq_flags);
-       if (fence->emitted) {
+       if (fence->seq && fence->seq < RADEON_FENCE_NOTEMITED_SEQ) {
                write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
                return 0;
        }
-       fence->seq = atomic_add_return(1, &rdev->fence_drv[fence->ring].seq);
+       /* we are protected by the ring emission mutex */
+       fence->seq = ++rdev->fence_drv[fence->ring].seq;
        radeon_fence_ring_emit(rdev, fence->ring, fence);
        trace_radeon_fence_emit(rdev->ddev, fence->seq);
-       fence->emitted = true;
        /* are we the first fence on a previusly idle ring? */
        if (list_empty(&rdev->fence_drv[fence->ring].emitted)) {
                rdev->fence_drv[fence->ring].last_activity = jiffies;
@@ -87,14 +87,60 @@ static bool radeon_fence_poll_locked(struct radeon_device *rdev, int ring)
  {
        struct radeon_fence *fence;
        struct list_head *i, *n;
-       uint32_t seq;
+       uint64_t seq, last_seq;
+       unsigned count_loop = 0;
        bool wake = false;
 
-       seq = radeon_fence_read(rdev, ring);
-       if (seq == rdev->fence_drv[ring].last_seq)
-               return false;
+       /* Note there is a scenario here for an infinite loop but it's
+        * very unlikely to happen. For it to happen, the current polling
+        * process need to be interrupted by another process and another
+        * process needs to update the last_seq btw the atomic read and
+        * xchg of the current process.
+        *
+        * More over for this to go in infinite loop there need to be
+        * continuously new fence signaled ie radeon_fence_read needs
+        * to return a different value each time for both the currently
+        * polling process and the other process that xchg the last_seq
+        * btw atomic read and xchg of the current process. And the
+        * value the other process set as last seq must be higher than
+        * the seq value we just read. Which means that current process
+        * need to be interrupted after radeon_fence_read and before
+        * atomic xchg.
+        *
+        * To be even more safe we count the number of time we loop and
+        * we bail after 10 loop just accepting the fact that we might
+        * have temporarly set the last_seq not to the true real last
+        * seq but to an older one.
+        */
+       last_seq = atomic64_read(&rdev->fence_drv[ring].last_seq);
+       do {
+               seq = radeon_fence_read(rdev, ring);
+               seq |= last_seq & 0xffffffff00000000LL;
+               if (seq < last_seq) {
+                       seq += 0x100000000LL;
+               }
 
-       rdev->fence_drv[ring].last_seq = seq;
+               if (!wake && seq == last_seq) {
+                       return false;
+               }
+               /* If we loop over we don't want to return without
+                * checking if a fence is signaled as it means that the
+                * seq we just read is different from the previous on.
+                */
+               wake = true;
+               if ((count_loop++) > 10) {
+                       /* We looped over too many time leave with the
+                        * fact that we might have set an older fence
+                        * seq then the current real last seq as signaled
+                        * by the hw.
+                        */
+                       break;
+               }
+               last_seq = seq;
+       } while (atomic64_xchg(&rdev->fence_drv[ring].last_seq, seq) > seq);
+
+       /* reset wake to false */
+       wake = false;
        rdev->fence_drv[ring].last_activity = jiffies;
 
        n = NULL;
@@ -112,7 +158,7 @@ static bool radeon_fence_poll_locked(struct radeon_device *rdev, int ring)
                        n = i->prev;
                        list_move_tail(i, &rdev->fence_drv[ring].signaled);
                        fence = list_entry(i, struct radeon_fence, list);
-                       fence->signaled = true;
+                       fence->seq = RADEON_FENCE_SIGNALED_SEQ;
                        i = n;
                } while (i != &rdev->fence_drv[ring].emitted);
                wake = true;
@@ -128,7 +174,7 @@ static void radeon_fence_destroy(struct kref *kref)
        fence = container_of(kref, struct radeon_fence, kref);
        write_lock_irqsave(&fence->rdev->fence_lock, irq_flags);
        list_del(&fence->list);
-       fence->emitted = false;
+       fence->seq = RADEON_FENCE_NOTEMITED_SEQ;
        write_unlock_irqrestore(&fence->rdev->fence_lock, irq_flags);
        if (fence->semaphore)
                radeon_semaphore_free(fence->rdev, fence->semaphore);
@@ -145,9 +191,7 @@ int radeon_fence_create(struct radeon_device *rdev,
        }
        kref_init(&((*fence)->kref));
        (*fence)->rdev = rdev;
-       (*fence)->emitted = false;
-       (*fence)->signaled = false;
-       (*fence)->seq = 0;
+       (*fence)->seq = RADEON_FENCE_NOTEMITED_SEQ;
        (*fence)->ring = ring;
        (*fence)->semaphore = NULL;
        INIT_LIST_HEAD(&(*fence)->list);
@@ -163,18 +207,18 @@ bool radeon_fence_signaled(struct radeon_fence *fence)
                return true;
 
        write_lock_irqsave(&fence->rdev->fence_lock, irq_flags);
-       signaled = fence->signaled;
+       signaled = (fence->seq == RADEON_FENCE_SIGNALED_SEQ);
        /* if we are shuting down report all fence as signaled */
        if (fence->rdev->shutdown) {
                signaled = true;
        }
-       if (!fence->emitted) {
+       if (fence->seq == RADEON_FENCE_NOTEMITED_SEQ) {
                WARN(1, "Querying an unemitted fence : %p !\n", fence);
                signaled = true;
        }
        if (!signaled) {
                radeon_fence_poll_locked(fence->rdev, fence->ring);
-               signaled = fence->signaled;
+               signaled = (fence->seq == RADEON_FENCE_SIGNALED_SEQ);
        }
        write_unlock_irqrestore(&fence->rdev->fence_lock, irq_flags);
        return signaled;
@@ -183,8 +227,8 @@ bool radeon_fence_signaled(struct radeon_fence *fence)
  int radeon_fence_wait(struct radeon_fence *fence, bool intr)
  {
        struct radeon_device *rdev;
-       unsigned long irq_flags, timeout;
-       u32 seq;
+       unsigned long irq_flags, timeout, last_activity;
+       uint64_t seq;
        int i, r;
        bool signaled;
 
@@ -207,7 +251,9 @@ int radeon_fence_wait(struct radeon_fence *fence, bool intr)
                        timeout = 1;
                }
                /* save current sequence value used to check for GPU lockups */
-               seq = rdev->fence_drv[fence->ring].last_seq;
+               seq = atomic64_read(&rdev->fence_drv[fence->ring].last_seq);
+               /* Save current last activity valuee, used to check for GPU lockups */
+               last_activity = rdev->fence_drv[fence->ring].last_activity;
                read_unlock_irqrestore(&rdev->fence_lock, irq_flags);
 
                trace_radeon_fence_wait_begin(rdev->ddev, seq);
@@ -235,24 +281,23 @@ int radeon_fence_wait(struct radeon_fence *fence, bool intr)
                        }
 
                        write_lock_irqsave(&rdev->fence_lock, irq_flags);
-                       /* check if sequence value has changed since last_activity */
-                       if (seq != rdev->fence_drv[fence->ring].last_seq) {
+                       /* test if somebody else has already decided that this is a lockup */
+                       if (last_activity != rdev->fence_drv[fence->ring].last_activity) {
                                write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
                                continue;
                        }
 
-                       /* 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])) {
-
                                /* 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);
+                               dev_warn(rdev->dev, "GPU lockup (waiting for 0x%016llx last fence id 0x%016llx)\n",
+                                        fence->seq, seq);
+
+                               /* change last activity so nobody else think there is a lockup */
+                               for (i = 0; i < RADEON_NUM_RINGS; ++i) {
+                                       rdev->fence_drv[i].last_activity = jiffies;
+                               }
 
                                /* mark the ring as not ready any more */
                                rdev->ring[fence->ring].ready = false;
@@ -387,9 +432,9 @@ int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring)
        }
        rdev->fence_drv[ring].cpu_addr = &rdev->wb.wb[index/4];
        rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr + index;
-       radeon_fence_write(rdev, atomic_read(&rdev->fence_drv[ring].seq), ring);
+       radeon_fence_write(rdev, rdev->fence_drv[ring].seq, ring);
        rdev->fence_drv[ring].initialized = true;
-       DRM_INFO("fence driver on ring %d use gpu addr 0x%08Lx and cpu addr 0x%p\n",
+       DRM_INFO("fence driver on ring %d use gpu addr 0x%016llx and cpu addr 0x%p\n",
                 ring, rdev->fence_drv[ring].gpu_addr, rdev->fence_drv[ring].cpu_addr);
        write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
        return 0;
@@ -400,7 +445,8 @@ static void radeon_fence_driver_init_ring(struct radeon_device *rdev, int ring)
        rdev->fence_drv[ring].scratch_reg = -1;
        rdev->fence_drv[ring].cpu_addr = NULL;
        rdev->fence_drv[ring].gpu_addr = 0;
-       atomic_set(&rdev->fence_drv[ring].seq, 0);
+       rdev->fence_drv[ring].seq = 0;
+       atomic64_set(&rdev->fence_drv[ring].last_seq, 0);
        INIT_LIST_HEAD(&rdev->fence_drv[ring].emitted);
        INIT_LIST_HEAD(&rdev->fence_drv[ring].signaled);
        init_waitqueue_head(&rdev->fence_drv[ring].queue);
@@ -458,12 +504,12 @@ static int radeon_debugfs_fence_info(struct seq_file *m, void *data)
                        continue;
 
                seq_printf(m, "--- ring %d ---\n", i);
-               seq_printf(m, "Last signaled fence 0x%08X\n",
-                          radeon_fence_read(rdev, i));
+               seq_printf(m, "Last signaled fence 0x%016lx\n",
+                          atomic64_read(&rdev->fence_drv[i].last_seq));
                if (!list_empty(&rdev->fence_drv[i].emitted)) {
                        fence = list_entry(rdev->fence_drv[i].emitted.prev,
                                           struct radeon_fence, list);
-                       seq_printf(m, "Last emitted fence %p with 0x%08X\n",
+                       seq_printf(m, "Last emitted fence %p with 0x%016llx\n",
                                   fence,  fence->seq);
                }
        }
drivers/gpu/drm/radeon/radeon_ring.c +5 -5
index a4d60ae..4ae222b 100644
@@ -82,7 +82,7 @@ bool radeon_ib_try_free(struct radeon_device *rdev, struct radeon_ib *ib)
        bool done = false;
 
        /* only free ib which have been emited */
-       if (ib->fence && ib->fence->emitted) {
+       if (ib->fence && ib->fence->seq < RADEON_FENCE_NOTEMITED_SEQ) {
                if (radeon_fence_signaled(ib->fence)) {
                        radeon_fence_unref(&ib->fence);
                        radeon_sa_bo_free(rdev, &ib->sa_bo);
@@ -149,8 +149,9 @@ retry:
        /* this should be rare event, ie all ib scheduled none signaled yet.
         */
        for (i = 0; i < RADEON_IB_POOL_SIZE; i++) {
-               if (rdev->ib_pool.ibs[idx].fence && rdev->ib_pool.ibs[idx].fence->emitted) {
-                       r = radeon_fence_wait(rdev->ib_pool.ibs[idx].fence, false);
+               struct radeon_fence *fence = rdev->ib_pool.ibs[idx].fence;
+               if (fence && fence->seq < RADEON_FENCE_NOTEMITED_SEQ) {
+                       r = radeon_fence_wait(fence, false);
                        if (!r) {
                                goto retry;
                        }
@@ -173,7 +174,7 @@ void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib)
                return;
        }
        radeon_mutex_lock(&rdev->ib_pool.mutex);
-       if (tmp->fence && !tmp->fence->emitted) {
+       if (tmp->fence && tmp->fence->seq == RADEON_FENCE_NOTEMITED_SEQ) {
                radeon_sa_bo_free(rdev, &tmp->sa_bo);
                radeon_fence_unref(&tmp->fence);
        }
--

1.7.5.4

#6 lore raw

Re: [PATCH 04/20] drm/radeon: convert fence to uint64_t v4

Quoted 20 lines · Jerome Glisse
Quoted 19 lines · Christian König

From: Jerome Glisse<[email protected]>

This convert fence to use uint64_t sequence number intention is to use the fact that uin64_t is big enough that we don't need to care about wrap around.

Tested with and without writeback using 0xFFFFF000 as initial fence sequence and thus allowing to test the wrap around from 32bits to 64bits.

v2: Add comment about possible race btw CPU& GPU, add comment
stressing that we need 2 dword aligned for R600_WB_EVENT_OFFSET Read fence sequenc in reverse order of GPU write them so we mitigate the race btw CPU and GPU.

v3: Drop the need for ring to emit the 64bits fence, and just have
each ring emit the lower 32bits of the fence sequence. We handle the wrap over 32bits in fence_process.

Quoted 8 lines
Quoted 4 lines

v4: Just a small optimization: Don't reread the last_seq value
if loop restarts, since we already know its value anyway. Also start at zero not one for seq value and use pre instead of post increment in emmit, otherwise wait_empty will deadlock.

Why changing that v3 was already good no deadlock. I started at 1 especialy for that, a signaled fence is set to 0 so it always compare as signaled. Just using preincrement is exactly like starting at one. I don't see the need for this change but if it makes you happy.

Not exactly, the last emitted sequence is also used in radeon_fence_wait_empty. So when you use post increment radeon_fence_wait_empty will actually not wait for the last emitted fence to be signaled, but for last emitted + 1, so it practically waits forever.

Without this change suspend (for example) will just lockup.

Cheers,
Christian.

Quoted 356 lines

Cheers,
Jerome

Quoted 353 lines
---
  drivers/gpu/drm/radeon/radeon.h       |   39 ++++++-----
  drivers/gpu/drm/radeon/radeon_fence.c |  116 +++++++++++++++++++++++----------
  drivers/gpu/drm/radeon/radeon_ring.c  |    9 ++-
  3 files changed, 107 insertions(+), 57 deletions(-)
drivers/gpu/drm/radeon/radeon.h +21 -18
index e99ea81..cdf46bc 100644
@@ -100,28 +100,32 @@ extern int radeon_lockup_timeout;
  * Copy from radeon_drv.h so we don't have to include both and have conflicting
  * symbol;
  */
-#define RADEON_MAX_USEC_TIMEOUT                100000  /* 100 ms */
-#define RADEON_FENCE_JIFFIES_TIMEOUT   (HZ / 2)
+#define RADEON_MAX_USEC_TIMEOUT                        100000  /* 100 ms */
+#define RADEON_FENCE_JIFFIES_TIMEOUT           (HZ / 2)
  /* RADEON_IB_POOL_SIZE must be a power of 2 */
-#define RADEON_IB_POOL_SIZE            16
-#define RADEON_DEBUGFS_MAX_COMPONENTS  32
-#define RADEONFB_CONN_LIMIT            4
-#define RADEON_BIOS_NUM_SCRATCH                8
+#define RADEON_IB_POOL_SIZE                    16
+#define RADEON_DEBUGFS_MAX_COMPONENTS          32
+#define RADEONFB_CONN_LIMIT                    4
+#define RADEON_BIOS_NUM_SCRATCH                        8
 
  /* max number of rings */
-#define RADEON_NUM_RINGS 3
+#define RADEON_NUM_RINGS                       3
+
+/* fence seq are set to this number when signaled */
+#define RADEON_FENCE_SIGNALED_SEQ              0LL
+#define RADEON_FENCE_NOTEMITED_SEQ             (~0LL)
 
  /* internal ring indices */
  /* r1xx+ has gfx CP ring */
-#define RADEON_RING_TYPE_GFX_INDEX  0
+#define RADEON_RING_TYPE_GFX_INDEX             0
 
  /* cayman has 2 compute CP rings */
-#define CAYMAN_RING_TYPE_CP1_INDEX 1
-#define CAYMAN_RING_TYPE_CP2_INDEX 2
+#define CAYMAN_RING_TYPE_CP1_INDEX             1
+#define CAYMAN_RING_TYPE_CP2_INDEX             2
 
  /* hardcode those limit for now */
-#define RADEON_VA_RESERVED_SIZE                (8<<  20)
-#define RADEON_IB_VM_MAX_SIZE          (64<<  10)
+#define RADEON_VA_RESERVED_SIZE                        (8<<  20)
+#define RADEON_IB_VM_MAX_SIZE                  (64<<  10)
 
  /*
  * Errata workarounds.
@@ -254,8 +258,9 @@ struct radeon_fence_driver {
        uint32_t                        scratch_reg;
        uint64_t                        gpu_addr;
        volatile uint32_t               *cpu_addr;
-       atomic_t                        seq;
-       uint32_t                        last_seq;
+       /* seq is protected by ring emission lock */
+       uint64_t                        seq;
+       atomic64_t                      last_seq;
        unsigned long                   last_activity;
        wait_queue_head_t               queue;
        struct list_head                emitted;
@@ -268,11 +273,9 @@ struct radeon_fence {
        struct kref                     kref;
        struct list_head                list;
        /* protected by radeon_fence.lock */
-       uint32_t                        seq;
-       bool                            emitted;
-       bool                            signaled;
+       uint64_t                        seq;
        /* RB, DMA, etc. */
-       int                             ring;
+       unsigned                        ring;
        struct radeon_semaphore         *semaphore;
  };
 
drivers/gpu/drm/radeon/radeon_fence.c +81 -35
index 5bb78bf..feb2bbc 100644
@@ -66,14 +66,14 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
        unsigned long irq_flags;
 
        write_lock_irqsave(&rdev->fence_lock, irq_flags);
-       if (fence->emitted) {
+       if (fence->seq&&  fence->seq<  RADEON_FENCE_NOTEMITED_SEQ) {
                write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
                return 0;
        }
-       fence->seq = atomic_add_return(1,&rdev->fence_drv[fence->ring].seq);
+       /* we are protected by the ring emission mutex */
+       fence->seq = ++rdev->fence_drv[fence->ring].seq;
        radeon_fence_ring_emit(rdev, fence->ring, fence);
        trace_radeon_fence_emit(rdev->ddev, fence->seq);
-       fence->emitted = true;
        /* are we the first fence on a previusly idle ring? */
        if (list_empty(&rdev->fence_drv[fence->ring].emitted)) {
                rdev->fence_drv[fence->ring].last_activity = jiffies;
@@ -87,14 +87,60 @@ static bool radeon_fence_poll_locked(struct radeon_device *rdev, int ring)
  {
        struct radeon_fence *fence;
        struct list_head *i, *n;
-       uint32_t seq;
+       uint64_t seq, last_seq;
+       unsigned count_loop = 0;
        bool wake = false;
 
-       seq = radeon_fence_read(rdev, ring);
-       if (seq == rdev->fence_drv[ring].last_seq)
-               return false;
+       /* Note there is a scenario here for an infinite loop but it's
+        * very unlikely to happen. For it to happen, the current polling
+        * process need to be interrupted by another process and another
+        * process needs to update the last_seq btw the atomic read and
+        * xchg of the current process.
+        *
+        * More over for this to go in infinite loop there need to be
+        * continuously new fence signaled ie radeon_fence_read needs
+        * to return a different value each time for both the currently
+        * polling process and the other process that xchg the last_seq
+        * btw atomic read and xchg of the current process. And the
+        * value the other process set as last seq must be higher than
+        * the seq value we just read. Which means that current process
+        * need to be interrupted after radeon_fence_read and before
+        * atomic xchg.
+        *
+        * To be even more safe we count the number of time we loop and
+        * we bail after 10 loop just accepting the fact that we might
+        * have temporarly set the last_seq not to the true real last
+        * seq but to an older one.
+        */
+       last_seq = atomic64_read(&rdev->fence_drv[ring].last_seq);
+       do {
+               seq = radeon_fence_read(rdev, ring);
+               seq |= last_seq&  0xffffffff00000000LL;
+               if (seq<  last_seq) {
+                       seq += 0x100000000LL;
+               }
 
-       rdev->fence_drv[ring].last_seq = seq;
+               if (!wake&&  seq == last_seq) {
+                       return false;
+               }
+               /* If we loop over we don't want to return without
+                * checking if a fence is signaled as it means that the
+                * seq we just read is different from the previous on.
+                */
+               wake = true;
+               if ((count_loop++)>  10) {
+                       /* We looped over too many time leave with the
+                        * fact that we might have set an older fence
+                        * seq then the current real last seq as signaled
+                        * by the hw.
+                        */
+                       break;
+               }
+               last_seq = seq;
+       } while (atomic64_xchg(&rdev->fence_drv[ring].last_seq, seq)>  seq);
+
+       /* reset wake to false */
+       wake = false;
        rdev->fence_drv[ring].last_activity = jiffies;
 
        n = NULL;
@@ -112,7 +158,7 @@ static bool radeon_fence_poll_locked(struct radeon_device *rdev, int ring)
                        n = i->prev;
                        list_move_tail(i,&rdev->fence_drv[ring].signaled);
                        fence = list_entry(i, struct radeon_fence, list);
-                       fence->signaled = true;
+                       fence->seq = RADEON_FENCE_SIGNALED_SEQ;
                        i = n;
                } while (i !=&rdev->fence_drv[ring].emitted);
                wake = true;
@@ -128,7 +174,7 @@ static void radeon_fence_destroy(struct kref *kref)
        fence = container_of(kref, struct radeon_fence, kref);
        write_lock_irqsave(&fence->rdev->fence_lock, irq_flags);
        list_del(&fence->list);
-       fence->emitted = false;
+       fence->seq = RADEON_FENCE_NOTEMITED_SEQ;
        write_unlock_irqrestore(&fence->rdev->fence_lock, irq_flags);
        if (fence->semaphore)
                radeon_semaphore_free(fence->rdev, fence->semaphore);
@@ -145,9 +191,7 @@ int radeon_fence_create(struct radeon_device *rdev,
        }
        kref_init(&((*fence)->kref));
        (*fence)->rdev = rdev;
-       (*fence)->emitted = false;
-       (*fence)->signaled = false;
-       (*fence)->seq = 0;
+       (*fence)->seq = RADEON_FENCE_NOTEMITED_SEQ;
        (*fence)->ring = ring;
        (*fence)->semaphore = NULL;
        INIT_LIST_HEAD(&(*fence)->list);
@@ -163,18 +207,18 @@ bool radeon_fence_signaled(struct radeon_fence *fence)
                return true;
 
        write_lock_irqsave(&fence->rdev->fence_lock, irq_flags);
-       signaled = fence->signaled;
+       signaled = (fence->seq == RADEON_FENCE_SIGNALED_SEQ);
        /* if we are shuting down report all fence as signaled */
        if (fence->rdev->shutdown) {
                signaled = true;
        }
-       if (!fence->emitted) {
+       if (fence->seq == RADEON_FENCE_NOTEMITED_SEQ) {
                WARN(1, "Querying an unemitted fence : %p !\n", fence);
                signaled = true;
        }
        if (!signaled) {
                radeon_fence_poll_locked(fence->rdev, fence->ring);
-               signaled = fence->signaled;
+               signaled = (fence->seq == RADEON_FENCE_SIGNALED_SEQ);
        }
        write_unlock_irqrestore(&fence->rdev->fence_lock, irq_flags);
        return signaled;
@@ -183,8 +227,8 @@ bool radeon_fence_signaled(struct radeon_fence *fence)
  int radeon_fence_wait(struct radeon_fence *fence, bool intr)
  {
        struct radeon_device *rdev;
-       unsigned long irq_flags, timeout;
-       u32 seq;
+       unsigned long irq_flags, timeout, last_activity;
+       uint64_t seq;
        int i, r;
        bool signaled;
 
@@ -207,7 +251,9 @@ int radeon_fence_wait(struct radeon_fence *fence, bool intr)
                        timeout = 1;
                }
                /* save current sequence value used to check for GPU lockups */
-               seq = rdev->fence_drv[fence->ring].last_seq;
+               seq = atomic64_read(&rdev->fence_drv[fence->ring].last_seq);
+               /* Save current last activity valuee, used to check for GPU lockups */
+               last_activity = rdev->fence_drv[fence->ring].last_activity;
                read_unlock_irqrestore(&rdev->fence_lock, irq_flags);
 
                trace_radeon_fence_wait_begin(rdev->ddev, seq);
@@ -235,24 +281,23 @@ int radeon_fence_wait(struct radeon_fence *fence, bool intr)
                        }
 
                        write_lock_irqsave(&rdev->fence_lock, irq_flags);
-                       /* check if sequence value has changed since last_activity */
-                       if (seq != rdev->fence_drv[fence->ring].last_seq) {
+                       /* test if somebody else has already decided that this is a lockup */
+                       if (last_activity != rdev->fence_drv[fence->ring].last_activity) {
                                write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
                                continue;
                        }
 
-                       /* 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])) {
-
                                /* 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);
+                               dev_warn(rdev->dev, "GPU lockup (waiting for 0x%016llx last fence id 0x%016llx)\n",
+                                        fence->seq, seq);
+
+                               /* change last activity so nobody else think there is a lockup */
+                               for (i = 0; i<  RADEON_NUM_RINGS; ++i) {
+                                       rdev->fence_drv[i].last_activity = jiffies;
+                               }
 
                                /* mark the ring as not ready any more */
                                rdev->ring[fence->ring].ready = false;
@@ -387,9 +432,9 @@ int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring)
        }
        rdev->fence_drv[ring].cpu_addr =&rdev->wb.wb[index/4];
        rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr + index;
-       radeon_fence_write(rdev, atomic_read(&rdev->fence_drv[ring]..seq), ring);
+       radeon_fence_write(rdev, rdev->fence_drv[ring].seq, ring);
        rdev->fence_drv[ring].initialized = true;
-       DRM_INFO("fence driver on ring %d use gpu addr 0x%08Lx and cpu addr 0x%p\n",
+       DRM_INFO("fence driver on ring %d use gpu addr 0x%016llx and cpu addr 0x%p\n",
                 ring, rdev->fence_drv[ring].gpu_addr, rdev->fence_drv[ring].cpu_addr);
        write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
        return 0;
@@ -400,7 +445,8 @@ static void radeon_fence_driver_init_ring(struct radeon_device *rdev, int ring)
        rdev->fence_drv[ring].scratch_reg = -1;
        rdev->fence_drv[ring].cpu_addr = NULL;
        rdev->fence_drv[ring].gpu_addr = 0;
-       atomic_set(&rdev->fence_drv[ring].seq, 0);
+       rdev->fence_drv[ring].seq = 0;
+       atomic64_set(&rdev->fence_drv[ring].last_seq, 0);
        INIT_LIST_HEAD(&rdev->fence_drv[ring].emitted);
        INIT_LIST_HEAD(&rdev->fence_drv[ring].signaled);
        init_waitqueue_head(&rdev->fence_drv[ring].queue);
@@ -458,12 +504,12 @@ static int radeon_debugfs_fence_info(struct seq_file *m, void *data)
                        continue;
 
                seq_printf(m, "--- ring %d ---\n", i);
-               seq_printf(m, "Last signaled fence 0x%08X\n",
-                          radeon_fence_read(rdev, i));
+               seq_printf(m, "Last signaled fence 0x%016lx\n",
+                          atomic64_read(&rdev->fence_drv[i].last_seq));
                if (!list_empty(&rdev->fence_drv[i].emitted)) {
                        fence = list_entry(rdev->fence_drv[i].emitted.prev,
                                           struct radeon_fence, list);
-                       seq_printf(m, "Last emitted fence %p with 0x%08X\n",
+                       seq_printf(m, "Last emitted fence %p with 0x%016llx\n",
                                   fence,  fence->seq);
                }
        }
drivers/gpu/drm/radeon/radeon_ring.c +5 -5
index a4d60ae..4ae222b 100644
@@ -82,7 +82,7 @@ bool radeon_ib_try_free(struct radeon_device *rdev, struct radeon_ib *ib)
        bool done = false;
 
        /* only free ib which have been emited */
-       if (ib->fence&&  ib->fence->emitted) {
+       if (ib->fence&&  ib->fence->seq<  RADEON_FENCE_NOTEMITED_SEQ) {
                if (radeon_fence_signaled(ib->fence)) {
                        radeon_fence_unref(&ib->fence);
                        radeon_sa_bo_free(rdev,&ib->sa_bo);
@@ -149,8 +149,9 @@ retry:
        /* this should be rare event, ie all ib scheduled none signaled yet.
         */
        for (i = 0; i<  RADEON_IB_POOL_SIZE; i++) {
-               if (rdev->ib_pool.ibs[idx].fence&&  rdev->ib_pool.ibs[idx].fence->emitted) {
-                       r = radeon_fence_wait(rdev->ib_pool.ibs[idx].fence, false);
+               struct radeon_fence *fence = rdev->ib_pool.ibs[idx].fence;
+               if (fence&&  fence->seq<  RADEON_FENCE_NOTEMITED_SEQ) {
+                       r = radeon_fence_wait(fence, false);
                        if (!r) {
                                goto retry;
                        }
@@ -173,7 +174,7 @@ void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib)
                return;
        }
        radeon_mutex_lock(&rdev->ib_pool.mutex);
-       if (tmp->fence&&  !tmp->fence->emitted) {
+       if (tmp->fence&&  tmp->fence->seq == RADEON_FENCE_NOTEMITED_SEQ) {
                radeon_sa_bo_free(rdev,&tmp->sa_bo);
                radeon_fence_unref(&tmp->fence);
        }
--

1.7.5.4

#7 lore raw

Re: [PATCH 04/20] drm/radeon: convert fence to uint64_t v4

Quoted 41 lines · Christian König
Quoted 29 lines · Jerome Glisse
Quoted 17 lines · Christian König

From: Jerome Glisse<[email protected]>

This convert fence to use uint64_t sequence number intention is to use the fact that uin64_t is big enough that we don't need to care about wrap around.

Tested with and without writeback using 0xFFFFF000 as initial fence sequence and thus allowing to test the wrap around from 32bits to 64bits.

v2: Add comment about possible race btw CPU&  GPU, add comment

   stressing that we need 2 dword aligned for R600_WB_EVENT_OFFSET Read fence sequenc in reverse order of GPU write them so we mitigate the race btw CPU and GPU.

Quoted 8 lines

v3: Drop the need for ring to emit the 64bits fence, and just have each ring emit the lower 32bits of the fence sequence. We handle the wrap over 32bits in fence_process.

v4: Just a small optimization: Don't reread the last_seq value if loop restarts, since we already know its value anyway. Also start at zero not one for seq value and use pre instead of post increment in emmit, otherwise wait_empty will deadlock.

Quoted 4 lines

Why changing that v3 was already good no deadlock. I started at 1 especialy for that, a signaled fence is set to 0 so it always compare as signaled. Just using preincrement is exactly like starting at one. I don't see the need for this change but if it makes you happy.

Not exactly, the last emitted sequence is also used in radeon_fence_wait_empty. So when you use post increment radeon_fence_wait_empty will actually not wait for the last emitted fence to be signaled, but for last emitted + 1, so it practically waits forever.

Quoted 4 lines

Without this change suspend (for example) will just lockup.

Cheers,
Christian.

Yeah you right, my tree had a fix for that. I probably messed up the rebase patch at one point. Well as your version fix it i am fine with it.

Cheers,
Jerome

Quoted 420 lines
Quoted 419 lines

Cheers,
Jerome

Quoted 416 lines

---
 drivers/gpu/drm/radeon/radeon.h       |   39 ++++++----- drivers/gpu/drm/radeon/radeon_fence.c |  116
+++++++++++++++++++++++----------
 drivers/gpu/drm/radeon/radeon_ring.c  |    9 ++-

 3 files changed, 107 insertions(+), 57 deletions(-)
drivers/gpu/drm/radeon/radeon.h +0 -0
index e99ea81..cdf46bc 100644
@@ -100,28 +100,32 @@ extern int radeon_lockup_timeout;
  * Copy from radeon_drv.h so we don't have to include both and have

conflicting
 * symbol;
 */

drivers/gpu/drm/radeon/radeon.h +1 -2
-#define RADEON_MAX_USEC_TIMEOUT                100000  /* 100 ms */
-#define RADEON_FENCE_JIFFIES_TIMEOUT   (HZ / 2)
+#define RADEON_MAX_USEC_TIMEOUT                        100000  /* 100 ms

*/
+#define RADEON_FENCE_JIFFIES_TIMEOUT           (HZ / 2) /* RADEON_IB_POOL_SIZE must be a power of 2 */

drivers/gpu/drm/radeon/radeon.h +4 -4
-#define RADEON_IB_POOL_SIZE            16
-#define RADEON_DEBUGFS_MAX_COMPONENTS  32
-#define RADEONFB_CONN_LIMIT            4
-#define RADEON_BIOS_NUM_SCRATCH                8
+#define RADEON_IB_POOL_SIZE                    16
+#define RADEON_DEBUGFS_MAX_COMPONENTS          32
+#define RADEONFB_CONN_LIMIT                    4
+#define RADEON_BIOS_NUM_SCRATCH                        8

 /* max number of rings */

drivers/gpu/drm/radeon/radeon.h +5 -1
-#define RADEON_NUM_RINGS 3
+#define RADEON_NUM_RINGS                       3
+
+/* fence seq are set to this number when signaled */
+#define RADEON_FENCE_SIGNALED_SEQ              0LL
+#define RADEON_FENCE_NOTEMITED_SEQ             (~0LL)

 /* internal ring indices */
 /* r1xx+ has gfx CP ring */

drivers/gpu/drm/radeon/radeon.h +1 -1
-#define RADEON_RING_TYPE_GFX_INDEX  0
+#define RADEON_RING_TYPE_GFX_INDEX             0

 /* cayman has 2 compute CP rings */

drivers/gpu/drm/radeon/radeon.h +2 -2
-#define CAYMAN_RING_TYPE_CP1_INDEX 1
-#define CAYMAN_RING_TYPE_CP2_INDEX 2
+#define CAYMAN_RING_TYPE_CP1_INDEX             1
+#define CAYMAN_RING_TYPE_CP2_INDEX             2

 /* hardcode those limit for now */

drivers/gpu/drm/radeon/radeon.h +2 -2
-#define RADEON_VA_RESERVED_SIZE                (8<<  20)
-#define RADEON_IB_VM_MAX_SIZE          (64<<  10)
+#define RADEON_VA_RESERVED_SIZE                        (8<<  20)
+#define RADEON_IB_VM_MAX_SIZE                  (64<<  10)

 /*
 * Errata workarounds.

drivers/gpu/drm/radeon/radeon.h +5 -6
@@ -254,8 +258,9 @@ struct radeon_fence_driver {
        uint32_t                        scratch_reg;
        uint64_t                        gpu_addr;
        volatile uint32_t               *cpu_addr;
-       atomic_t                        seq;
-       uint32_t                        last_seq;
+       /* seq is protected by ring emission lock */
+       uint64_t                        seq;
+       atomic64_t                      last_seq;
        unsigned long                   last_activity;
        wait_queue_head_t               queue;
        struct list_head                emitted;
@@ -268,11 +273,9 @@ struct radeon_fence {
        struct kref                     kref;
        struct list_head                list;
        /* protected by radeon_fence.lock */
-       uint32_t                        seq;
-       bool                            emitted;
-       bool                            signaled;
+       uint64_t                        seq;
        /* RB, DMA, etc. */
-       int                             ring;
+       unsigned                        ring;
        struct radeon_semaphore         *semaphore;
  };
 
drivers/gpu/drm/radeon/radeon_fence.c +3 -2
index 5bb78bf..feb2bbc 100644
@@ -66,14 +66,14 @@ int radeon_fence_emit(struct radeon_device *rdev,
 struct radeon_fence *fence)
        unsigned long irq_flags;
 
        write_lock_irqsave(&rdev->fence_lock, irq_flags);
-       if (fence->emitted) {
+       if (fence->seq&&  fence->seq<  RADEON_FENCE_NOTEMITED_SEQ) {
 
                write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
                return 0;
        }
-       fence->seq =
 atomic_add_return(1,&rdev->fence_drv[fence->ring].seq);
 
+       /* we are protected by the ring emission mutex */
+       fence->seq = ++rdev->fence_drv[fence->ring].seq;
        radeon_fence_ring_emit(rdev, fence->ring, fence);

       trace_radeon_fence_emit(rdev->ddev, fence->seq);
-       fence->emitted = true;
       /* are we the first fence on a previusly idle ring? */ if (list_empty(&rdev->fence_drv[fence->ring].emitted)) { rdev->fence_drv[fence->ring].last_activity = jiffies;

drivers/gpu/drm/radeon/radeon_fence.c +48 -5
@@ -87,14 +87,60 @@ static bool radeon_fence_poll_locked(struct
 radeon_device *rdev, int ring)
  {
        struct radeon_fence *fence;
        struct list_head *i, *n;
-       uint32_t seq;
+       uint64_t seq, last_seq;
+       unsigned count_loop = 0;
        bool wake = false;
 
-       seq = radeon_fence_read(rdev, ring);
-       if (seq == rdev->fence_drv[ring].last_seq)
-               return false;
+       /* Note there is a scenario here for an infinite loop but it's
+        * very unlikely to happen. For it to happen, the current polling
+        * process need to be interrupted by another process and another
+        * process needs to update the last_seq btw the atomic read and
+        * xchg of the current process.
+        *
+        * More over for this to go in infinite loop there need to be
+        * continuously new fence signaled ie radeon_fence_read needs
+        * to return a different value each time for both the currently
+        * polling process and the other process that xchg the last_seq
+        * btw atomic read and xchg of the current process. And the
+        * value the other process set as last seq must be higher than
+        * the seq value we just read. Which means that current process
+        * need to be interrupted after radeon_fence_read and before
+        * atomic xchg.
+        *
+        * To be even more safe we count the number of time we loop and
+        * we bail after 10 loop just accepting the fact that we might
+        * have temporarly set the last_seq not to the true real last
+        * seq but to an older one.
+        */
+       last_seq = atomic64_read(&rdev->fence_drv[ring].last_seq);
+       do {
+               seq = radeon_fence_read(rdev, ring);
+               seq |= last_seq&  0xffffffff00000000LL;
 
+               if (seq<  last_seq) {
+                       seq += 0x100000000LL;
+               }
 
-       rdev->fence_drv[ring].last_seq = seq;
+               if (!wake&&  seq == last_seq) {
 
+                       return false;
+               }
+               /* If we loop over we don't want to return without
+                * checking if a fence is signaled as it means that the
+                * seq we just read is different from the previous on.
+                */
+               wake = true;
+               if ((count_loop++)>  10) {
+                       /* We looped over too many time leave with the
+                        * fact that we might have set an older fence
+                        * seq then the current real last seq as signaled
+                        * by the hw.
+                        */
+                       break;
+               }
+               last_seq = seq;
+       } while (atomic64_xchg(&rdev->fence_drv[ring].last_seq, seq)>

 seq);
+
+       /* reset wake to false */
+       wake = false; rdev->fence_drv[ring].last_activity = jiffies;

       n = NULL;

drivers/gpu/drm/radeon/radeon_fence.c +1 -1
@@ -112,7 +158,7 @@ static bool radeon_fence_poll_locked(struct
 radeon_device *rdev, int ring)
                        n = i->prev;
                        list_move_tail(i,&rdev->fence_drv[ring].signaled);
 
                        fence = list_entry(i, struct radeon_fence, list);
-                       fence->signaled = true;
+                       fence->seq = RADEON_FENCE_SIGNALED_SEQ;
                        i = n;

               } while (i !=&rdev->fence_drv[ring].emitted);

               wake = true;

drivers/gpu/drm/radeon/radeon_fence.c +5 -7
@@ -128,7 +174,7 @@ static void radeon_fence_destroy(struct kref *kref)
        fence = container_of(kref, struct radeon_fence, kref);
        write_lock_irqsave(&fence->rdev->fence_lock, irq_flags);
        list_del(&fence->list);
-       fence->emitted = false;
+       fence->seq = RADEON_FENCE_NOTEMITED_SEQ;
        write_unlock_irqrestore(&fence->rdev->fence_lock, irq_flags);
        if (fence->semaphore)
                radeon_semaphore_free(fence->rdev, fence->semaphore);
@@ -145,9 +191,7 @@ int radeon_fence_create(struct radeon_device *rdev,
        }
        kref_init(&((*fence)->kref));
        (*fence)->rdev = rdev;
-       (*fence)->emitted = false;
-       (*fence)->signaled = false;
-       (*fence)->seq = 0;
+       (*fence)->seq = RADEON_FENCE_NOTEMITED_SEQ;
        (*fence)->ring = ring;
        (*fence)->semaphore = NULL;
        INIT_LIST_HEAD(&(*fence)->list);
@@ -163,18 +207,18 @@ bool radeon_fence_signaled(struct radeon_fence
 *fence)
                return true;
 
        write_lock_irqsave(&fence->rdev->fence_lock, irq_flags);
-       signaled = fence->signaled;
+       signaled = (fence->seq == RADEON_FENCE_SIGNALED_SEQ);
        /* if we are shuting down report all fence as signaled */
        if (fence->rdev->shutdown) {
                signaled = true;
        }
-       if (!fence->emitted) {
+       if (fence->seq == RADEON_FENCE_NOTEMITED_SEQ) {
                WARN(1, "Querying an unemitted fence : %p !\n", fence);
                signaled = true;
        }
        if (!signaled) {
                radeon_fence_poll_locked(fence->rdev, fence->ring);
-               signaled = fence->signaled;
+               signaled = (fence->seq == RADEON_FENCE_SIGNALED_SEQ);
        }
        write_unlock_irqrestore(&fence->rdev->fence_lock, irq_flags);

       return signaled;

drivers/gpu/drm/radeon/radeon_fence.c +2 -2
@@ -183,8 +227,8 @@ bool radeon_fence_signaled(struct radeon_fence
 *fence)
  int radeon_fence_wait(struct radeon_fence *fence, bool intr)
  {
        struct radeon_device *rdev;
-       unsigned long irq_flags, timeout;
-       u32 seq;
+       unsigned long irq_flags, timeout, last_activity;
+       uint64_t seq;
        int i, r;
        bool signaled;
@@ -207,7 +251,9 @@ int radeon_fence_wait(struct radeon_fence *fence,
 bool intr)
                        timeout = 1;
                }
                /* save current sequence value used to check for GPU

lockups */
-               seq = rdev->fence_drv[fence->ring].last_seq;
+               seq = atomic64_read(&rdev->fence_drv[fence->ring].last_seq);
+               /* Save current last activity valuee, used to check for GPU lockups */
+               last_activity = rdev->fence_drv[fence->ring].last_activity; read_unlock_irqrestore(&rdev->fence_lock, irq_flags);

               trace_radeon_fence_wait_begin(rdev->ddev, seq);

drivers/gpu/drm/radeon/radeon_fence.c +0 -1
@@ -235,24 +281,23 @@ int radeon_fence_wait(struct radeon_fence *fence,
 bool intr)
                        }
 
                        write_lock_irqsave(&rdev->fence_lock, irq_flags);
-                       /* check if sequence value has changed since

last_activity */
-                       if (seq != rdev->fence_drv[fence->ring].last_seq) {
+                       /* test if somebody else has already decided that this is a lockup */
+                       if (last_activity != rdev->fence_drv[fence->ring].last_activity) { write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
                               continue;
                       }

-                       /* 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])) {

-
                               /* 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);
+                               dev_warn(rdev->dev, "GPU lockup (waiting for 0x%016llx last fence id 0x%016llx)\n",
+                                        fence->seq, seq);
+
+                               /* change last activity so nobody else think there is a lockup */
+                               for (i = 0; i<  RADEON_NUM_RINGS; ++i) {
+                                       rdev->fence_drv[i].last_activity = jiffies;
+                               }

                               /* mark the ring as not ready any more */ rdev->ring[fence->ring].ready = false;

drivers/gpu/drm/radeon/radeon_fence.c +1 -2
@@ -387,9 +432,9 @@ int radeon_fence_driver_start_ring(struct
 radeon_device *rdev, int ring)
        }
        rdev->fence_drv[ring].cpu_addr =&rdev->wb.wb[index/4];
 
        rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr + index;
-       radeon_fence_write(rdev,
 atomic_read(&rdev->fence_drv[ring]..seq), ring);
 
+       radeon_fence_write(rdev, rdev->fence_drv[ring].seq, ring);
        rdev->fence_drv[ring].initialized = true;
-       DRM_INFO("fence driver on ring %d use gpu addr 0x%08Lx and cpu

addr 0x%p\n",
+       DRM_INFO("fence driver on ring %d use gpu addr 0x%016llx and cpu addr 0x%p\n",
                ring, rdev->fence_drv[ring].gpu_addr, rdev->fence_drv[ring].cpu_addr); write_unlock_irqrestore(&rdev->fence_lock, irq_flags); return 0;

drivers/gpu/drm/radeon/radeon_fence.c +2 -1
@@ -400,7 +445,8 @@ static void radeon_fence_driver_init_ring(struct
 radeon_device *rdev, int ring)
        rdev->fence_drv[ring].scratch_reg = -1;
        rdev->fence_drv[ring].cpu_addr = NULL;
        rdev->fence_drv[ring].gpu_addr = 0;
-       atomic_set(&rdev->fence_drv[ring].seq, 0);
+       rdev->fence_drv[ring].seq = 0;
+       atomic64_set(&rdev->fence_drv[ring].last_seq, 0);
        INIT_LIST_HEAD(&rdev->fence_drv[ring].emitted);
        INIT_LIST_HEAD(&rdev->fence_drv[ring].signaled);

       init_waitqueue_head(&rdev->fence_drv[ring].queue);

drivers/gpu/drm/radeon/radeon_fence.c +2 -2
@@ -458,12 +504,12 @@ static int radeon_debugfs_fence_info(struct
 seq_file *m, void *data)
                        continue;
 
                seq_printf(m, "--- ring %d ---\n", i);
-               seq_printf(m, "Last signaled fence 0x%08X\n",
-                          radeon_fence_read(rdev, i));
+               seq_printf(m, "Last signaled fence 0x%016lx\n",
+                          atomic64_read(&rdev->fence_drv[i].last_seq));
                if (!list_empty(&rdev->fence_drv[i].emitted)) {

                       fence = list_entry(rdev->fence_drv[i].emitted.prev,
                                          struct radeon_fence, list);
-                       seq_printf(m, "Last emitted fence %p with 0x%08X\n",
+                       seq_printf(m, "Last emitted fence %p with 0x%016llx\n",
                                  fence,  fence->seq);
               }
       }

drivers/gpu/drm/radeon/radeon_ring.c +1 -1
index a4d60ae..4ae222b 100644
@@ -82,7 +82,7 @@ bool radeon_ib_try_free(struct radeon_device *rdev,
 struct radeon_ib *ib)
        bool done = false;
 
        /* only free ib which have been emited */
-       if (ib->fence&&  ib->fence->emitted) {
+       if (ib->fence&&  ib->fence->seq<  RADEON_FENCE_NOTEMITED_SEQ) {
 
                if (radeon_fence_signaled(ib->fence)) {

                       radeon_fence_unref(&ib->fence); radeon_sa_bo_free(rdev,&ib->sa_bo);

drivers/gpu/drm/radeon/radeon_ring.c +0 -0
@@ -149,8 +149,9 @@ retry:
        /* this should be rare event, ie all ib scheduled none signaled

yet.
        */
       for (i = 0; i<  RADEON_IB_POOL_SIZE; i++) {
-               if (rdev->ib_pool.ibs[idx].fence&& rdev->ib_pool.ibs[idx].fence->emitted) {

-                       r = radeon_fence_wait(rdev->ib_pool.ibs[idx].fence, false);
+               struct radeon_fence *fence = rdev->ib_pool.ibs[idx].fence;
+               if (fence&&  fence->seq<  RADEON_FENCE_NOTEMITED_SEQ) {

+                       r = radeon_fence_wait(fence, false); if (!r) {
                               goto retry;
                       }

drivers/gpu/drm/radeon/radeon_ring.c +1 -1
@@ -173,7 +174,7 @@ void radeon_ib_free(struct radeon_device *rdev,
 struct radeon_ib **ib)
                return;
        }
        radeon_mutex_lock(&rdev->ib_pool.mutex);
-       if (tmp->fence&&  !tmp->fence->emitted) {
+       if (tmp->fence&&  tmp->fence->seq == RADEON_FENCE_NOTEMITED_SEQ)
 {
                radeon_sa_bo_free(rdev,&tmp->sa_bo);

               radeon_fence_unref(&tmp->fence);
       }
--
1.7.5.4

#8 lore raw

PATCH 5/20 drm/radeon: rework fence handling, drop fence list v5

In reply to Christian König

From: Jerome Glisse <[email protected]>

Using 64bits fence sequence we can directly compare sequence number to know if a fence is signaled or not. Thus the fence list became useless, so does the fence lock that mainly protected the fence list.

Things like ring.ready are no longer behind a lock, this should be ok as ring.ready is initialized once and will only change when facing lockup. Worst case is that we return an -EBUSY just after a successfull GPU reset, or we go into wait state instead of returning -EBUSY (thus delaying reporting -EBUSY to fence wait caller).

v2: Remove left over comment, force using writeback on cayman and
newer, thus not having to suffer from possibly scratch reg exhaustion
v3: Rebase on top of change to uint64 fence patch
v4: Change DCE5 test to force write back on cayman and newer but
also any APU such as PALM or SUMO family
v5: Rebase on top of new uint64 fence patch
v6: Just break if seq doesn't change any more. Use radeon_fence
prefix for all function names. Even if it's now highly optimized, try avoiding polling to often.

---
 drivers/gpu/drm/radeon/radeon.h        |    6 +-
 drivers/gpu/drm/radeon/radeon_device.c |    8 +-
 drivers/gpu/drm/radeon/radeon_fence.c  |  289 +++++++++++++-------------------
 3 files changed, 118 insertions(+), 185 deletions(-)
drivers/gpu/drm/radeon/radeon.h +1 -5
index cdf46bc..7c87117 100644
@@ -263,15 +263,12 @@ struct radeon_fence_driver {
 	atomic64_t			last_seq;
 	unsigned long			last_activity;
 	wait_queue_head_t		queue;
-	struct list_head		emitted;
-	struct list_head		signaled;
 	bool				initialized;
 };
 
 struct radeon_fence {
 	struct radeon_device		*rdev;
 	struct kref			kref;
-	struct list_head		list;
 	/* protected by radeon_fence.lock */
 	uint64_t			seq;
 	/* RB, DMA, etc. */
@@ -291,7 +288,7 @@ int radeon_fence_wait_next(struct radeon_device *rdev, int ring);
 int radeon_fence_wait_empty(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);
+unsigned radeon_fence_count_emitted(struct radeon_device *rdev, int ring);
 
 /*
  * Tiling registers
@@ -1534,7 +1531,6 @@ struct radeon_device {
 	struct radeon_mode_info		mode_info;
 	struct radeon_scratch		scratch;
 	struct radeon_mman		mman;
-	rwlock_t			fence_lock;
 	struct radeon_fence_driver	fence_drv[RADEON_NUM_RINGS];
 	struct radeon_semaphore_driver	semaphore_drv;
 	struct mutex			ring_lock;
drivers/gpu/drm/radeon/radeon_device.c +4 -4
index 3f6ff2a..0e7b72a 100644
@@ -225,9 +225,9 @@ int radeon_wb_init(struct radeon_device *rdev)
 	/* disable event_write fences */
 	rdev->wb.use_event = false;
 	/* disabled via module param */
-	if (radeon_no_wb == 1)
+	if (radeon_no_wb == 1) {
 		rdev->wb.enabled = false;
-	else {
+	} else {
 		if (rdev->flags & RADEON_IS_AGP) {
 			/* often unreliable on AGP */
 			rdev->wb.enabled = false;
@@ -237,8 +237,9 @@ int radeon_wb_init(struct radeon_device *rdev)
 		} else {
 			rdev->wb.enabled = true;
 			/* event_write fences are only available on r600+ */
-			if (rdev->family >= CHIP_R600)
+			if (rdev->family >= CHIP_R600) {
 				rdev->wb.use_event = true;
+			}
 		}
 	}
 	/* always use writeback/events on NI, APUs */
@@ -731,7 +732,6 @@ int radeon_device_init(struct radeon_device *rdev,
 	mutex_init(&rdev->gem.mutex);
 	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);
drivers/gpu/drm/radeon/radeon_fence.c +113 -176

481 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
#9 lore raw

PATCH 6/20 drm/radeon: rework locking ring emission mutex in fence deadlock detection

In reply to Christian König

Some callers illegal called fence_wait_next/empty while holding the ring emission mutex. So don't relock the mutex in that cases, and move the actual locking into the fence code.

---
 drivers/gpu/drm/radeon/radeon.h        |    4 +-
 drivers/gpu/drm/radeon/radeon_device.c |    5 +++-
 drivers/gpu/drm/radeon/radeon_fence.c  |   39 ++++++++++++++++++++-----------
 drivers/gpu/drm/radeon/radeon_pm.c     |    8 +-----
 drivers/gpu/drm/radeon/radeon_ring.c   |    6 +----
 5 files changed, 33 insertions(+), 29 deletions(-)
drivers/gpu/drm/radeon/radeon.h +2 -2
index 7c87117..701094b 100644
@@ -284,8 +284,8 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence);
 void radeon_fence_process(struct radeon_device *rdev, int ring);
 bool radeon_fence_signaled(struct radeon_fence *fence);
 int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
-int radeon_fence_wait_next(struct radeon_device *rdev, int ring);
-int radeon_fence_wait_empty(struct radeon_device *rdev, int ring);
+int radeon_fence_wait_next_locked(struct radeon_device *rdev, int ring);
+int radeon_fence_wait_empty_locked(struct radeon_device *rdev, int ring);
 struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence);
 void radeon_fence_unref(struct radeon_fence **fence);
 unsigned radeon_fence_count_emitted(struct radeon_device *rdev, int ring);
drivers/gpu/drm/radeon/radeon_device.c +4 -1
index 0e7b72a..b827b2e 100644
@@ -912,9 +912,12 @@ int radeon_suspend_kms(struct drm_device *dev, pm_message_t state)
 	}
 	/* evict vram memory */
 	radeon_bo_evict_vram(rdev);
+
+	mutex_lock(&rdev->ring_lock);
 	/* wait for gpu to finish processing current batch */
 	for (i = 0; i < RADEON_NUM_RINGS; i++)
-		radeon_fence_wait_empty(rdev, i);
+		radeon_fence_wait_empty_locked(rdev, i);
+	mutex_unlock(&rdev->ring_lock);
 
 	radeon_save_bios_scratch_regs(rdev);
 
drivers/gpu/drm/radeon/radeon_fence.c +25 -14
index f386807..8034b42 100644
@@ -192,7 +192,7 @@ bool radeon_fence_signaled(struct radeon_fence *fence)
 }
 
 static int radeon_fence_wait_seq(struct radeon_device *rdev, u64 target_seq,
-				 unsigned ring, bool intr)
+				 unsigned ring, bool intr, bool lock_ring)
 {
 	unsigned long timeout, last_activity;
 	uint64_t seq;
@@ -247,8 +247,14 @@ static int radeon_fence_wait_seq(struct radeon_device *rdev, u64 target_seq,
 			if (seq != atomic64_read(&rdev->fence_drv[ring].last_seq)) {
 				continue;
 			}
+
+			if (lock_ring) {
+				mutex_lock(&rdev->ring_lock);
+			}
+
 			/* test if somebody else has already decided that this is a lockup */
 			if (last_activity != rdev->fence_drv[ring].last_activity) {
+				mutex_unlock(&rdev->ring_lock);
 				continue;
 			}
 
@@ -262,15 +268,15 @@ static int radeon_fence_wait_seq(struct radeon_device *rdev, u64 target_seq,
 					rdev->fence_drv[i].last_activity = jiffies;
 				}
 
-				/* change last activity so nobody else think there is a lockup */
-				for (i = 0; i < RADEON_NUM_RINGS; ++i) {
-					rdev->fence_drv[i].last_activity = jiffies;
-				}
-
 				/* mark the ring as not ready any more */
 				rdev->ring[ring].ready = false;
+				mutex_unlock(&rdev->ring_lock);
 				return -EDEADLK;
 			}
+
+			if (lock_ring) {
+				mutex_unlock(&rdev->ring_lock);
+			}
 		}
 	}
 	return 0;
@@ -285,7 +291,8 @@ int radeon_fence_wait(struct radeon_fence *fence, bool intr)
 		return -EINVAL;
 	}
 
-	r = radeon_fence_wait_seq(fence->rdev, fence->seq, fence->ring, intr);
+	r = radeon_fence_wait_seq(fence->rdev, fence->seq,
+				  fence->ring, intr, true);
 	if (r) {
 		return r;
 	}
@@ -293,7 +300,7 @@ int radeon_fence_wait(struct radeon_fence *fence, bool intr)
 	return 0;
 }
 
-int radeon_fence_wait_next(struct radeon_device *rdev, int ring)
+int radeon_fence_wait_next_locked(struct radeon_device *rdev, int ring)
 {
 	uint64_t seq;
 
@@ -303,20 +310,22 @@ int radeon_fence_wait_next(struct radeon_device *rdev, int ring)
 	 */
 	seq = atomic64_read(&rdev->fence_drv[ring].last_seq) + 1ULL;
 	if (seq >= rdev->fence_drv[ring].seq) {
-		/* nothing to wait for, last_seq is already the last emited fence */
-		return 0;
+		/* nothing to wait for, last_seq is
+		   already the last emited fence */
+		return -ENOENT;
 	}
-	return radeon_fence_wait_seq(rdev, seq, ring, false);
+	return radeon_fence_wait_seq(rdev, seq, ring, false, false);
 }
 
-int radeon_fence_wait_empty(struct radeon_device *rdev, int ring)
+int radeon_fence_wait_empty_locked(struct radeon_device *rdev, int ring)
 {
 	/* We are not protected by ring lock when reading current seq
 	 * but it's ok as wait empty is call from place where no more
 	 * activity can be scheduled so there won't be concurrent access
 	 * to seq value.
 	 */
-	return radeon_fence_wait_seq(rdev, rdev->fence_drv[ring].seq, ring, false);
+	return radeon_fence_wait_seq(rdev, rdev->fence_drv[ring].seq,
+				     ring, false, false);
 }
 
 struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence)
@@ -418,14 +427,16 @@ void radeon_fence_driver_fini(struct radeon_device *rdev)
 {
 	int ring;
 
+	mutex_lock(&rdev->ring_lock);
 	for (ring = 0; ring < RADEON_NUM_RINGS; ring++) {
 		if (!rdev->fence_drv[ring].initialized)
 			continue;
-		radeon_fence_wait_empty(rdev, ring);
+		radeon_fence_wait_empty_locked(rdev, ring);
 		wake_up_all(&rdev->fence_drv[ring].queue);
 		radeon_scratch_free(rdev, rdev->fence_drv[ring].scratch_reg);
 		rdev->fence_drv[ring].initialized = false;
 	}
+	mutex_unlock(&rdev->ring_lock);
 }
 
 
drivers/gpu/drm/radeon/radeon_pm.c +1 -7
index 7c38745..0882554 100644
@@ -270,13 +270,7 @@ static void radeon_pm_set_clocks(struct radeon_device *rdev)
 	} else {
 		struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
 		if (ring->ready) {
-			struct radeon_fence *fence;
-			radeon_ring_alloc(rdev, ring, 64);
-			radeon_fence_create(rdev, &fence, radeon_ring_index(rdev, ring));
-			radeon_fence_emit(rdev, fence);
-			radeon_ring_commit(rdev, ring);
-			radeon_fence_wait(fence, false);
-			radeon_fence_unref(&fence);
+			radeon_fence_wait_empty_locked(rdev, RADEON_RING_TYPE_GFX_INDEX);
 		}
 	}
 	radeon_unmap_vram_bos(rdev);
drivers/gpu/drm/radeon/radeon_ring.c +1 -5
index 4ae222b..2fdc8c3 100644
@@ -347,9 +347,7 @@ int radeon_ring_alloc(struct radeon_device *rdev, struct radeon_ring *ring, unsi
 		if (ndw < ring->ring_free_dw) {
 			break;
 		}
-		mutex_unlock(&rdev->ring_lock);
-		r = radeon_fence_wait_next(rdev, radeon_ring_index(rdev, ring));
-		mutex_lock(&rdev->ring_lock);
+		r = radeon_fence_wait_next_locked(rdev, radeon_ring_index(rdev, ring));
 		if (r)
 			return r;
 	}
@@ -408,7 +406,6 @@ void radeon_ring_force_activity(struct radeon_device *rdev, struct radeon_ring *
 {
 	int r;
 
-	mutex_lock(&rdev->ring_lock);
 	radeon_ring_free_size(rdev, ring);
 	if (ring->rptr == ring->wptr) {
 		r = radeon_ring_alloc(rdev, ring, 1);
@@ -417,7 +414,6 @@ void radeon_ring_force_activity(struct radeon_device *rdev, struct radeon_ring *
 			radeon_ring_commit(rdev, ring);
 		}
 	}
-	mutex_unlock(&rdev->ring_lock);
 }
 
 void radeon_ring_lockup_update(struct radeon_ring *ring)
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 7/20 drm/radeon: use inline functions to calc sa_bo addr

In reply to Christian König

Instead of hacking the calculation multiple times.

---
 drivers/gpu/drm/radeon/radeon_gart.c      |    6 ++----
 drivers/gpu/drm/radeon/radeon_object.h    |   11 +++++++++++
 drivers/gpu/drm/radeon/radeon_ring.c      |    6 ++----
 drivers/gpu/drm/radeon/radeon_semaphore.c |    6 ++----
 4 files changed, 17 insertions(+), 12 deletions(-)
drivers/gpu/drm/radeon/radeon_gart.c +2 -4
index c58a036..4a5d9d4 100644
@@ -404,10 +404,8 @@ retry:
 		radeon_vm_unbind(rdev, vm_evict);
 		goto retry;
 	}
-	vm->pt = rdev->vm_manager.sa_manager.cpu_ptr;
-	vm->pt += (vm->sa_bo.offset >> 3);
-	vm->pt_gpu_addr = rdev->vm_manager.sa_manager.gpu_addr;
-	vm->pt_gpu_addr += vm->sa_bo.offset;
+	vm->pt = radeon_sa_bo_cpu_addr(&vm->sa_bo);
+	vm->pt_gpu_addr = radeon_sa_bo_gpu_addr(&vm->sa_bo);
 	memset(vm->pt, 0, RADEON_GPU_PAGE_ALIGN(vm->last_pfn * 8));
 
 retry_id:
drivers/gpu/drm/radeon/radeon_object.h +11 -0
index f9104be..c120ab9 100644
@@ -146,6 +146,17 @@ extern struct radeon_bo_va *radeon_bo_va(struct radeon_bo *rbo,
 /*
  * sub allocation
  */
+
+static inline uint64_t radeon_sa_bo_gpu_addr(struct radeon_sa_bo *sa_bo)
+{
+	return sa_bo->manager->gpu_addr + sa_bo->offset;
+}
+
+static inline void * radeon_sa_bo_cpu_addr(struct radeon_sa_bo *sa_bo)
+{
+	return sa_bo->manager->cpu_ptr + sa_bo->offset;
+}
+
 extern int radeon_sa_bo_manager_init(struct radeon_device *rdev,
 				     struct radeon_sa_manager *sa_manager,
 				     unsigned size, u32 domain);
drivers/gpu/drm/radeon/radeon_ring.c +2 -4
index 2fdc8c3..116be5e 100644
@@ -127,10 +127,8 @@ retry:
 					     size, 256);
 			if (!r) {
 				*ib = &rdev->ib_pool.ibs[idx];
-				(*ib)->ptr = rdev->ib_pool.sa_manager.cpu_ptr;
-				(*ib)->ptr += ((*ib)->sa_bo.offset >> 2);
-				(*ib)->gpu_addr = rdev->ib_pool.sa_manager.gpu_addr;
-				(*ib)->gpu_addr += (*ib)->sa_bo.offset;
+				(*ib)->ptr = radeon_sa_bo_cpu_addr(&(*ib)->sa_bo);
+				(*ib)->gpu_addr = radeon_sa_bo_gpu_addr(&(*ib)->sa_bo);
 				(*ib)->fence = fence;
 				(*ib)->vm_id = 0;
 				(*ib)->is_const_ib = false;
drivers/gpu/drm/radeon/radeon_semaphore.c +2 -4
index c5b3d8e..f312ba5 100644
@@ -53,10 +53,8 @@ static int radeon_semaphore_add_bo(struct radeon_device *rdev)
 		kfree(bo);
 		return r;
 	}
-	gpu_addr = rdev->ib_pool.sa_manager.gpu_addr;
-	gpu_addr += bo->ib->sa_bo.offset;
-	cpu_ptr = rdev->ib_pool.sa_manager.cpu_ptr;
-	cpu_ptr += (bo->ib->sa_bo.offset >> 2);
+	gpu_addr = radeon_sa_bo_gpu_addr(&bo->ib->sa_bo);
+	cpu_ptr = radeon_sa_bo_cpu_addr(&bo->ib->sa_bo);
 	for (i = 0; i < (RADEON_SEMAPHORE_BO_SIZE/8); i++) {
 		bo->semaphores[i].gpu_addr = gpu_addr;
 		bo->semaphores[i].cpu_ptr = cpu_ptr;
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 8/20 drm/radeon: add proper locking to the SA v3

In reply to Christian König

Make the suballocator self containing to locking.

v2: split the bugfix into a seperate patch.
v3: remove some unreleated changes.

---
 drivers/gpu/drm/radeon/radeon.h    |    1 +
 drivers/gpu/drm/radeon/radeon_sa.c |    6 ++++++
 2 files changed, 7 insertions(+), 0 deletions(-)
drivers/gpu/drm/radeon/radeon.h +1 -0
index 701094b..8a6b1b3 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 +6 -0
index 8fbfe69..aed0a8c 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;
@@ -139,6 +140,7 @@ int radeon_sa_bo_new(struct radeon_device *rdev,
 
 	BUG_ON(align > RADEON_GPU_PAGE_SIZE);
 	BUG_ON(size > sa_manager->size);
+	spin_lock(&sa_manager->lock);
 
 	/* no one ? */
 	head = sa_manager->sa_bo.prev;
@@ -172,6 +174,7 @@ int radeon_sa_bo_new(struct radeon_device *rdev,
 	offset += wasted;
 	if ((sa_manager->size - offset) < size) {
 		/* failed to find somethings big enough */
+		spin_unlock(&sa_manager->lock);
 		return -ENOMEM;
 	}
 
@@ -180,10 +183,13 @@ out:
 	sa_bo->offset = offset;
 	sa_bo->size = size;
 	list_add(&sa_bo->list, head);
+	spin_unlock(&sa_manager->lock);
 	return 0;
 }
 
 void radeon_sa_bo_free(struct radeon_device *rdev, struct radeon_sa_bo *sa_bo)
 {
+	spin_lock(&sa_bo->manager->lock);
 	list_del_init(&sa_bo->list);
+	spin_unlock(&sa_bo->manager->lock);
 }
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 9/20 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     |   14 ++++++++++++++
 3 files changed, 41 insertions(+), 0 deletions(-)
drivers/gpu/drm/radeon/radeon_object.h +5 -0
index c120ab9..d9fca1e 100644
@@ -172,5 +172,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 116be5e..f49c9c0 100644
@@ -601,6 +601,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)
@@ -627,6 +644,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 +14 -0
index aed0a8c..1db0568 100644
@@ -193,3 +193,17 @@ void radeon_sa_bo_free(struct radeon_device *rdev, struct radeon_sa_bo *sa_bo)
 	list_del_init(&sa_bo->list);
 	spin_unlock(&sa_bo->manager->lock);
 }
+
+#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;
+
+	spin_lock(&sa_manager->lock);
+	list_for_each_entry(i, &sa_manager->sa_bo, list) {
+		seq_printf(m, "offset %08d: size %4d\n", i->offset, i->size);
+	}
+	spin_unlock(&sa_manager->lock);
+}
+#endif
Signature · 6 lines
1.7.5.4

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

PATCH 10/20 drm/radeon: keep start and end offset in the SA

In reply to Christian König

Instead of offset + size keep start and end offset directly.

---
 drivers/gpu/drm/radeon/radeon.h        |    4 ++--
 drivers/gpu/drm/radeon/radeon_cs.c     |    4 ++--
 drivers/gpu/drm/radeon/radeon_object.h |    4 ++--
 drivers/gpu/drm/radeon/radeon_sa.c     |   13 +++++++------
 4 files changed, 13 insertions(+), 12 deletions(-)
drivers/gpu/drm/radeon/radeon.h +2 -2
index 8a6b1b3..d1c2154 100644
@@ -396,8 +396,8 @@ struct radeon_sa_bo;
 struct radeon_sa_bo {
 	struct list_head		list;
 	struct radeon_sa_manager	*manager;
-	unsigned			offset;
-	unsigned			size;
+	unsigned			soffset;
+	unsigned			eoffset;
 };
 
 /*
drivers/gpu/drm/radeon/radeon_cs.c +2 -2
index 289b0d7..b778037 100644
@@ -477,7 +477,7 @@ static int radeon_cs_ib_vm_chunk(struct radeon_device *rdev,
 		/* ib pool is bind at 0 in virtual address space to gpu_addr is the
 		 * offset inside the pool bo
 		 */
-		parser->const_ib->gpu_addr = parser->const_ib->sa_bo.offset;
+		parser->const_ib->gpu_addr = parser->const_ib->sa_bo.soffset;
 		r = radeon_ib_schedule(rdev, parser->const_ib);
 		if (r)
 			goto out;
@@ -487,7 +487,7 @@ static int radeon_cs_ib_vm_chunk(struct radeon_device *rdev,
 	/* ib pool is bind at 0 in virtual address space to gpu_addr is the
 	 * offset inside the pool bo
 	 */
-	parser->ib->gpu_addr = parser->ib->sa_bo.offset;
+	parser->ib->gpu_addr = parser->ib->sa_bo.soffset;
 	parser->ib->is_const_ib = false;
 	r = radeon_ib_schedule(rdev, parser->ib);
 out:
drivers/gpu/drm/radeon/radeon_object.h +2 -2
index d9fca1e..99ab46a 100644
@@ -149,12 +149,12 @@ extern struct radeon_bo_va *radeon_bo_va(struct radeon_bo *rbo,
 
 static inline uint64_t radeon_sa_bo_gpu_addr(struct radeon_sa_bo *sa_bo)
 {
-	return sa_bo->manager->gpu_addr + sa_bo->offset;
+	return sa_bo->manager->gpu_addr + sa_bo->soffset;
 }
 
 static inline void * radeon_sa_bo_cpu_addr(struct radeon_sa_bo *sa_bo)
 {
-	return sa_bo->manager->cpu_ptr + sa_bo->offset;
+	return sa_bo->manager->cpu_ptr + sa_bo->soffset;
 }
 
 extern int radeon_sa_bo_manager_init(struct radeon_device *rdev,
drivers/gpu/drm/radeon/radeon_sa.c +7 -6
index 1db0568..3bea7ba 100644
@@ -152,11 +152,11 @@ int radeon_sa_bo_new(struct radeon_device *rdev,
 	offset = 0;
 	list_for_each_entry(tmp, &sa_manager->sa_bo, list) {
 		/* room before this object ? */
-		if (offset < tmp->offset && (tmp->offset - offset) >= size) {
+		if (offset < tmp->soffset && (tmp->soffset - offset) >= size) {
 			head = tmp->list.prev;
 			goto out;
 		}
-		offset = tmp->offset + tmp->size;
+		offset = tmp->eoffset;
 		wasted = offset % align;
 		if (wasted) {
 			wasted = align - wasted;
@@ -166,7 +166,7 @@ int radeon_sa_bo_new(struct radeon_device *rdev,
 	/* room at the end ? */
 	head = sa_manager->sa_bo.prev;
 	tmp = list_entry(head, struct radeon_sa_bo, list);
-	offset = tmp->offset + tmp->size;
+	offset = tmp->eoffset;
 	wasted = offset % align;
 	if (wasted) {
 		wasted = align - wasted;
@@ -180,8 +180,8 @@ int radeon_sa_bo_new(struct radeon_device *rdev,
 
 out:
 	sa_bo->manager = sa_manager;
-	sa_bo->offset = offset;
-	sa_bo->size = size;
+	sa_bo->soffset = offset;
+	sa_bo->eoffset = offset + size;
 	list_add(&sa_bo->list, head);
 	spin_unlock(&sa_manager->lock);
 	return 0;
@@ -202,7 +202,8 @@ void radeon_sa_bo_dump_debug_info(struct radeon_sa_manager *sa_manager,
 
 	spin_lock(&sa_manager->lock);
 	list_for_each_entry(i, &sa_manager->sa_bo, list) {
-		seq_printf(m, "offset %08d: size %4d\n", i->offset, i->size);
+		seq_printf(m, "[%08x %08x] size %4d [%p]\n",
+			   i->soffset, i->eoffset, i->eoffset - i->soffset, i);
 	}
 	spin_unlock(&sa_manager->lock);
 }
Signature · 6 lines
1.7.5.4

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

PATCH 11/20 drm/radeon: make sa bo a stand alone object

In reply to Christian König

Allocating and freeing it seperately.

---
 drivers/gpu/drm/radeon/radeon.h           |    4 ++--
 drivers/gpu/drm/radeon/radeon_cs.c        |    4 ++--
 drivers/gpu/drm/radeon/radeon_gart.c      |    4 ++--
 drivers/gpu/drm/radeon/radeon_object.h    |    4 ++--
 drivers/gpu/drm/radeon/radeon_ring.c      |    6 +++---
 drivers/gpu/drm/radeon/radeon_sa.c        |   28 +++++++++++++++++++---------
 drivers/gpu/drm/radeon/radeon_semaphore.c |    4 ++--
 7 files changed, 32 insertions(+), 22 deletions(-)
drivers/gpu/drm/radeon/radeon.h +2 -2
index d1c2154..9374ab1 100644
@@ -638,7 +638,7 @@ void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc);
  */
 
 struct radeon_ib {
-	struct radeon_sa_bo	sa_bo;
+	struct radeon_sa_bo	*sa_bo;
 	unsigned		idx;
 	uint32_t		length_dw;
 	uint64_t		gpu_addr;
@@ -693,7 +693,7 @@ struct radeon_vm {
 	unsigned			last_pfn;
 	u64				pt_gpu_addr;
 	u64				*pt;
-	struct radeon_sa_bo		sa_bo;
+	struct radeon_sa_bo		*sa_bo;
 	struct mutex			mutex;
 	/* last fence for cs using this vm */
 	struct radeon_fence		*fence;
drivers/gpu/drm/radeon/radeon_cs.c +2 -2
index b778037..5c065bf 100644
@@ -477,7 +477,7 @@ static int radeon_cs_ib_vm_chunk(struct radeon_device *rdev,
 		/* ib pool is bind at 0 in virtual address space to gpu_addr is the
 		 * offset inside the pool bo
 		 */
-		parser->const_ib->gpu_addr = parser->const_ib->sa_bo.soffset;
+		parser->const_ib->gpu_addr = parser->const_ib->sa_bo->soffset;
 		r = radeon_ib_schedule(rdev, parser->const_ib);
 		if (r)
 			goto out;
@@ -487,7 +487,7 @@ static int radeon_cs_ib_vm_chunk(struct radeon_device *rdev,
 	/* ib pool is bind at 0 in virtual address space to gpu_addr is the
 	 * offset inside the pool bo
 	 */
-	parser->ib->gpu_addr = parser->ib->sa_bo.soffset;
+	parser->ib->gpu_addr = parser->ib->sa_bo->soffset;
 	parser->ib->is_const_ib = false;
 	r = radeon_ib_schedule(rdev, parser->ib);
 out:
drivers/gpu/drm/radeon/radeon_gart.c +2 -2
index 4a5d9d4..c5789ef 100644
@@ -404,8 +404,8 @@ retry:
 		radeon_vm_unbind(rdev, vm_evict);
 		goto retry;
 	}
-	vm->pt = radeon_sa_bo_cpu_addr(&vm->sa_bo);
-	vm->pt_gpu_addr = radeon_sa_bo_gpu_addr(&vm->sa_bo);
+	vm->pt = radeon_sa_bo_cpu_addr(vm->sa_bo);
+	vm->pt_gpu_addr = radeon_sa_bo_gpu_addr(vm->sa_bo);
 	memset(vm->pt, 0, RADEON_GPU_PAGE_ALIGN(vm->last_pfn * 8));
 
 retry_id:
drivers/gpu/drm/radeon/radeon_object.h +2 -2
index 99ab46a..4fc7f07 100644
@@ -168,10 +168,10 @@ extern int radeon_sa_bo_manager_suspend(struct radeon_device *rdev,
 					struct radeon_sa_manager *sa_manager);
 extern int radeon_sa_bo_new(struct radeon_device *rdev,
 			    struct radeon_sa_manager *sa_manager,
-			    struct radeon_sa_bo *sa_bo,
+			    struct radeon_sa_bo **sa_bo,
 			    unsigned size, unsigned align);
 extern void radeon_sa_bo_free(struct radeon_device *rdev,
-			      struct radeon_sa_bo *sa_bo);
+			      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);
drivers/gpu/drm/radeon/radeon_ring.c +3 -3
index f49c9c0..45adb37 100644
@@ -127,8 +127,8 @@ retry:
 					     size, 256);
 			if (!r) {
 				*ib = &rdev->ib_pool.ibs[idx];
-				(*ib)->ptr = radeon_sa_bo_cpu_addr(&(*ib)->sa_bo);
-				(*ib)->gpu_addr = radeon_sa_bo_gpu_addr(&(*ib)->sa_bo);
+				(*ib)->ptr = radeon_sa_bo_cpu_addr((*ib)->sa_bo);
+				(*ib)->gpu_addr = radeon_sa_bo_gpu_addr((*ib)->sa_bo);
 				(*ib)->fence = fence;
 				(*ib)->vm_id = 0;
 				(*ib)->is_const_ib = false;
@@ -227,7 +227,7 @@ int radeon_ib_pool_init(struct radeon_device *rdev)
 		rdev->ib_pool.ibs[i].fence = NULL;
 		rdev->ib_pool.ibs[i].idx = i;
 		rdev->ib_pool.ibs[i].length_dw = 0;
-		INIT_LIST_HEAD(&rdev->ib_pool.ibs[i].sa_bo.list);
+		rdev->ib_pool.ibs[i].sa_bo = NULL;
 	}
 	rdev->ib_pool.head_id = 0;
 	rdev->ib_pool.ready = true;
drivers/gpu/drm/radeon/radeon_sa.c +19 -9
index 3bea7ba..625f2d4 100644
@@ -131,7 +131,7 @@ int radeon_sa_bo_manager_suspend(struct radeon_device *rdev,
  */
 int radeon_sa_bo_new(struct radeon_device *rdev,
 		     struct radeon_sa_manager *sa_manager,
-		     struct radeon_sa_bo *sa_bo,
+		     struct radeon_sa_bo **sa_bo,
 		     unsigned size, unsigned align)
 {
 	struct radeon_sa_bo *tmp;
@@ -140,6 +140,9 @@ int radeon_sa_bo_new(struct radeon_device *rdev,
 
 	BUG_ON(align > RADEON_GPU_PAGE_SIZE);
 	BUG_ON(size > sa_manager->size);
+
+	*sa_bo = kmalloc(sizeof(struct radeon_sa_bo), GFP_KERNEL);
+
 	spin_lock(&sa_manager->lock);
 
 	/* no one ? */
@@ -175,23 +178,30 @@ int radeon_sa_bo_new(struct radeon_device *rdev,
 	if ((sa_manager->size - offset) < size) {
 		/* failed to find somethings big enough */
 		spin_unlock(&sa_manager->lock);
+		kfree(*sa_bo);
+		*sa_bo = NULL;
 		return -ENOMEM;
 	}
 
 out:
-	sa_bo->manager = sa_manager;
-	sa_bo->soffset = offset;
-	sa_bo->eoffset = offset + size;
-	list_add(&sa_bo->list, head);
+	(*sa_bo)->manager = sa_manager;
+	(*sa_bo)->soffset = offset;
+	(*sa_bo)->eoffset = offset + size;
+	list_add(&(*sa_bo)->list, head);
 	spin_unlock(&sa_manager->lock);
 	return 0;
 }
 
-void radeon_sa_bo_free(struct radeon_device *rdev, struct radeon_sa_bo *sa_bo)
+void radeon_sa_bo_free(struct radeon_device *rdev, struct radeon_sa_bo **sa_bo)
 {
-	spin_lock(&sa_bo->manager->lock);
-	list_del_init(&sa_bo->list);
-	spin_unlock(&sa_bo->manager->lock);
+	if (!sa_bo || !*sa_bo)
+		return;
+
+	spin_lock(&(*sa_bo)->manager->lock);
+	list_del_init(&(*sa_bo)->list);
+	spin_unlock(&(*sa_bo)->manager->lock);
+	kfree(*sa_bo);
+	*sa_bo = NULL;
 }
 
 #if defined(CONFIG_DEBUG_FS)
drivers/gpu/drm/radeon/radeon_semaphore.c +2 -2
index f312ba5..d518d32 100644
@@ -53,8 +53,8 @@ static int radeon_semaphore_add_bo(struct radeon_device *rdev)
 		kfree(bo);
 		return r;
 	}
-	gpu_addr = radeon_sa_bo_gpu_addr(&bo->ib->sa_bo);
-	cpu_ptr = radeon_sa_bo_cpu_addr(&bo->ib->sa_bo);
+	gpu_addr = radeon_sa_bo_gpu_addr(bo->ib->sa_bo);
+	cpu_ptr = radeon_sa_bo_cpu_addr(bo->ib->sa_bo);
 	for (i = 0; i < (RADEON_SEMAPHORE_BO_SIZE/8); i++) {
 		bo->semaphores[i].gpu_addr = gpu_addr;
 		bo->semaphores[i].cpu_ptr = cpu_ptr;
Signature · 6 lines
1.7.5.4

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

PATCH 12/20 drm/radeon: define new SA interface v3

In reply to Christian König

Define the interface without modifying the allocation algorithm in any way.

v2: rebase on top of fence new uint64 patch
v3: add ring to debugfs output

---
 drivers/gpu/drm/radeon/radeon.h           |    1 +
 drivers/gpu/drm/radeon/radeon_gart.c      |    6 +-
 drivers/gpu/drm/radeon/radeon_object.h    |    5 +-
 drivers/gpu/drm/radeon/radeon_ring.c      |    8 ++--
 drivers/gpu/drm/radeon/radeon_sa.c        |   60 ++++++++++++++++++++++++----
 drivers/gpu/drm/radeon/radeon_semaphore.c |    2 +-
 6 files changed, 63 insertions(+), 19 deletions(-)
drivers/gpu/drm/radeon/radeon.h +1 -0
index 9374ab1..ada70d1 100644
@@ -398,6 +398,7 @@ struct radeon_sa_bo {
 	struct radeon_sa_manager	*manager;
 	unsigned			soffset;
 	unsigned			eoffset;
+	struct radeon_fence		*fence;
 };
 
 /*
drivers/gpu/drm/radeon/radeon_gart.c +3 -3
index c5789ef..53dba8e 100644
@@ -326,7 +326,7 @@ static void radeon_vm_unbind_locked(struct radeon_device *rdev,
 	rdev->vm_manager.use_bitmap &= ~(1 << vm->id);
 	list_del_init(&vm->list);
 	vm->id = -1;
-	radeon_sa_bo_free(rdev, &vm->sa_bo);
+	radeon_sa_bo_free(rdev, &vm->sa_bo, NULL);
 	vm->pt = NULL;
 
 	list_for_each_entry(bo_va, &vm->va, vm_list) {
@@ -395,7 +395,7 @@ int radeon_vm_bind(struct radeon_device *rdev, struct radeon_vm *vm)
 retry:
 	r = radeon_sa_bo_new(rdev, &rdev->vm_manager.sa_manager, &vm->sa_bo,
 			     RADEON_GPU_PAGE_ALIGN(vm->last_pfn * 8),
-			     RADEON_GPU_PAGE_SIZE);
+			     RADEON_GPU_PAGE_SIZE, false);
 	if (r) {
 		if (list_empty(&rdev->vm_manager.lru_vm)) {
 			return r;
@@ -426,7 +426,7 @@ retry_id:
 	/* do hw bind */
 	r = rdev->vm_manager.funcs->bind(rdev, vm, id);
 	if (r) {
-		radeon_sa_bo_free(rdev, &vm->sa_bo);
+		radeon_sa_bo_free(rdev, &vm->sa_bo, NULL);
 		return r;
 	}
 	rdev->vm_manager.use_bitmap |= 1 << id;
drivers/gpu/drm/radeon/radeon_object.h +3 -2
index 4fc7f07..befec7d 100644
@@ -169,9 +169,10 @@ extern int radeon_sa_bo_manager_suspend(struct radeon_device *rdev,
 extern int radeon_sa_bo_new(struct radeon_device *rdev,
 			    struct radeon_sa_manager *sa_manager,
 			    struct radeon_sa_bo **sa_bo,
-			    unsigned size, unsigned align);
+			    unsigned size, unsigned align, bool block);
 extern void radeon_sa_bo_free(struct radeon_device *rdev,
-			      struct radeon_sa_bo **sa_bo);
+			      struct radeon_sa_bo **sa_bo,
+			      struct radeon_fence *fence);
 #if defined(CONFIG_DEBUG_FS)
 extern void radeon_sa_bo_dump_debug_info(struct radeon_sa_manager *sa_manager,
 					 struct seq_file *m);
drivers/gpu/drm/radeon/radeon_ring.c +4 -4
index 45adb37..1748d93 100644
@@ -85,7 +85,7 @@ bool radeon_ib_try_free(struct radeon_device *rdev, struct radeon_ib *ib)
 	if (ib->fence && ib->fence->seq < RADEON_FENCE_NOTEMITED_SEQ) {
 		if (radeon_fence_signaled(ib->fence)) {
 			radeon_fence_unref(&ib->fence);
-			radeon_sa_bo_free(rdev, &ib->sa_bo);
+			radeon_sa_bo_free(rdev, &ib->sa_bo, NULL);
 			done = true;
 		}
 	}
@@ -124,7 +124,7 @@ retry:
 		if (rdev->ib_pool.ibs[idx].fence == NULL) {
 			r = radeon_sa_bo_new(rdev, &rdev->ib_pool.sa_manager,
 					     &rdev->ib_pool.ibs[idx].sa_bo,
-					     size, 256);
+					     size, 256, false);
 			if (!r) {
 				*ib = &rdev->ib_pool.ibs[idx];
 				(*ib)->ptr = radeon_sa_bo_cpu_addr((*ib)->sa_bo);
@@ -173,7 +173,7 @@ void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib)
 	}
 	radeon_mutex_lock(&rdev->ib_pool.mutex);
 	if (tmp->fence && tmp->fence->seq == RADEON_FENCE_NOTEMITED_SEQ) {
-		radeon_sa_bo_free(rdev, &tmp->sa_bo);
+		radeon_sa_bo_free(rdev, &tmp->sa_bo, NULL);
 		radeon_fence_unref(&tmp->fence);
 	}
 	radeon_mutex_unlock(&rdev->ib_pool.mutex);
@@ -247,7 +247,7 @@ void radeon_ib_pool_fini(struct radeon_device *rdev)
 	radeon_mutex_lock(&rdev->ib_pool.mutex);
 	if (rdev->ib_pool.ready) {
 		for (i = 0; i < RADEON_IB_POOL_SIZE; i++) {
-			radeon_sa_bo_free(rdev, &rdev->ib_pool.ibs[i].sa_bo);
+			radeon_sa_bo_free(rdev, &rdev->ib_pool.ibs[i].sa_bo, NULL);
 			radeon_fence_unref(&rdev->ib_pool.ibs[i].fence);
 		}
 		radeon_sa_bo_manager_fini(rdev, &rdev->ib_pool.sa_manager);
drivers/gpu/drm/radeon/radeon_sa.c +51 -9

107 lines not on this page · raw message

drivers/gpu/drm/radeon/radeon_semaphore.c +1 -1
index d518d32..dbde874 100644
@@ -72,7 +72,7 @@ static int radeon_semaphore_add_bo(struct radeon_device *rdev)
 static void radeon_semaphore_del_bo_locked(struct radeon_device *rdev,
 					   struct radeon_semaphore_bo *bo)
 {
-	radeon_sa_bo_free(rdev, &bo->ib->sa_bo);
+	radeon_sa_bo_free(rdev, &bo->ib->sa_bo, NULL);
 	radeon_fence_unref(&bo->ib->fence);
 	list_del(&bo->list);
 	kfree(bo);
Signature · 6 lines
1.7.5.4

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

PATCH 13/20 drm/radeon: use one wait queue for all rings add fence_wait_any v2

In reply to Christian König

From: Jerome Glisse <[email protected]>

Use one wait queue for all rings. When one ring progress, other likely does to and we are not expecting to have a lot of waiter anyway.

Also add a fence_wait_any that will wait until the first fence in the fence array (one fence per ring) is signaled. This allow to wait on all rings.

v2: some minor cleanups and improvements.

---
 drivers/gpu/drm/radeon/radeon.h       |    5 +-
 drivers/gpu/drm/radeon/radeon_fence.c |  163 ++++++++++++++++++++++++++++++++-
 2 files changed, 162 insertions(+), 6 deletions(-)
drivers/gpu/drm/radeon/radeon.h +4 -1
index ada70d1..37a7459 100644
@@ -262,7 +262,6 @@ struct radeon_fence_driver {
 	uint64_t			seq;
 	atomic64_t			last_seq;
 	unsigned long			last_activity;
-	wait_queue_head_t		queue;
 	bool				initialized;
 };
 
@@ -286,6 +285,9 @@ bool radeon_fence_signaled(struct radeon_fence *fence);
 int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
 int radeon_fence_wait_next_locked(struct radeon_device *rdev, int ring);
 int radeon_fence_wait_empty_locked(struct radeon_device *rdev, int ring);
+int radeon_fence_wait_any(struct radeon_device *rdev,
+			  struct radeon_fence **fences,
+			  bool intr);
 struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence);
 void radeon_fence_unref(struct radeon_fence **fence);
 unsigned radeon_fence_count_emitted(struct radeon_device *rdev, int ring);
@@ -1534,6 +1536,7 @@ struct radeon_device {
 	struct radeon_scratch		scratch;
 	struct radeon_mman		mman;
 	struct radeon_fence_driver	fence_drv[RADEON_NUM_RINGS];
+	wait_queue_head_t		fence_queue;
 	struct radeon_semaphore_driver	semaphore_drv;
 	struct mutex			ring_lock;
 	struct radeon_ring		ring[RADEON_NUM_RINGS];
drivers/gpu/drm/radeon/radeon_fence.c +158 -5

202 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
#17 lore raw

PATCH 14/20 drm/radeon: multiple ring allocator v2

In reply to Christian König

A startover with a new idea for a multiple ring allocator. Should perform as well as a normal ring allocator as long as only one ring does somthing, but falls back to a more complex algorithm if more complex things start to happen.

We store the last allocated bo in last, we always try to allocate after the last allocated bo. Principle is that in a linear GPU ring progression was is after last is the oldest bo we allocated and thus the first one that should no longer be in use by the GPU.

If it's not the case we skip over the bo after last to the closest done bo if such one exist. If none exist and we are not asked to block we report failure to allocate.

If we are asked to block we wait on all the oldest fence of all rings. We just wait for any of those fence to complete.

v2: We need to be able to let hole point to the list_head, otherwise
try free will never free the first allocation of the list. Also stop calling radeon_fence_signalled more than necessary.

---
 drivers/gpu/drm/radeon/radeon.h      |    7 +-
 drivers/gpu/drm/radeon/radeon_ring.c |   19 +--
 drivers/gpu/drm/radeon/radeon_sa.c   |  292 +++++++++++++++++++++++-----------
 3 files changed, 210 insertions(+), 108 deletions(-)
drivers/gpu/drm/radeon/radeon.h +5 -2
index 37a7459..cc7f16a 100644
@@ -385,7 +385,9 @@ struct radeon_bo_list {
 struct radeon_sa_manager {
 	spinlock_t		lock;
 	struct radeon_bo	*bo;
-	struct list_head	sa_bo;
+	struct list_head	*hole;
+	struct list_head	flist[RADEON_NUM_RINGS];
+	struct list_head	olist;
 	unsigned		size;
 	uint64_t		gpu_addr;
 	void			*cpu_ptr;
@@ -396,7 +398,8 @@ struct radeon_sa_bo;
 
 /* sub-allocation buffer */
 struct radeon_sa_bo {
-	struct list_head		list;
+	struct list_head		olist;
+	struct list_head		flist;
 	struct radeon_sa_manager	*manager;
 	unsigned			soffset;
 	unsigned			eoffset;
drivers/gpu/drm/radeon/radeon_ring.c +8 -11
index 1748d93..e074ff5 100644
@@ -204,25 +204,22 @@ 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_IB_POOL_SIZE*64*1024,
-				      RADEON_GEM_DOMAIN_GTT);
-	if (r) {
-		return r;
-	}
-
 	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);
+	r = radeon_sa_bo_manager_init(rdev, &rdev->ib_pool.sa_manager,
+				      RADEON_IB_POOL_SIZE*64*1024,
+				      RADEON_GEM_DOMAIN_GTT);
+	if (r) {
+		radeon_mutex_unlock(&rdev->ib_pool.mutex);
+		return r;
+	}
+
 	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 +197 -95

368 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
#18 lore raw

Re: [PATCH 14/20] drm/radeon: multiple ring allocator v2

Quoted 17 lines · Christian König

A startover with a new idea for a multiple ring allocator. Should perform as well as a normal ring allocator as long as only one ring does somthing, but falls back to a more complex algorithm if more complex things start to happen.

We store the last allocated bo in last, we always try to allocate after the last allocated bo. Principle is that in a linear GPU ring progression was is after last is the oldest bo we allocated and thus the first one that should no longer be in use by the GPU.

If it's not the case we skip over the bo after last to the closest done bo if such one exist. If none exist and we are not asked to block we report failure to allocate.

If we are asked to block we wait on all the oldest fence of all rings. We just wait for any of those fence to complete.

Quoted 6 lines

v2: We need to be able to let hole point to the list_head, otherwise try free will never free the first allocation of the list. Also stop calling radeon_fence_signalled more than necessary.

This one is NAK please use my patch. Yes in my patch we never try to free anything if there is only on sa_bo in the list if you really care about this it's a one line change:
http://people.freedesktop.org/~glisse/reset5/0001-drm-radeon-multiple-ring-allocator-v2.patch

Your patch here can enter in infinite loop and never return holding the lock. See below.

Cheers,
Jerome

Quoted 362 lines

---
 drivers/gpu/drm/radeon/radeon.h      |    7 +- drivers/gpu/drm/radeon/radeon_ring.c |   19 +-- drivers/gpu/drm/radeon/radeon_sa.c   |  292 +++++++++++++++++++++++-----------

 3 files changed, 210 insertions(+), 108 deletions(-)
drivers/gpu/drm/radeon/radeon.h +5 -2
index 37a7459..cc7f16a 100644
@@ -385,7 +385,9 @@ struct radeon_bo_list {
  struct radeon_sa_manager {
        spinlock_t              lock;
        struct radeon_bo        *bo;
-       struct list_head        sa_bo;
+       struct list_head        *hole;
+       struct list_head        flist[RADEON_NUM_RINGS];
+       struct list_head        olist;
        unsigned                size;
        uint64_t                gpu_addr;
        void                    *cpu_ptr;
@@ -396,7 +398,8 @@ struct radeon_sa_bo;
 
  /* sub-allocation buffer */
  struct radeon_sa_bo {
-       struct list_head                list;
+       struct list_head                olist;
+       struct list_head                flist;
        struct radeon_sa_manager        *manager;
        unsigned                        soffset;
        unsigned                        eoffset;
drivers/gpu/drm/radeon/radeon_ring.c +8 -11
index 1748d93..e074ff5 100644
@@ -204,25 +204,22 @@ 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_IB_POOL_SIZE*64*1024,
-                                     RADEON_GEM_DOMAIN_GTT);
-       if (r) {
-               return r;
-       }
-
        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);
+       r = radeon_sa_bo_manager_init(rdev, &rdev->ib_pool.sa_manager,
+                                     RADEON_IB_POOL_SIZE*64*1024,
+                                     RADEON_GEM_DOMAIN_GTT);
+       if (r) {
+               radeon_mutex_unlock(&rdev->ib_pool.mutex);
+               return r;
+       }
+
        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 +167 -69
index 90ee8ad..757a9d4 100644
@@ -27,21 +27,42 @@
  * Authors:
  *    Jerome Glisse <[email protected]>
  */
+/* Algorithm:
+ *
+ * We store the last allocated bo in "hole", we always try to allocate
+ * after the last allocated bo. Principle is that in a linear GPU ring
+ * progression was is after last is the oldest bo we allocated and thus
+ * the first one that should no longer be in use by the GPU.
+ *
+ * If it's not the case we skip over the bo after last to the closest
+ * done bo if such one exist. If none exist and we are not asked to
+ * block we report failure to allocate.
+ *
+ * If we are asked to block we wait on all the oldest fence of all
+ * rings. We just wait for any of those fence to complete.
+ */
  #include "drmP.h"
  #include "drm.h"
  #include "radeon.h"
 
+static void radeon_sa_bo_remove_locked(struct radeon_sa_bo *sa_bo);
+static void radeon_sa_bo_try_free(struct radeon_sa_manager *sa_manager);
+
  int radeon_sa_bo_manager_init(struct radeon_device *rdev,
                              struct radeon_sa_manager *sa_manager,
                              unsigned size, u32 domain)
  {
-       int r;
+       int i, r;
 
        spin_lock_init(&sa_manager->lock);
        sa_manager->bo = NULL;
        sa_manager->size = size;
        sa_manager->domain = domain;
-       INIT_LIST_HEAD(&sa_manager->sa_bo);
+       sa_manager->hole = &sa_manager->olist;
+       INIT_LIST_HEAD(&sa_manager->olist);
+       for (i = 0; i < RADEON_NUM_RINGS; ++i) {
+               INIT_LIST_HEAD(&sa_manager->flist[i]);
+       }
 
        r = radeon_bo_create(rdev, size, RADEON_GPU_PAGE_SIZE, true,
                             RADEON_GEM_DOMAIN_CPU, &sa_manager->bo);
@@ -58,11 +79,15 @@ void radeon_sa_bo_manager_fini(struct radeon_device *rdev,
  {
        struct radeon_sa_bo *sa_bo, *tmp;
 
-       if (!list_empty(&sa_manager->sa_bo)) {
-               dev_err(rdev->dev, "sa_manager is not empty, clearing anyway\n");
+       if (!list_empty(&sa_manager->olist)) {
+               sa_manager->hole = &sa_manager->olist,
+               radeon_sa_bo_try_free(sa_manager);
+               if (!list_empty(&sa_manager->olist)) {
+                       dev_err(rdev->dev, "sa_manager is not empty, clearing anyway\n");
+               }
        }
-       list_for_each_entry_safe(sa_bo, tmp, &sa_manager->sa_bo, list) {
-               list_del_init(&sa_bo->list);
+       list_for_each_entry_safe(sa_bo, tmp, &sa_manager->olist, olist) {
+               radeon_sa_bo_remove_locked(sa_bo);
        }
        radeon_bo_unref(&sa_manager->bo);
        sa_manager->size = 0;
@@ -114,111 +139,181 @@ int radeon_sa_bo_manager_suspend(struct radeon_device *rdev,
        return r;
  }
 
-/*
- * Principe is simple, we keep a list of sub allocation in offset
- * order (first entry has offset == 0, last entry has the highest
- * offset).
- *
- * When allocating new object we first check if there is room at
- * the end total_size - (last_object_offset + last_object_size) >=
- * alloc_size. If so we allocate new object there.
- *
- * When there is not enough room at the end, we start waiting for
- * each sub object until we reach object_offset+object_size >=
- * alloc_size, this object then become the sub object we return.
- *
- * Alignment can't be bigger than page size
- */
-
  static void radeon_sa_bo_remove_locked(struct radeon_sa_bo *sa_bo)
  {
-       list_del(&sa_bo->list);
+       struct radeon_sa_manager *sa_manager = sa_bo->manager;
+       if (sa_manager->hole == &sa_bo->olist) {
+               sa_manager->hole = sa_bo->olist.prev;
+       }
+       list_del_init(&sa_bo->olist);
+       list_del_init(&sa_bo->flist);
        radeon_fence_unref(&sa_bo->fence);
        kfree(sa_bo);
  }
 
+static void radeon_sa_bo_try_free(struct radeon_sa_manager *sa_manager)
+{
+       struct radeon_sa_bo *sa_bo, *tmp;
+
+       if (sa_manager->hole->next == &sa_manager->olist)
+               return;
+
+       sa_bo = list_entry(sa_manager->hole->next, struct radeon_sa_bo, olist);
+       list_for_each_entry_safe_from(sa_bo, tmp, &sa_manager->olist, olist) {
+               if (sa_bo->fence == NULL || !radeon_fence_signaled(sa_bo->fence)) {
+                       return;
+               }
+               radeon_sa_bo_remove_locked(sa_bo);
+       }
+}
+
+static inline unsigned radeon_sa_bo_hole_soffset(struct radeon_sa_manager *sa_manager)
+{
+       struct list_head *hole = sa_manager->hole;
+
+       if (hole != &sa_manager->olist) {
+               return list_entry(hole, struct radeon_sa_bo, olist)->eoffset;
+       }
+       return 0;
+}
+
+static inline unsigned radeon_sa_bo_hole_eoffset(struct radeon_sa_manager *sa_manager)
+{
+       struct list_head *hole = sa_manager->hole;
+
+       if (hole->next != &sa_manager->olist) {
+               return list_entry(hole->next, struct radeon_sa_bo, olist)->soffset;
+       }
+       return sa_manager->size;
+}
+
+static bool radeon_sa_bo_try_alloc(struct radeon_sa_manager *sa_manager,
+                                  struct radeon_sa_bo *sa_bo,
+                                  unsigned size, unsigned align)
+{
+       unsigned soffset, eoffset, wasted;
+
+       soffset = radeon_sa_bo_hole_soffset(sa_manager);
+       eoffset = radeon_sa_bo_hole_eoffset(sa_manager);
+       wasted = (align - (soffset % align)) % align;
+
+       if ((eoffset - soffset) >= (size + wasted)) {
+               soffset += wasted;
+
+               sa_bo->manager = sa_manager;
+               sa_bo->soffset = soffset;
+               sa_bo->eoffset = soffset + size;
+               list_add(&sa_bo->olist, sa_manager->hole);
+               INIT_LIST_HEAD(&sa_bo->flist);
+               sa_manager->hole = &sa_bo->olist;
+               return true;
+       }
+       return false;
+}
+
+static bool radeon_sa_bo_next_hole(struct radeon_sa_manager *sa_manager,
+                                  struct radeon_fence **fences)
+{
+       unsigned i, soffset, best, tmp;
+
+       /* if hole points to the end of the buffer */
+       if (sa_manager->hole->next == &sa_manager->olist) {
+               /* try again with its beginning */
+               sa_manager->hole = &sa_manager->olist;
+               return true;
+       }
+
+       soffset = radeon_sa_bo_hole_soffset(sa_manager);
+       /* to handle wrap around we add sa_manager->size */
+       best = sa_manager->size * 2;
+       /* go over all fence list and try to find the closest sa_bo
+        * of the current last
+        */
+       for (i = 0; i < RADEON_NUM_RINGS; ++i) {
+               struct radeon_sa_bo *sa_bo;
+
+               if (list_empty(&sa_manager->flist[i])) {
+                       fences[i] = NULL;
+                       continue;
+               }
+
+               sa_bo = list_first_entry(&sa_manager->flist[i],
+                                        struct radeon_sa_bo, flist);
+
+               if (!radeon_fence_signaled(sa_bo->fence)) {
+                       fences[i] = sa_bo->fence;
+                       continue;
+               }
+
+               tmp = sa_bo->soffset;
+               if (tmp < soffset) {
+                       /* wrap around, pretend it's after */
+                       tmp += sa_manager->size;
+               }
+               tmp -= soffset;
+               if (tmp < best) {
+                       /* this sa bo is the closest one */
+                       best = tmp;
+                       sa_manager->hole = sa_bo->olist.prev;
+               }
+
+               /* we knew that this one is signaled,
+                  so it's save to remote it */
+               radeon_sa_bo_remove_locked(sa_bo);
+       }
+       return best != sa_manager->size * 2;
+}
+
  int radeon_sa_bo_new(struct radeon_device *rdev,
                     struct radeon_sa_manager *sa_manager,
                     struct radeon_sa_bo **sa_bo,
                     unsigned size, unsigned align, bool block)
  {
-       struct radeon_fence *fence = NULL;
-       struct radeon_sa_bo *tmp, *next;
-       struct list_head *head;
-       unsigned offset = 0, wasted = 0;
-       int r;
+       struct radeon_fence *fences[RADEON_NUM_RINGS];
+       int r = -ENOMEM;
 
        BUG_ON(align > RADEON_GPU_PAGE_SIZE);
        BUG_ON(size > sa_manager->size);
 
        *sa_bo = kmalloc(sizeof(struct radeon_sa_bo), GFP_KERNEL);
-
-retry:
+       if ((*sa_bo) == NULL) {
+               return -ENOMEM;
+       }
+       (*sa_bo)->manager = sa_manager;
+       (*sa_bo)->fence = NULL;
+       INIT_LIST_HEAD(&(*sa_bo)->olist);
+       INIT_LIST_HEAD(&(*sa_bo)->flist);
 
        spin_lock(&sa_manager->lock);
+       do {
+               /* try to allocate couple time before going to wait */
+               do {
+                       radeon_sa_bo_try_free(sa_manager);
 
-       /* no one ? */
-       head = sa_manager->sa_bo.prev;
-       if (list_empty(&sa_manager->sa_bo)) {
-               goto out;
-       }
-
-       /* look for a hole big enough */
-       offset = 0;
-       list_for_each_entry_safe(tmp, next, &sa_manager->sa_bo, list) {
-               /* try to free this object */
-               if (tmp->fence) {
-                       if (radeon_fence_signaled(tmp->fence)) {
-                               radeon_sa_bo_remove_locked(tmp);
-                               continue;
-                       } else {
-                               fence = tmp->fence;
+                       if (radeon_sa_bo_try_alloc(sa_manager, *sa_bo,
+                                                  size, align)) {
+                               spin_unlock(&sa_manager->lock);
+                               return 0;
                        }
-               }
 
-               /* room before this object ? */
-               if (offset < tmp->soffset && (tmp->soffset - offset) >= size) {
-                       head = tmp->list.prev;
-                       goto out;
-               }
-               offset = tmp->eoffset;
-               wasted = offset % align;
-               if (wasted) {
-                       wasted = align - wasted;
-               }
-               offset += wasted;
-       }
-       /* room at the end ? */
-       head = sa_manager->sa_bo.prev;
-       tmp = list_entry(head, struct radeon_sa_bo, list);
-       offset = tmp->eoffset;
-       wasted = offset % align;
-       if (wasted) {
-               wasted = align - wasted;
-       }
-       offset += wasted;
-       if ((sa_manager->size - offset) < size) {

drivers/gpu/drm/radeon/radeon_sa.c int radeon_sa_bo_manager_suspend(struct radeon_device *rdev, · line 300

Quoted 10 lines
drivers/gpu/drm/radeon/radeon_sa.c +2 -8
-               /* failed to find somethings big enough */
-               spin_unlock(&sa_manager->lock);
-               if (block && fence) {
-                       r = radeon_fence_wait(fence, false);
-                       if (r)
-                               return r;
-
-                       goto retry;
+                       /* see if we can skip over some allocations */
+               } while (radeon_sa_bo_next_hole(sa_manager, fences));

Here you can infinite loop, in the case there is a bunch of hole in the allocator but none of them allow to full fill the allocation. radeon_sa_bo_next_hole will keep returning true looping over and over on all the all. That's why i only restrict my patch to 2 hole skeeping and then fails the allocation or try to wait. I believe sadly we need an heuristic and 2 hole skeeping at most sounded like a good one.

Quoted 77 lines
drivers/gpu/drm/radeon/radeon_sa.c +28 -19
+
+               if (block) {
+                       spin_unlock(&sa_manager->lock);
+                       r = radeon_fence_wait_any(rdev, fences, false);
+                       spin_lock(&sa_manager->lock);
+                       if (r) {
+                               goto out_err;
+                       }
                }
-               kfree(*sa_bo);
-               *sa_bo = NULL;
-               return -ENOMEM;
-       }
+       } while (block);
 
-out:
-       (*sa_bo)->manager = sa_manager;
-       (*sa_bo)->soffset = offset;
-       (*sa_bo)->eoffset = offset + size;
-       list_add(&(*sa_bo)->list, head);
+out_err:
        spin_unlock(&sa_manager->lock);
-       return 0;
+       kfree(*sa_bo);
+       *sa_bo = NULL;
+       return r;
  }
 
  void radeon_sa_bo_free(struct radeon_device *rdev, struct radeon_sa_bo **sa_bo,
@@ -226,13 +321,16 @@ void radeon_sa_bo_free(struct radeon_device *rdev, struct radeon_sa_bo **sa_bo,
  {
        struct radeon_sa_manager *sa_manager;
 
-       if (!sa_bo || !*sa_bo)
+       if (sa_bo == NULL || *sa_bo == NULL) {
                return;
+       }
 
        sa_manager = (*sa_bo)->manager;
        spin_lock(&sa_manager->lock);
        if (fence && fence->seq && fence->seq < RADEON_FENCE_NOTEMITED_SEQ) {
                (*sa_bo)->fence = radeon_fence_ref(fence);
+               list_add_tail(&(*sa_bo)->flist,
+                             &sa_manager->flist[fence->ring]);
        } else {
                radeon_sa_bo_remove_locked(*sa_bo);
        }
@@ -247,15 +345,19 @@ void radeon_sa_bo_dump_debug_info(struct radeon_sa_manager *sa_manager,
        struct radeon_sa_bo *i;
 
        spin_lock(&sa_manager->lock);
-       list_for_each_entry(i, &sa_manager->sa_bo, list) {
-               seq_printf(m, "[%08x %08x] size %4d (%p)",
-                          i->soffset, i->eoffset, i->eoffset - i->soffset, i);
-               if (i->fence) {
-                       seq_printf(m, " protected by %Ld (%p) on ring %d\n",
-                                  i->fence->seq, i->fence, i->fence->ring);
+       list_for_each_entry(i, &sa_manager->olist, olist) {
+               if (&i->olist == sa_manager->hole) {
+                       seq_printf(m, ">");
                } else {
-                       seq_printf(m, "\n");
+                       seq_printf(m, " ");
+               }
+               seq_printf(m, "[0x%08x 0x%08x] size %8d",
+                          i->soffset, i->eoffset, i->eoffset - i->soffset);
+               if (i->fence) {
+                       seq_printf(m, " protected by 0x%016llx on ring %d",
+                                  i->fence->seq, i->fence->ring);
                }
+               seq_printf(m, "\n");
        }
        spin_unlock(&sa_manager->lock);
  }
--

1.7.5.4

#19 lore raw

Re: [PATCH 14/20] drm/radeon: multiple ring allocator v2

Quoted 22 lines · Jerome Glisse
Quoted 21 lines · Christian König

A startover with a new idea for a multiple ring allocator. Should perform as well as a normal ring allocator as long as only one ring does somthing, but falls back to a more complex algorithm if more complex things start to happen.

We store the last allocated bo in last, we always try to allocate after the last allocated bo. Principle is that in a linear GPU ring progression was is after last is the oldest bo we allocated and thus the first one that should no longer be in use by the GPU.

If it's not the case we skip over the bo after last to the closest done bo if such one exist. If none exist and we are not asked to block we report failure to allocate.

If we are asked to block we wait on all the oldest fence of all rings. We just wait for any of those fence to complete.

v2: We need to be able to let hole point to the list_head, otherwise
try free will never free the first allocation of the list. Also stop calling radeon_fence_signalled more than necessary.

Quoted 6 lines
Quoted 2 lines

This one is NAK please use my patch. Yes in my patch we never try to free anything if there is only on sa_bo in the list if you really care about this it's a one line change:
http://people.freedesktop.org/~glisse/reset5/0001-drm-radeon-multiple-ring-allocator-v2.patch

Nope that won't work correctly, "last" is pointing to the last allocation and that's the most unlikely to be freed at this time. Also in this version (like in the one before) radeon_sa_bo_next_hole lets hole point to the "prev" of the found sa_bo without checking if this isn't the lists head. That might cause a crash if an to be freed allocation is the first one in the buffer.

What radeon_sa_bo_try_free would need to do to get your approach working is to loop over the end of the buffer and also try to free at the beginning, but saying that keeping the last allocation results in a whole bunch of extra cases and "if"s, while just keeping a pointer to the "hole" (e.g. where the next allocation is most likely to succeed) simplifies the code quite a bit (but I agree that on the down side it makes it harder to understand).

Quoted 11 lines

Your patch here can enter in infinite loop and never return holding the lock. See below.

[SNIP]

Quoted 1 line

+ } while (radeon_sa_bo_next_hole(sa_manager, fences));

Here you can infinite loop, in the case there is a bunch of hole in the allocator but none of them allow to full fill the allocation. radeon_sa_bo_next_hole will keep returning true looping over and over on all the all. That's why i only restrict my patch to 2 hole skeeping and then fails the allocation or try to wait. I believe sadly we need an heuristic and 2 hole skeeping at most sounded like a good one.

Nope, that can't be an infinite loop, cause radeon_sa_bo_next_hole in conjunction with radeon_sa_bo_try_free are eating up the opportunities for holes.

Look again, it probably will never loop more than RADEON_NUM_RINGS + 1, with the exception for allocating in a complete scattered buffer, and even then it will never loop more often than halve the number of current allocations (and that is really really unlikely).

Cheers,
Christian.

A message that is not in the archive (sent off-list or not yet received): CAH3drwb=qkpeLrSL9dejg0WEt_bCk98TkR0vtggpn3_maN6gZg@mail.gmail.com

#21 lore raw

PATCH 14/20 drm/radeon: multiple ring allocator v2

Quoted 68 lines · Jerome Glisse
Quoted 25 lines
Quoted 22 lines · Christian König

A startover with a new idea for a multiple ring allocator. Should perform as well as a normal ring allocator as long as only one ring does somthing, but falls back to a more complex algorithm if more complex things start to happen.

We store the last allocated bo in last, we always try to allocate after the last allocated bo. Principle is that in a linear GPU ring progression was is after last is the oldest bo we allocated and thus the first one that should no longer be in use by the GPU.

If it's not the case we skip over the bo after last to the closest done bo if such one exist. If none exist and we are not asked to block we report failure to allocate.

If we are asked to block we wait on all the oldest fence of all rings. We just wait for any of those fence to complete.

v2: We need to be able to let hole point to the list_head, otherwise try free will never free the first allocation of the list. Also stop calling radeon_fence_signalled more than necessary.

Quoted 8 lines
Quoted 2 lines

This one is NAK please use my patch. Yes in my patch we never try to free anything if there is only on sa_bo in the list if you really care about this it's a one line change:

http://people.freedesktop.org/~glisse/reset5/0001-drm-radeon-multiple-ring-allocator-v2.patch

Nope that won't work correctly, "last" is pointing to the last allocation and that's the most unlikely to be freed at this time. Also in this version (like in the one before) radeon_sa_bo_next_hole lets hole point to the "prev" of the found sa_bo without checking if this isn't the lists head. That might cause a crash if an to be freed allocation is the first one in the buffer.

What radeon_sa_bo_try_free would need to do to get your approach working is to loop over the end of the buffer and also try to free at the beginning, but saying that keeping the last allocation results in a whole bunch of extra cases and "if"s, while just keeping a pointer to the "hole" (e.g. where the next allocation is most likely to succeed) simplifies the code quite a bit (but I agree that on the down side it makes it harder to understand).

Quoted 5 lines

Your patch here can enter in infinite loop and never return holding the lock. See below.

[SNIP]

Quoted 8 lines
Quoted 1 line

+               } while (radeon_sa_bo_next_hole(sa_manager, fences));

Here you can infinite loop, in the case there is a bunch of hole in the allocator but none of them allow to full fill the allocation. radeon_sa_bo_next_hole will keep returning true looping over and over on all the all. That's why i only restrict my patch to 2 hole skeeping and then fails the allocation or try to wait. I believe sadly we need an heuristic and 2 hole skeeping at most sounded like a good one.

Nope, that can't be an infinite loop, cause radeon_sa_bo_next_hole in conjunction with radeon_sa_bo_try_free are eating up the opportunities for holes.

Quoted 7 lines

Look again, it probably will never loop more than RADEON_NUM_RINGS + 1, with the exception for allocating in a complete scattered buffer, and even then it will never loop more often than halve the number of current allocations (and that is really really unlikely).

Cheers,
Christian.

I looked again and yes it can loop infinitly, think of hole you can never free ie radeon_sa_bo_try_free can't free anything. This situation can happen if you have several thread allocating sa bo at the same time while none of them are yet done with there sa_bo (ie none have call sa_bo_free yet). I updated a v3 that track oldest and fix all things you were pointing out above.

http://people.freedesktop.org/~glisse/reset5/0001-drm-radeon-multiple-ring-allocator-v3.patch

Cheers,
Jerome

#22 lore raw

Re: [PATCH 14/20] drm/radeon: multiple ring allocator v2

Quoted 83 lines · Jerome Glisse
Quoted 68 lines · Jerome Glisse
Quoted 25 lines
Quoted 22 lines · Christian König

A startover with a new idea for a multiple ring allocator. Should perform as well as a normal ring allocator as long as only one ring does somthing, but falls back to a more complex algorithm if more complex things start to happen.

We store the last allocated bo in last, we always try to allocate after the last allocated bo. Principle is that in a linear GPU ring progression was is after last is the oldest bo we allocated and thus the first one that should no longer be in use by the GPU.

If it's not the case we skip over the bo after last to the closest done bo if such one exist. If none exist and we are not asked to block we report failure to allocate.

If we are asked to block we wait on all the oldest fence of all rings. We just wait for any of those fence to complete.

v2: We need to be able to let hole point to the list_head, otherwise try free will never free the first allocation of the list. Also stop calling radeon_fence_signalled more than necessary.

Quoted 8 lines
Quoted 2 lines

This one is NAK please use my patch. Yes in my patch we never try to free anything if there is only on sa_bo in the list if you really care about this it's a one line change:

http://people.freedesktop.org/~glisse/reset5/0001-drm-radeon-multiple-ring-allocator-v2.patch

Nope that won't work correctly, "last" is pointing to the last allocation and that's the most unlikely to be freed at this time. Also in this version (like in the one before) radeon_sa_bo_next_hole lets hole point to the "prev" of the found sa_bo without checking if this isn't the lists head. That might cause a crash if an to be freed allocation is the first one in the buffer.

What radeon_sa_bo_try_free would need to do to get your approach working is to loop over the end of the buffer and also try to free at the beginning, but saying that keeping the last allocation results in a whole bunch of extra cases and "if"s, while just keeping a pointer to the "hole" (e.g. where the next allocation is most likely to succeed) simplifies the code quite a bit (but I agree that on the down side it makes it harder to understand).

Quoted 5 lines

Your patch here can enter in infinite loop and never return holding the lock. See below.

[SNIP]

Quoted 8 lines
Quoted 1 line

+               } while (radeon_sa_bo_next_hole(sa_manager, fences));

Here you can infinite loop, in the case there is a bunch of hole in the allocator but none of them allow to full fill the allocation. radeon_sa_bo_next_hole will keep returning true looping over and over on all the all. That's why i only restrict my patch to 2 hole skeeping and then fails the allocation or try to wait. I believe sadly we need an heuristic and 2 hole skeeping at most sounded like a good one.

Nope, that can't be an infinite loop, cause radeon_sa_bo_next_hole in conjunction with radeon_sa_bo_try_free are eating up the opportunities for holes.

Quoted 7 lines

Look again, it probably will never loop more than RADEON_NUM_RINGS + 1, with the exception for allocating in a complete scattered buffer, and even then it will never loop more often than halve the number of current allocations (and that is really really unlikely).

Cheers,
Christian.

I looked again and yes it can loop infinitly, think of hole you can never free ie radeon_sa_bo_try_free can't free anything. This situation can happen if you have several thread allocating sa bo at the same time while none of them are yet done with there sa_bo (ie none have call sa_bo_free yet). I updated a v3 that track oldest and fix all things you were pointing out above.

Quoted 4 lines

http://people.freedesktop.org/~glisse/reset5/0001-drm-radeon-multiple-ring-allocator-v3.patch

Cheers,
Jerome

Of course by tracking oldest it defeat the algo so updated patch :
http://people.freedesktop.org/~glisse/reset5/0001-drm-radeon-multiple-ring-allocator-v3.patch

Just fix the corner case of list of single entry.

Cheers,
Jerome

#23 lore raw

Re: [PATCH 14/20] drm/radeon: multiple ring allocator v2

Quoted 68 lines · Jerome Glisse
Quoted 67 lines · Jerome Glisse
Quoted 67 lines · Jerome Glisse
Quoted 23 lines
Quoted 21 lines · Christian König

A startover with a new idea for a multiple ring allocator. Should perform as well as a normal ring allocator as long as only one ring does somthing, but falls back to a more complex algorithm if more complex things start to happen.

We store the last allocated bo in last, we always try to allocate after the last allocated bo. Principle is that in a linear GPU ring progression was is after last is the oldest bo we allocated and thus the first one that should no longer be in use by the GPU.

If it's not the case we skip over the bo after last to the closest done bo if such one exist. If none exist and we are not asked to block we report failure to allocate.

If we are asked to block we wait on all the oldest fence of all rings. We just wait for any of those fence to complete.

v2: We need to be able to let hole point to the list_head, otherwise
try free will never free the first allocation of the list. Also stop calling radeon_fence_signalled more than necessary.

Quoted 7 lines
Quoted 2 lines

This one is NAK please use my patch. Yes in my patch we never try to free anything if there is only on sa_bo in the list if you really care about this it's a one line change:

http://people.freedesktop.org/~glisse/reset5/0001-drm-radeon-multiple-ring-allocator-v2.patch

Nope that won't work correctly, "last" is pointing to the last allocation and that's the most unlikely to be freed at this time. Also in this version (like in the one before) radeon_sa_bo_next_hole lets hole point to the "prev" of the found sa_bo without checking if this isn't the lists head. That might cause a crash if an to be freed allocation is the first one in the buffer.

What radeon_sa_bo_try_free would need to do to get your approach working is to loop over the end of the buffer and also try to free at the beginning, but saying that keeping the last allocation results in a whole bunch of extra cases and "if"s, while just keeping a pointer to the "hole" (e.g. where the next allocation is most likely to succeed) simplifies the code quite a bit (but I agree that on the down side it makes it harder to understand).

Quoted 5 lines

Your patch here can enter in infinite loop and never return holding the lock. See below.

[SNIP]

Quoted 7 lines
Quoted 1 line

+ } while (radeon_sa_bo_next_hole(sa_manager, fences));

Here you can infinite loop, in the case there is a bunch of hole in the allocator but none of them allow to full fill the allocation. radeon_sa_bo_next_hole will keep returning true looping over and over on all the all. That's why i only restrict my patch to 2 hole skeeping and then fails the allocation or try to wait. I believe sadly we need an heuristic and 2 hole skeeping at most sounded like a good one.

Nope, that can't be an infinite loop, cause radeon_sa_bo_next_hole in conjunction with radeon_sa_bo_try_free are eating up the opportunities for holes.

Look again, it probably will never loop more than RADEON_NUM_RINGS + 1, with the exception for allocating in a complete scattered buffer, and even then it will never loop more often than halve the number of current allocations (and that is really really unlikely).

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

Cheers,
Christian.

I looked again and yes it can loop infinitly, think of hole you can never free ie radeon_sa_bo_try_free can't free anything. This situation can happen if you have several thread allocating sa bo at the same time while none of them are yet done with there sa_bo (ie none have call sa_bo_free yet). I updated a v3 that track oldest and fix all things you were pointing out above.

No that isn't a problem, radeon_sa_bo_next_hole takes the firsts entries of the flist, so it only considers holes that have a signaled fence and so can be freed.

Having multiple threads allocate objects that can't be freed yet will just result in empty flists, and so radeon_sa_bo_next_hole will return false, resulting in calling radeon_fence_wait_any with an empty fence list, which in turn will result in an ENOENT and abortion of allocation (ok maybe we should catch that and return -ENOMEM instead).

So even the corner cases should now be handled fine.

Quoted 9 lines
Quoted 5 lines

http://people.freedesktop.org/~glisse/reset5/0001-drm-radeon-multiple-ring-allocator-v3.patch

Cheers,
Jerome

Of course by tracking oldest it defeat the algo so updated patch :
http://people.freedesktop.org/~glisse/reset5/0001-drm-radeon-multiple-ring-allocator-v3.patch

Just fix the corner case of list of single entry.

That still won't work correctly, cause the corner case isn't that there is just one allocation left on the list, the corner case is that we need to be able to allocate something before the first sa_bo, just consider the following with your current implementation:

B F F F F 1 2 3 4 F E

B is the beginning of the buffer.
F is free space.
1,2,3,4 are allocations.
E is the end of the buffer.

So lets say that we have an allocation that won't fit in the free space between "4" and "E", now even if if radeon_sa_next_hole sets "last" to 1, we aren't able to allocate anything at the beginning of the buffer...

Christian.

#24 lore raw

Re: [PATCH 14/20] drm/radeon: multiple ring allocator v2

Quoted 102 lines · Christian König
Quoted 90 lines · Jerome Glisse
Quoted 88 lines · Jerome Glisse
Quoted 87 lines · Jerome Glisse
Quoted 29 lines
Quoted 18 lines · Christian König

A startover with a new idea for a multiple ring allocator. Should perform as well as a normal ring allocator as long as only one ring does somthing, but falls back to a more complex algorithm if more complex things start to happen.

We store the last allocated bo in last, we always try to allocate after the last allocated bo. Principle is that in a linear GPU ring progression was is after last is the oldest bo we allocated and thus the first one that should no longer be in use by the GPU.

If it's not the case we skip over the bo after last to the closest done bo if such one exist. If none exist and we are not asked to block we report failure to allocate.

If we are asked to block we wait on all the oldest fence of all rings. We just wait for any of those fence to complete.

Quoted 6 lines

v2: We need to be able to let hole point to the list_head, otherwise try free will never free the first allocation of the list. Also stop calling radeon_fence_signalled more than necessary.

Quoted 6 lines

This one is NAK please use my patch. Yes in my patch we never try to free anything if there is only on sa_bo in the list if you really care about this it's a one line change:

http://people.freedesktop.org/~glisse/reset5/0001-drm-radeon-multiple-ring-allocator-v2.patch

Nope that won't work correctly, "last" is pointing to the last allocation
and that's the most unlikely to be freed at this time. Also in this version
(like in the one before) radeon_sa_bo_next_hole lets hole point to the "prev" of the found sa_bo without checking if this isn't the lists head. That might cause a crash if an to be freed allocation is the first one in
the buffer.

What radeon_sa_bo_try_free would need to do to get your approach working is
to loop over the end of the buffer and also try to free at the beginning,
but saying that keeping the last allocation results in a whole bunch of extra cases and "if"s, while just keeping a pointer to the "hole" (e.g. where the next allocation is most likely to succeed) simplifies the code quite a bit (but I agree that on the down side it makes it harder to understand).

Quoted 5 lines

Your patch here can enter in infinite loop and never return holding the lock. See below.

[SNIP]

Quoted 8 lines
Quoted 1 line

+               } while (radeon_sa_bo_next_hole(sa_manager, fences));

Here you can infinite loop, in the case there is a bunch of hole in the allocator but none of them allow to full fill the allocation. radeon_sa_bo_next_hole will keep returning true looping over and over on all the all. That's why i only restrict my patch to 2 hole skeeping and then fails the allocation or try to wait. I believe sadly we need an heuristic and 2 hole skeeping at most sounded like a good one.

Nope, that can't be an infinite loop, cause radeon_sa_bo_next_hole in conjunction with radeon_sa_bo_try_free are eating up the opportunities for
holes.

Look again, it probably will never loop more than RADEON_NUM_RINGS + 1, with
the exception for allocating in a complete scattered buffer, and even then
it will never loop more often than halve the number of current allocations
(and that is really really unlikely).

Cheers,
Christian.

Quoted 6 lines
Quoted 6 lines

I looked again and yes it can loop infinitly, think of hole you can never free ie radeon_sa_bo_try_free can't free anything. This situation can happen if you have several thread allocating sa bo at the same time while none of them are yet done with there sa_bo (ie none have call sa_bo_free yet). I updated a v3 that track oldest and fix all things you were pointing out above.

No that isn't a problem, radeon_sa_bo_next_hole takes the firsts entries of the flist, so it only considers holes that have a signaled fence and so can be freed.

Quoted 7 lines

Having multiple threads allocate objects that can't be freed yet will just result in empty flists, and so radeon_sa_bo_next_hole will return false, resulting in calling radeon_fence_wait_any with an empty fence list, which in turn will result in an ENOENT and abortion of allocation (ok maybe we should catch that and return -ENOMEM instead).

So even the corner cases should now be handled fine.

No, there is still infinite loop possible with gpu lockup, i am against the while (next_hole) using for on 2 iteration looks a lot better and it avoids sa allocator possibly looping too much (because it can loop a lot more than RADEON_NUM_RINGS, the maximum number of loop is sa_manager->size/4).

Quoted 26 lines
Quoted 5 lines
Quoted 5 lines

http://people.freedesktop.org/~glisse/reset5/0001-drm-radeon-multiple-ring-allocator-v3.patch

Quoted 8 lines
Quoted 2 lines

Cheers,
Jerome

Of course by tracking oldest it defeat the algo so updated patch :

 http://people.freedesktop.org/~glisse/reset5/0001-drm-radeon-multiple-ring-allocator-v3.patch

Just fix the corner case of list of single entry.

That still won't work correctly, cause the corner case isn't that there is just one allocation left on the list, the corner case is that we need to be able to allocate something before the first sa_bo, just consider the following with your current implementation:

B F F F F 1 2 3 4 F E

B is the beginning of the buffer.
F is free space.
1,2,3,4 are allocations.
E is the end of the buffer.

Quoted 5 lines

So lets say that we have an allocation that won't fit in the free space between "4" and "E", now even if if radeon_sa_next_hole sets "last" to 1, we aren't able to allocate anything at the beginning of the buffer...

Christian.

Yes that isn't handled

Cheers,
Jerome

#25 lore raw

Re: [PATCH 14/20] drm/radeon: multiple ring allocator v2

Quoted 47 lines · Jerome Glisse
Quoted 46 lines · Christian König
Quoted 27 lines · Jerome Glisse
Quoted 26 lines · Jerome Glisse
Quoted 26 lines · Jerome Glisse
Quoted 5 lines

Your patch here can enter in infinite loop and never return holding the lock. See below.

[SNIP]

Quoted 7 lines
Quoted 1 line

+ } while (radeon_sa_bo_next_hole(sa_manager, fences));

Here you can infinite loop, in the case there is a bunch of hole in the allocator but none of them allow to full fill the allocation. radeon_sa_bo_next_hole will keep returning true looping over and over on all the all. That's why i only restrict my patch to 2 hole skeeping and then fails the allocation or try to wait. I believe sadly we need an heuristic and 2 hole skeeping at most sounded like a good one.

Nope, that can't be an infinite loop, cause radeon_sa_bo_next_hole in conjunction with radeon_sa_bo_try_free are eating up the opportunities for
holes.

Look again, it probably will never loop more than RADEON_NUM_RINGS + 1, with
the exception for allocating in a complete scattered buffer, and even then
it will never loop more often than halve the number of current allocations
(and that is really really unlikely).

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

Cheers,
Christian.

I looked again and yes it can loop infinitly, think of hole you can never free ie radeon_sa_bo_try_free can't free anything. This situation can happen if you have several thread allocating sa bo at the same time while none of them are yet done with there sa_bo (ie none have call sa_bo_free yet). I updated a v3 that track oldest and fix all things you were pointing out above.

No that isn't a problem, radeon_sa_bo_next_hole takes the firsts entries of the flist, so it only considers holes that have a signaled fence and so can be freed.

Having multiple threads allocate objects that can't be freed yet will just result in empty flists, and so radeon_sa_bo_next_hole will return false, resulting in calling radeon_fence_wait_any with an empty fence list, which in turn will result in an ENOENT and abortion of allocation (ok maybe we should catch that and return -ENOMEM instead).

Quoted 6 lines
Quoted 1 line

So even the corner cases should now be handled fine.

No, there is still infinite loop possible with gpu lockup, i am against the while (next_hole) using for on 2 iteration looks a lot better and it avoids sa allocator possibly looping too much (because it can loop a lot more than RADEON_NUM_RINGS, the maximum number of loop is sa_manager->size/4).

I'm still pretty sure that there isn't the possibility for an infinite loop, so please explain further where exactly the problem is. radeon_sa_bo_next_hole will return true as long as it can find AND remove an allocation with an already signaled fence, and since nobody else can add allocations while we are in the loop we sooner or later run out of allocations and so the loop ends.

Also what the loop does is just cleaning up all the already signaled allocations, and it doesn't matter if there is one allocation or a million, we need to clean them up anyway. So aborting the loop and trying to wait for anything to be signaled makes no sense at all, and aborting the whole allocation at this point makes even less sense, cause that only delays the work that needs to be done anyway (freeing the allocations) to a later call to radeon_sa_bo_new.

What could make sense is limiting how often we are waiting for some fences, since while waiting we release the lock and then other processes can jump in and grab what we wanted to have by waiting for something to happen.

Cheers,
Christian.

#26 lore raw

Re: [PATCH 14/20] drm/radeon: multiple ring allocator v2

Quoted 74 lines · Christian König
Quoted 65 lines · Jerome Glisse
Quoted 62 lines · Christian König
Quoted 39 lines · Jerome Glisse
Quoted 36 lines · Jerome Glisse
Quoted 35 lines · Jerome Glisse
Quoted 9 lines

Your patch here can enter in infinite loop and never return holding the lock. See below.

[SNIP]

Quoted 2 lines

+               } while (radeon_sa_bo_next_hole(sa_manager, fences));

Quoted 7 lines

Here you can infinite loop, in the case there is a bunch of hole in the allocator but none of them allow to full fill the allocation. radeon_sa_bo_next_hole will keep returning true looping over and over on all the all. That's why i only restrict my patch to 2 hole skeeping
and then fails the allocation or try to wait. I believe sadly we need an heuristic and 2 hole skeeping at most sounded like a good one.

Nope, that can't be an infinite loop, cause radeon_sa_bo_next_hole in conjunction with radeon_sa_bo_try_free are eating up the opportunities for
holes.

Look again, it probably will never loop more than RADEON_NUM_RINGS + 1,
with
the exception for allocating in a complete scattered buffer, and even then
it will never loop more often than halve the number of current allocations
(and that is really really unlikely).

Cheers,
Christian.

Quoted 6 lines
Quoted 6 lines

I looked again and yes it can loop infinitly, think of hole you can never free ie radeon_sa_bo_try_free can't free anything. This situation can happen if you have several thread allocating sa bo at the same time while none of them are yet done with there sa_bo (ie none have call sa_bo_free yet). I updated a v3 that track oldest and fix all things you were pointing out above.

No that isn't a problem, radeon_sa_bo_next_hole takes the firsts entries of
the flist, so it only considers holes that have a signaled fence and so can
be freed.

Having multiple threads allocate objects that can't be freed yet will just
result in empty flists, and so radeon_sa_bo_next_hole will return false, resulting in calling radeon_fence_wait_any with an empty fence list, which
in turn will result in an ENOENT and abortion of allocation (ok maybe we should catch that and return -ENOMEM instead).

Quoted 7 lines
Quoted 1 line

So even the corner cases should now be handled fine.

No, there is still infinite loop possible with gpu lockup, i am against the while (next_hole) using for on 2 iteration looks a lot better and it avoids sa allocator possibly looping too much (because it can loop a lot more than RADEON_NUM_RINGS, the maximum number of loop is sa_manager->size/4).

Quoted 6 lines

I'm still pretty sure that there isn't the possibility for an infinite loop, so please explain further where exactly the problem is. radeon_sa_bo_next_hole will return true as long as it can find AND remove an allocation with an already signaled fence, and since nobody else can add allocations while we are in the loop we sooner or later run out of allocations and so the loop ends.

Yeah you right

Quoted 8 lines

Also what the loop does is just cleaning up all the already signaled allocations, and it doesn't matter if there is one allocation or a million, we need to clean them up anyway. So aborting the loop and trying to wait for anything to be signaled makes no sense at all, and aborting the whole allocation at this point makes even less sense, cause that only delays the work that needs to be done anyway (freeing the allocations) to a later call to radeon_sa_bo_new.

Quoted 6 lines

What could make sense is limiting how often we are waiting for some fences, since while waiting we release the lock and then other processes can jump in and grab what we wanted to have by waiting for something to happen.

Cheers,
Christian.

Still i don't want to loop more than necessary, it's bad, i am ok with :
http://people.freedesktop.org/~glisse/reset5/0001-drm-radeon-multiple-ring-allocator-v3.patch

If there is fence signaled it will retry 2 times at most, otherwise it will go to wait and
that way better. Because with your while loop the worst case is something proportional to
the manager size given it's 1Mo it can loop for a long long time.

Cheers,
Jerome

#27 lore raw

Re: [PATCH 14/20] drm/radeon: multiple ring allocator v2

Quoted 8 lines · Jerome Glisse

Still i don't want to loop more than necessary, it's bad, i am ok with :
http://people.freedesktop.org/~glisse/reset5/0001-drm-radeon-multiple-ring-allocator-v3.patch

If there is fence signaled it will retry 2 times at most, otherwise it will go to wait and
that way better. Because with your while loop the worst case is something proportional to
the manager size given it's 1Mo it can loop for a long long time.

Yeah, this loop can indeed consume quite some time. Ok then let's at least give every ring a chance to supply some holes, otherwise I fear that we might not even found something worth to wait for after only 2 tries.

Going to send that out after figuring out why the patchset still causes texture corruptions on my system.

Christian.

#28 lore raw

PATCH 15/20 drm/radeon: simplify semaphore handling v2

In reply to Christian König

From: Jerome Glisse <[email protected]>

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

v2: rebased on new SA interface.

---
 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_fence.c     |    2 +-
 drivers/gpu/drm/radeon/radeon_semaphore.c |  137 +++++------------------------
 drivers/gpu/drm/radeon/radeon_test.c      |    4 +-
 drivers/gpu/drm/radeon/rv770.c            |    1 -
 drivers/gpu/drm/radeon/si.c               |    1 -
 10 files changed, 30 insertions(+), 149 deletions(-)
drivers/gpu/drm/radeon/evergreen.c +0 -1
index ecc29bc..7e7ac3d 100644
@@ -3550,7 +3550,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 9cd2657..107b217 100644
@@ -1744,7 +1744,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 87a2333..0ae2d2d 100644
@@ -2658,7 +2658,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 +4 -25
index cc7f16a..45164e1 100644
@@ -434,34 +434,13 @@ 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;
+	struct radeon_sa_bo		*sa_bo;
+	signed				waiters;
 	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;
-};
-
-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,
@@ -473,7 +452,8 @@ int radeon_semaphore_sync_rings(struct radeon_device *rdev,
 				bool sync_to[RADEON_NUM_RINGS],
 				int dst_ring);
 void radeon_semaphore_free(struct radeon_device *rdev,
-			   struct radeon_semaphore *semaphore);
+			   struct radeon_semaphore *semaphore,
+			   struct radeon_fence *fence);
 
 /*
  * GART structures, functions & helpers
@@ -1540,7 +1520,6 @@ struct radeon_device {
 	struct radeon_mman		mman;
 	struct radeon_fence_driver	fence_drv[RADEON_NUM_RINGS];
 	wait_queue_head_t		fence_queue;
-	struct radeon_semaphore_driver	semaphore_drv;
 	struct mutex			ring_lock;
 	struct radeon_ring		ring[RADEON_NUM_RINGS];
 	struct radeon_ib_pool		ib_pool;
drivers/gpu/drm/radeon/radeon_device.c +0 -2
index b827b2e..48876c1 100644
@@ -732,11 +732,9 @@ int radeon_device_init(struct radeon_device *rdev,
 	mutex_init(&rdev->gem.mutex);
 	mutex_init(&rdev->pm.mutex);
 	mutex_init(&rdev->vram_mutex);
-	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_fence.c +1 -1
index 45d4e6e..6767381 100644
@@ -138,7 +138,7 @@ static void radeon_fence_destroy(struct kref *kref)
 	fence = container_of(kref, struct radeon_fence, kref);
 	fence->seq = RADEON_FENCE_NOTEMITED_SEQ;
 	if (fence->semaphore)
-		radeon_semaphore_free(fence->rdev, fence->semaphore);
+		radeon_semaphore_free(fence->rdev, fence->semaphore, NULL);
 	kfree(fence);
 }
 
drivers/gpu/drm/radeon/radeon_semaphore.c +23 -114

170 lines not on this page · raw message

drivers/gpu/drm/radeon/radeon_test.c +2 -2
index dc5dcf4..b057387 100644
@@ -317,7 +317,7 @@ void radeon_test_ring_sync(struct radeon_device *rdev,
 
 out_cleanup:
 	if (semaphore)
-		radeon_semaphore_free(rdev, semaphore);
+		radeon_semaphore_free(rdev, semaphore, NULL);
 
 	if (fence1)
 		radeon_fence_unref(&fence1);
@@ -437,7 +437,7 @@ void radeon_test_ring_sync2(struct radeon_device *rdev,
 
 out_cleanup:
 	if (semaphore)
-		radeon_semaphore_free(rdev, semaphore);
+		radeon_semaphore_free(rdev, semaphore, NULL);
 
 	if (fenceA)
 		radeon_fence_unref(&fenceA);
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 0bad5ff..d6b7fbc 100644
@@ -4110,7 +4110,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
#29 lore raw

PATCH 16/20 drm/radeon: rip out the ib pool

In reply to Christian König

From: Jerome Glisse <[email protected]>

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

---
 drivers/gpu/drm/radeon/radeon.h           |   17 +--
 drivers/gpu/drm/radeon/radeon_device.c    |    1 -
 drivers/gpu/drm/radeon/radeon_gart.c      |   12 +-
 drivers/gpu/drm/radeon/radeon_ring.c      |  241 ++++++++---------------------
 drivers/gpu/drm/radeon/radeon_semaphore.c |    2 +-
 5 files changed, 71 insertions(+), 202 deletions(-)
drivers/gpu/drm/radeon/radeon.h +2 -15
index 45164e1..6170307 100644
@@ -625,7 +625,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;
@@ -634,18 +633,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;
@@ -787,7 +774,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);
@@ -1522,7 +1508,8 @@ struct radeon_device {
 	wait_queue_head_t		fence_queue;
 	struct mutex			ring_lock;
 	struct radeon_ring		ring[RADEON_NUM_RINGS];
-	struct radeon_ib_pool		ib_pool;
+	bool				ib_pool_ready;
+	struct radeon_sa_manager	ring_tmp_bo;
 	struct radeon_irq		irq;
 	struct radeon_asic		*asic;
 	struct radeon_gem		gem;
drivers/gpu/drm/radeon/radeon_device.c +0 -1
index 48876c1..e1bc7e9 100644
@@ -724,7 +724,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);
 	mutex_init(&rdev->ring_lock);
 	mutex_init(&rdev->dc_hw_i2c_mutex);
 	if (rdev->family >= CHIP_R600)
drivers/gpu/drm/radeon/radeon_gart.c +6 -6
index 53dba8e..8e9ef34 100644
@@ -432,8 +432,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->ring_tmp_bo.bo,
+				       &rdev->ring_tmp_bo.bo->tbo.mem);
 }
 
 /* object have to be reserved */
@@ -631,7 +631,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->ring_tmp_bo.bo, 0,
 			     RADEON_VM_PAGE_READABLE | RADEON_VM_PAGE_SNOOPED);
 	return r;
 }
@@ -648,12 +648,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->ring_tmp_bo.bo, false);
 	if (!r) {
-		bo_va = radeon_bo_va(rdev->ib_pool.sa_manager.bo, vm);
+		bo_va = radeon_bo_va(rdev->ring_tmp_bo.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->ring_tmp_bo.bo);
 		kfree(bo_va);
 	}
 	if (!list_empty(&vm->va)) {
drivers/gpu/drm/radeon/radeon_ring.c +62 -179

340 lines not on this page · raw message

drivers/gpu/drm/radeon/radeon_semaphore.c +1 -1
index 1bc5513..e2ace5d 100644
@@ -41,7 +41,7 @@ int radeon_semaphore_create(struct radeon_device *rdev,
 	if (*semaphore == NULL) {
 		return -ENOMEM;
 	}
-	r = radeon_sa_bo_new(rdev, &rdev->ib_pool.sa_manager,
+	r = radeon_sa_bo_new(rdev, &rdev->ring_tmp_bo,
 			     &(*semaphore)->sa_bo, 8, 8, true);
 	if (r) {
 		kfree(*semaphore);
Signature · 6 lines
1.7.5.4

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

PATCH 17/20 drm/radeon: immediately free ttm-move semaphore

In reply to Christian König

We can now protected the semaphore ram by a
fence, so free it immediately.

---
 drivers/gpu/drm/radeon/radeon_ttm.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_ttm.c +5 -2
index 5e3d54d..0f6aee8 100644
@@ -223,6 +223,7 @@ static int radeon_move_blit(struct ttm_buffer_object *bo,
 	struct radeon_device *rdev;
 	uint64_t old_start, new_start;
 	struct radeon_fence *fence, *old_fence;
+	struct radeon_semaphore *sem = NULL;
 	int r;
 
 	rdev = radeon_get_rdev(bo->bdev);
@@ -272,15 +273,16 @@ static int radeon_move_blit(struct ttm_buffer_object *bo,
 		bool sync_to_ring[RADEON_NUM_RINGS] = { };
 		sync_to_ring[old_fence->ring] = true;
 
-		r = radeon_semaphore_create(rdev, &fence->semaphore);
+		r = radeon_semaphore_create(rdev, &sem);
 		if (r) {
 			radeon_fence_unref(&fence);
 			return r;
 		}
 
-		r = radeon_semaphore_sync_rings(rdev, fence->semaphore,
+		r = radeon_semaphore_sync_rings(rdev, sem,
 						sync_to_ring, fence->ring);
 		if (r) {
+			radeon_semaphore_free(rdev, sem, NULL);
 			radeon_fence_unref(&fence);
 			return r;
 		}
@@ -292,6 +294,7 @@ static int radeon_move_blit(struct ttm_buffer_object *bo,
 	/* FIXME: handle copy error */
 	r = ttm_bo_move_accel_cleanup(bo, (void *)fence, NULL,
 				      evict, no_wait_reserve, no_wait_gpu, new_mem);
+	radeon_semaphore_free(rdev, sem, fence);
 	radeon_fence_unref(&fence);
 	return r;
 }
Signature · 6 lines
1.7.5.4

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

PATCH 18/20 drm/radeon: move the semaphore from the fence into the ib

In reply to Christian König

From: Jerome Glisse <[email protected]>

It never really belonged there in the first place.

---
 drivers/gpu/drm/radeon/radeon.h       |   16 ++++++++--------
 drivers/gpu/drm/radeon/radeon_cs.c    |    4 ++--
 drivers/gpu/drm/radeon/radeon_fence.c |    3 ---
 drivers/gpu/drm/radeon/radeon_ring.c  |    2 ++
 4 files changed, 12 insertions(+), 13 deletions(-)
drivers/gpu/drm/radeon/radeon.h +8 -8
index 6170307..9507be0 100644
@@ -272,7 +272,6 @@ struct radeon_fence {
 	uint64_t			seq;
 	/* RB, DMA, etc. */
 	unsigned			ring;
-	struct radeon_semaphore		*semaphore;
 };
 
 int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring);
@@ -624,13 +623,14 @@ void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc);
  */
 
 struct radeon_ib {
-	struct radeon_sa_bo	*sa_bo;
-	uint32_t		length_dw;
-	uint64_t		gpu_addr;
-	uint32_t		*ptr;
-	struct radeon_fence	*fence;
-	unsigned		vm_id;
-	bool			is_const_ib;
+	struct radeon_sa_bo		*sa_bo;
+	uint32_t			length_dw;
+	uint64_t			gpu_addr;
+	uint32_t			*ptr;
+	struct radeon_fence		*fence;
+	unsigned			vm_id;
+	bool				is_const_ib;
+	struct radeon_semaphore		*semaphore;
 };
 
 struct radeon_ring {
drivers/gpu/drm/radeon/radeon_cs.c +2 -2
index 5c065bf..dcfe2a0 100644
@@ -138,12 +138,12 @@ static int radeon_cs_sync_rings(struct radeon_cs_parser *p)
 		return 0;
 	}
 
-	r = radeon_semaphore_create(p->rdev, &p->ib->fence->semaphore);
+	r = radeon_semaphore_create(p->rdev, &p->ib->semaphore);
 	if (r) {
 		return r;
 	}
 
-	return radeon_semaphore_sync_rings(p->rdev, p->ib->fence->semaphore,
+	return radeon_semaphore_sync_rings(p->rdev, p->ib->semaphore,
 					   sync_to_ring, p->ring);
 }
 
drivers/gpu/drm/radeon/radeon_fence.c +0 -3
index 6767381..c1f5233 100644
@@ -137,8 +137,6 @@ static void radeon_fence_destroy(struct kref *kref)
 
 	fence = container_of(kref, struct radeon_fence, kref);
 	fence->seq = RADEON_FENCE_NOTEMITED_SEQ;
-	if (fence->semaphore)
-		radeon_semaphore_free(fence->rdev, fence->semaphore, NULL);
 	kfree(fence);
 }
 
@@ -154,7 +152,6 @@ int radeon_fence_create(struct radeon_device *rdev,
 	(*fence)->rdev = rdev;
 	(*fence)->seq = RADEON_FENCE_NOTEMITED_SEQ;
 	(*fence)->ring = ring;
-	(*fence)->semaphore = NULL;
 	return 0;
 }
 
drivers/gpu/drm/radeon/radeon_ring.c +2 -0
index b3d6942..af8e1ee 100644
@@ -93,6 +93,7 @@ int radeon_ib_get(struct radeon_device *rdev, int ring,
 	(*ib)->gpu_addr = radeon_sa_bo_gpu_addr((*ib)->sa_bo);
 	(*ib)->vm_id = 0;
 	(*ib)->is_const_ib = false;
+	(*ib)->semaphore = NULL;
 
 	return 0;
 }
@@ -105,6 +106,7 @@ void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib)
 	if (tmp == NULL) {
 		return;
 	}
+	radeon_semaphore_free(rdev, tmp->semaphore, tmp->fence);
 	radeon_sa_bo_free(rdev, &tmp->sa_bo, tmp->fence);
 	radeon_fence_unref(&tmp->fence);
 	kfree(tmp);
Signature · 6 lines
1.7.5.4

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

PATCH 19/20 drm/radeon: remove r600 blit mutex v2

In reply to Christian König

If we don't store local data into global variables it isn't necessary to lock anything.

v2: rebased on new SA interface

---
 drivers/gpu/drm/radeon/evergreen_blit_kms.c |    1 -
 drivers/gpu/drm/radeon/r600.c               |   13 +---
 drivers/gpu/drm/radeon/r600_blit_kms.c      |   99 +++++++++++----------------
 drivers/gpu/drm/radeon/radeon.h             |    3 -
 drivers/gpu/drm/radeon/radeon_asic.h        |    9 ++-
 5 files changed, 50 insertions(+), 75 deletions(-)
drivers/gpu/drm/radeon/evergreen_blit_kms.c +0 -1
index 222acd2..30f0480 100644
@@ -637,7 +637,6 @@ int evergreen_blit_init(struct radeon_device *rdev)
 	if (rdev->r600_blit.shader_obj)
 		goto done;
 
-	mutex_init(&rdev->r600_blit.mutex);
 	rdev->r600_blit.state_offset = 0;
 
 	if (rdev->family < CHIP_CAYMAN)
drivers/gpu/drm/radeon/r600.c +4 -9
index 0ae2d2d..9d6009a 100644
@@ -2363,20 +2363,15 @@ int r600_copy_blit(struct radeon_device *rdev,
 		   unsigned num_gpu_pages,
 		   struct radeon_fence *fence)
 {
+	struct radeon_sa_bo *vb = NULL;
 	int r;
 
-	mutex_lock(&rdev->r600_blit.mutex);
-	rdev->r600_blit.vb_ib = NULL;
-	r = r600_blit_prepare_copy(rdev, num_gpu_pages);
+	r = r600_blit_prepare_copy(rdev, num_gpu_pages, &vb);
 	if (r) {
-		if (rdev->r600_blit.vb_ib)
-			radeon_ib_free(rdev, &rdev->r600_blit.vb_ib);
-		mutex_unlock(&rdev->r600_blit.mutex);
 		return r;
 	}
-	r600_kms_blit_copy(rdev, src_offset, dst_offset, num_gpu_pages);
-	r600_blit_done_copy(rdev, fence);
-	mutex_unlock(&rdev->r600_blit.mutex);
+	r600_kms_blit_copy(rdev, src_offset, dst_offset, num_gpu_pages, vb);
+	r600_blit_done_copy(rdev, fence, vb);
 	return 0;
 }
 
drivers/gpu/drm/radeon/r600_blit_kms.c +40 -59

173 lines not on this page · raw message

drivers/gpu/drm/radeon/radeon.h +0 -3
index 9507be0..659855a 100644
@@ -743,7 +743,6 @@ struct r600_blit_cp_primitives {
 };
 
 struct r600_blit {
-	struct mutex		mutex;
 	struct radeon_bo	*shader_obj;
 	struct r600_blit_cp_primitives primitives;
 	int max_dim;
@@ -753,8 +752,6 @@ struct r600_blit {
 	u32 vs_offset, ps_offset;
 	u32 state_offset;
 	u32 state_len;
-	u32 vb_used, vb_total;
-	struct radeon_ib *vb_ib;
 };
 
 void r600_blit_suspend(struct radeon_device *rdev);
drivers/gpu/drm/radeon/radeon_asic.h +6 -3
index 7830931..05a4e15 100644
@@ -368,11 +368,14 @@ void r600_hdmi_init(struct drm_encoder *encoder);
 int r600_hdmi_buffer_status_changed(struct drm_encoder *encoder);
 void r600_hdmi_update_audio_settings(struct drm_encoder *encoder);
 /* r600 blit */
-int r600_blit_prepare_copy(struct radeon_device *rdev, unsigned num_gpu_pages);
-void r600_blit_done_copy(struct radeon_device *rdev, struct radeon_fence *fence);
+int r600_blit_prepare_copy(struct radeon_device *rdev, unsigned num_gpu_pages,
+			   struct radeon_sa_bo **vb);
+void r600_blit_done_copy(struct radeon_device *rdev, struct radeon_fence *fence,
+			 struct radeon_sa_bo *vb);
 void r600_kms_blit_copy(struct radeon_device *rdev,
 			u64 src_gpu_addr, u64 dst_gpu_addr,
-			unsigned num_gpu_pages);
+			unsigned num_gpu_pages,
+			struct radeon_sa_bo *vb);
 int r600_mc_wait_for_idle(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
#33 lore raw

PATCH 20/20 drm/radeon: make the ib an inline object

In reply to Christian König

From: Jerome Glisse <[email protected]>

No need to malloc it any more.

---
 drivers/gpu/drm/radeon/evergreen_cs.c |   10 +++---
 drivers/gpu/drm/radeon/r100.c         |   38 ++++++++++----------
 drivers/gpu/drm/radeon/r200.c         |    2 +-
 drivers/gpu/drm/radeon/r300.c         |    4 +-
 drivers/gpu/drm/radeon/r600.c         |   16 ++++----
 drivers/gpu/drm/radeon/r600_cs.c      |   22 +++++------
 drivers/gpu/drm/radeon/radeon.h       |    8 ++--
 drivers/gpu/drm/radeon/radeon_cs.c    |   63 ++++++++++++++++-----------------
 drivers/gpu/drm/radeon/radeon_ring.c  |   41 +++++++--------------
 9 files changed, 93 insertions(+), 111 deletions(-)
drivers/gpu/drm/radeon/evergreen_cs.c +5 -5
index 70089d3..4e7dd2b 100644
@@ -1057,7 +1057,7 @@ static int evergreen_cs_packet_parse_vline(struct radeon_cs_parser *p)
 	uint32_t header, h_idx, reg, wait_reg_mem_info;
 	volatile uint32_t *ib;
 
-	ib = p->ib->ptr;
+	ib = p->ib.ptr;
 
 	/* parse the WAIT_REG_MEM */
 	r = evergreen_cs_packet_parse(p, &wait_reg_mem, p->idx);
@@ -1215,7 +1215,7 @@ static int evergreen_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx)
 		if (!(evergreen_reg_safe_bm[i] & m))
 			return 0;
 	}
-	ib = p->ib->ptr;
+	ib = p->ib.ptr;
 	switch (reg) {
 	/* force following reg to 0 in an attempt to disable out buffer
 	 * which will need us to better understand how it works to perform
@@ -1896,7 +1896,7 @@ static int evergreen_packet3_check(struct radeon_cs_parser *p,
 	u32 idx_value;
 
 	track = (struct evergreen_cs_track *)p->track;
-	ib = p->ib->ptr;
+	ib = p->ib.ptr;
 	idx = pkt->idx + 1;
 	idx_value = radeon_get_ib_value(p, idx);
 
@@ -2610,8 +2610,8 @@ int evergreen_cs_parse(struct radeon_cs_parser *p)
 		}
 	} while (p->idx < p->chunks[p->chunk_ib_idx].length_dw);
 #if 0
-	for (r = 0; r < p->ib->length_dw; r++) {
-		printk(KERN_INFO "%05d  0x%08X\n", r, p->ib->ptr[r]);
+	for (r = 0; r < p->ib.length_dw; r++) {
+		printk(KERN_INFO "%05d  0x%08X\n", r, p->ib.ptr[r]);
 		mdelay(1);
 	}
 #endif
drivers/gpu/drm/radeon/r100.c +19 -19
index ad6ceb7..0874a6d 100644
@@ -139,9 +139,9 @@ int r100_reloc_pitch_offset(struct radeon_cs_parser *p,
 		}
 
 		tmp |= tile_flags;
-		p->ib->ptr[idx] = (value & 0x3fc00000) | tmp;
+		p->ib.ptr[idx] = (value & 0x3fc00000) | tmp;
 	} else
-		p->ib->ptr[idx] = (value & 0xffc00000) | tmp;
+		p->ib.ptr[idx] = (value & 0xffc00000) | tmp;
 	return 0;
 }
 
@@ -156,7 +156,7 @@ int r100_packet3_load_vbpntr(struct radeon_cs_parser *p,
 	volatile uint32_t *ib;
 	u32 idx_value;
 
-	ib = p->ib->ptr;
+	ib = p->ib.ptr;
 	track = (struct r100_cs_track *)p->track;
 	c = radeon_get_ib_value(p, idx++) & 0x1F;
 	if (c > 16) {
@@ -1275,7 +1275,7 @@ void r100_cs_dump_packet(struct radeon_cs_parser *p,
 	unsigned i;
 	unsigned idx;
 
-	ib = p->ib->ptr;
+	ib = p->ib.ptr;
 	idx = pkt->idx;
 	for (i = 0; i <= (pkt->count + 1); i++, idx++) {
 		DRM_INFO("ib[%d]=0x%08X\n", idx, ib[idx]);
@@ -1354,7 +1354,7 @@ int r100_cs_packet_parse_vline(struct radeon_cs_parser *p)
 	uint32_t header, h_idx, reg;
 	volatile uint32_t *ib;
 
-	ib = p->ib->ptr;
+	ib = p->ib.ptr;
 
 	/* parse the wait until */
 	r = r100_cs_packet_parse(p, &waitreloc, p->idx);
@@ -1533,7 +1533,7 @@ static int r100_packet0_check(struct radeon_cs_parser *p,
 	u32 tile_flags = 0;
 	u32 idx_value;
 
-	ib = p->ib->ptr;
+	ib = p->ib.ptr;
 	track = (struct r100_cs_track *)p->track;
 
 	idx_value = radeon_get_ib_value(p, idx);
@@ -1889,7 +1889,7 @@ static int r100_packet3_check(struct radeon_cs_parser *p,
 	volatile uint32_t *ib;
 	int r;
 
-	ib = p->ib->ptr;
+	ib = p->ib.ptr;
 	idx = pkt->idx + 1;
 	track = (struct r100_cs_track *)p->track;
 	switch (pkt->opcode) {
@@ -3684,7 +3684,7 @@ void r100_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
 
 int r100_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
 {
-	struct radeon_ib *ib;
+	struct radeon_ib ib;
 	uint32_t scratch;
 	uint32_t tmp = 0;
 	unsigned i;
@@ -3700,22 +3700,22 @@ int r100_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
 	if (r) {
 		return r;
 	}
-	ib->ptr[0] = PACKET0(scratch, 0);
-	ib->ptr[1] = 0xDEADBEEF;
-	ib->ptr[2] = PACKET2(0);
-	ib->ptr[3] = PACKET2(0);
-	ib->ptr[4] = PACKET2(0);
-	ib->ptr[5] = PACKET2(0);
-	ib->ptr[6] = PACKET2(0);
-	ib->ptr[7] = PACKET2(0);
-	ib->length_dw = 8;
-	r = radeon_ib_schedule(rdev, ib);
+	ib.ptr[0] = PACKET0(scratch, 0);
+	ib.ptr[1] = 0xDEADBEEF;
+	ib.ptr[2] = PACKET2(0);
+	ib.ptr[3] = PACKET2(0);
+	ib.ptr[4] = PACKET2(0);
+	ib.ptr[5] = PACKET2(0);
+	ib.ptr[6] = PACKET2(0);
+	ib.ptr[7] = PACKET2(0);
+	ib.length_dw = 8;
+	r = radeon_ib_schedule(rdev, &ib);
 	if (r) {
 		radeon_scratch_free(rdev, scratch);
 		radeon_ib_free(rdev, &ib);
 		return r;
 	}
-	r = radeon_fence_wait(ib->fence, false);
+	r = radeon_fence_wait(ib.fence, false);
 	if (r) {
 		return r;
 	}
drivers/gpu/drm/radeon/r200.c +1 -1
index a59cc47..a26144d 100644
@@ -154,7 +154,7 @@ int r200_packet0_check(struct radeon_cs_parser *p,
 	u32 tile_flags = 0;
 	u32 idx_value;
 
-	ib = p->ib->ptr;
+	ib = p->ib.ptr;
 	track = (struct r100_cs_track *)p->track;
 	idx_value = radeon_get_ib_value(p, idx);
 	switch (reg) {
drivers/gpu/drm/radeon/r300.c +2 -2
index 6419a59..97722a3 100644
@@ -604,7 +604,7 @@ static int r300_packet0_check(struct radeon_cs_parser *p,
 	int r;
 	u32 idx_value;
 
-	ib = p->ib->ptr;
+	ib = p->ib.ptr;
 	track = (struct r100_cs_track *)p->track;
 	idx_value = radeon_get_ib_value(p, idx);
 
@@ -1146,7 +1146,7 @@ static int r300_packet3_check(struct radeon_cs_parser *p,
 	unsigned idx;
 	int r;
 
-	ib = p->ib->ptr;
+	ib = p->ib.ptr;
 	idx = pkt->idx + 1;
 	track = (struct r100_cs_track *)p->track;
 	switch(pkt->opcode) {
drivers/gpu/drm/radeon/r600.c +8 -8
index 9d6009a..4c7fafe 100644
@@ -2681,7 +2681,7 @@ void r600_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
 
 int r600_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
 {
-	struct radeon_ib *ib;
+	struct radeon_ib ib;
 	uint32_t scratch;
 	uint32_t tmp = 0;
 	unsigned i;
@@ -2699,18 +2699,18 @@ int r600_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
 		DRM_ERROR("radeon: failed to get ib (%d).\n", r);
 		return r;
 	}
-	ib->ptr[0] = PACKET3(PACKET3_SET_CONFIG_REG, 1);
-	ib->ptr[1] = ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
-	ib->ptr[2] = 0xDEADBEEF;
-	ib->length_dw = 3;
-	r = radeon_ib_schedule(rdev, ib);
+	ib.ptr[0] = PACKET3(PACKET3_SET_CONFIG_REG, 1);
+	ib.ptr[1] = ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
+	ib.ptr[2] = 0xDEADBEEF;
+	ib.length_dw = 3;
+	r = radeon_ib_schedule(rdev, &ib);
 	if (r) {
 		radeon_scratch_free(rdev, scratch);
 		radeon_ib_free(rdev, &ib);
 		DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
 		return r;
 	}
-	r = radeon_fence_wait(ib->fence, false);
+	r = radeon_fence_wait(ib.fence, false);
 	if (r) {
 		DRM_ERROR("radeon: fence wait failed (%d).\n", r);
 		return r;
@@ -2722,7 +2722,7 @@ int r600_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
 		DRM_UDELAY(1);
 	}
 	if (i < rdev->usec_timeout) {
-		DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib->fence->ring, i);
+		DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib.fence->ring, i);
 	} else {
 		DRM_ERROR("radeon: ib test failed (scratch(0x%04X)=0x%08X)\n",
 			  scratch, tmp);
drivers/gpu/drm/radeon/r600_cs.c +10 -12
index b8e12af..0133f5f 100644
@@ -345,7 +345,7 @@ static int r600_cs_track_validate_cb(struct radeon_cs_parser *p, int i)
 	u32 height, height_align, pitch, pitch_align, depth_align;
 	u64 base_offset, base_align;
 	struct array_mode_checker array_check;
-	volatile u32 *ib = p->ib->ptr;
+	volatile u32 *ib = p->ib.ptr;
 	unsigned array_mode;
 	u32 format;
 
@@ -471,7 +471,7 @@ static int r600_cs_track_validate_db(struct radeon_cs_parser *p)
 	u64 base_offset, base_align;
 	struct array_mode_checker array_check;
 	int array_mode;
-	volatile u32 *ib = p->ib->ptr;
+	volatile u32 *ib = p->ib.ptr;
 
 
 	if (track->db_bo == NULL) {
@@ -961,7 +961,7 @@ static int r600_cs_packet_parse_vline(struct radeon_cs_parser *p)
 	uint32_t header, h_idx, reg, wait_reg_mem_info;
 	volatile uint32_t *ib;
 
-	ib = p->ib->ptr;
+	ib = p->ib.ptr;
 
 	/* parse the WAIT_REG_MEM */
 	r = r600_cs_packet_parse(p, &wait_reg_mem, p->idx);
@@ -1110,7 +1110,7 @@ static int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx)
 	m = 1 << ((reg >> 2) & 31);
 	if (!(r600_reg_safe_bm[i] & m))
 		return 0;
-	ib = p->ib->ptr;
+	ib = p->ib.ptr;
 	switch (reg) {
 	/* force following reg to 0 in an attempt to disable out buffer
 	 * which will need us to better understand how it works to perform
@@ -1714,7 +1714,7 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
 	u32 idx_value;
 
 	track = (struct r600_cs_track *)p->track;
-	ib = p->ib->ptr;
+	ib = p->ib.ptr;
 	idx = pkt->idx + 1;
 	idx_value = radeon_get_ib_value(p, idx);
 
@@ -2249,8 +2249,8 @@ int r600_cs_parse(struct radeon_cs_parser *p)
 		}
 	} while (p->idx < p->chunks[p->chunk_ib_idx].length_dw);
 #if 0
-	for (r = 0; r < p->ib->length_dw; r++) {
-		printk(KERN_INFO "%05d  0x%08X\n", r, p->ib->ptr[r]);
+	for (r = 0; r < p->ib.length_dw; r++) {
+		printk(KERN_INFO "%05d  0x%08X\n", r, p->ib.ptr[r]);
 		mdelay(1);
 	}
 #endif
@@ -2298,7 +2298,6 @@ int r600_cs_legacy(struct drm_device *dev, void *data, struct drm_file *filp,
 {
 	struct radeon_cs_parser parser;
 	struct radeon_cs_chunk *ib_chunk;
-	struct radeon_ib fake_ib;
 	struct r600_cs_track *track;
 	int r;
 
@@ -2314,9 +2313,8 @@ int r600_cs_legacy(struct drm_device *dev, void *data, struct drm_file *filp,
 	parser.dev = &dev->pdev->dev;
 	parser.rdev = NULL;
 	parser.family = family;
-	parser.ib = &fake_ib;
 	parser.track = track;
-	fake_ib.ptr = ib;
+	parser.ib.ptr = ib;
 	r = radeon_cs_parser_init(&parser, data);
 	if (r) {
 		DRM_ERROR("Failed to initialize parser !\n");
@@ -2333,8 +2331,8 @@ int r600_cs_legacy(struct drm_device *dev, void *data, struct drm_file *filp,
 	 * input memory (cached) and write to the IB (which can be
 	 * uncached). */
 	ib_chunk = &parser.chunks[parser.chunk_ib_idx];
-	parser.ib->length_dw = ib_chunk->length_dw;
-	*l = parser.ib->length_dw;
+	parser.ib.length_dw = ib_chunk->length_dw;
+	*l = parser.ib.length_dw;
 	r = r600_cs_parse(&parser);
 	if (r) {
 		DRM_ERROR("Invalid command stream !\n");
drivers/gpu/drm/radeon/radeon.h +4 -4
index 659855a..60233d7 100644
@@ -769,8 +769,8 @@ 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);
+		  struct radeon_ib *ib, unsigned size);
+void radeon_ib_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);
@@ -838,8 +838,8 @@ struct radeon_cs_parser {
 	int			chunk_relocs_idx;
 	int			chunk_flags_idx;
 	int			chunk_const_ib_idx;
-	struct radeon_ib	*ib;
-	struct radeon_ib	*const_ib;
+	struct radeon_ib	ib;
+	struct radeon_ib	const_ib;
 	void			*track;
 	unsigned		family;
 	int			parser_error;
drivers/gpu/drm/radeon/radeon_cs.c +31 -32

169 lines not on this page · raw message

drivers/gpu/drm/radeon/radeon_ring.c +13 -28

64 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
#34 lore raw
In reply to Christian König
Quoted 10 lines · Christian König

Hi Jerome & everybody on the list,

this gathers together every patch we developed over the last week or so and which is not already in drm-next.

I've run quite some tests with them yesterday and today and as far as I can see hammered out every known bug. For the SA allocator I reverted to tracking the hole pointer instead of just the last allocation, cause otherwise we will never release the first allocation on the list. Glxgears now even keeps happily running if I deadlock on the not GFX rings on purpose.

Now we will release the first entry if we use the last allocate ptr i believe it's cleaner to use the last ptr.

Quoted 6 lines

Please take a second look at them and if nobody objects any more we should commit them to drm-next.

Cheers,
Christian.

Cheers,
Jerome

#35 lore raw
Quoted 6 lines · Jerome Glisse
Quoted 5 lines · Christian König

Hi Jerome & everybody on the list,

this gathers together every patch we developed over the last week or so and which is not already in drm-next.

Quoted 11 lines
Quoted 5 lines

I've run quite some tests with them yesterday and today and as far as I can see hammered out every known bug. For the SA allocator I reverted to tracking the hole pointer instead of just the last allocation, cause otherwise we will never release the first allocation on the list. Glxgears now even keeps happily running if I deadlock on the not GFX rings on purpose.

Now we will release the first entry if we use the last allocate ptr i believe it's cleaner to use the last ptr.

Quoted 2 lines

Please take a second look at them and if nobody objects any more we should commit them to drm-next.

Ok took a second look all looks good expect the 14 sa allocator. See my reply to it.

Cheers,
Jerome