Skip to contentSkip to conversation

drm/i915: Fix context size calculation on SNB/IVB/VLV

PATCH Applied [email protected] 3 participants 8 messages Aug 22, 2013 – Aug 23, 2013

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

PATCH 1/1 drm/i915: Fix context size calculation on SNB/IVB/VLV

From: Ville Syrjälä <[email protected]>

All the different context sizes reported in the CXT_SIZE register aren't meant to be simply added together.

While BSpec is somewhat unclear on the topic of the actual context size, empirical tests have now revealed the truth. So let's add a big fat comment to remind people how it all works.

As a result of correctly interpreting CXT_SIZE, the IVB context size is reduced from three pages to two, while SNB context size remains at two pages.

---
 drivers/gpu/drm/i915/i915_reg.h | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/i915_reg.h +15 -8
index 53d0e70..ee0660d 100644
@@ -1707,15 +1707,26 @@
  */
 #define CCID			0x2180
 #define   CCID_EN		(1<<0)
+/*
+ * Notes on SNB/IVB/VLV context size:
+ * - Power context is saved elsewhere (LLC or stolen)
+ * - Ring/execlist context is saved on SNB, not on IVB
+ * - Extended context size already includes render context size
+ * - We always need to follow the extended context size.
+ *   SNB BSpec has comments indicating that we should use the
+ *   render context size instead if execlists are disabled, but
+ *   based on empirical testing that's just nonsense.
+ * - Pipelined/VF state is saved on SNB/IVB respectively
+ * - GT1 size just indicates how much of render context
+ *   doesn't need saving on GT1
+ */
 #define CXT_SIZE		0x21a0
 #define GEN6_CXT_POWER_SIZE(cxt_reg)	((cxt_reg >> 24) & 0x3f)
 #define GEN6_CXT_RING_SIZE(cxt_reg)	((cxt_reg >> 18) & 0x3f)
 #define GEN6_CXT_RENDER_SIZE(cxt_reg)	((cxt_reg >> 12) & 0x3f)
 #define GEN6_CXT_EXTENDED_SIZE(cxt_reg)	((cxt_reg >> 6) & 0x3f)
 #define GEN6_CXT_PIPELINE_SIZE(cxt_reg)	((cxt_reg >> 0) & 0x3f)
-#define GEN6_CXT_TOTAL_SIZE(cxt_reg)	(GEN6_CXT_POWER_SIZE(cxt_reg) + \
-					GEN6_CXT_RING_SIZE(cxt_reg) + \
-					GEN6_CXT_RENDER_SIZE(cxt_reg) + \
+#define GEN6_CXT_TOTAL_SIZE(cxt_reg)	(GEN6_CXT_RING_SIZE(cxt_reg) + \
 					GEN6_CXT_EXTENDED_SIZE(cxt_reg) + \
 					GEN6_CXT_PIPELINE_SIZE(cxt_reg))
 #define GEN7_CXT_SIZE		0x21a8
@@ -1725,11 +1736,7 @@
 #define GEN7_CXT_EXTENDED_SIZE(ctx_reg)	((ctx_reg >> 9) & 0x7f)
 #define GEN7_CXT_GT1_SIZE(ctx_reg)	((ctx_reg >> 6) & 0x7)
 #define GEN7_CXT_VFSTATE_SIZE(ctx_reg)	((ctx_reg >> 0) & 0x3f)
-#define GEN7_CXT_TOTAL_SIZE(ctx_reg)	(GEN7_CXT_POWER_SIZE(ctx_reg) + \
-					 GEN7_CXT_RING_SIZE(ctx_reg) + \
-					 GEN7_CXT_RENDER_SIZE(ctx_reg) + \
-					 GEN7_CXT_EXTENDED_SIZE(ctx_reg) + \
-					 GEN7_CXT_GT1_SIZE(ctx_reg) + \
+#define GEN7_CXT_TOTAL_SIZE(ctx_reg)	(GEN7_CXT_EXTENDED_SIZE(ctx_reg) + \
 					 GEN7_CXT_VFSTATE_SIZE(ctx_reg))
 /* Haswell does have the CXT_SIZE register however it does not appear to be
  * valid. Now, docs explain in dwords what is in the context object. The full
Signature · 6 lines
1.8.1.5

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw
Quoted 8 lines · On Thu, Aug 22, 2013 at 07:23:13PM +0300, [email protected] wrote:

From: Ville Syrjälä <[email protected]>

All the different context sizes reported in the CXT_SIZE register aren't meant to be simply added together.

While BSpec is somewhat unclear on the topic of the actual context size, empirical tests have now revealed the truth. So let's add a big fat comment to remind people how it all works.

By the way. I've done some digging. I believe (75% certain) pre-HSW, every context save writes the entire data. So if you wanted to set some pattern and see what HW actually overwrites, it should be doable. HSW+ though we can't do that.

[snip]

Signature · 5 lines
Ben Widawsky, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw
Quoted 6 lines · Ben Widawsky
Quoted 5 lines · On Thu, Aug 22, 2013 at 07:23:13PM +0300, [email protected] wrote:

From: Ville Syrjälä <[email protected]>

All the different context sizes reported in the CXT_SIZE register aren't meant to be simply added together.

Quoted 8 lines
Quoted 3 lines

While BSpec is somewhat unclear on the topic of the actual context size, empirical tests have now revealed the truth. So let's add a big fat comment to remind people how it all works.

By the way. I've done some digging. I believe (75% certain) pre-HSW, every context save writes the entire data. So if you wanted to set some pattern and see what HW actually overwrites, it should be doable. HSW+ though we can't do that.

That's actually what I did. I dumped the context to disk and looked for magic numbers and checked their offsets against the context layout information in BSpec.

Now sure how HSW works. If it just jumps over some parts of the context that don't need saving, then we could certainly use the same method. Just identify some magic numbers in some high offsets, make sure to use that part of the hardware to force it to save it, and then look for those magic numbers in the dump. That'd easily tell us which parts of the context it never saves (eg. the execlist context).

But if it dynamically rearranges the contents of the context image every time, then it won't work obviously.

Signature · 2 lines
Ville Syrjälä
Intel OTC
#3 lore raw
In reply to Ben Widawsky
Quoted 6 lines · Ben Widawsky
Quoted 5 lines · On Thu, Aug 22, 2013 at 07:23:13PM +0300, [email protected] wrote:

From: Ville Syrjälä <[email protected]>

All the different context sizes reported in the CXT_SIZE register aren't meant to be simply added together.

Quoted 8 lines
Quoted 3 lines

While BSpec is somewhat unclear on the topic of the actual context size, empirical tests have now revealed the truth. So let's add a big fat comment to remind people how it all works.

By the way. I've done some digging. I believe (75% certain) pre-HSW, every context save writes the entire data. So if you wanted to set some pattern and see what HW actually overwrites, it should be doable. HSW+ though we can't do that.

Ah right, so you were thinking of initializing the context w/ some poison, and then see how much is left after the HW has saved. That I didnb't actually do. Should be reasonable trivial though, so I guess I'll try it. The same method could also be used to identify whether HSW skips parts or rearranges the context dynamically.

Signature · 2 lines
Ville Syrjälä
Intel OTC
#4 lore raw
Quoted 16 lines · Ville Syrjälä
Quoted 6 lines · Ben Widawsky
Quoted 5 lines · On Thu, Aug 22, 2013 at 07:23:13PM +0300, [email protected] wrote:

From: Ville Syrjälä <[email protected]>

All the different context sizes reported in the CXT_SIZE register aren't meant to be simply added together.

Quoted 8 lines
Quoted 3 lines

While BSpec is somewhat unclear on the topic of the actual context size, empirical tests have now revealed the truth. So let's add a big fat comment to remind people how it all works.

By the way. I've done some digging. I believe (75% certain) pre-HSW, every context save writes the entire data. So if you wanted to set some pattern and see what HW actually overwrites, it should be doable. HSW+ though we can't do that.

Quoted 5 lines

Ah right, so you were thinking of initializing the context w/ some poison, and then see how much is left after the HW has saved. That I didnb't actually do. Should be reasonable trivial though, so I guess I'll try it. The same method could also be used to identify whether HSW skips parts or rearranges the context dynamically.

Yes, the only problem is it's not always trivial to invoke writes of some parts of the context (I fear).

Signature · 5 lines
Ben Widawsky, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#5 lore raw
In reply to Ben Widawsky
Quoted 6 lines · Ben Widawsky
Quoted 5 lines · On Thu, Aug 22, 2013 at 07:23:13PM +0300, [email protected] wrote:

From: Ville Syrjälä <[email protected]>

All the different context sizes reported in the CXT_SIZE register aren't meant to be simply added together.

Quoted 8 lines
Quoted 3 lines

While BSpec is somewhat unclear on the topic of the actual context size, empirical tests have now revealed the truth. So let's add a big fat comment to remind people how it all works.

By the way. I've done some digging. I believe (75% certain) pre-HSW, every context save writes the entire data. So if you wanted to set some pattern and see what HW actually overwrites, it should be doable. HSW+ though we can't do that.

So I did this test on SNB and IVB and it confirms my earlier findings. This experiment also showed that while SNB leaves room for the ring context, it doesn't actually write to it.

Signature · 2 lines
Ville Syrjälä
Intel OTC
Acked-by on v1 1/1
#6 lore raw
In reply to [email protected]
Quoted 9 lines · On Thu, Aug 22, 2013 at 07:23:13PM +0300, [email protected] wrote:

From: Ville Syrjälä <[email protected]>

All the different context sizes reported in the CXT_SIZE register aren't meant to be simply added together.

While BSpec is somewhat unclear on the topic of the actual context size, empirical tests have now revealed the truth. So let's add a big fat comment to remind people how it all works.

Quoted 5 lines

As a result of correctly interpreting CXT_SIZE, the IVB context size is reduced from three pages to two, while SNB context size remains at two pages.

[snip]

Signature · 5 lines
Ben Widawsky, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#7 lore raw
Quoted 10 lines · Ben Widawsky
Quoted 9 lines · On Thu, Aug 22, 2013 at 07:23:13PM +0300, [email protected] wrote:

From: Ville Syrjälä <[email protected]>

All the different context sizes reported in the CXT_SIZE register aren't meant to be simply added together.

While BSpec is somewhat unclear on the topic of the actual context size, empirical tests have now revealed the truth. So let's add a big fat comment to remind people how it all works.

Quoted 6 lines
Quoted 5 lines

As a result of correctly interpreting CXT_SIZE, the IVB context size is reduced from three pages to two, while SNB context size remains at two pages.

Queued for -next, thanks for the patch.
-Daniel

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