Skip to contentSkip to conversation

drm/i915: Emit to ringbuffer directly

RFC Superseded Tvrtko Ursulin 4 participants 15 messages Sep 8, 2016 – Sep 12, 2016

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

RFC 1/1 drm/i915: Emit to ringbuffer directly

From: Tvrtko Ursulin <[email protected]>

This removes the usage of intel_ring_emit in favour of directly writing to the ring buffer.

intel_ring_emit was preventing the compiler for optimising fetch and increment of the current ring buffer pointer and therefore generating very verbose code for every write.

It had no useful purpose since all ringbuffer operations are started and ended with intel_ring_begin and intel_ring_advance respectively, with no bail out in the middle possible, so it is fine to increment the tail in intel_ring_begin and let the code manage the pointer itself.

Useless instruction removal amounts to approximately 2384 bytes of saved text on my build.

Not sure if this has any measurable performance implications but executing a ton of useless instructions on fast paths cannot be good.

Patch is not fully polished, but it compiles and runs on Gen9 at least.

---
 drivers/gpu/drm/i915/i915_gem_context.c    |  62 ++--
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |  27 +-
 drivers/gpu/drm/i915/i915_gem_gtt.c        |  57 ++--
 drivers/gpu/drm/i915/intel_display.c       | 113 ++++---
 drivers/gpu/drm/i915/intel_lrc.c           | 223 +++++++-------
 drivers/gpu/drm/i915/intel_mocs.c          |  43 +--
 drivers/gpu/drm/i915/intel_overlay.c       |  69 ++---
 drivers/gpu/drm/i915/intel_ringbuffer.c    | 480 +++++++++++++++--------------
 drivers/gpu/drm/i915/intel_ringbuffer.h    |  19 +-
 9 files changed, 555 insertions(+), 538 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +27 -35
index 35950ee46a1d..c9b61953f23b 100644
@@ -577,7 +577,6 @@ static inline int
 mi_set_context(struct drm_i915_gem_request *req, u32 hw_flags)
 {
 	struct drm_i915_private *dev_priv = req->i915;
-	struct intel_ring *ring = req->ring;
 	struct intel_engine_cs *engine = req->engine;
 	u32 flags = hw_flags | MI_MM_SPACE_GTT;
 	const int num_rings =
@@ -585,6 +584,7 @@ mi_set_context(struct drm_i915_gem_request *req, u32 hw_flags)
 		i915.semaphores ?
 		INTEL_INFO(dev_priv)->num_rings - 1 :
 		0;
+	u32 *rbuf;
 	int len, ret;
 
 	/* w/a: If Flush TLB Invalidation Mode is enabled, driver must do a TLB
@@ -609,70 +609,61 @@ mi_set_context(struct drm_i915_gem_request *req, u32 hw_flags)
 	if (INTEL_GEN(dev_priv) >= 7)
 		len += 2 + (num_rings ? 4*num_rings + 6 : 0);
 
-	ret = intel_ring_begin(req, len);
+	ret = intel_ring_begin(req, len, &rbuf);
 	if (ret)
 		return ret;
 
 	/* WaProgramMiArbOnOffAroundMiSetContext:ivb,vlv,hsw,bdw,chv */
 	if (INTEL_GEN(dev_priv) >= 7) {
-		intel_ring_emit(ring, MI_ARB_ON_OFF | MI_ARB_DISABLE);
+		*rbuf++ = MI_ARB_ON_OFF | MI_ARB_DISABLE;
 		if (num_rings) {
 			struct intel_engine_cs *signaller;
 
-			intel_ring_emit(ring,
-					MI_LOAD_REGISTER_IMM(num_rings));
+			*rbuf++ = MI_LOAD_REGISTER_IMM(num_rings);
 			for_each_engine(signaller, dev_priv) {
 				if (signaller == engine)
 					continue;
 
-				intel_ring_emit_reg(ring,
-						    RING_PSMI_CTL(signaller->mmio_base));
-				intel_ring_emit(ring,
-						_MASKED_BIT_ENABLE(GEN6_PSMI_SLEEP_MSG_DISABLE));
+				*rbuf++ = RING_PSMI_CTL(signaller->mmio_base).reg;
+				*rbuf++ = _MASKED_BIT_ENABLE(GEN6_PSMI_SLEEP_MSG_DISABLE);
 			}
 		}
 	}
 
-	intel_ring_emit(ring, MI_NOOP);
-	intel_ring_emit(ring, MI_SET_CONTEXT);
-	intel_ring_emit(ring,
-			i915_ggtt_offset(req->ctx->engine[RCS].state) | flags);
+	*rbuf++ = MI_NOOP;
+	*rbuf++ = MI_SET_CONTEXT;
+	*rbuf++ = i915_ggtt_offset(req->ctx->engine[RCS].state) | flags;
 	/*
 	 * w/a: MI_SET_CONTEXT must always be followed by MI_NOOP
 	 * WaMiSetContext_Hang:snb,ivb,vlv
 	 */
-	intel_ring_emit(ring, MI_NOOP);
+	*rbuf++ = MI_NOOP;
 
 	if (INTEL_GEN(dev_priv) >= 7) {
 		if (num_rings) {
 			struct intel_engine_cs *signaller;
 			i915_reg_t last_reg = {}; /* keep gcc quiet */
 
-			intel_ring_emit(ring,
-					MI_LOAD_REGISTER_IMM(num_rings));
+			*rbuf++ = MI_LOAD_REGISTER_IMM(num_rings);
 			for_each_engine(signaller, dev_priv) {
 				if (signaller == engine)
 					continue;
 
 				last_reg = RING_PSMI_CTL(signaller->mmio_base);
-				intel_ring_emit_reg(ring, last_reg);
-				intel_ring_emit(ring,
-						_MASKED_BIT_DISABLE(GEN6_PSMI_SLEEP_MSG_DISABLE));
+				*rbuf++ = last_reg.reg;
+				*rbuf++ = _MASKED_BIT_DISABLE(GEN6_PSMI_SLEEP_MSG_DISABLE);
 			}
 
 			/* Insert a delay before the next switch! */
-			intel_ring_emit(ring,
-					MI_STORE_REGISTER_MEM |
-					MI_SRM_LRM_GLOBAL_GTT);
-			intel_ring_emit_reg(ring, last_reg);
-			intel_ring_emit(ring,
-					i915_ggtt_offset(engine->scratch));
-			intel_ring_emit(ring, MI_NOOP);
+			*rbuf++ = MI_STORE_REGISTER_MEM | MI_SRM_LRM_GLOBAL_GTT;
+			*rbuf++ = last_reg.reg;
+			*rbuf++ = i915_ggtt_offset(engine->scratch);
+			*rbuf++ = MI_NOOP;
 		}
-		intel_ring_emit(ring, MI_ARB_ON_OFF | MI_ARB_ENABLE);
+		*rbuf++ = MI_ARB_ON_OFF | MI_ARB_ENABLE;
 	}
 
-	intel_ring_advance(ring);
+	intel_ring_advance(req->ring);
 
 	return ret;
 }
@@ -680,13 +671,13 @@ mi_set_context(struct drm_i915_gem_request *req, u32 hw_flags)
 static int remap_l3(struct drm_i915_gem_request *req, int slice)
 {
 	u32 *remap_info = req->i915->l3_parity.remap_info[slice];
-	struct intel_ring *ring = req->ring;
+	u32 *rbuf;
 	int i, ret;
 
 	if (!remap_info)
 		return 0;
 
-	ret = intel_ring_begin(req, GEN7_L3LOG_SIZE/4 * 2 + 2);
+	ret = intel_ring_begin(req, GEN7_L3LOG_SIZE/4 * 2 + 2, &rbuf);
 	if (ret)
 		return ret;
 
@@ -695,13 +686,14 @@ static int remap_l3(struct drm_i915_gem_request *req, int slice)
 	 * here because no other code should access these registers other than
 	 * at initialization time.
 	 */
-	intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(GEN7_L3LOG_SIZE/4));
+	*rbuf++ = MI_LOAD_REGISTER_IMM(GEN7_L3LOG_SIZE/4);
 	for (i = 0; i < GEN7_L3LOG_SIZE/4; i++) {
-		intel_ring_emit_reg(ring, GEN7_L3LOG(slice, i));
-		intel_ring_emit(ring, remap_info[i]);
+		*rbuf++ = GEN7_L3LOG(slice, i).reg;
+		*rbuf++ = remap_info[i];
 	}
-	intel_ring_emit(ring, MI_NOOP);
-	intel_ring_advance(ring);
+	*rbuf++ = MI_NOOP;
+
+	intel_ring_advance(req->ring);
 
 	return 0;
 }
drivers/gpu/drm/i915/i915_gem_execbuffer.c +14 -13
index 9432d4ce9ffb..d9a226ea768c 100644
@@ -1358,7 +1358,7 @@ i915_gem_execbuffer_move_to_active(struct list_head *vmas,
 static int
 i915_reset_gen7_sol_offsets(struct drm_i915_gem_request *req)
 {
-	struct intel_ring *ring = req->ring;
+	u32 *rbuf;
 	int ret, i;
 
 	if (!IS_GEN7(req->i915) || req->engine->id != RCS) {
@@ -1366,17 +1366,17 @@ i915_reset_gen7_sol_offsets(struct drm_i915_gem_request *req)
 		return -EINVAL;
 	}
 
-	ret = intel_ring_begin(req, 4 * 3);
+	ret = intel_ring_begin(req, 4 * 3, &rbuf);
 	if (ret)
 		return ret;
 
 	for (i = 0; i < 4; i++) {
-		intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
-		intel_ring_emit_reg(ring, GEN7_SO_WRITE_OFFSET(i));
-		intel_ring_emit(ring, 0);
+		*rbuf++ = MI_LOAD_REGISTER_IMM(1);
+		*rbuf++ = GEN7_SO_WRITE_OFFSET(i).reg;
+		*rbuf++ = 0;
 	}
 
-	intel_ring_advance(ring);
+	intel_ring_advance(req->ring);
 
 	return 0;
 }
@@ -1483,17 +1483,18 @@ execbuf_submit(struct i915_execbuffer_params *params,
 
 	if (params->engine->id == RCS &&
 	    instp_mode != dev_priv->relative_constants_mode) {
-		struct intel_ring *ring = params->request->ring;
+		u32 *rbuf;
 
-		ret = intel_ring_begin(params->request, 4);
+		ret = intel_ring_begin(params->request, 4, &rbuf);
 		if (ret)
 			return ret;
 
-		intel_ring_emit(ring, MI_NOOP);
-		intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
-		intel_ring_emit_reg(ring, INSTPM);
-		intel_ring_emit(ring, instp_mask << 16 | instp_mode);
-		intel_ring_advance(ring);
+		*rbuf++ = MI_NOOP;
+		*rbuf++ = MI_LOAD_REGISTER_IMM(1);
+		*rbuf++ = INSTPM.reg;
+		*rbuf++ = instp_mask << 16 | instp_mode;
+
+		intel_ring_advance(params->request->ring);
 
 		dev_priv->relative_constants_mode = instp_mode;
 	}
drivers/gpu/drm/i915/i915_gem_gtt.c +30 -27

103 lines not on this page · raw message

drivers/gpu/drm/i915/intel_display.c +56 -57

211 lines not on this page · raw message

drivers/gpu/drm/i915/intel_lrc.c +110 -113

369 lines not on this page · raw message

drivers/gpu/drm/i915/intel_mocs.c +22 -21

98 lines not on this page · raw message

drivers/gpu/drm/i915/intel_overlay.c +33 -36

146 lines not on this page · raw message

drivers/gpu/drm/i915/intel_ringbuffer.c +245 -235

890 lines not on this page · raw message

drivers/gpu/drm/i915/intel_ringbuffer.h +18 -1
index 84aea549de5d..1182116f20a0 100644
@@ -443,7 +443,24 @@ void intel_engine_cleanup(struct intel_engine_cs *engine);
 
 int intel_ring_alloc_request_extras(struct drm_i915_gem_request *request);
 
-int __must_check intel_ring_begin(struct drm_i915_gem_request *req, int n);
+int __must_check __intel_ring_begin(struct drm_i915_gem_request *req, int n);
+
+static inline int __must_check
+intel_ring_begin(struct drm_i915_gem_request *req, int n, u32 **rbuf)
+{
+	struct intel_ring *ring = req->ring;
+	int ret;
+
+	ret = __intel_ring_begin(req, n);
+	if (unlikely(ret))
+		return ret;
+
+	*rbuf = (u32 *)(ring->vaddr + ring->tail);
+	ring->tail += n * sizeof(u32);
+
+	return 0;
+}
+
 int __must_check intel_ring_cacheline_align(struct drm_i915_gem_request *req);
 
 static inline void intel_ring_emit(struct intel_ring *ring, u32 data)
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

✗ Fi.CI.BAT: failure for drm/i915: Emit to ringbuffer directly

== Series Details ==

== Series Details ==

Series: drm/i915: Emit to ringbuffer directly
URL : https://patchwork.freedesktop.org/series/12186/
State : failure

== Summary ==

Series 12186v1 drm/i915: Emit to ringbuffer directly
http://patchwork.freedesktop.org/api/1.0/series/12186/revisions/1/mbox/

Test drv_module_reload_basic:

                skip       -> PASS       (fi-skl-6260u)
Test kms_cursor_legacy:
        Subgroup basic-cursor-vs-flip-legacy:
                pass       -> FAIL       (fi-bsw-n3050)
fi-bdw-5557u     total:252  pass:236  dwarn:0   dfail:0   fail:1   skip:15 
fi-bsw-n3050     total:252  pass:204  dwarn:0   dfail:0   fail:2   skip:46 
fi-hsw-4770k     total:252  pass:229  dwarn:0   dfail:0   fail:1   skip:22 
fi-hsw-4770r     total:252  pass:225  dwarn:0   dfail:0   fail:1   skip:26 
fi-ilk-650       total:252  pass:182  dwarn:0   dfail:0   fail:3   skip:67 
fi-ivb-3520m     total:252  pass:220  dwarn:0   dfail:0   fail:1   skip:31 
fi-ivb-3770      total:252  pass:220  dwarn:0   dfail:0   fail:1   skip:31 
fi-skl-6260u     total:252  pass:237  dwarn:0   dfail:0   fail:1   skip:14 
fi-skl-6700k     total:252  pass:222  dwarn:1   dfail:0   fail:1   skip:28 
fi-snb-2520m     total:252  pass:206  dwarn:0   dfail:0   fail:1   skip:45 
fi-snb-2600      total:252  pass:206  dwarn:0   dfail:0   fail:1   skip:45 

fi-byt-n2820 failed to collect. IGT log at Patchwork_2494/fi-byt-n2820/igt.log

Results at /archive/results/CI_IGT_test/Patchwork_2494/

5986f290e25f42d3d5df390411cc43683deb1301 drm-intel-nightly: 2016y-09m-08d-09h-11m-50s UTC integration manifest bbd9747 drm/i915: Emit to ringbuffer directly

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

#2 lore raw
In reply to Tvrtko Ursulin
Quoted 4 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

This removes the usage of intel_ring_emit in favour of directly writing to the ring buffer.

I have the same patch! But I called it out, for historical reasons.

Oh, except mine uses out[0]...out[N] because gcc prefers that over *out++ = ...

Quoted 11 lines

intel_ring_emit was preventing the compiler for optimising fetch and increment of the current ring buffer pointer and therefore generating very verbose code for every write.

It had no useful purpose since all ringbuffer operations are started and ended with intel_ring_begin and intel_ring_advance respectively, with no bail out in the middle possible, so it is fine to increment the tail in intel_ring_begin and let the code manage the pointer itself.

Quoted 6 lines

Useless instruction removal amounts to approximately 2384 bytes of saved text on my build.

Not sure if this has any measurable performance implications but executing a ton of useless instructions on fast paths cannot be good.

It does show up in perf.

Quoted 4 lines

Patch is not fully polished, but it compiles and runs on Gen9 at least.

Quoted 11 lines
---
 drivers/gpu/drm/i915/i915_gem_context.c    |  62 ++--
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |  27 +-
 drivers/gpu/drm/i915/i915_gem_gtt.c        |  57 ++--
 drivers/gpu/drm/i915/intel_display.c       | 113 ++++---
 drivers/gpu/drm/i915/intel_lrc.c           | 223 +++++++-------
 drivers/gpu/drm/i915/intel_mocs.c          |  43 +--
 drivers/gpu/drm/i915/intel_overlay.c       |  69 ++---
 drivers/gpu/drm/i915/intel_ringbuffer.c    | 480 +++++++++++++++--------------
 drivers/gpu/drm/i915/intel_ringbuffer.h    |  19 +-
 9 files changed, 555 insertions(+), 538 deletions(-)

Hmm, mine is bigger.

 drivers/gpu/drm/i915/i915_gem_context.c    |  85 ++--
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |  37 +-
 drivers/gpu/drm/i915/i915_gem_gtt.c        |  62 +--
 drivers/gpu/drm/i915/i915_gem_request.c    | 135 ++++-
 drivers/gpu/drm/i915/i915_gem_request.h    |   2 +
 drivers/gpu/drm/i915/intel_display.c       | 133 +++--
 drivers/gpu/drm/i915/intel_lrc.c           | 188 ++++---
 drivers/gpu/drm/i915/intel_lrc.h           |   2 -
 drivers/gpu/drm/i915/intel_mocs.c          |  50 +-
 drivers/gpu/drm/i915/intel_overlay.c       |  77 ++-
 drivers/gpu/drm/i915/intel_ringbuffer.c    | 762 ++++++++++++-----------------
 drivers/gpu/drm/i915/intel_ringbuffer.h    |  36 +-
 12 files changed, 721 insertions(+), 848 deletions(-)

(this includes moving the intel_ring_begin to i915_gem_request)

plus an ealier

 drivers/gpu/drm/i915/i915_gem_request.c |  26 ++---
 drivers/gpu/drm/i915/intel_lrc.c        | 121 ++++++++---------------
 drivers/gpu/drm/i915/intel_ringbuffer.c | 168 +++++++++++---------------------
 drivers/gpu/drm/i915/intel_ringbuffer.h |  10 +-
 4 files changed, 112 insertions(+), 213 deletions(-)

since I wanted parts of it for emitting timelines. -Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw
Quoted 7 lines · Chris Wilson
Quoted 4 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

This removes the usage of intel_ring_emit in favour of directly writing to the ring buffer.

I have the same patch! But I called it out, for historical reasons.

Yes I know we talked about it in the past but I did not think you will find time to actually write it amongst all the other things.

Quoted 2 lines

Oh, except mine uses out[0]...out[N] because gcc prefers that over *out++ = ...

It copes just fine with the latter here, for example:

	*rbuf++ = cmd;
	*rbuf++ = I915_GEM_HWS_SCRATCH_ADDR | MI_FLUSH_DW_USE_GTT;
	*rbuf++ = 0; /* upper addr */
	*rbuf++ = 0; /* value */

Is:

     3e9:       89 10                   mov    %edx,(%rax)
     3eb:       c7 40 04 04 01 00 00    movl   $0x104,0x4(%rax)
     3f2:       c7 40 08 00 00 00 00    movl   $0x0,0x8(%rax)
     3f9:       c7 40 0c 00 00 00 00    movl   $0x0,0xc(%rax)

And for the record, before this patch, with intel_ring_emit:

     53a:       8b 53 3c                mov    0x3c(%rbx),%edx
     53d:       48 8b 4b 08             mov    0x8(%rbx),%rcx
     541:       89 04 11                mov    %eax,(%rcx,%rdx,1)
     544:       8b 43 3c                mov    0x3c(%rbx),%eax
     547:       48 8b 53 08             mov    0x8(%rbx),%rdx
     54b:       83 c0 04                add    $0x4,%eax
     54e:       89 43 3c                mov    %eax,0x3c(%rbx)
     551:       c7 04 02 04 01 00 00    movl   $0x104,(%rdx,%rax,1)
     558:       8b 43 3c                mov    0x3c(%rbx),%eax
     55b:       48 8b 53 08             mov    0x8(%rbx),%rdx
     55f:       83 c0 04                add    $0x4,%eax
     562:       89 43 3c                mov    %eax,0x3c(%rbx)
     565:       c7 04 02 00 00 00 00    movl   $0x0,(%rdx,%rax,1)
     56c:       8b 43 3c                mov    0x3c(%rbx),%eax
     56f:       48 8b 53 08             mov    0x8(%rbx),%rdx
     573:       83 c0 04                add    $0x4,%eax
     576:       89 43 3c                mov    %eax,0x3c(%rbx)
     579:       c7 04 02 00 00 00 00    movl   $0x0,(%rdx,%rax,1)

Yuck :) At least they are not function calls to iowrite any more. :)

Quoted 11 lines
Quoted 11 lines

intel_ring_emit was preventing the compiler for optimising fetch and increment of the current ring buffer pointer and therefore generating very verbose code for every write.

It had no useful purpose since all ringbuffer operations are started and ended with intel_ring_begin and intel_ring_advance respectively, with no bail out in the middle possible, so it is fine to increment the tail in intel_ring_begin and let the code manage the pointer itself.

Quoted 8 lines
Quoted 6 lines

Useless instruction removal amounts to approximately 2384 bytes of saved text on my build.

Not sure if this has any measurable performance implications but executing a ton of useless instructions on fast paths cannot be good.

It does show up in perf.

Cool.

Quoted 36 lines
Quoted 4 lines

Patch is not fully polished, but it compiles and runs on Gen9 at least.

Quoted 11 lines
---
  drivers/gpu/drm/i915/i915_gem_context.c    |  62 ++--
  drivers/gpu/drm/i915/i915_gem_execbuffer.c |  27 +-
  drivers/gpu/drm/i915/i915_gem_gtt.c        |  57 ++--
  drivers/gpu/drm/i915/intel_display.c       | 113 ++++---
  drivers/gpu/drm/i915/intel_lrc.c           | 223 +++++++-------
  drivers/gpu/drm/i915/intel_mocs.c          |  43 +--
  drivers/gpu/drm/i915/intel_overlay.c       |  69 ++---
  drivers/gpu/drm/i915/intel_ringbuffer.c    | 480 +++++++++++++++--------------
  drivers/gpu/drm/i915/intel_ringbuffer.h    |  19 +-
  9 files changed, 555 insertions(+), 538 deletions(-)

Hmm, mine is bigger.

  drivers/gpu/drm/i915/i915_gem_context.c    |  85 ++--
  drivers/gpu/drm/i915/i915_gem_execbuffer.c |  37 +-
  drivers/gpu/drm/i915/i915_gem_gtt.c        |  62 +--
  drivers/gpu/drm/i915/i915_gem_request.c    | 135 ++++-
  drivers/gpu/drm/i915/i915_gem_request.h    |   2 +
  drivers/gpu/drm/i915/intel_display.c       | 133 +++--
  drivers/gpu/drm/i915/intel_lrc.c           | 188 ++++---
  drivers/gpu/drm/i915/intel_lrc.h           |   2 -
  drivers/gpu/drm/i915/intel_mocs.c          |  50 +-
  drivers/gpu/drm/i915/intel_overlay.c       |  77 ++-
  drivers/gpu/drm/i915/intel_ringbuffer.c    | 762 ++++++++++++-----------------
  drivers/gpu/drm/i915/intel_ringbuffer.h    |  36 +-
  12 files changed, 721 insertions(+), 848 deletions(-)

(this includes moving the intel_ring_begin to i915_gem_request)

plus an ealier

Quoted 7 lines
  drivers/gpu/drm/i915/i915_gem_request.c |  26 ++---
  drivers/gpu/drm/i915/intel_lrc.c        | 121 ++++++++---------------
  drivers/gpu/drm/i915/intel_ringbuffer.c | 168 +++++++++++---------------------
  drivers/gpu/drm/i915/intel_ringbuffer.h |  10 +-
  4 files changed, 112 insertions(+), 213 deletions(-)

since I wanted parts of it for emitting timelines.

Ok what do you want to do?

Regards,

Tvrtko

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

#4 lore raw
Quoted 48 lines · Tvrtko Ursulin
Quoted 7 lines · Chris Wilson
Quoted 4 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

This removes the usage of intel_ring_emit in favour of directly writing to the ring buffer.

I have the same patch! But I called it out, for historical reasons.

Yes I know we talked about it in the past but I did not think you will find time to actually write it amongst all the other things.

Quoted 2 lines

Oh, except mine uses out[0]...out[N] because gcc prefers that over *out++ = ...

It copes just fine with the latter here, for example:

    *rbuf++ = cmd;
    *rbuf++ = I915_GEM_HWS_SCRATCH_ADDR | MI_FLUSH_DW_USE_GTT;
    *rbuf++ = 0; /* upper addr */
    *rbuf++ = 0; /* value */

Is:

     3e9:       89 10                   mov    %edx,(%rax)
     3eb:       c7 40 04 04 01 00 00    movl   $0x104,0x4(%rax)
     3f2:       c7 40 08 00 00 00 00    movl   $0x0,0x8(%rax)
     3f9:       c7 40 0c 00 00 00 00    movl   $0x0,0xc(%rax)

And for the record, before this patch, with intel_ring_emit:

     53a:       8b 53 3c                mov    0x3c(%rbx),%edx
     53d:       48 8b 4b 08             mov    0x8(%rbx),%rcx
     541:       89 04 11                mov    %eax,(%rcx,%rdx,1)
     544:       8b 43 3c                mov    0x3c(%rbx),%eax
     547:       48 8b 53 08             mov    0x8(%rbx),%rdx
     54b:       83 c0 04                add    $0x4,%eax
     54e:       89 43 3c                mov    %eax,0x3c(%rbx)
     551:       c7 04 02 04 01 00 00    movl   $0x104,(%rdx,%rax,1)
     558:       8b 43 3c                mov    0x3c(%rbx),%eax
     55b:       48 8b 53 08             mov    0x8(%rbx),%rdx
     55f:       83 c0 04                add    $0x4,%eax
     562:       89 43 3c                mov    %eax,0x3c(%rbx)
     565:       c7 04 02 00 00 00 00    movl   $0x0,(%rdx,%rax,1)
Quoted 7 lines
     56c:       8b 43 3c                mov    0x3c(%rbx),%eax
     56f:       48 8b 53 08             mov    0x8(%rbx),%rdx
     573:       83 c0 04                add    $0x4,%eax
     576:       89 43 3c                mov    %eax,0x3c(%rbx)
     579:       c7 04 02 00 00 00 00    movl   $0x0,(%rdx,%rax,1)

Yuck :) At least they are not function calls to iowrite any more. :)

Curious that the inlining wasn't doing a better job, though. For example, it's not preserving %eax as a local cache of 0x3c(%rbx).

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

intel_ring_emit was preventing the compiler for optimising fetch and increment of the current ring buffer pointer and therefore generating very verbose code for every write.

It had no useful purpose since all ringbuffer operations are started and ended with intel_ring_begin and intel_ring_advance respectively, with no bail out in the middle possible, so it is fine to increment the tail in intel_ring_begin and let the code manage the pointer itself.

Or you could have intel_ring_advance() take the updated local and use that to update the ring->tail. It could then check that you hadn't exceeded your allocation, OR that you had used exactly as much as you'd allocated. I'm sure I had a version that did that, long ago.

Quoted 56 lines
Quoted 8 lines
Quoted 6 lines

Useless instruction removal amounts to approximately 2384 bytes of saved text on my build.

Not sure if this has any measurable performance implications but executing a ton of useless instructions on fast paths cannot be good.

It does show up in perf.

Cool.

Quoted 45 lines
Quoted 4 lines

Patch is not fully polished, but it compiles and runs on Gen9 at least.

Quoted 12 lines
---
  drivers/gpu/drm/i915/i915_gem_context.c    |  62 ++--
  drivers/gpu/drm/i915/i915_gem_execbuffer.c |  27 +-
  drivers/gpu/drm/i915/i915_gem_gtt.c        |  57 ++--
  drivers/gpu/drm/i915/intel_display.c       | 113 ++++---
  drivers/gpu/drm/i915/intel_lrc.c           | 223 +++++++-------
  drivers/gpu/drm/i915/intel_mocs.c          |  43 +--
  drivers/gpu/drm/i915/intel_overlay.c       |  69 ++---
  drivers/gpu/drm/i915/intel_ringbuffer.c    | 480
+++++++++++++++--------------
  drivers/gpu/drm/i915/intel_ringbuffer.h    |  19 +-
  9 files changed, 555 insertions(+), 538 deletions(-)

Hmm, mine is bigger.

  drivers/gpu/drm/i915/i915_gem_context.c    |  85 ++--
  drivers/gpu/drm/i915/i915_gem_execbuffer.c |  37 +-
  drivers/gpu/drm/i915/i915_gem_gtt.c        |  62 +--
  drivers/gpu/drm/i915/i915_gem_request.c    | 135 ++++-
  drivers/gpu/drm/i915/i915_gem_request.h    |   2 +
  drivers/gpu/drm/i915/intel_display.c       | 133 +++--
  drivers/gpu/drm/i915/intel_lrc.c           | 188 ++++---
  drivers/gpu/drm/i915/intel_lrc.h           |   2 -
  drivers/gpu/drm/i915/intel_mocs.c          |  50 +-
  drivers/gpu/drm/i915/intel_overlay.c       |  77 ++-
  drivers/gpu/drm/i915/intel_ringbuffer.c    | 762
++++++++++++-----------------
  drivers/gpu/drm/i915/intel_ringbuffer.h    |  36 +-
  12 files changed, 721 insertions(+), 848 deletions(-)

(this includes moving the intel_ring_begin to i915_gem_request)

plus an ealier

  drivers/gpu/drm/i915/i915_gem_request.c |  26 ++---
  drivers/gpu/drm/i915/intel_lrc.c        | 121 ++++++++---------------
  drivers/gpu/drm/i915/intel_ringbuffer.c | 168
+++++++++++---------------------
  drivers/gpu/drm/i915/intel_ringbuffer.h |  10 +-
  4 files changed, 112 insertions(+), 213 deletions(-)
Quoted 6 lines
Quoted 1 line

since I wanted parts of it for emitting timelines.

Ok what do you want to do?

Regards,
Tvrtko

You are giving up the possibility of wrapping over the end of the buffer, but we avoid doing that at present and it doesn't work on some hardware, so no great loss.

What about

	rptr = ring_begin(req, len);
	if (unlikely(IS_ERR(rptr))
		return PTR_ERR(rptr);

rather than

	ret = intel_ring_begin(req, len, &rbuf);

if (ret)
return ret;

(because returning values through ref parameters is ugly).

Do you have/do you want a Coccinelle script to automate this?

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

#5 lore raw
Quoted 55 lines · Dave Gordon
Quoted 54 lines · Tvrtko Ursulin
Quoted 7 lines · Chris Wilson
Quoted 4 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

This removes the usage of intel_ring_emit in favour of directly writing to the ring buffer.

I have the same patch! But I called it out, for historical reasons.

Yes I know we talked about it in the past but I did not think you will find time to actually write it amongst all the other things.

Quoted 2 lines

Oh, except mine uses out[0]...out[N] because gcc prefers that over *out++ = ...

It copes just fine with the latter here, for example:

    *rbuf++ = cmd;
    *rbuf++ = I915_GEM_HWS_SCRATCH_ADDR | MI_FLUSH_DW_USE_GTT;
    *rbuf++ = 0; /* upper addr */
    *rbuf++ = 0; /* value */

Is:

     3e9:       89 10                   mov    %edx,(%rax)
     3eb:       c7 40 04 04 01 00 00    movl   $0x104,0x4(%rax)
     3f2:       c7 40 08 00 00 00 00    movl   $0x0,0x8(%rax)
     3f9:       c7 40 0c 00 00 00 00    movl   $0x0,0xc(%rax)

And for the record, before this patch, with intel_ring_emit:

     53a:       8b 53 3c                mov    0x3c(%rbx),%edx
     53d:       48 8b 4b 08             mov    0x8(%rbx),%rcx
     541:       89 04 11                mov    %eax,(%rcx,%rdx,1)
     544:       8b 43 3c                mov    0x3c(%rbx),%eax
     547:       48 8b 53 08             mov    0x8(%rbx),%rdx
     54b:       83 c0 04                add    $0x4,%eax
     54e:       89 43 3c                mov    %eax,0x3c(%rbx)
     551:       c7 04 02 04 01 00 00    movl   $0x104,(%rdx,%rax,1)
     558:       8b 43 3c                mov    0x3c(%rbx),%eax
     55b:       48 8b 53 08             mov    0x8(%rbx),%rdx
     55f:       83 c0 04                add    $0x4,%eax
     562:       89 43 3c                mov    %eax,0x3c(%rbx)
     565:       c7 04 02 00 00 00 00    movl   $0x0,(%rdx,%rax,1)
     56c:       8b 43 3c                mov    0x3c(%rbx),%eax
     56f:       48 8b 53 08             mov    0x8(%rbx),%rdx
     573:       83 c0 04                add    $0x4,%eax
     576:       89 43 3c                mov    %eax,0x3c(%rbx)
     579:       c7 04 02 00 00 00 00    movl   $0x0,(%rdx,%rax,1)
Quoted 4 lines
Quoted 1 line

Yuck :) At least they are not function calls to iowrite any more. :)

Curious that the inlining wasn't doing a better job, though. For example, it's not preserving %eax as a local cache of 0x3c(%rbx).

Yeah I don't know. Even by employing the restrict keyword in various ways I couldn't make it do a better job.

Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

intel_ring_emit was preventing the compiler for optimising fetch and increment of the current ring buffer pointer and therefore generating very verbose code for every write.

It had no useful purpose since all ringbuffer operations are started and ended with intel_ring_begin and intel_ring_advance respectively, with no bail out in the middle possible, so it is fine to increment the tail in intel_ring_begin and let the code manage the pointer itself.

Quoted 4 lines

Or you could have intel_ring_advance() take the updated local and use that to update the ring->tail. It could then check that you hadn't exceeded your allocation, OR that you had used exactly as much as you'd allocated. I'm sure I had a version that did that, long ago.

Sounds good to me.

Quoted 73 lines
Quoted 56 lines
Quoted 8 lines
Quoted 6 lines

Useless instruction removal amounts to approximately 2384 bytes of saved text on my build.

Not sure if this has any measurable performance implications but executing a ton of useless instructions on fast paths cannot be good.

It does show up in perf.

Cool.

Quoted 45 lines
Quoted 4 lines

Patch is not fully polished, but it compiles and runs on Gen9 at least.

Quoted 12 lines
---
  drivers/gpu/drm/i915/i915_gem_context.c    |  62 ++--
  drivers/gpu/drm/i915/i915_gem_execbuffer.c |  27 +-
  drivers/gpu/drm/i915/i915_gem_gtt.c        |  57 ++--
  drivers/gpu/drm/i915/intel_display.c       | 113 ++++---
  drivers/gpu/drm/i915/intel_lrc.c           | 223 +++++++-------
  drivers/gpu/drm/i915/intel_mocs.c          |  43 +--
  drivers/gpu/drm/i915/intel_overlay.c       |  69 ++---
  drivers/gpu/drm/i915/intel_ringbuffer.c    | 480
+++++++++++++++--------------
  drivers/gpu/drm/i915/intel_ringbuffer.h    |  19 +-
  9 files changed, 555 insertions(+), 538 deletions(-)

Hmm, mine is bigger.

  drivers/gpu/drm/i915/i915_gem_context.c    |  85 ++--
  drivers/gpu/drm/i915/i915_gem_execbuffer.c |  37 +-
  drivers/gpu/drm/i915/i915_gem_gtt.c        |  62 +--
  drivers/gpu/drm/i915/i915_gem_request.c    | 135 ++++-
  drivers/gpu/drm/i915/i915_gem_request.h    |   2 +
  drivers/gpu/drm/i915/intel_display.c       | 133 +++--
  drivers/gpu/drm/i915/intel_lrc.c           | 188 ++++---
  drivers/gpu/drm/i915/intel_lrc.h           |   2 -
  drivers/gpu/drm/i915/intel_mocs.c          |  50 +-
  drivers/gpu/drm/i915/intel_overlay.c       |  77 ++-
  drivers/gpu/drm/i915/intel_ringbuffer.c    | 762
++++++++++++-----------------
  drivers/gpu/drm/i915/intel_ringbuffer.h    |  36 +-
  12 files changed, 721 insertions(+), 848 deletions(-)

(this includes moving the intel_ring_begin to i915_gem_request)

plus an ealier

  drivers/gpu/drm/i915/i915_gem_request.c |  26 ++---
  drivers/gpu/drm/i915/intel_lrc.c        | 121 ++++++++---------------
  drivers/gpu/drm/i915/intel_ringbuffer.c | 168
+++++++++++---------------------
  drivers/gpu/drm/i915/intel_ringbuffer.h |  10 +-
  4 files changed, 112 insertions(+), 213 deletions(-)
Quoted 6 lines
Quoted 1 line

since I wanted parts of it for emitting timelines.

Ok what do you want to do?

Regards,
Tvrtko

You are giving up the possibility of wrapping over the end of the buffer, but we avoid doing that at present and it doesn't work on some hardware, so no great loss.

What about

     rptr = ring_begin(req, len);
     if (unlikely(IS_ERR(rptr))
         return PTR_ERR(rptr);
Quoted 7 lines

rather than

     ret = intel_ring_begin(req, len, &rbuf);
      if (ret)
          return ret;

(because returning values through ref parameters is ugly).

I tried that first but then just got reminded how error pointers make gcc generate more verbose code. Especially in this case where it would do ERR_PTR followed by PTR_ERR for nothing. So I thought since I am shrinking it, lets go full hog.

Quoted 1 line

Do you have/do you want a Coccinelle script to automate this?

I don't and why not - more Coccinelle examples in the public domain the better. :)

Regards,

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

#6 lore raw

RFC v2 1/1 drm/i915: Emit to ringbuffer directly

From: Tvrtko Ursulin <[email protected]>

This removes the usage of intel_ring_emit in favour of directly writing to the ring buffer.

intel_ring_emit was preventing the compiler for optimising fetch and increment of the current ring buffer pointer and therefore generating very verbose code for every write.

It had no useful purpose since all ringbuffer operations are started and ended with intel_ring_begin and intel_ring_advance respectively, with no bail out in the middle possible, so it is fine to increment the tail in intel_ring_begin and let the code manage the pointer itself.

Useless instruction removal amounts to approximately two and half kilobytes of saved text on my build.

Not sure if this has any measurable performance implications but executing a ton of useless instructions on fast paths cannot be good.

Patch is not fully polished, but it compiles and runs on Gen9 at least.

v2:
* Change return from intel_ring_begin to error pointer by popular demand.
* Move tail increment to intel_ring_advance to enable some error checking.

Cc Chris Wilson <[email protected]>
Cc Dave Gordon <[email protected]>
---
 drivers/gpu/drm/i915/i915_gem_context.c    |  72 ++--
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |  37 +-
 drivers/gpu/drm/i915/i915_gem_gtt.c        |  70 ++--
 drivers/gpu/drm/i915/intel_display.c       | 137 +++---
 drivers/gpu/drm/i915/intel_lrc.c           | 231 +++++------
 drivers/gpu/drm/i915/intel_mocs.c          |  53 ++-
 drivers/gpu/drm/i915/intel_overlay.c       |  88 ++--
 drivers/gpu/drm/i915/intel_ringbuffer.c    | 642 ++++++++++++++---------------
 drivers/gpu/drm/i915/intel_ringbuffer.h    |  17 +-
 9 files changed, 658 insertions(+), 689 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +32 -40
index 35950ee46a1d..a6193cda743f 100644
@@ -577,7 +577,6 @@ static inline int
 mi_set_context(struct drm_i915_gem_request *req, u32 hw_flags)
 {
 	struct drm_i915_private *dev_priv = req->i915;
-	struct intel_ring *ring = req->ring;
 	struct intel_engine_cs *engine = req->engine;
 	u32 flags = hw_flags | MI_MM_SPACE_GTT;
 	const int num_rings =
@@ -585,6 +584,7 @@ mi_set_context(struct drm_i915_gem_request *req, u32 hw_flags)
 		i915.semaphores ?
 		INTEL_INFO(dev_priv)->num_rings - 1 :
 		0;
+	u32 *rbuf;
 	int len, ret;
 
 	/* w/a: If Flush TLB Invalidation Mode is enabled, driver must do a TLB
@@ -609,70 +609,61 @@ mi_set_context(struct drm_i915_gem_request *req, u32 hw_flags)
 	if (INTEL_GEN(dev_priv) >= 7)
 		len += 2 + (num_rings ? 4*num_rings + 6 : 0);
 
-	ret = intel_ring_begin(req, len);
-	if (ret)
-		return ret;
+	rbuf = intel_ring_begin(req, len);
+	if (IS_ERR(rbuf))
+		return PTR_ERR(rbuf);
 
 	/* WaProgramMiArbOnOffAroundMiSetContext:ivb,vlv,hsw,bdw,chv */
 	if (INTEL_GEN(dev_priv) >= 7) {
-		intel_ring_emit(ring, MI_ARB_ON_OFF | MI_ARB_DISABLE);
+		*rbuf++ = MI_ARB_ON_OFF | MI_ARB_DISABLE;
 		if (num_rings) {
 			struct intel_engine_cs *signaller;
 
-			intel_ring_emit(ring,
-					MI_LOAD_REGISTER_IMM(num_rings));
+			*rbuf++ = MI_LOAD_REGISTER_IMM(num_rings);
 			for_each_engine(signaller, dev_priv) {
 				if (signaller == engine)
 					continue;
 
-				intel_ring_emit_reg(ring,
-						    RING_PSMI_CTL(signaller->mmio_base));
-				intel_ring_emit(ring,
-						_MASKED_BIT_ENABLE(GEN6_PSMI_SLEEP_MSG_DISABLE));
+				*rbuf++ = RING_PSMI_CTL(signaller->mmio_base).reg;
+				*rbuf++ = _MASKED_BIT_ENABLE(GEN6_PSMI_SLEEP_MSG_DISABLE);
 			}
 		}
 	}
 
-	intel_ring_emit(ring, MI_NOOP);
-	intel_ring_emit(ring, MI_SET_CONTEXT);
-	intel_ring_emit(ring,
-			i915_ggtt_offset(req->ctx->engine[RCS].state) | flags);
+	*rbuf++ = MI_NOOP;
+	*rbuf++ = MI_SET_CONTEXT;
+	*rbuf++ = i915_ggtt_offset(req->ctx->engine[RCS].state) | flags;
 	/*
 	 * w/a: MI_SET_CONTEXT must always be followed by MI_NOOP
 	 * WaMiSetContext_Hang:snb,ivb,vlv
 	 */
-	intel_ring_emit(ring, MI_NOOP);
+	*rbuf++ = MI_NOOP;
 
 	if (INTEL_GEN(dev_priv) >= 7) {
 		if (num_rings) {
 			struct intel_engine_cs *signaller;
 			i915_reg_t last_reg = {}; /* keep gcc quiet */
 
-			intel_ring_emit(ring,
-					MI_LOAD_REGISTER_IMM(num_rings));
+			*rbuf++ = MI_LOAD_REGISTER_IMM(num_rings);
 			for_each_engine(signaller, dev_priv) {
 				if (signaller == engine)
 					continue;
 
 				last_reg = RING_PSMI_CTL(signaller->mmio_base);
-				intel_ring_emit_reg(ring, last_reg);
-				intel_ring_emit(ring,
-						_MASKED_BIT_DISABLE(GEN6_PSMI_SLEEP_MSG_DISABLE));
+				*rbuf++ = last_reg.reg;
+				*rbuf++ = _MASKED_BIT_DISABLE(GEN6_PSMI_SLEEP_MSG_DISABLE);
 			}
 
 			/* Insert a delay before the next switch! */
-			intel_ring_emit(ring,
-					MI_STORE_REGISTER_MEM |
-					MI_SRM_LRM_GLOBAL_GTT);
-			intel_ring_emit_reg(ring, last_reg);
-			intel_ring_emit(ring,
-					i915_ggtt_offset(engine->scratch));
-			intel_ring_emit(ring, MI_NOOP);
+			*rbuf++ = MI_STORE_REGISTER_MEM | MI_SRM_LRM_GLOBAL_GTT;
+			*rbuf++ = last_reg.reg;
+			*rbuf++ = i915_ggtt_offset(engine->scratch);
+			*rbuf++ = MI_NOOP;
 		}
-		intel_ring_emit(ring, MI_ARB_ON_OFF | MI_ARB_ENABLE);
+		*rbuf++ = MI_ARB_ON_OFF | MI_ARB_ENABLE;
 	}
 
-	intel_ring_advance(ring);
+	intel_ring_advance(req->ring, rbuf);
 
 	return ret;
 }
@@ -680,28 +671,29 @@ mi_set_context(struct drm_i915_gem_request *req, u32 hw_flags)
 static int remap_l3(struct drm_i915_gem_request *req, int slice)
 {
 	u32 *remap_info = req->i915->l3_parity.remap_info[slice];
-	struct intel_ring *ring = req->ring;
-	int i, ret;
+	u32 *rbuf;
+	int i;
 
 	if (!remap_info)
 		return 0;
 
-	ret = intel_ring_begin(req, GEN7_L3LOG_SIZE/4 * 2 + 2);
-	if (ret)
-		return ret;
+	rbuf = intel_ring_begin(req, GEN7_L3LOG_SIZE/4 * 2 + 2);
+	if (IS_ERR(rbuf))
+		return PTR_ERR(rbuf);
 
 	/*
 	 * Note: We do not worry about the concurrent register cacheline hang
 	 * here because no other code should access these registers other than
 	 * at initialization time.
 	 */
-	intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(GEN7_L3LOG_SIZE/4));
+	*rbuf++ = MI_LOAD_REGISTER_IMM(GEN7_L3LOG_SIZE/4);
 	for (i = 0; i < GEN7_L3LOG_SIZE/4; i++) {
-		intel_ring_emit_reg(ring, GEN7_L3LOG(slice, i));
-		intel_ring_emit(ring, remap_info[i]);
+		*rbuf++ = GEN7_L3LOG(slice, i).reg;
+		*rbuf++ = remap_info[i];
 	}
-	intel_ring_emit(ring, MI_NOOP);
-	intel_ring_advance(ring);
+	*rbuf++ = MI_NOOP;
+
+	intel_ring_advance(req->ring, rbuf);
 
 	return 0;
 }
drivers/gpu/drm/i915/i915_gem_execbuffer.c +19 -18
index 9432d4ce9ffb..50954c0bc725 100644
@@ -1358,25 +1358,25 @@ i915_gem_execbuffer_move_to_active(struct list_head *vmas,
 static int
 i915_reset_gen7_sol_offsets(struct drm_i915_gem_request *req)
 {
-	struct intel_ring *ring = req->ring;
-	int ret, i;
+	u32 *rbuf;
+	int i;
 
 	if (!IS_GEN7(req->i915) || req->engine->id != RCS) {
 		DRM_DEBUG("sol reset is gen7/rcs only\n");
 		return -EINVAL;
 	}
 
-	ret = intel_ring_begin(req, 4 * 3);
-	if (ret)
-		return ret;
+	rbuf = intel_ring_begin(req, 4 * 3);
+	if (IS_ERR(rbuf))
+		return PTR_ERR(rbuf);
 
 	for (i = 0; i < 4; i++) {
-		intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
-		intel_ring_emit_reg(ring, GEN7_SO_WRITE_OFFSET(i));
-		intel_ring_emit(ring, 0);
+		*rbuf++ = MI_LOAD_REGISTER_IMM(1);
+		*rbuf++ = GEN7_SO_WRITE_OFFSET(i).reg;
+		*rbuf++ = 0;
 	}
 
-	intel_ring_advance(ring);
+	intel_ring_advance(req->ring, rbuf);
 
 	return 0;
 }
@@ -1483,17 +1483,18 @@ execbuf_submit(struct i915_execbuffer_params *params,
 
 	if (params->engine->id == RCS &&
 	    instp_mode != dev_priv->relative_constants_mode) {
-		struct intel_ring *ring = params->request->ring;
+		u32 *rbuf;
 
-		ret = intel_ring_begin(params->request, 4);
-		if (ret)
-			return ret;
+		rbuf = intel_ring_begin(params->request, 4);
+		if (IS_ERR(rbuf))
+			return PTR_ERR(rbuf);
+
+		*rbuf++ = MI_NOOP;
+		*rbuf++ = MI_LOAD_REGISTER_IMM(1);
+		*rbuf++ = INSTPM.reg;
+		*rbuf++ = instp_mask << 16 | instp_mode;
 
-		intel_ring_emit(ring, MI_NOOP);
-		intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
-		intel_ring_emit_reg(ring, INSTPM);
-		intel_ring_emit(ring, instp_mask << 16 | instp_mode);
-		intel_ring_advance(ring);
+		intel_ring_advance(params->request->ring, rbuf);
 
 		dev_priv->relative_constants_mode = instp_mode;
 	}
drivers/gpu/drm/i915/i915_gem_gtt.c +36 -34

109 lines not on this page · raw message

drivers/gpu/drm/i915/intel_display.c +66 -71

227 lines not on this page · raw message

drivers/gpu/drm/i915/intel_lrc.c +114 -117

367 lines not on this page · raw message

drivers/gpu/drm/i915/intel_mocs.c +26 -27

102 lines not on this page · raw message

drivers/gpu/drm/i915/intel_overlay.c +41 -47

158 lines not on this page · raw message

drivers/gpu/drm/i915/intel_ringbuffer.c +317 -325

1,004 lines not on this page · raw message

drivers/gpu/drm/i915/intel_ringbuffer.h +7 -10
index 84aea549de5d..07bcc650c7bc 100644
@@ -443,7 +443,7 @@ void intel_engine_cleanup(struct intel_engine_cs *engine);
 
 int intel_ring_alloc_request_extras(struct drm_i915_gem_request *request);
 
-int __must_check intel_ring_begin(struct drm_i915_gem_request *req, int n);
+u32 __must_check *intel_ring_begin(struct drm_i915_gem_request *req, int n);
 int __must_check intel_ring_cacheline_align(struct drm_i915_gem_request *req);
 
 static inline void intel_ring_emit(struct intel_ring *ring, u32 data)
@@ -457,16 +457,13 @@ static inline void intel_ring_emit_reg(struct intel_ring *ring, i915_reg_t reg)
 	intel_ring_emit(ring, i915_mmio_reg_offset(reg));
 }
 
-static inline void intel_ring_advance(struct intel_ring *ring)
+static inline void intel_ring_advance(struct intel_ring *ring, u32 *rbuf)
 {
-	/* Dummy function.
-	 *
-	 * This serves as a placeholder in the code so that the reader
-	 * can compare against the preceding intel_ring_begin() and
-	 * check that the number of dwords emitted matches the space
-	 * reserved for the command packet (i.e. the value passed to
-	 * intel_ring_begin()).
-	 */
+	unsigned int written = (void *)rbuf - (ring->vaddr + ring->tail);
+
+	GEM_BUG_ON(ring->tail + written <= ring->size);
+
+	ring->tail += written;
 }
 
 static inline u32 intel_ring_offset(struct intel_ring *ring, u32 value)
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#7 lore raw
Quoted 23 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

This removes the usage of intel_ring_emit in favour of directly writing to the ring buffer.

intel_ring_emit was preventing the compiler for optimising fetch and increment of the current ring buffer pointer and therefore generating very verbose code for every write.

It had no useful purpose since all ringbuffer operations are started and ended with intel_ring_begin and intel_ring_advance respectively, with no bail out in the middle possible, so it is fine to increment the tail in intel_ring_begin and let the code manage the pointer itself.

Useless instruction removal amounts to approximately two and half kilobytes of saved text on my build.

Not sure if this has any measurable performance implications but executing a ton of useless instructions on fast paths cannot be good.

Quoted 8 lines

Patch is not fully polished, but it compiles and runs on Gen9 at least.

v2:
* Change return from intel_ring_begin to error pointer by popular demand.
* Move tail increment to intel_ring_advance to enable some error checking.

The increment can stay in begin (it's not intel_ring_begin() anymore since it operates on the request!) as that will be smaller at no usability cost.

Just check that rbuf == ring->vaddr + ring->tail at end. -Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#8 lore raw

PATCH v3 1/1 drm/i915: Emit to ringbuffer directly

From: Tvrtko Ursulin <[email protected]>

This removes the usage of intel_ring_emit in favour of directly writing to the ring buffer.

intel_ring_emit was preventing the compiler for optimising fetch and increment of the current ring buffer pointer and therefore generating very verbose code for every write.

It had no useful purpose since all ringbuffer operations are started and ended with intel_ring_begin and intel_ring_advance respectively, with no bail out in the middle possible, so it is fine to increment the tail in intel_ring_begin and let the code manage the pointer itself.

Useless instruction removal amounts to approximately two and half kilobytes of saved text on my build.

Not sure if this has any measurable performance implications but executing a ton of useless instructions on fast paths cannot be good.

Patch is not fully polished, but it compiles and runs on Gen9 at least.

v2:
* Change return from intel_ring_begin to error pointer by popular demand.
* Move tail increment to intel_ring_advance to enable some error checking.

v3:
* Move tail advance back into intel_ring_begin.
* Rebase and tidy.

Cc Chris Wilson <[email protected]>
Cc Dave Gordon <[email protected]>
---
 drivers/gpu/drm/i915/i915_gem_context.c    |  75 ++--
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |  37 +-
 drivers/gpu/drm/i915/i915_gem_gtt.c        |  70 ++--
 drivers/gpu/drm/i915/intel_display.c       | 132 +++---
 drivers/gpu/drm/i915/intel_lrc.c           | 245 ++++++-----
 drivers/gpu/drm/i915/intel_mocs.c          |  53 ++-
 drivers/gpu/drm/i915/intel_overlay.c       |  88 ++--
 drivers/gpu/drm/i915/intel_ringbuffer.c    | 638 ++++++++++++++---------------
 drivers/gpu/drm/i915/intel_ringbuffer.h    |  24 +-
 9 files changed, 655 insertions(+), 707 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +35 -40
index df10f4e95736..1394408203c3 100644
@@ -561,7 +561,6 @@ static inline int
 mi_set_context(struct drm_i915_gem_request *req, u32 hw_flags)
 {
 	struct drm_i915_private *dev_priv = req->i915;
-	struct intel_ring *ring = req->ring;
 	struct intel_engine_cs *engine = req->engine;
 	u32 flags = hw_flags | MI_MM_SPACE_GTT;
 	const int num_rings =
@@ -569,6 +568,7 @@ mi_set_context(struct drm_i915_gem_request *req, u32 hw_flags)
 		i915.semaphores ?
 		INTEL_INFO(dev_priv)->num_rings - 1 :
 		0;
+	u32 *rbuf;
 	int len, ret;
 
 	/* w/a: If Flush TLB Invalidation Mode is enabled, driver must do a TLB
@@ -593,70 +593,64 @@ mi_set_context(struct drm_i915_gem_request *req, u32 hw_flags)
 	if (INTEL_GEN(dev_priv) >= 7)
 		len += 2 + (num_rings ? 4*num_rings + 6 : 0);
 
-	ret = intel_ring_begin(req, len);
-	if (ret)
-		return ret;
+	rbuf = intel_ring_begin(req, len);
+	if (IS_ERR(rbuf))
+		return PTR_ERR(rbuf);
 
 	/* WaProgramMiArbOnOffAroundMiSetContext:ivb,vlv,hsw,bdw,chv */
 	if (INTEL_GEN(dev_priv) >= 7) {
-		intel_ring_emit(ring, MI_ARB_ON_OFF | MI_ARB_DISABLE);
+		*rbuf++ = MI_ARB_ON_OFF | MI_ARB_DISABLE;
 		if (num_rings) {
 			struct intel_engine_cs *signaller;
 
-			intel_ring_emit(ring,
-					MI_LOAD_REGISTER_IMM(num_rings));
+			*rbuf++ = MI_LOAD_REGISTER_IMM(num_rings);
 			for_each_engine(signaller, dev_priv) {
 				if (signaller == engine)
 					continue;
 
-				intel_ring_emit_reg(ring,
-						    RING_PSMI_CTL(signaller->mmio_base));
-				intel_ring_emit(ring,
-						_MASKED_BIT_ENABLE(GEN6_PSMI_SLEEP_MSG_DISABLE));
+				*rbuf++ = i915_mmio_reg_offset(
+					  RING_PSMI_CTL(signaller->mmio_base));
+				*rbuf++ = _MASKED_BIT_ENABLE(
+					   GEN6_PSMI_SLEEP_MSG_DISABLE);
 			}
 		}
 	}
 
-	intel_ring_emit(ring, MI_NOOP);
-	intel_ring_emit(ring, MI_SET_CONTEXT);
-	intel_ring_emit(ring,
-			i915_ggtt_offset(req->ctx->engine[RCS].state) | flags);
+	*rbuf++ = MI_NOOP;
+	*rbuf++ = MI_SET_CONTEXT;
+	*rbuf++ = i915_ggtt_offset(req->ctx->engine[RCS].state) | flags;
 	/*
 	 * w/a: MI_SET_CONTEXT must always be followed by MI_NOOP
 	 * WaMiSetContext_Hang:snb,ivb,vlv
 	 */
-	intel_ring_emit(ring, MI_NOOP);
+	*rbuf++ = MI_NOOP;
 
 	if (INTEL_GEN(dev_priv) >= 7) {
 		if (num_rings) {
 			struct intel_engine_cs *signaller;
 			i915_reg_t last_reg = {}; /* keep gcc quiet */
 
-			intel_ring_emit(ring,
-					MI_LOAD_REGISTER_IMM(num_rings));
+			*rbuf++ = MI_LOAD_REGISTER_IMM(num_rings);
 			for_each_engine(signaller, dev_priv) {
 				if (signaller == engine)
 					continue;
 
 				last_reg = RING_PSMI_CTL(signaller->mmio_base);
-				intel_ring_emit_reg(ring, last_reg);
-				intel_ring_emit(ring,
-						_MASKED_BIT_DISABLE(GEN6_PSMI_SLEEP_MSG_DISABLE));
+				*rbuf++ = i915_mmio_reg_offset(last_reg);
+				*rbuf++ = _MASKED_BIT_DISABLE(
+					  GEN6_PSMI_SLEEP_MSG_DISABLE);
 			}
 
 			/* Insert a delay before the next switch! */
-			intel_ring_emit(ring,
-					MI_STORE_REGISTER_MEM |
-					MI_SRM_LRM_GLOBAL_GTT);
-			intel_ring_emit_reg(ring, last_reg);
-			intel_ring_emit(ring,
-					i915_ggtt_offset(engine->scratch));
-			intel_ring_emit(ring, MI_NOOP);
+			*rbuf++ = MI_STORE_REGISTER_MEM | MI_SRM_LRM_GLOBAL_GTT;
+			*rbuf++ = i915_mmio_reg_offset(last_reg);
+			*rbuf++ = i915_ggtt_offset(engine->scratch);
+			*rbuf++ = MI_NOOP;
 		}
-		intel_ring_emit(ring, MI_ARB_ON_OFF | MI_ARB_ENABLE);
+		*rbuf++ = MI_ARB_ON_OFF | MI_ARB_ENABLE;
 	}
 
-	intel_ring_advance(ring);
+	intel_ring_advance(req->ring, rbuf);
 
 	return ret;
 }
@@ -664,28 +658,29 @@ mi_set_context(struct drm_i915_gem_request *req, u32 hw_flags)
 static int remap_l3(struct drm_i915_gem_request *req, int slice)
 {
 	u32 *remap_info = req->i915->l3_parity.remap_info[slice];
-	struct intel_ring *ring = req->ring;
-	int i, ret;
+	u32 *rbuf;
+	int i;
 
 	if (!remap_info)
 		return 0;
 
-	ret = intel_ring_begin(req, GEN7_L3LOG_SIZE/4 * 2 + 2);
-	if (ret)
-		return ret;
+	rbuf = intel_ring_begin(req, GEN7_L3LOG_SIZE / 4 * 2 + 2);
+	if (IS_ERR(rbuf))
+		return PTR_ERR(rbuf);
 
 	/*
 	 * Note: We do not worry about the concurrent register cacheline hang
 	 * here because no other code should access these registers other than
 	 * at initialization time.
 	 */
-	intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(GEN7_L3LOG_SIZE/4));
+	*rbuf++ = MI_LOAD_REGISTER_IMM(GEN7_L3LOG_SIZE / 4);
 	for (i = 0; i < GEN7_L3LOG_SIZE/4; i++) {
-		intel_ring_emit_reg(ring, GEN7_L3LOG(slice, i));
-		intel_ring_emit(ring, remap_info[i]);
+		*rbuf++ = i915_mmio_reg_offset(GEN7_L3LOG(slice, i));
+		*rbuf++ = remap_info[i];
 	}
-	intel_ring_emit(ring, MI_NOOP);
-	intel_ring_advance(ring);
+	*rbuf++ = MI_NOOP;
+
+	intel_ring_advance(req->ring, rbuf);
 
 	return 0;
 }
drivers/gpu/drm/i915/i915_gem_execbuffer.c +19 -18
index 33c85227643d..06f3aad37bc6 100644
@@ -1370,25 +1370,25 @@ i915_gem_execbuffer_move_to_active(struct list_head *vmas,
 static int
 i915_reset_gen7_sol_offsets(struct drm_i915_gem_request *req)
 {
-	struct intel_ring *ring = req->ring;
-	int ret, i;
+	u32 *rbuf;
+	int i;
 
 	if (!IS_GEN7(req->i915) || req->engine->id != RCS) {
 		DRM_DEBUG("sol reset is gen7/rcs only\n");
 		return -EINVAL;
 	}
 
-	ret = intel_ring_begin(req, 4 * 3);
-	if (ret)
-		return ret;
+	rbuf = intel_ring_begin(req, 4 * 3);
+	if (IS_ERR(rbuf))
+		return PTR_ERR(rbuf);
 
 	for (i = 0; i < 4; i++) {
-		intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
-		intel_ring_emit_reg(ring, GEN7_SO_WRITE_OFFSET(i));
-		intel_ring_emit(ring, 0);
+		*rbuf++ = MI_LOAD_REGISTER_IMM(1);
+		*rbuf++ = i915_mmio_reg_offset(GEN7_SO_WRITE_OFFSET(i));
+		*rbuf++ = 0;
 	}
 
-	intel_ring_advance(ring);
+	intel_ring_advance(req->ring, rbuf);
 
 	return 0;
 }
@@ -1495,17 +1495,18 @@ execbuf_submit(struct i915_execbuffer_params *params,
 
 	if (params->engine->id == RCS &&
 	    instp_mode != dev_priv->relative_constants_mode) {
-		struct intel_ring *ring = params->request->ring;
+		u32 *rbuf;
 
-		ret = intel_ring_begin(params->request, 4);
-		if (ret)
-			return ret;
+		rbuf = intel_ring_begin(params->request, 4);
+		if (IS_ERR(rbuf))
+			return PTR_ERR(rbuf);
+
+		*rbuf++ = MI_NOOP;
+		*rbuf++ = MI_LOAD_REGISTER_IMM(1);
+		*rbuf++ = i915_mmio_reg_offset(INSTPM);
+		*rbuf++ = instp_mask << 16 | instp_mode;
 
-		intel_ring_emit(ring, MI_NOOP);
-		intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
-		intel_ring_emit_reg(ring, INSTPM);
-		intel_ring_emit(ring, instp_mask << 16 | instp_mode);
-		intel_ring_advance(ring);
+		intel_ring_advance(params->request->ring, rbuf);
 
 		dev_priv->relative_constants_mode = instp_mode;
 	}
drivers/gpu/drm/i915/i915_gem_gtt.c +36 -34

109 lines not on this page · raw message

drivers/gpu/drm/i915/intel_display.c +61 -71

222 lines not on this page · raw message

drivers/gpu/drm/i915/intel_lrc.c +120 -125

389 lines not on this page · raw message

drivers/gpu/drm/i915/intel_mocs.c +26 -27

102 lines not on this page · raw message

drivers/gpu/drm/i915/intel_overlay.c +41 -47

158 lines not on this page · raw message

drivers/gpu/drm/i915/intel_ringbuffer.c +314 -324

1,007 lines not on this page · raw message

drivers/gpu/drm/i915/intel_ringbuffer.h +3 -21
index 7f64d611159b..53dcd7b9a72d 100644
@@ -456,30 +456,12 @@ void intel_legacy_submission_resume(struct drm_i915_private *dev_priv);
 
 int intel_ring_alloc_request_extras(struct drm_i915_gem_request *request);
 
-int __must_check intel_ring_begin(struct drm_i915_gem_request *req, int n);
+u32 __must_check *intel_ring_begin(struct drm_i915_gem_request *req, int n);
 int __must_check intel_ring_cacheline_align(struct drm_i915_gem_request *req);
 
-static inline void intel_ring_emit(struct intel_ring *ring, u32 data)
+static inline void intel_ring_advance(struct intel_ring *ring, u32 *rbuf)
 {
-	*(uint32_t *)(ring->vaddr + ring->tail) = data;
-	ring->tail += 4;
-}
-
-static inline void intel_ring_emit_reg(struct intel_ring *ring, i915_reg_t reg)
-{
-	intel_ring_emit(ring, i915_mmio_reg_offset(reg));
-}
-
-static inline void intel_ring_advance(struct intel_ring *ring)
-{
-	/* Dummy function.
-	 *
-	 * This serves as a placeholder in the code so that the reader
-	 * can compare against the preceding intel_ring_begin() and
-	 * check that the number of dwords emitted matches the space
-	 * reserved for the command packet (i.e. the value passed to
-	 * intel_ring_begin()).
-	 */
+	GEM_BUG_ON((ring->vaddr + ring->tail) != rbuf);
 }
 
 static inline u32 intel_ring_offset(struct intel_ring *ring, u32 value)
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#9 lore raw
Quoted 26 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

This removes the usage of intel_ring_emit in favour of directly writing to the ring buffer.

intel_ring_emit was preventing the compiler for optimising fetch and increment of the current ring buffer pointer and therefore generating very verbose code for every write.

It had no useful purpose since all ringbuffer operations are started and ended with intel_ring_begin and intel_ring_advance respectively, with no bail out in the middle possible, so it is fine to increment the tail in intel_ring_begin and let the code manage the pointer itself.

Useless instruction removal amounts to approximately two and half kilobytes of saved text on my build.

Not sure if this has any measurable performance implications but executing a ton of useless instructions on fast paths cannot be good.

Patch is not fully polished, but it compiles and runs on Gen9 at least.

Quoted 8 lines

v2:
* Change return from intel_ring_begin to error pointer by popular demand.
* Move tail increment to intel_ring_advance to enable some error checking.

v3:
* Move tail advance back into intel_ring_begin.

Downside of this is that you now have no check that _advance() is ever called, let alone called once per begin. If we want to strictly enforce the begin-advance pairing, _advance() has to do something, either something that is necessary for the next _begin(), or at least reset some state flag that tracks whether we're between a begin and an advance, or an advance and a begin (when writing to the ring is not allowed!).

.Dave.

Quoted 17 lines

* Rebase and tidy.

Cc Chris Wilson <[email protected]>
Cc Dave Gordon <[email protected]>
---
 drivers/gpu/drm/i915/i915_gem_context.c    |  75 ++--
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |  37 +-
 drivers/gpu/drm/i915/i915_gem_gtt.c        |  70 ++--
 drivers/gpu/drm/i915/intel_display.c       | 132 +++---
 drivers/gpu/drm/i915/intel_lrc.c           | 245 ++++++-----
 drivers/gpu/drm/i915/intel_mocs.c          |  53 ++-
 drivers/gpu/drm/i915/intel_overlay.c       |  88 ++--
 drivers/gpu/drm/i915/intel_ringbuffer.c    | 638 ++++++++++++++---------------
 drivers/gpu/drm/i915/intel_ringbuffer.h    |  24 +-
 9 files changed, 655 insertions(+), 707 deletions(-)

[snip]

Quoted 29 lines
drivers/gpu/drm/i915/intel_ringbuffer.h +2 -15
index 7f64d611159b..53dcd7b9a72d 100644
@@ -456,30 +456,12 @@ void intel_legacy_submission_resume(struct drm_i915_private *dev_priv);
 
 int intel_ring_alloc_request_extras(struct drm_i915_gem_request *request);
 
-int __must_check intel_ring_begin(struct drm_i915_gem_request *req, int n);
+u32 __must_check *intel_ring_begin(struct drm_i915_gem_request *req, int n);
 int __must_check intel_ring_cacheline_align(struct drm_i915_gem_request *req);
 
-static inline void intel_ring_emit(struct intel_ring *ring, u32 data)
+static inline void intel_ring_advance(struct intel_ring *ring, u32 *rbuf)
 {
-	*(uint32_t *)(ring->vaddr + ring->tail) = data;
-	ring->tail += 4;
-}
-
-static inline void intel_ring_emit_reg(struct intel_ring *ring, i915_reg_t reg)
-{
-	intel_ring_emit(ring, i915_mmio_reg_offset(reg));
-}
-
-static inline void intel_ring_advance(struct intel_ring *ring)
-{
-	/* Dummy function.
-	 *

drivers/gpu/drm/i915/intel_ringbuffer.h void intel_legacy_submission_resume(struct drm_i915_private *dev_priv); · line 467

Quoted 10 lines
drivers/gpu/drm/i915/intel_ringbuffer.h +1 -6
-	 * This serves as a placeholder in the code so that the reader
-	 * can compare against the preceding intel_ring_begin() and
-	 * check that the number of dwords emitted matches the space
-	 * reserved for the command packet (i.e. the value passed to
-	 * intel_ring_begin()).
-	 */
+	GEM_BUG_ON((ring->vaddr + ring->tail) != rbuf);
 }
 
 static inline u32 intel_ring_offset(struct intel_ring *ring, u32 value)

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

#10 lore raw
In reply to Tvrtko Ursulin
Quoted 23 lines · Tvrtko Ursulin
Quoted 7 lines · Chris Wilson
Quoted 4 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

This removes the usage of intel_ring_emit in favour of directly writing to the ring buffer.

I have the same patch! But I called it out, for historical reasons.

Yes I know we talked about it in the past but I did not think you will find time to actually write it amongst all the other things.

Quoted 2 lines

Oh, except mine uses out[0]...out[N] because gcc prefers that over *out++ = ...

It copes just fine with the latter here, for example:

	*rbuf++ = cmd;
	*rbuf++ = I915_GEM_HWS_SCRATCH_ADDR | MI_FLUSH_DW_USE_GTT;
	*rbuf++ = 0; /* upper addr */
	*rbuf++ = 0; /* value */
Quoted 6 lines

Is:

     3e9:       89 10                   mov    %edx,(%rax)
     3eb:       c7 40 04 04 01 00 00    movl   $0x104,0x4(%rax)
     3f2:       c7 40 08 00 00 00 00    movl   $0x0,0x8(%rax)
     3f9:       c7 40 0c 00 00 00 00    movl   $0x0,0xc(%rax)

Great. Last time we had a conversation about this, and when we looked at constructing batchbuffers in userpspace, gcc was still generating two instuctions (*ptr followed by ptr++) rather than emitting the mov to a fixed offset for that sequence.

Quoted 11 lines
Quoted 9 lines

plus an ealier

 drivers/gpu/drm/i915/i915_gem_request.c |  26 ++---
 drivers/gpu/drm/i915/intel_lrc.c        | 121 ++++++++---------------
 drivers/gpu/drm/i915/intel_ringbuffer.c | 168 +++++++++++---------------------
 drivers/gpu/drm/i915/intel_ringbuffer.h |  10 +-
 4 files changed, 112 insertions(+), 213 deletions(-)

since I wanted parts of it for emitting timelines.

Ok what do you want to do?

I have plans to use that particular patch soon, but updating intel_ring_begin() itself is a long way down my list. Given that you have a patch ready, let's keep going. I'm just curious as to what I did differently to trim off the extra lines (probably intel_ring_advance()). The other thing I did was to relax the restriction to only emit in qword aligned packets (by fixing up the tail for qword alignment on sealing the request). Also, I would rather the function be expressed as operating on the request, i915_gem_request_emit() was my choice.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#11 lore raw
In reply to Tvrtko Ursulin
Quoted 23 lines · Tvrtko Ursulin
Quoted 7 lines · Chris Wilson
Quoted 4 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

This removes the usage of intel_ring_emit in favour of directly writing to the ring buffer.

I have the same patch! But I called it out, for historical reasons.

Yes I know we talked about it in the past but I did not think you will find time to actually write it amongst all the other things.

Quoted 2 lines

Oh, except mine uses out[0]...out[N] because gcc prefers that over *out++ = ...

It copes just fine with the latter here, for example:

	*rbuf++ = cmd;
	*rbuf++ = I915_GEM_HWS_SCRATCH_ADDR | MI_FLUSH_DW_USE_GTT;
	*rbuf++ = 0; /* upper addr */
	*rbuf++ = 0; /* value */
Quoted 6 lines

Is:

     3e9:       89 10                   mov    %edx,(%rax)
     3eb:       c7 40 04 04 01 00 00    movl   $0x104,0x4(%rax)
     3f2:       c7 40 08 00 00 00 00    movl   $0x0,0x8(%rax)
     3f9:       c7 40 0c 00 00 00 00    movl   $0x0,0xc(%rax)

Last time Dave suggested using something like

i915_gem_request_emit(req, (struct cmd_packet){ dw0, dw1, dw2 });

I tried mocking something up, but just found gcc was constructing the struct on the stack and then copying across, and generating far more code than the sequence above. Worth seeing if that is better (or if my mockup was just bad).
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#12 lore raw
Quoted 31 lines · Chris Wilson
Quoted 23 lines · Tvrtko Ursulin
Quoted 7 lines · Chris Wilson
Quoted 4 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

This removes the usage of intel_ring_emit in favour of directly writing to the ring buffer.

I have the same patch! But I called it out, for historical reasons.

Yes I know we talked about it in the past but I did not think you will find time to actually write it amongst all the other things.

Quoted 2 lines

Oh, except mine uses out[0]...out[N] because gcc prefers that over *out++ = ...

It copes just fine with the latter here, for example:

	*rbuf++ = cmd;
	*rbuf++ = I915_GEM_HWS_SCRATCH_ADDR | MI_FLUSH_DW_USE_GTT;
	*rbuf++ = 0; /* upper addr */
	*rbuf++ = 0; /* value */
Quoted 6 lines

Is:

      3e9:       89 10                   mov    %edx,(%rax)
      3eb:       c7 40 04 04 01 00 00    movl   $0x104,0x4(%rax)
      3f2:       c7 40 08 00 00 00 00    movl   $0x0,0x8(%rax)
      3f9:       c7 40 0c 00 00 00 00    movl   $0x0,0xc(%rax)
Quoted 8 lines

Last time Dave suggested using something like

i915_gem_request_emit(req, (struct cmd_packet){ dw0, dw1, dw2 });

I tried mocking something up, but just found gcc was constructing the struct on the stack and then copying across, and generating far more code than the sequence above. Worth seeing if that is better (or if my mockup was just bad).

Not sure that I like that. It would be a bit ugly in cases where batches are built dynamically, no? Perhaps I am misunderstanding the idea?

Regards,

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

#13 lore raw

✗ Fi.CI.BAT: failure for drm/i915: Emit to ringbuffer directly (rev2)

In reply to Tvrtko Ursulin
== Series Details ==

== Series Details ==

Series: drm/i915: Emit to ringbuffer directly (rev2)
URL : https://patchwork.freedesktop.org/series/12186/
State : failure

== Summary ==

Series 12186v2 drm/i915: Emit to ringbuffer directly
http://patchwork.freedesktop.org/api/1.0/series/12186/revisions/2/mbox/

Test drv_module_reload_basic:

                skip       -> PASS       (fi-skl-6260u)
Test kms_busy:
        Subgroup basic-flip-default-a:
                pass       -> TIMEOUT    (fi-ilk-650)
                pass       -> TIMEOUT    (fi-snb-2600)
                pass       -> INCOMPLETE (fi-snb-2520m)
        Subgroup basic-flip-default-b:
                pass       -> INCOMPLETE (fi-ilk-650)
                pass       -> INCOMPLETE (fi-snb-2600)
Test kms_frontbuffer_tracking:
        Subgroup basic:
                pass       -> DMESG-FAIL (fi-ivb-3770)
                pass       -> DMESG-FAIL (fi-hsw-4770k)
                pass       -> DMESG-FAIL (fi-hsw-4770r)
                pass       -> DMESG-FAIL (fi-ivb-3520m)
                pass       -> DMESG-FAIL (fi-byt-n2820)
fi-bdw-5557u     total:254  pass:238  dwarn:0   dfail:0   fail:1   skip:15 
fi-bsw-n3050     total:254  pass:207  dwarn:0   dfail:0   fail:1   skip:46 
fi-byt-n2820     total:254  pass:210  dwarn:0   dfail:1   fail:2   skip:41 
fi-hsw-4770k     total:254  pass:230  dwarn:0   dfail:1   fail:1   skip:22 
fi-hsw-4770r     total:254  pass:226  dwarn:0   dfail:1   fail:1   skip:26 
fi-ilk-650       total:185  pass:129  dwarn:0   dfail:0   fail:1   skip:53 
fi-ivb-3520m     total:254  pass:221  dwarn:0   dfail:1   fail:1   skip:31 
fi-ivb-3770      total:254  pass:221  dwarn:0   dfail:1   fail:1   skip:31 
fi-skl-6260u     total:254  pass:239  dwarn:0   dfail:0   fail:1   skip:14 
fi-skl-6700hq    total:254  pass:226  dwarn:0   dfail:0   fail:2   skip:26 
fi-skl-6700k     total:254  pass:224  dwarn:1   dfail:0   fail:1   skip:28 
fi-snb-2520m     total:184  pass:151  dwarn:0   dfail:0   fail:0   skip:32 
fi-snb-2600      total:185  pass:151  dwarn:0   dfail:0   fail:0   skip:32 

Results at /archive/results/CI_IGT_test/Patchwork_2503/

5986f290e25f42d3d5df390411cc43683deb1301 drm-intel-nightly: 2016y-09m-08d-09h-11m-50s UTC integration manifest 0909701 drm/i915: Emit to ringbuffer directly

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

#14 lore raw

✓ Fi.CI.BAT: success for drm/i915: Emit to ringbuffer directly (rev3)

In reply to Tvrtko Ursulin
== Series Details ==

== Series Details ==

Series: drm/i915: Emit to ringbuffer directly (rev3)
URL : https://patchwork.freedesktop.org/series/12186/
State : success

== Summary ==

Series 12186v3 drm/i915: Emit to ringbuffer directly
https://patchwork.freedesktop.org/api/1.0/series/12186/revisions/3/mbox/

Test kms_cursor_legacy:

        Subgroup basic-cursor-vs-flip-varying-size:
                fail       -> PASS       (fi-bsw-n3050)
fi-bdw-5557u     total:254  pass:239  dwarn:0   dfail:0   fail:0   skip:15 
fi-bsw-n3050     total:254  pass:208  dwarn:0   dfail:0   fail:0   skip:46 
fi-byt-n2820     total:254  pass:212  dwarn:0   dfail:0   fail:1   skip:41 
fi-hsw-4770k     total:254  pass:232  dwarn:0   dfail:0   fail:0   skip:22 
fi-hsw-4770r     total:254  pass:228  dwarn:0   dfail:0   fail:0   skip:26 
fi-ilk-650       total:254  pass:184  dwarn:0   dfail:0   fail:2   skip:68 
fi-ivb-3520m     total:254  pass:223  dwarn:0   dfail:0   fail:0   skip:31 
fi-ivb-3770      total:254  pass:223  dwarn:0   dfail:0   fail:0   skip:31 
fi-skl-6260u     total:254  pass:240  dwarn:0   dfail:0   fail:0   skip:14 
fi-skl-6700hq    total:254  pass:227  dwarn:0   dfail:0   fail:1   skip:26 
fi-skl-6700k     total:254  pass:225  dwarn:1   dfail:0   fail:0   skip:28 
fi-snb-2520m     total:254  pass:209  dwarn:0   dfail:0   fail:0   skip:45 
fi-snb-2600      total:254  pass:209  dwarn:0   dfail:0   fail:0   skip:45 

Results at /archive/results/CI_IGT_test/Patchwork_2511/

bef9c1f4afe24cfff578d386bde349add65673eb drm-intel-nightly: 2016y-09m-12d-08h-35m-02s UTC integration manifest 2f42e1d drm/i915: Emit to ringbuffer directly

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