drm/i915 : Added Programming of the MOCS
Subsystems (2)
PATCH v5 1/1 drm/i915 : Added Programming of the MOCS
This change adds the programming of the MOCS registers to the gen 9+ platforms. This change set programs the MOCS register values to a set of values that are defined to be optimal.
It creates a fixed register set that is programmed across the different engines so that all engines have the same table. This is done as the main RCS context only holds the registers for itself and the shared L3 values. By trying to keep the registers consistent across the different engines it should make the programming for the registers consistent.
v2:
-'static const' for private data structures and style changes.(Matt Turner) v3:
- Make the tables "slightly" more readable. (Damien Lespiau)
- Updated tables fix performance regression.
v4:
- Code formatting. (Chris Wilson)
- re-privatised mocs code. (Daniel Vetter)
v5:
- Changed the name of a function. (Chris Wilson)
--- drivers/gpu/drm/i915/Makefile | 1 + drivers/gpu/drm/i915/i915_reg.h | 9 + drivers/gpu/drm/i915/intel_lrc.c | 10 +- drivers/gpu/drm/i915/intel_lrc.h | 4 + drivers/gpu/drm/i915/intel_mocs.c | 370 ++++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/intel_mocs.h | 61 +++++++ 6 files changed, 454 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/i915/intel_mocs.c create mode 100644 drivers/gpu/drm/i915/intel_mocs.h
drivers/gpu/drm/i915/Makefile +1 -0
@@ -35,6 +35,7 @@ i915-y += i915_cmd_parser.o \ i915_irq.o \ i915_trace_points.o \ intel_lrc.o \ + intel_mocs.o \ intel_ringbuffer.o \ intel_uncore.o
drivers/gpu/drm/i915/i915_reg.h +9 -0
@@ -7829,4 +7829,13 @@ enum skl_disp_power_wells {#define _PALETTE_A (dev_priv->info.display_mmio_offset + 0xa000)#define _PALETTE_B (dev_priv->info.display_mmio_offset + 0xa800) +/* MOCS (Memory Object Control State) registers */ +#define GEN9_LNCFCMOCS0 (0xB020)/* L3 Cache Control base */ + +#define GEN9_GFX_MOCS_0 (0xc800)/* Graphics MOCS base register*/ +#define GEN9_MFX0_MOCS_0 (0xc900)/* Media 0 MOCS base register*/ +#define GEN9_MFX1_MOCS_0 (0xcA00)/* Media 1 MOCS base register*/ +#define GEN9_VEBOX_MOCS_0 (0xcB00)/* Video MOCS base register*/ +#define GEN9_BLT_MOCS_0 (0xcc00)/* Blitter MOCS base register*/ +#endif /* _I915_REG_H_ */
drivers/gpu/drm/i915/intel_lrc.c +9 -1
@@ -135,6 +135,7 @@#include <drm/drmP.h> #include <drm/i915_drm.h> #include "i915_drv.h" +#include "intel_mocs.h" #define GEN9_LR_CONTEXT_RENDER_SIZE (22 * PAGE_SIZE)#define GEN8_LR_CONTEXT_RENDER_SIZE (20 * PAGE_SIZE)
@@ -796,7 +797,7 @@ static int logical_ring_prepare(struct intel_ringbuffer *ringbuf,* * Return: non-zero if the ringbuffer is not ready to be written to. */ -static int intel_logical_ring_begin (struct intel_ringbuffer *ringbuf, +int intel_logical_ring_begin (struct intel_ringbuffer *ringbuf,struct intel_context *ctx,int num_dwords) {struct intel_engine_cs *ring = ringbuf->ring;
@@ -1379,6 +1380,13 @@ static int gen8_init_rcs_context(struct intel_engine_cs *ring,if (ret)return ret; +/* +* Failing to program the MOCS is non-fatal.The system will not +* run at peak performance. So generate a warning and carry on. +*/ +if (intel_rcs_context_init_mocs (ring, ctx) !=0 ) +DRM_ERROR ("MOCS failed to program: expect performance issues." ); +return intel_lr_context_render_state_init (ring, ctx); }
drivers/gpu/drm/i915/intel_lrc.h +4 -0
@@ -44,6 +44,10 @@ int intel_logical_rings_init(struct drm_device *dev);int logical_ring_flush_all_caches (struct intel_ringbuffer *ringbuf,struct intel_context *ctx); + +int intel_logical_ring_begin (struct intel_ringbuffer *ringbuf, +struct intel_context *ctx,int num_dwords); +/** * intel_logical_ring_advance() - advance the ringbuffer tail * @ringbuf: Ringbuffer to advance.
drivers/gpu/drm/i915/intel_mocs.c new file +370 -0
370 lines not on this page · raw message
drivers/gpu/drm/i915/intel_mocs.h new file +61 -0
61 lines not on this page · raw message
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
drivers/gpu/drm/i915/intel_lrc.c static int gen8_init_rcs_context(struct intel_engine_cs *ring, · line 1388
Quoted 10 lines · Peter Antoine
drivers/gpu/drm/i915/intel_lrc.c +6
-0@@ -1379,6 +1380,13 @@ static int gen8_init_rcs_context(struct intel_engine_cs *ring,if (ret)return ret; +/* +* Failing to program the MOCS is non-fatal.The system will not +* run at peak performance. So generate a warning and carry on. +*/ +if (intel_rcs_context_init_mocs (ring, ctx) !=0 ) +DRM_ERROR ("MOCS failed to program: expect performance issues." );
You said to expect display corruption as well if this failed. Fortunately, if this fails, we have severe driver issues...
Quoted 8 lines
drivers/gpu/drm/i915/intel_mocs.c new file +8
-0+/** +* emit_mocs_l3cc_table() - emit the mocs control table +* @ringbuf: DRM device. +* @table: The values to program into the control regs. +* +* This function simply emits a MI_LOAD_REGISTER_IMM command for the +* given table starting at the given address. This register set is programmed +* in pairs.
drivers/gpu/drm/i915/intel_mocs.c line 269
Quoted 10 lines
drivers/gpu/drm/i915/intel_mocs.c new file +10
-0+* +* Return: Nothing. +*/ +static void emit_mocs_l3cc_table (struct intel_ringbuffer *ringbuf, +struct drm_i915_mocs_table *table) { +unsigned int count; +unsigned int i; +u32 value; +u32 filler = (table->table[0 ].l3cc_value &0xffff ) | + ((table->table[0 ].l3cc_value &0xffff ) <<16 );
l3cc_value is only u16, & 0xffff is just noise, without & you don't need the parantheses.
Quoted 9 lines
drivers/gpu/drm/i915/intel_mocs.c new file +9
-0+int intel_rcs_context_init_mocs (struct intel_engine_cs *ring, +struct intel_context *ctx) +{ +int ret =0 ; + +struct drm_i915_mocs_table t; +struct drm_device *dev = ring->dev; +struct intel_ringbuffer *ringbuf = ctx->engine[ring->id].ringbuf; +
drivers/gpu/drm/i915/intel_mocs.c line 340
Quoted 10 lines
drivers/gpu/drm/i915/intel_mocs.c new file +10
-0+if (get_mocs_settings (dev, &t)) { +u32 table_size; + +/* +* OK. For each supported ring: +* number of mocs entries * 2 dwords for each control_value +* plus number of mocs entries /2 dwords for l3cc values. +* +* Plus 1 for the load command and 1 for the NOOP per ring +* and the l3cc programming.
*
* With 5 rings and 63 mocs entries, this gives 715
* dwords.
drivers/gpu/drm/i915/intel_mocs.c line 344
Quoted 5 lines
drivers/gpu/drm/i915/intel_mocs.c new file +4
-0+*/ + table_size =GEN9_NUM_MOCS_RINGS * + ((2 *GEN9_NUM_MOCS_ENTRIES ) +2 ) + +GEN9_NUM_MOCS_ENTRIES +2 ;
If you pushed the ring_begin into each function, not only would it be easier to verify, you then don't need an explanation that starts with "This looks like a mistake". Validation of ring_begin/ring_advance is by review, so it has to be easy to review.
Quoted 5 lines
drivers/gpu/drm/i915/intel_mocs.c new file +5
-0+ ret =intel_logical_ring_begin (ringbuf, ctx, table_size); +if (ret) { +DRM_DEBUG ("intel_logical_ring_begin failed %d\n" , ret); +return ret; + }
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
drivers/gpu/drm/i915/intel_lrc.c static int gen8_init_rcs_context(struct intel_engine_cs *ring, · line 1389
Quoted 11 lines · Peter Antoine
drivers/gpu/drm/i915/intel_lrc.c +7
-0@@ -1379,6 +1380,13 @@ static int gen8_init_rcs_context(struct intel_engine_cs *ring,if (ret)return ret; +/* +* Failing to program the MOCS is non-fatal.The system will not +* run at peak performance. So generate a warning and carry on. +*/ +if (intel_rcs_context_init_mocs (ring, ctx) !=0 ) +DRM_ERROR ("MOCS failed to program: expect performance issues." ); +
Missing a '\n'.
drivers/gpu/drm/i915/intel_mocs.c line 91
Quoted 7 lines
drivers/gpu/drm/i915/intel_mocs.c new file +7
-0+static const struct drm_i915_mocs_entry skylake_mocs_table[] = { +/* {0x00000009, 0x0010} */ + {(MOCS_CACHEABILITY (EDRAM_UC ) |MOCS_TGT_CACHE (LLC_ELLC ) | +MOCS_LRUM (0 ) |MOCS_AOM (0 ) |MOCS_LECC_ESC (0 ) |MOCS_SCC (0 ) | +MOC_PFM (0 ) |MOCS_SCF (0 )), + (MOCS_ESC (0 ) |MOCS_SCC (0 ) |MOCS_L3_CACHEABILITY (L3_UC ))}, +/* {0x0000003b, 0x0030} */
We're still missing the usage hints for those configuration entries That'd help user space a lot, which means make this patch land quicker as well.
Quoted 25 lines
drivers/gpu/drm/i915/intel_mocs.c new file +25
-0+int intel_rcs_context_init_mocs (struct intel_engine_cs *ring, +struct intel_context *ctx) +{ +int ret =0 ; + +struct drm_i915_mocs_table t; +struct drm_device *dev = ring->dev; +struct intel_ringbuffer *ringbuf = ctx->engine[ring->id].ringbuf; + +if (get_mocs_settings (dev, &t)) { +u32 table_size; + +/* +* OK. For each supported ring: +* number of mocs entries * 2 dwords for each control_value +* plus number of mocs entries /2 dwords for l3cc values. +* +* Plus 1 for the load command and 1 for the NOOP per ring +* and the l3cc programming. +*/ + table_size =GEN9_NUM_MOCS_RINGS * + ((2 *GEN9_NUM_MOCS_ENTRIES ) +2 ) + +GEN9_NUM_MOCS_ENTRIES +2 ; + ret =intel_logical_ring_begin (ringbuf, ctx, table_size); +if (ret) {
drivers/gpu/drm/i915/intel_mocs.c line 356
Quoted 10 lines
drivers/gpu/drm/i915/intel_mocs.c new file +10
-0+DRM_DEBUG ("intel_logical_ring_begin failed %d\n" , ret); +return ret; + } + +/* program the control registers */ +emit_mocs_control_table (ringbuf, &t,GEN9_GFX_MOCS_0 ); +emit_mocs_control_table (ringbuf, &t,GEN9_MFX0_MOCS_0 ); +emit_mocs_control_table (ringbuf, &t,GEN9_MFX1_MOCS_0 ); +emit_mocs_control_table (ringbuf, &t,GEN9_VEBOX_MOCS_0 ); +emit_mocs_control_table (ringbuf, &t,GEN9_BLT_MOCS_0 );
So, if I'm not mistaken, I think this only works because we fully initialize the default context at start/reset time through:
+ i915_gem_init_hw()
+ i915_gem_context_enable()
+ cycle through all the rings and call ring->init_context()
+ gen8_init_rcs_context()
+ intel_rcs_context_init_mocs()
(initalize ALL the MOCS!)
So, intializing the other (non-render) MOCS in gen8_init_rcs_context() isn't the most logical thing to do I'm afraid. What happens if we suddenly decide that we don't want to fully initialize the default context at startup but initialize each ring on-demand for that context as well? We can end up in a situation where we use the blitter first and we wouldn't have the blitter MOCS initialized.
In that sense, that code makes an assumption about how we do things in a completely different part of the driver and that's always a potential source of bugs.
Chris, how far am I ? :p
One way to "solve" this (if that's indeed the issue pointed at by Chris) would be to decouple the render MOCS from the others, still keep the render ones in there as they need to be emitted from the ring but put the other writes (which could be done through MMIO as well) higher in the chain, could probably make sense in i915_gem_context_enable()? (which, by the way is awfully namedm should have an _init somewhere?). It could also be a per-ring vfunc I suppose.
For similar reasons, I think the GuC MOCS should be part of the GuC init as well so we don't couple too hard different part of the code.
Now, is that really a blocker? I'd say no if we had userspace ready and could commit that today, because we really want it. Still something to look at, I could be totally wrong.
The separate header for a single function isn't something we usually do either, but that can always be folded in later.
Signature · 5 lines
Damien _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
-----Original Message-----
From: Lespiau, Damien
Sent: Thursday, June 18, 2015 2:51 PM
To: Antoine, Peter
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v5] drm/i915 : Added Programming of the MOCS
drivers/gpu/drm/i915/intel_lrc.c static int gen8_init_rcs_context(struct intel_engine_cs *ring, · line 1389
Quoted 11 lines · Peter Antoine
drivers/gpu/drm/i915/intel_lrc.c +7
-0@@ -1379,6 +1380,13 @@ static int gen8_init_rcs_context(struct intel_engine_cs *ring,if (ret)return ret; +/* +* Failing to program the MOCS is non-fatal.The system will not +* run at peak performance. So generate a warning and carry on. +*/ +if (intel_rcs_context_init_mocs (ring, ctx) !=0 ) +DRM_ERROR ("MOCS failed to program: expect performance issues." ); +
Missing a '\n'.
Will fix.
drivers/gpu/drm/i915/intel_mocs.c line 91
Quoted 7 lines
drivers/gpu/drm/i915/intel_mocs.c new file +7
-0+static const struct drm_i915_mocs_entry skylake_mocs_table[] = { +/* {0x00000009, 0x0010} */ + {(MOCS_CACHEABILITY (EDRAM_UC ) |MOCS_TGT_CACHE (LLC_ELLC ) | +MOCS_LRUM (0 ) |MOCS_AOM (0 ) |MOCS_LECC_ESC (0 ) |MOCS_SCC (0 ) | +MOC_PFM (0 ) |MOCS_SCF (0 )), + (MOCS_ESC (0 ) |MOCS_SCC (0 ) |MOCS_L3_CACHEABILITY (L3_UC ))}, +/* {0x0000003b, 0x0030} */
We're still missing the usage hints for those configuration entries That'd help user space a lot, which means make this patch land quicker as well.
These are boiled down from 250+ requirements from different usecases (opencl, Media, etc...), I can't really generate anymore usage hints.
Quoted 25 lines
drivers/gpu/drm/i915/intel_mocs.c new file +25
-0+int intel_rcs_context_init_mocs (struct intel_engine_cs *ring, +struct intel_context *ctx) +{ +int ret =0 ; + +struct drm_i915_mocs_table t; +struct drm_device *dev = ring->dev; +struct intel_ringbuffer *ringbuf = ctx->engine[ring->id].ringbuf; + +if (get_mocs_settings (dev, &t)) { +u32 table_size; + +/* +* OK. For each supported ring: +* number of mocs entries * 2 dwords for each control_value +* plus number of mocs entries /2 dwords for l3cc values. +* +* Plus 1 for the load command and 1 for the NOOP per ring +* and the l3cc programming. +*/ + table_size =GEN9_NUM_MOCS_RINGS * + ((2 *GEN9_NUM_MOCS_ENTRIES ) +2 ) + +GEN9_NUM_MOCS_ENTRIES +2 ; + ret =intel_logical_ring_begin (ringbuf, ctx, table_size); +if (ret) {
drivers/gpu/drm/i915/intel_mocs.c line 356
Quoted 10 lines
drivers/gpu/drm/i915/intel_mocs.c new file +10
-0+DRM_DEBUG ("intel_logical_ring_begin failed %d\n" , ret); +return ret; + } + +/* program the control registers */ +emit_mocs_control_table (ringbuf, &t,GEN9_GFX_MOCS_0 ); +emit_mocs_control_table (ringbuf, &t,GEN9_MFX0_MOCS_0 ); +emit_mocs_control_table (ringbuf, &t,GEN9_MFX1_MOCS_0 ); +emit_mocs_control_table (ringbuf, &t,GEN9_VEBOX_MOCS_0 ); +emit_mocs_control_table (ringbuf, &t,GEN9_BLT_MOCS_0 );
So, if I'm not mistaken, I think this only works because we fully initialize the default context at start/reset time through:
+ i915_gem_init_hw()
+ i915_gem_context_enable()
+ cycle through all the rings and call ring->init_context()
+ gen8_init_rcs_context()
+ intel_rcs_context_init_mocs()
(initalize ALL the MOCS!)
Yes.
So, intializing the other (non-render) MOCS in gen8_init_rcs_context() isn't the most logical thing to do I'm afraid. What happens if we suddenly decide that we don't want to fully initialize the default context at startup but initialize each ring on-demand for that context as well? We can end up in a situation where we use the blitter first and we wouldn't have the blitter MOCS initialized.
In that sense, that code makes an assumption about how we do things in a completely different part of the driver and that's always a potential source of bugs.
Yes, but this is the same with the golden context and the workarounds (as I understand it) so all this code would have to be moved.
Chris, how far am I ? :p
One way to "solve" this (if that's indeed the issue pointed at by Chris) would be to decouple the render MOCS from the others, still keep the render ones in there as they need to be emitted from the ring but put the other writes (which could be done through MMIO as well) higher in the chain, could probably make sense in i915_gem_context_enable()? (which, by the way is awfully namedm should have an _init somewhere?).
It could also be a per-ring vfunc I suppose.
For similar reasons, I think the GuC MOCS should be part of the GuC init as well so we don't couple too hard different part of the code.
Now, is that really a blocker? I'd say no if we had userspace ready and could commit that today, because we really want it. Still something to look at, I could be totally wrong.
Not a blocker. It gets a little more interesting, as the L3CC registers are shared across all engines, but is only saved in the RCS context. But, it is reset on the context switch when ELSP is set. So we would have to program it (i.e. MMIO) and also set it in the batch start for the RCS. Each ring would have to have a proper init_context() and these registers programmed there.
The separate header for a single function isn't something we usually do either, but that can always be folded in later.
Yep, I agree that is overkill.
--
Damien
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 8 lines
Quoted 8 lines · Peter
So, intializing the other (non-render) MOCS in
gen8_init_rcs_context()isn't the most logical thing to do I'm afraid. What happens if we suddenly decide that we don't want to fully initialize the default context at startup but initialize each ring on-demand for that context as well? We can end up in a situation where we use the blitter first and we wouldn't have the blitter MOCS initialized.
Quoted 7 lines
Quoted 4 lines
In that sense, that code makes an assumption about how we do things in a completely different part of the driver and that's always a potential source of bugs.
Yes, but this is the same with the golden context and the workarounds (as I understand it) so all this code would have to be moved.
Ah, but the workarounds in that function are only for registers in the render context, not other rings/engine.
Signature · 5 lines
Damien _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 13 lines · Damien Lespiau
Quoted 13 lines
Quoted 12 lines · Peter
So, intializing the other (non-render) MOCS in
gen8_init_rcs_context()isn't the most logical thing to do I'm afraid. What happens if we suddenly decide that we don't want to fully initialize the default context at startup but initialize each ring on-demand for that context as well? We can end up in a situation where we use the blitter first and we wouldn't have the blitter MOCS initialized.In that sense, that code makes an assumption about how we do things in a completely different part of the driver and that's always a potential source of bugs.
Quoted 5 lines
Quoted 2 lines
Yes, but this is the same with the golden context and the workarounds (as I understand it) so all this code would have to be moved.
Ah, but the workarounds in that function are only for registers in the render context, not other rings/engine.
Yes, but it just so happens that we initialise the default context before userspace so that we know that context is pristine before sending batches to the GPU.
This is the reason why I think it is important to mark this function as being executed at that stage, so that all parties can be sure that the execution is before real use of the GPU and so we can use the RCS to initialise the other rings. At the moment, I am happy with baking that assumption into the code, we can readdress it later if there are non-RCS operations that must be performed at context init and conflict with the RCS programming.
If you can think of a suitable comment to forewarn us in future about potential conflicts in adding xcs->init_context(), be my guest. -Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 6 lines · Peter
Not a blocker. It gets a little more interesting, as the L3CC registers are shared across all engines, but is only saved in the RCS context. But, it is reset on the context switch when ELSP is set. So we would have to program it (i.e. MMIO) and also set it in the batch start for the RCS. Each ring would have to have a proper
init_context()and these registers programmed there.
Hum, so yes, it's like you say. I think leaving a comment somewhere in the init path telling us we rely on the RCS init_context() for all the rings would be nice, but that's extra topping that can be done any time.
Signature · 5 lines
Damien _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 8 lines · Damien Lespiau
Quoted 6 lines · Peter
Not a blocker. It gets a little more interesting, as the L3CC registers are shared across all engines, but is only saved in the RCS context. But, it is reset on the context switch when ELSP is set. So we would have to program it (i.e. MMIO) and also set it in the batch start for the RCS. Each ring would have to have a proper
init_context()and these registers programmed there.
Quoted 4 lines
Hum, so yes, it's like you say. I think leaving a comment somewhere in the init path telling us we rely on the RCS
init_context()for all the rings would be nice, but that's extra topping that can be done any time.
It is in the file header for the mocs.h in the comment before the table is defines and in the function header for the init. I can add another one before it's called, but that might be a little overkill. :)
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 9 lines · Peter
Quoted 8 lines · Damien Lespiau
Quoted 6 lines · Peter
Not a blocker. It gets a little more interesting, as the L3CC registers are shared across all engines, but is only saved in the RCS context. But, it is reset on the context switch when ELSP is set. So we would have to program it (i.e. MMIO) and also set it in the batch start for the RCS. Each ring would have to have a proper
init_context()and these registers programmed there.
Quoted 7 lines
Quoted 4 lines
Hum, so yes, it's like you say. I think leaving a comment somewhere in the init path telling us we rely on the RCS
init_context()for all the rings would be nice, but that's extra topping that can be done any time.It is in the file header for the
mocs.hin the comment before the table is defines and in the function header for the init. I can add another one before it's called, but that might be a little overkill. :)
Or can we demote the init_context vfunc to a device-global one? We're already piling up gt vfuncs in dev_priv->gt, I think it'd fit in there nicely. Bonus points for pulling the actual setup calls out of per-ring code too.
Doing setup across all rings in an RCS callback is indeed really surprising and pretty much guarantees tears and screaming down the road. Our init paths are littered with little confusions like this causing really annoying bugs all over.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx