drm/i915: Dumb down the semaphore logic
Subsystems (2)
PATCH v4 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...
v2:
Remove magic per Keith's suggestions.
Ran Daniel's gem_ring_sync_loop test on this.
v3:
Ignored one of Keith's suggestions.
v4:
Removed some bloat per Daniel's recommendation.
--- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 3 +- drivers/gpu/drm/i915/i915_reg.h | 13 +++ drivers/gpu/drm/i915/intel_ringbuffer.c | 143 ++++++++++++++++++++-------- drivers/gpu/drm/i915/intel_ringbuffer.h | 8 +- 4 files changed, 123 insertions(+), 44 deletions(-)
drivers/gpu/drm/i915/i915_gem_execbuffer.c +2 -1
@@ -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 +13 -0
@@ -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 */
@@ -296,6 +303,12 @@#define RING_CTL (base) ((base)+0x3c)#define RING_SYNC_0 (base) ((base)+0x40)#define RING_SYNC_1 (base) ((base)+0x44) +#define GEN6_RVSYNC (RING_SYNC_0(RENDER_RING_BASE)) +#define GEN6_RBSYNC (RING_SYNC_1(RENDER_RING_BASE)) +#define GEN6_VRSYNC (RING_SYNC_1(GEN6_BSD_RING_BASE)) +#define GEN6_VBSYNC (RING_SYNC_0(GEN6_BSD_RING_BASE)) +#define GEN6_BRSYNC (RING_SYNC_0(BLT_RING_BASE)) +#define GEN6_BVSYNC (RING_SYNC_1(BLT_RING_BASE))#define RING_MAX_IDLE (base) ((base)+0x54)#define RING_HWS_PGA (base) ((base)+0x80)#define RING_HWS_PGA_GEN6 (base) ((base)+0x2080)
drivers/gpu/drm/i915/intel_ringbuffer.c +103 -40
200 lines not on this page · raw message
drivers/gpu/drm/i915/intel_ringbuffer.h +5 -3
@@ -75,7 +75,12 @@ 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 ];/*our mbox written by others */ +u32 signal_mbox[2 ];/* mboxes this ring signals to */ /** * List of objects currently involved in rendering from the * ringbuffer.
@@ -180,9 +185,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
PATCH v4 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
@@ -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 = %d, signal mbox 2 = %d" , +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
@@ -361,6 +361,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 0 ; }
@@ -392,6 +394,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
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...
v2:
Remove magic per Keith's suggestions.
Ran Daniel'sgem_ring_sync_looptest on this.
Quoted 5 lines
v3:
Ignored one of Keith's suggestions.v4:
Removed some bloat per Daniel's recommendation.
Just to clarify, I think I like the existing code a bit better than what the code looked like with Daniel's other recommendation to cut out the per ring sync_to function. If he shows me something good, there will be a v5, I guess.