Skip to contentSkip to conversation

drm/i915: Dumb down the semaphore logic

PATCH Superseded Ben Widawsky 5 participants 9 messages Sep 7, 2011 – Sep 11, 2011

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/i915: Dumb down the semaphore logic

While I think the previous code is correct, it was hard to follow and hard to debug. Since we already have a ring abstraction, might as well use it to handle the semaphore updates and compares.

I don't expect this code to make semaphores better or worse, but you never know...

Cc Chris Wilson <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Eric Anholt <[email protected]>
---
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |    3 +-
 drivers/gpu/drm/i915/i915_reg.h            |    7 +
 drivers/gpu/drm/i915/intel_ringbuffer.c    |  176 +++++++++++++++++++++-------
 drivers/gpu/drm/i915/intel_ringbuffer.h    |    7 +-
 4 files changed, 145 insertions(+), 48 deletions(-)
drivers/gpu/drm/i915/i915_gem_execbuffer.c +2 -1
index 4934cf8..3693e83 100644
@@ -784,7 +784,8 @@ i915_gem_execbuffer_sync_rings(struct drm_i915_gem_object *obj,
 	}
 
 	from->sync_seqno[idx] = seqno;
-	return intel_ring_sync(to, from, seqno - 1);
+
+	return to->sync_to(to, from, seqno - 1);
 }
 
 static int
drivers/gpu/drm/i915/i915_reg.h +7 -0
index 542453f..f0b5287 100644
@@ -194,6 +194,13 @@
 #define  MI_SEMAPHORE_UPDATE	    (1<<21)
 #define  MI_SEMAPHORE_COMPARE	    (1<<20)
 #define  MI_SEMAPHORE_REGISTER	    (1<<18)
+#define  MI_SEMAPHORE_SYNC_RV	    (2<<16)
+#define  MI_SEMAPHORE_SYNC_RB	    (0<<16)
+#define  MI_SEMAPHORE_SYNC_VR	    (0<<16)
+#define  MI_SEMAPHORE_SYNC_VB	    (2<<16)
+#define  MI_SEMAPHORE_SYNC_BR	    (2<<16)
+#define  MI_SEMAPHORE_SYNC_BV	    (0<<16)
+#define  MI_SEMAPHORE_SYNC_INVALID  (1<<0)
 /*
  * 3D instructions used by the kernel
  */
drivers/gpu/drm/i915/intel_ringbuffer.c +132 -44

254 lines not on this page · raw message

drivers/gpu/drm/i915/intel_ringbuffer.h +4 -3
index 39ac2b6..98052fd 100644
@@ -75,7 +75,11 @@ struct  intel_ring_buffer {
 	int		(*dispatch_execbuffer)(struct intel_ring_buffer *ring,
 					       u32 offset, u32 length);
 	void		(*cleanup)(struct intel_ring_buffer *ring);
+	int		(*sync_to)(struct intel_ring_buffer *ring,
+				   struct intel_ring_buffer *to,
+				   u32 seqno);
 
+	u32		semaphore_register[3];
 	/**
 	 * List of objects currently involved in rendering from the
 	 * ringbuffer.
@@ -180,9 +184,6 @@ static inline void intel_ring_emit(struct intel_ring_buffer *ring,
 void intel_ring_advance(struct intel_ring_buffer *ring);
 
 u32 intel_ring_get_seqno(struct intel_ring_buffer *ring);
-int intel_ring_sync(struct intel_ring_buffer *ring,
-		    struct intel_ring_buffer *to,
-		    u32 seqno);
 
 int intel_init_render_ring_buffer(struct drm_device *dev);
 int intel_init_bsd_ring_buffer(struct drm_device *dev);
Signature · 1 line
1.7.6.1
#1 lore raw

PATCH 2/2 drm/i915: tracepoints for semaphores

The tracepoints give enough info to figure the updates and compares (document terminology for signals and waits) and dependencies therein of the semaphore mailboxes.

Here are arguments to perf to get interesting info (mostly copied from
Chris):
record -f -g -c 1 -e i915:intel_ringbuffer_add_request -e i915:intel_ringbuffer_consume_semaphore -a

---
 drivers/gpu/drm/i915/i915_trace.h       |   61 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_ringbuffer.c |    4 ++
 2 files changed, 65 insertions(+), 0 deletions(-)
drivers/gpu/drm/i915/i915_trace.h +61 -0
index d623fef..493a0d3 100644
@@ -410,6 +410,67 @@ TRACE_EVENT(i915_reg_rw,
 		     (u32)(__entry->val >> 32))
 );
 
+#define SEMAPHORE_REG_NAME(x) (\
+	(x == RENDER_RING_BASE + 0x40) ? ("RVSYNC") : \
+	((x == RENDER_RING_BASE + 0x44) ? ("RBSYNC") : \
+	((x == GEN6_BSD_RING_BASE + 0x40) ? ("VRSYNC") : \
+	((x == GEN6_BSD_RING_BASE + 0x44) ? ("VBSYNC") : \
+	((x == BLT_RING_BASE + 0x40) ? ("BVSYNC") : \
+	((x == BLT_RING_BASE + 0x44) ? ("BRSYNC") : \
+	("UNKNOWN")))))))
+
+#define RING_NAME(x) (\
+	(x == 1) ? ("rcs") : \
+	((x == 2) ? ("vcs") : \
+	((x == 4) ? ("bcs") : \
+	("unk"))))
+
+TRACE_EVENT(intel_ringbuffer_add_request,
+	    TP_PROTO(struct intel_ring_buffer *ring,
+		     u32 seqno,
+		     u32 reg1,
+		     u32 reg2),
+	    TP_ARGS(ring, seqno, reg1, reg2),
+	    TP_STRUCT__entry(
+			     __field(int, id)
+			     __field(u32, seqno)
+			     __field(u32, reg1)
+			     __field(u32, reg2)
+			    ),
+	    TP_fast_assign(
+			   __entry->id = ring->id;
+			   __entry->seqno = seqno;
+			   __entry->reg1 = reg1;
+			   __entry->reg2 = reg2;
+			  ),
+	    TP_printk("ring = %s, seqno = %u, signal mbox 1 = %s, signal mbox 2 = %s",
+		      RING_NAME(__entry->id), __entry->seqno,
+		      SEMAPHORE_REG_NAME(__entry->reg1),
+		      SEMAPHORE_REG_NAME(__entry->reg2))
+);
+
+TRACE_EVENT(intel_ringbuffer_consume_semaphore,
+	    TP_PROTO(struct intel_ring_buffer *updater,
+		     struct intel_ring_buffer *comparer,
+		     u32 seqno),
+	    TP_ARGS(updater, comparer, seqno),
+	    TP_STRUCT__entry(
+			     __field(int, src)
+			     __field(int, dest)
+			     __field(u32, seqno)
+			    ),
+	    TP_fast_assign(
+			   __entry->src = updater->id;
+			   __entry->dest = comparer->id;
+			   __entry->seqno = seqno;
+			  ),
+	    /* It's not easy to macro the consuming mbox register */
+	    TP_printk("signaller = %s, waiter = %s, seqno = %u",
+		      RING_NAME(__entry->src),
+		      RING_NAME(__entry->dest),
+		      __entry->seqno)
+);
+
 #endif /* _I915_TRACE_H_ */
 
 /* This part must be outside protection */
drivers/gpu/drm/i915/intel_ringbuffer.c +4 -0
index 8f902a1..f816070 100644
@@ -358,6 +358,8 @@ gen6_add_request(struct intel_ring_buffer *ring,
 	intel_ring_emit(ring, MI_USER_INTERRUPT);
 	intel_ring_advance(ring);
 
+	trace_intel_ringbuffer_add_request(ring, seqno, mbox1_reg, mbox2_reg);
+
 	return seqno;
 }
 
@@ -420,6 +422,8 @@ intel_ring_sync(struct intel_ring_buffer *waiter,
 	intel_ring_emit(waiter, MI_NOOP);
 	intel_ring_advance(waiter);
 
+	trace_intel_ringbuffer_consume_semaphore(signaller, waiter, seqno);
+
 	return 0;
 }
 
Signature · 1 line
1.7.6.1
#2 lore raw
In reply to Ben Widawsky
Quoted 11 lines · Ben Widawsky

While I think the previous code is correct, it was hard to follow and hard to debug. Since we already have a ring abstraction, might as well use it to handle the semaphore updates and compares.

I don't expect this code to make semaphores better or worse, but you never know...

Cc Chris Wilson <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Eric Anholt <[email protected]>
Quoted 7 lines

---
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |    3 +- drivers/gpu/drm/i915/i915_reg.h            |    7 + drivers/gpu/drm/i915/intel_ringbuffer.c    |  176 +++++++++++++++++++++------- drivers/gpu/drm/i915/intel_ringbuffer.h    |    7 +-

 4 files changed, 145 insertions(+), 48 deletions(-)

Sadly, it still instantly crashes.

--Andy

#3 lore raw
Quoted 20 lines · Andrew Lutomirski
Quoted 11 lines · Ben Widawsky

While I think the previous code is correct, it was hard to follow and hard to debug. Since we already have a ring abstraction, might as well use it to handle the semaphore updates and compares.

I don't expect this code to make semaphores better or worse, but you never know...

Cc Chris Wilson <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Eric Anholt <[email protected]>
Quoted 7 lines
---
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |    3 +-
 drivers/gpu/drm/i915/i915_reg.h            |    7 +
 drivers/gpu/drm/i915/intel_ringbuffer.c    |  176 +++++++++++++++++++++-------
 drivers/gpu/drm/i915/intel_ringbuffer.h    |    7 +-
 4 files changed, 145 insertions(+), 48 deletions(-)
Quoted 3 lines

Sadly, it still instantly crashes.

--Andy

Remind me again... Does ssh still work?

#4 lore raw
Quoted 24 lines · Ben Widawsky
Quoted 20 lines · Andrew Lutomirski
Quoted 18 lines · Ben Widawsky

While I think the previous code is correct, it was hard to follow and hard to debug. Since we already have a ring abstraction, might as well use it to handle the semaphore updates and compares.

I don't expect this code to make semaphores better or worse, but you never know...

Cc Chris Wilson <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Eric Anholt <[email protected]>

---
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |    3 +- drivers/gpu/drm/i915/i915_reg.h            |    7 + drivers/gpu/drm/i915/intel_ringbuffer.c    |  176 +++++++++++++++++++++------- drivers/gpu/drm/i915/intel_ringbuffer.h    |    7 +-

 4 files changed, 145 insertions(+), 48 deletions(-)
Quoted 5 lines
Quoted 3 lines

Sadly, it still instantly crashes.

--Andy

Remind me again... Does ssh still work?

I haven't tried, but I'd be surprised. The *reset* button (the hardware one that's attached to the motherboard) doesn't work.

--Andy

#5 lore raw
In reply to Ben Widawsky

drivers/gpu/drm/i915/intel_ringbuffer.c static void render_ring_cleanup(struct intel_ring_buffer *ring) · line 320

Quoted 4 lines · Ben Widawsky
drivers/gpu/drm/i915/intel_ringbuffer.c +3 -1
-update_semaphore(struct intel_ring_buffer *ring, int i, u32 seqno)
+update_mboxes(struct intel_ring_buffer *ring,
+	    u32 seqno,
+	    u32 mmio_offset)

Yeah, definitely like this change; lots less magic here.

Quoted 6 lines
drivers/gpu/drm/i915/intel_ringbuffer.c +5 -1
-static int
+/**
+ * gen6_add_request - Update the semaphore mailbox registers
+ * 
+ * @ring - ring that is adding a request
+ * @mbox1_reg - mailbox address for RCS or VCS ring

drivers/gpu/drm/i915/intel_ringbuffer.c static void render_ring_cleanup(struct intel_ring_buffer *ring) · line 343

Quoted 10 lines
drivers/gpu/drm/i915/intel_ringbuffer.c +8 -1
+ * @mbox2_reg - mailbox address for VCS or BCS ring
+ *
+ * Update the mailbox registers in the *other* rings with the current seqno.
+ * This acts like a signal in the canonical semaphore.
+ */
+static u32
 gen6_add_request(struct intel_ring_buffer *ring,
-		 u32 *result)
+		 u32 mbox1_reg,
+		 u32 mbox2_reg)

I think you're losing the ability to return errors from here.

drivers/gpu/drm/i915/intel_ringbuffer.c static void render_ring_cleanup(struct intel_ring_buffer *ring) · line 353

Quoted 9 lines
drivers/gpu/drm/i915/intel_ringbuffer.c +1 -1
 	u32 seqno;
 	int ret;
+	seqno = i915_gem_get_seqno(ring->dev);
 
 	ret = intel_ring_begin(ring, 10);
 	if (ret)
 		return ret;
 
-	seqno = i915_gem_get_seqno(ring->dev);

Why change the ordering of get_seqno relative to ring_begin here?

drivers/gpu/drm/i915/intel_ringbuffer.c static void render_ring_cleanup(struct intel_ring_buffer *ring) · line 373

Quoted 10 lines
drivers/gpu/drm/i915/intel_ringbuffer.c +9 -0
+static int
+gen6_blt_add_request(struct intel_ring_buffer *ring,
+		     u32 *result)
+{
+	struct drm_device *dev = ring->dev;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	*result = gen6_add_request(ring,
+				   dev_priv->ring[RCS].mmio_base + 0x44,
+				   dev_priv->ring[VCS].mmio_base + 0x40);
 	return 0;

Why the magic constants? Can we have named values? And, note that this function never returns an error value, which is definitely not a good plan.

drivers/gpu/drm/i915/intel_ringbuffer.c static void render_ring_cleanup(struct intel_ring_buffer *ring) · line 415

Quoted 1 line
drivers/gpu/drm/i915/intel_ringbuffer.c +1 -0
+	temp |= MI_SEMAPHORE_REGISTER;

temp is a constant, why is it being |='d here?

drivers/gpu/drm/i915/intel_ringbuffer.c static void render_ring_cleanup(struct intel_ring_buffer *ring) · line 435

Quoted 10 lines
drivers/gpu/drm/i915/intel_ringbuffer.c +10 -0
+/* VCS->RCS (RVSYNC) or BCS->RCS (RBSYNC) */
+int
+render_ring_sync_to(struct intel_ring_buffer *waiter,
+		    struct intel_ring_buffer *signaller,
+		    u32 seqno)
+{
+	WARN_ON(signaller->semaphore_register[RCS] == MI_SEMAPHORE_SYNC_INVALID);
+	return intel_ring_sync(waiter,
+			       signaller,
+			       signaller->semaphore_register[RCS],

Should you just pass the index instead of the register value itself?

Otherwise, this seems like a reasonable change to me.

Signature · 1 line
[email protected]

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#6 lore raw
In reply to Ben Widawsky
Quoted 6 lines · Ben Widawsky

While I think the previous code is correct, it was hard to follow and hard to debug. Since we already have a ring abstraction, might as well use it to handle the semaphore updates and compares.

I don't expect this code to make semaphores better or worse, but you never know...

I kinda start to like this ;-)

While you stare at this, two things I'm pondering:
- Would it make sense to also move the !semaphores ring_sync_to case into the ringbuffer abstraction?
- Can we have a basic testcase for the magic values (and semaphores in general), please? I'm thinking of submitting a batchbuffer with a dummy r/w render relocation (hide it e.g. in the val field of MI_FLUSH_DW/PIPE_CONTROL without setting the write post-sync-op), and then randomly moving around the buffer to another ring. That should decently exercise the semaphores code in the kernel and sync hw in the gpu without (hopefully) anything else interfering.

-Daniel

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

PATCH 1/1 tests: basic ring<->cpu and ring<->ring tests

Using a dummy reloc that doesn't matter to trick the kernel into synchroizing the rings.

---
Hi Ben,

This is the test I've had in mind. Unfortunately this kills my snb machine both with semaphores=0 and semaphores=1. The ring<->cpu sync tests that employ the exact same batchbuffer commands work flawless.

-Daniel

 lib/intel_chipset.h          |    4 +
 tests/Makefile.am            |    2 +
 tests/gem_dummy_reloc_loop.c |  152 ++++++++++++++++++++++++++++++++++++++++++
 tests/gem_ring_sync_loop.c   |  138 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 296 insertions(+), 0 deletions(-)
 create mode 100644 tests/gem_dummy_reloc_loop.c
 create mode 100644 tests/gem_ring_sync_loop.c
lib/intel_chipset.h +4 -0
index a38f661..35edaf7 100755
@@ -169,6 +169,10 @@
 #define HAS_BLT_RING(devid)	(IS_GEN6(devid) || \
 				 IS_GEN7(devid))
 
+#define HAS_BSD_RING(devid)	(IS_GEN5(devid) || \
+				 IS_GEN6(devid) || \
+				 IS_GEN7(devid))
+
 #define IS_BROADWATER(devid)	(devid == PCI_CHIP_I946_GZ || \
 				 devid == PCI_CHIP_I965_G_1 || \
 				 devid == PCI_CHIP_I965_Q || \
tests/Makefile.am +2 -0
index 8c52454..46ec696 100644
@@ -47,6 +47,8 @@ TESTS = getversion \
 	gem_storedw_loop_bsd \
 	gem_storedw_batches_loop \
 	gem_pipe_control_store_loop \
+	gem_dummy_reloc_loop \
+	gem_ring_sync_loop \
 	$(NULL)
 
 HANG = \
tests/gem_dummy_reloc_loop.c new file +152 -0

152 lines not on this page · raw message

tests/gem_ring_sync_loop.c new file +138 -0

138 lines not on this page · raw message

Signature · 6 lines
1.7.6

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#8 lore raw
In reply to Daniel Vetter
Quoted 9 lines · On Thu, 8 Sep 2011 09:52:36 +0200 Daniel Vetter <[email protected]> wrote:
Quoted 6 lines · Ben Widawsky

While I think the previous code is correct, it was hard to follow and hard to debug. Since we already have a ring abstraction, might as well use it to handle the semaphore updates and compares.

I don't expect this code to make semaphores better or worse, but you never know...

I kinda start to like this ;-)

As I said, I am biased. To me it is much simpler to understand, but it's definitely more code, and more abstraction.

Quoted 4 lines

While you stare at this, two things I'm pondering:
- Would it make sense to also move the !semaphores ring_sync_to case into the ringbuffer abstraction?

That is an excellent idea. I will work on it with the other recommendations from Keith.

Quoted 2 lines

- Can we have a basic testcase for the magic values (and semaphores in general), please?

I really like what you've done with the test case after the fixes discussed on IRC. I will update my commit message to mention it if you manage to push that before I fix up the other things.

Ben