Skip to content

Commit 6d2cb5a

Browse files
committed
drm/i915/execlists: Read the context-status buffer from the HWSP
The engine provides a mirror of the CSB in the HWSP. If we use the cacheable reads from the HWSP, we can shave off a few mmio reads per context-switch interrupt (which are quite frequent!). Just removing a couple of mmio is not enough to actually reduce any latency, but a small reduction in overall cpu usage. Much appreciation for Ben dropping the bombshell that the CSB was in the HWSP and for Michel in digging out the details. v2: Don't be lazy, add the defines for the indices. v3: Include the HWSP in debugfs/i915_engine_info v4: Check for GVT-g, it currently depends on intercepting CSB mmio v5: Fixup GVT-g mmio path v6: Disable HWSP if VT-d is active as the iommu adds unpredictable memory latency. (Mika) v7: Also markup the CSB read with READ_ONCE() as it may still be an mmio read and we want to stop the compiler from issuing a later (v.slow) reload. Suggested-by: Ben Widawsky <benjamin.widawsky@intel.com> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Cc: Michel Thierry <michel.thierry@intel.com> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Cc: Mika Kuoppala <mika.kuoppala@intel.com> Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com> Cc: Zhenyu Wang <zhenyuw@linux.intel.com> Cc: Zhi Wang <zhi.a.wang@intel.com> Acked-by: Michel Thierry <michel.thierry@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20170913133534.26927-1-chris@chris-wilson.co.uk Reviewed-by: Mika Kuoppala <mika.kuoppala@intel.com>
1 parent 34a04e5 commit 6d2cb5a

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

drivers/gpu/drm/i915/i915_debugfs.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3315,6 +3315,7 @@ static int i915_engine_info(struct seq_file *m, void *unused)
33153315
upper_32_bits(addr), lower_32_bits(addr));
33163316

33173317
if (i915.enable_execlists) {
3318+
const u32 *hws = &engine->status_page.page_addr[I915_HWS_CSB_BUF0_INDEX];
33183319
u32 ptr, read, write;
33193320
unsigned int idx;
33203321

@@ -3337,10 +3338,12 @@ static int i915_engine_info(struct seq_file *m, void *unused)
33373338
write += GEN8_CSB_ENTRIES;
33383339
while (read < write) {
33393340
idx = ++read % GEN8_CSB_ENTRIES;
3340-
seq_printf(m, "\tExeclist CSB[%d]: 0x%08x, context: %d\n",
3341+
seq_printf(m, "\tExeclist CSB[%d]: 0x%08x [0x%08x in hwsp], context: %d [%d in hwsp]\n",
33413342
idx,
33423343
I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, idx)),
3343-
I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, idx)));
3344+
hws[idx * 2],
3345+
I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, idx)),
3346+
hws[idx * 2 + 1]);
33443347
}
33453348

33463349
rcu_read_lock();

drivers/gpu/drm/i915/intel_lrc.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,17 @@ static void intel_lrc_irq_handler(unsigned long data)
541541
while (test_bit(ENGINE_IRQ_EXECLIST, &engine->irq_posted)) {
542542
u32 __iomem *csb_mmio =
543543
dev_priv->regs + i915_mmio_reg_offset(RING_CONTEXT_STATUS_PTR(engine));
544-
u32 __iomem *buf =
545-
dev_priv->regs + i915_mmio_reg_offset(RING_CONTEXT_STATUS_BUF_LO(engine, 0));
544+
/* The HWSP contains a (cacheable) mirror of the CSB */
545+
const u32 *buf =
546+
&engine->status_page.page_addr[I915_HWS_CSB_BUF0_INDEX];
546547
unsigned int head, tail;
547548

549+
/* However GVT emulation depends upon intercepting CSB mmio */
550+
if (unlikely(engine->csb_use_mmio)) {
551+
buf = (u32 * __force)
552+
(dev_priv->regs + i915_mmio_reg_offset(RING_CONTEXT_STATUS_BUF_LO(engine, 0)));
553+
}
554+
548555
/* The write will be ordered by the uncached read (itself
549556
* a memory barrier), so we do not need another in the form
550557
* of a locked instruction. The race between the interrupt
@@ -584,13 +591,12 @@ static void intel_lrc_irq_handler(unsigned long data)
584591
* status notifier.
585592
*/
586593

587-
status = readl(buf + 2 * head);
594+
status = READ_ONCE(buf[2 * head]); /* maybe mmio! */
588595
if (!(status & GEN8_CTX_STATUS_COMPLETED_MASK))
589596
continue;
590597

591598
/* Check the context/desc id for this event matches */
592-
GEM_DEBUG_BUG_ON(readl(buf + 2 * head + 1) !=
593-
port->context_id);
599+
GEM_DEBUG_BUG_ON(buf[2 * head + 1] != port->context_id);
594600

595601
rq = port_unpack(port, &count);
596602
GEM_BUG_ON(count == 0);
@@ -1720,6 +1726,23 @@ logical_ring_default_irqs(struct intel_engine_cs *engine)
17201726
engine->irq_keep_mask = GT_CONTEXT_SWITCH_INTERRUPT << shift;
17211727
}
17221728

1729+
static bool irq_handler_force_mmio(struct drm_i915_private *i915)
1730+
{
1731+
/* GVT emulation depends upon intercepting CSB mmio */
1732+
if (intel_vgpu_active(i915))
1733+
return true;
1734+
1735+
/*
1736+
* IOMMU adds unpredictable latency causing the CSB write (from the
1737+
* GPU into the HWSP) to only be visible some time after the interrupt
1738+
* (missed breadcrumb syndrome).
1739+
*/
1740+
if (intel_vtd_active())
1741+
return true;
1742+
1743+
return false;
1744+
}
1745+
17231746
static void
17241747
logical_ring_setup(struct intel_engine_cs *engine)
17251748
{
@@ -1731,6 +1754,8 @@ logical_ring_setup(struct intel_engine_cs *engine)
17311754
/* Intentionally left blank. */
17321755
engine->buffer = NULL;
17331756

1757+
engine->csb_use_mmio = irq_handler_force_mmio(dev_priv);
1758+
17341759
fw_domains = intel_uncore_forcewake_for_reg(dev_priv,
17351760
RING_ELSP(engine),
17361761
FW_REG_WRITE);

drivers/gpu/drm/i915/intel_ringbuffer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ struct intel_engine_cs {
391391
struct rb_root execlist_queue;
392392
struct rb_node *execlist_first;
393393
unsigned int fw_domains;
394+
bool csb_use_mmio;
394395

395396
/* Contexts are pinned whilst they are active on the GPU. The last
396397
* context executed remains active whilst the GPU is idle - the
@@ -496,6 +497,8 @@ intel_write_status_page(struct intel_engine_cs *engine, int reg, u32 value)
496497
#define I915_GEM_HWS_SCRATCH_INDEX 0x40
497498
#define I915_GEM_HWS_SCRATCH_ADDR (I915_GEM_HWS_SCRATCH_INDEX << MI_STORE_DWORD_INDEX_SHIFT)
498499

500+
#define I915_HWS_CSB_BUF0_INDEX 0x10
501+
499502
struct intel_ring *
500503
intel_engine_create_ring(struct intel_engine_cs *engine, int size);
501504
int intel_ring_pin(struct intel_ring *ring,

0 commit comments

Comments
 (0)