Skip to contentSkip to conversation

drm/i915: Emit even number of dwords when emitting LRIs

PATCH In review Arun Siluvery 6 participants 9 messages Oct 22, 2014 – Oct 23, 2014

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

PATCH 1/1 drm/i915: Emit even number of dwords when emitting LRIs

The number of DWords should be even when doing ring emits as command sequences require QWord alignment.

v2: user LRI variant that can write multiple regs in one go (Damien). We can simply insert one NOP at the end instead of one per register write.

---
 drivers/gpu/drm/i915/intel_ringbuffer.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_ringbuffer.c +3 -2
index 497b836..a8f72e8 100644
@@ -680,15 +680,16 @@ static int intel_ring_workarounds_emit(struct intel_engine_cs *ring)
 	if (ret)
 		return ret;
 
-	ret = intel_ring_begin(ring, w->count * 3);
+	ret = intel_ring_begin(ring, (w->count * 2 + 2));
 	if (ret)
 		return ret;
 
+	intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(w->count));
 	for (i = 0; i < w->count; i++) {
-		intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
 		intel_ring_emit(ring, w->reg[i].addr);
 		intel_ring_emit(ring, w->reg[i].value);
 	}
+	intel_ring_emit(ring, MI_NOOP);
 
 	intel_ring_advance(ring);
 
Signature · 1 line
2.1.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Arun Siluvery

The number of DWords should be even when doing ring emits as command sequences require QWord alignment.

v2: user LRI variant that can write multiple regs in one go (Damien). We can simply insert one NOP at the end instead of one per register write.

Looks good to me (maybe without the extra '()' outlined below).

Signature · 1 line
Damien
Quoted 9 lines
---
 drivers/gpu/drm/i915/intel_ringbuffer.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_ringbuffer.c +0 -0
index 497b836..a8f72e8 100644

drivers/gpu/drm/i915/intel_ringbuffer.c static int intel_ring_workarounds_emit(struct intel_engine_cs *ring) · line 683

Quoted 5 lines
drivers/gpu/drm/i915/intel_ringbuffer.c +1 -1
@@ -680,15 +680,16 @@ static int intel_ring_workarounds_emit(struct intel_engine_cs *ring)
 	if (ret)
 		return ret;
 
-	ret = intel_ring_begin(ring, w->count * 3);
+	ret = intel_ring_begin(ring, (w->count * 2 + 2));

No need of the () around the second argument.

Quoted 20 lines
drivers/gpu/drm/i915/intel_ringbuffer.c +2 -1
 	if (ret)
 		return ret;
 
+	intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(w->count));
 	for (i = 0; i < w->count; i++) {
-		intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
 		intel_ring_emit(ring, w->reg[i].addr);
 		intel_ring_emit(ring, w->reg[i].value);
 	}
+	intel_ring_emit(ring, MI_NOOP);
 
 	intel_ring_advance(ring);
 
Signature · 6 lines
2.1.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw
In reply to Arun Siluvery
Quoted 17 lines · Arun Siluvery

The number of DWords should be even when doing ring emits as command sequences require QWord alignment.

v2: user LRI variant that can write multiple regs in one go (Damien). We can simply insert one NOP at the end instead of one per register write.

---
 drivers/gpu/drm/i915/intel_ringbuffer.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_ringbuffer.c +0 -0
index 497b836..a8f72e8 100644

drivers/gpu/drm/i915/intel_ringbuffer.c static int intel_ring_workarounds_emit(struct intel_engine_cs *ring) · line 687

Quoted 9 lines
drivers/gpu/drm/i915/intel_ringbuffer.c +2 -1
@@ -680,15 +680,16 @@ static int intel_ring_workarounds_emit(struct intel_engine_cs *ring)
 	if (ret)
 		return ret;
 
-	ret = intel_ring_begin(ring, w->count * 3);
+	ret = intel_ring_begin(ring, (w->count * 2 + 2));
 	if (ret)
 		return ret;
 
+	intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(w->count));

Afaik there's a limit to the size of an MI_LRI. Where's the check for that (probably with a WARN_ON for now to avoid unecessary complexity)? -Daniel

Quoted 16 lines
drivers/gpu/drm/i915/intel_ringbuffer.c +1 -1
 	for (i = 0; i < w->count; i++) {
-		intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
 		intel_ring_emit(ring, w->reg[i].addr);
 		intel_ring_emit(ring, w->reg[i].value);
 	}
+	intel_ring_emit(ring, MI_NOOP);
 
 	intel_ring_advance(ring);
 
Signature · 6 lines
2.1.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#3 lore raw
Quoted 26 lines · Daniel Vetter
Quoted 25 lines · Arun Siluvery

The number of DWords should be even when doing ring emits as command sequences require QWord alignment.

v2: user LRI variant that can write multiple regs in one go (Damien). We can simply insert one NOP at the end instead of one per register write.

---
 drivers/gpu/drm/i915/intel_ringbuffer.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_ringbuffer.c +1 -1
index 497b836..a8f72e8 100644
@@ -680,15 +680,16 @@ static int intel_ring_workarounds_emit(struct intel_engine_cs *ring)
 	if (ret)
 		return ret;
 
-	ret = intel_ring_begin(ring, w->count * 3);
+	ret = intel_ring_begin(ring, (w->count * 2 + 2));
 	if (ret)
 		return ret;
 
Quoted 4 lines

drivers/gpu/drm/i915/intel_ringbuffer.c static int intel_ring_workarounds_emit(struct intel_engine_cs *ring) · line 687

Quoted 1 line
drivers/gpu/drm/i915/intel_ringbuffer.c +1 -0
+	intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(w->count));

Afaik there's a limit to the size of an MI_LRI. Where's the check for that (probably with a WARN_ON for now to avoid unecessary complexity)?

I guess there's always the size of the length field, I don't see any other indication. Note that I can find the documentation of the multi-registers version of LRI either. So, well, we probably should double check it does work.

Signature · 1 line
Damien
#4 lore raw
Quoted 32 lines · Damien Lespiau
Quoted 26 lines · Daniel Vetter
Quoted 25 lines · Arun Siluvery

The number of DWords should be even when doing ring emits as command sequences require QWord alignment.

v2: user LRI variant that can write multiple regs in one go (Damien). We can simply insert one NOP at the end instead of one per register write.

---
 drivers/gpu/drm/i915/intel_ringbuffer.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_ringbuffer.c +1 -1
index 497b836..a8f72e8 100644
@@ -680,15 +680,16 @@ static int intel_ring_workarounds_emit(struct intel_engine_cs *ring)
 	if (ret)
 		return ret;
 
-	ret = intel_ring_begin(ring, w->count * 3);
+	ret = intel_ring_begin(ring, (w->count * 2 + 2));
 	if (ret)
 		return ret;
 
Quoted 4 lines

drivers/gpu/drm/i915/intel_ringbuffer.c static int intel_ring_workarounds_emit(struct intel_engine_cs *ring) · line 687

Quoted 1 line
drivers/gpu/drm/i915/intel_ringbuffer.c +1 -0
+	intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(w->count));

Afaik there's a limit to the size of an MI_LRI. Where's the check for that (probably with a WARN_ON for now to avoid unecessary complexity)?

Quoted 4 lines

I guess there's always the size of the length field, I don't see any other indication. Note that I can find the documentation of the multi-registers version of LRI either. So, well, we probably should double check it does work.

It does work. The max is around 60 iirc (the max length of the command).
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#5 lore raw
Quoted 33 lines · Chris Wilson
Quoted 32 lines · Damien Lespiau
Quoted 30 lines · Daniel Vetter
Quoted 17 lines · Arun Siluvery

The number of DWords should be even when doing ring emits as command sequences require QWord alignment.

v2: user LRI variant that can write multiple regs in one go (Damien). We can simply insert one NOP at the end instead of one per register write.

---
 drivers/gpu/drm/i915/intel_ringbuffer.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_ringbuffer.c +0 -0
index 497b836..a8f72e8 100644

drivers/gpu/drm/i915/intel_ringbuffer.c static int intel_ring_workarounds_emit(struct intel_engine_cs *ring) · line 687

Quoted 9 lines
drivers/gpu/drm/i915/intel_ringbuffer.c +2 -1
@@ -680,15 +680,16 @@ static int intel_ring_workarounds_emit(struct intel_engine_cs *ring)
 	if (ret)
 		return ret;
 
-	ret = intel_ring_begin(ring, w->count * 3);
+	ret = intel_ring_begin(ring, (w->count * 2 + 2));
 	if (ret)
 		return ret;
 
+	intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(w->count));

Afaik there's a limit to the size of an MI_LRI. Where's the check for that (probably with a WARN_ON for now to avoid unecessary complexity)?

Quoted 7 lines
Quoted 4 lines

I guess there's always the size of the length field, I don't see any other indication. Note that I can find the documentation of the multi-registers version of LRI either. So, well, we probably should double check it does work.

It does work. The max is around 60 iirc (the max length of the command).

The maximum length seems to be 0xff on gen6+ and 0x3f before that, which would mean at most 128 or 32 registers.

Also the context image is full of these multi register LRIs. Based on a quick glance the longest LRI in there is 0x5f on IVB, 0xcf on HSW, and 0xdf on BDW, which translate to 48, 104, and 108 registers per LRI. So we know at least those must work or context restore would not work. Before gen7 the context doesn't seem to resemble a batch, so I can't tell anything about those platforms based on the context image.

Signature · 2 lines
Ville Syrjälä
Intel OTC
#6 lore raw
Quoted 45 lines · Ville Syrjälä
Quoted 33 lines · Chris Wilson
Quoted 32 lines · Damien Lespiau
Quoted 30 lines · Daniel Vetter
Quoted 17 lines · Arun Siluvery

The number of DWords should be even when doing ring emits as command sequences require QWord alignment.

v2: user LRI variant that can write multiple regs in one go (Damien). We can simply insert one NOP at the end instead of one per register write.

---
  drivers/gpu/drm/i915/intel_ringbuffer.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_ringbuffer.c +0 -0
index 497b836..a8f72e8 100644

drivers/gpu/drm/i915/intel_ringbuffer.c static int intel_ring_workarounds_emit(struct intel_engine_cs *ring) · line 687

Quoted 9 lines
drivers/gpu/drm/i915/intel_ringbuffer.c +2 -1
@@ -680,15 +680,16 @@ static int intel_ring_workarounds_emit(struct intel_engine_cs *ring)
  	if (ret)
  		return ret;
 
-	ret = intel_ring_begin(ring, w->count * 3);
+	ret = intel_ring_begin(ring, (w->count * 2 + 2));
  	if (ret)
  		return ret;
 
+	intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(w->count));

Afaik there's a limit to the size of an MI_LRI. Where's the check for that (probably with a WARN_ON for now to avoid unecessary complexity)?

Quoted 7 lines
Quoted 4 lines

I guess there's always the size of the length field, I don't see any other indication. Note that I can find the documentation of the multi-registers version of LRI either. So, well, we probably should double check it does work.

It does work. The max is around 60 iirc (the max length of the command).

The maximum length seems to be 0xff on gen6+ and 0x3f before that, which would mean at most 128 or 32 registers.

Quoted 7 lines

Also the context image is full of these multi register LRIs. Based on a quick glance the longest LRI in there is 0x5f on IVB, 0xcf on HSW, and 0xdf on BDW, which translate to 48, 104, and 108 registers per LRI. So we know at least those must work or context restore would not work. Before gen7 the context doesn't seem to resemble a batch, so I can't tell anything about those platforms based on the context image.

w->count is already checked against max workarounds which is 16 now so we are well within the limit; I think additional check would be redundant here and it is unlikely to have more than 128 workarounds.

regards
Arun

#7 lore raw
In reply to Chris Wilson
Quoted 33 lines · Chris Wilson
Quoted 32 lines · Damien Lespiau
Quoted 30 lines · Daniel Vetter
Quoted 17 lines · Arun Siluvery

The number of DWords should be even when doing ring emits as command sequences require QWord alignment.

v2: user LRI variant that can write multiple regs in one go (Damien). We can simply insert one NOP at the end instead of one per register write.

---
 drivers/gpu/drm/i915/intel_ringbuffer.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_ringbuffer.c +0 -0
index 497b836..a8f72e8 100644

drivers/gpu/drm/i915/intel_ringbuffer.c static int intel_ring_workarounds_emit(struct intel_engine_cs *ring) · line 687

Quoted 9 lines
drivers/gpu/drm/i915/intel_ringbuffer.c +2 -1
@@ -680,15 +680,16 @@ static int intel_ring_workarounds_emit(struct intel_engine_cs *ring)
 	if (ret)
 		return ret;
 
-	ret = intel_ring_begin(ring, w->count * 3);
+	ret = intel_ring_begin(ring, (w->count * 2 + 2));
 	if (ret)
 		return ret;
 
+	intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(w->count));

Afaik there's a limit to the size of an MI_LRI. Where's the check for that (probably with a WARN_ON for now to avoid unecessary complexity)?

Quoted 9 lines
Quoted 4 lines

I guess there's always the size of the length field, I don't see any other indication. Note that I can find the documentation of the multi-registers version of LRI either. So, well, we probably should double check it does work.

It does work. The max is around 60 iirc (the max length of the command).
-Chris

I did some test with bdw:

The maximum is 128 writes, resulting the 8 bit length field of the command being 0xff, thus following the spec. The 128'th write went through.

Perhaps the max command length is then less in older gens?

Perhaps WARN_ON(x > 128) in MI_LOAD_REGISTER_IMM would be in place but one needs minor tweak to command parser a bit also then.

#define I915_MAX_WA_REGS 16

keeps us safe for now atleast.

-Mika

Quoted 2 lines
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#8 lore raw
Quoted 51 lines · Mika Kuoppala
Quoted 33 lines · Chris Wilson
Quoted 32 lines · Damien Lespiau
Quoted 30 lines · Daniel Vetter
Quoted 17 lines · Arun Siluvery

The number of DWords should be even when doing ring emits as command sequences require QWord alignment.

v2: user LRI variant that can write multiple regs in one go (Damien). We can simply insert one NOP at the end instead of one per register write.

---
 drivers/gpu/drm/i915/intel_ringbuffer.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_ringbuffer.c +0 -0
index 497b836..a8f72e8 100644

drivers/gpu/drm/i915/intel_ringbuffer.c static int intel_ring_workarounds_emit(struct intel_engine_cs *ring) · line 687

Quoted 9 lines
drivers/gpu/drm/i915/intel_ringbuffer.c +2 -1
@@ -680,15 +680,16 @@ static int intel_ring_workarounds_emit(struct intel_engine_cs *ring)
 	if (ret)
 		return ret;
 
-	ret = intel_ring_begin(ring, w->count * 3);
+	ret = intel_ring_begin(ring, (w->count * 2 + 2));
 	if (ret)
 		return ret;
 
+	intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(w->count));

Afaik there's a limit to the size of an MI_LRI. Where's the check for that (probably with a WARN_ON for now to avoid unecessary complexity)?

Quoted 9 lines
Quoted 4 lines

I guess there's always the size of the length field, I don't see any other indication. Note that I can find the documentation of the multi-registers version of LRI either. So, well, we probably should double check it does work.

It does work. The max is around 60 iirc (the max length of the command).
-Chris

I did some test with bdw:

The maximum is 128 writes, resulting the 8 bit length field of the command being 0xff, thus following the spec. The 128'th write went through.

Quoted 8 lines

Perhaps the max command length is then less in older gens?

Perhaps WARN_ON(x > 128) in MI_LOAD_REGISTER_IMM would be in place but one needs minor tweak to command parser a bit also then.

#define I915_MAX_WA_REGS 16

keeps us safe for now atleast.

Ok, that's good enough I think. I've summarized the discussion a bit in the commit message and merged the patch.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch