Skip to content

Commit e217f22

Browse files
committed
drm/i915/pmu: Add support for gen2
Implement pmu support for gen2 so that one can use intel_gpu_top on it once again. Gen2 lacks MI_MODE/MODE_IDLE so we'll have to do a bit more work to determine the state of the engine: - to determine if the ring contains unconsumed data we can simply compare RING_TAIL vs. RING_HEAD - also check RING_HEAD vs. ACTHD to catch cases where the hardware is still executing a batch buffer but the ring head has already caught up with the tail. Not entirely sure if that's actually possible or not, but maybe it can happen if the batch buffer is initiated from the very end of the ring? But even if not strictly necessary there's no real harm in checking anyway. - MI_WAIT_FOR_EVENT can be detected via a dedicated bit in RING_HEAD v2: Use genX_ prefix rarther than suffix (Jani) Signed-off-by: Ville Syrjälä <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Acked-by: Jani Nikula <[email protected]>
1 parent bdc2917 commit e217f22

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

drivers/gpu/drm/i915/gt/intel_engine_regs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define HEAD_WRAP_COUNT 0xFFE00000
1616
#define HEAD_WRAP_ONE 0x00200000
1717
#define HEAD_ADDR 0x001FFFFC
18+
#define HEAD_WAIT_I8XX (1 << 0) /* gen2, PRBx_HEAD */
1819
#define RING_START(base) _MMIO((base) + 0x38)
1920
#define RING_CTL(base) _MMIO((base) + 0x3c)
2021
#define RING_CTL_SIZE(size) ((size) - PAGE_SIZE) /* in bytes -> pages */
@@ -26,7 +27,6 @@
2627
#define RING_VALID_MASK 0x00000001
2728
#define RING_VALID 0x00000001
2829
#define RING_INVALID 0x00000000
29-
#define RING_WAIT_I8XX (1 << 0) /* gen2, PRBx_HEAD */
3030
#define RING_WAIT (1 << 11) /* gen3+, PRBx_CTL */
3131
#define RING_WAIT_SEMAPHORE (1 << 10) /* gen6+ */
3232
#define RING_SYNC_0(base) _MMIO((base) + 0x40)

drivers/gpu/drm/i915/i915_pmu.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ static bool exclusive_mmio_access(const struct drm_i915_private *i915)
356356
return GRAPHICS_VER(i915) == 7;
357357
}
358358

359-
static void engine_sample(struct intel_engine_cs *engine, unsigned int period_ns)
359+
static void gen3_engine_sample(struct intel_engine_cs *engine, unsigned int period_ns)
360360
{
361361
struct intel_engine_pmu *pmu = &engine->pmu;
362362
bool busy;
@@ -391,6 +391,31 @@ static void engine_sample(struct intel_engine_cs *engine, unsigned int period_ns
391391
add_sample(&pmu->sample[I915_SAMPLE_BUSY], period_ns);
392392
}
393393

394+
static void gen2_engine_sample(struct intel_engine_cs *engine, unsigned int period_ns)
395+
{
396+
struct intel_engine_pmu *pmu = &engine->pmu;
397+
u32 tail, head, acthd;
398+
399+
tail = ENGINE_READ_FW(engine, RING_TAIL);
400+
head = ENGINE_READ_FW(engine, RING_HEAD);
401+
acthd = ENGINE_READ_FW(engine, ACTHD);
402+
403+
if (head & HEAD_WAIT_I8XX)
404+
add_sample(&pmu->sample[I915_SAMPLE_WAIT], period_ns);
405+
406+
if (head & HEAD_WAIT_I8XX || head != acthd ||
407+
(head & HEAD_ADDR) != (tail & TAIL_ADDR))
408+
add_sample(&pmu->sample[I915_SAMPLE_BUSY], period_ns);
409+
}
410+
411+
static void engine_sample(struct intel_engine_cs *engine, unsigned int period_ns)
412+
{
413+
if (GRAPHICS_VER(engine->i915) >= 3)
414+
gen3_engine_sample(engine, period_ns);
415+
else
416+
gen2_engine_sample(engine, period_ns);
417+
}
418+
394419
static void
395420
engines_sample(struct intel_gt *gt, unsigned int period_ns)
396421
{
@@ -1243,11 +1268,6 @@ void i915_pmu_register(struct drm_i915_private *i915)
12431268

12441269
int ret = -ENOMEM;
12451270

1246-
if (GRAPHICS_VER(i915) <= 2) {
1247-
drm_info(&i915->drm, "PMU not supported for this GPU.");
1248-
return;
1249-
}
1250-
12511271
spin_lock_init(&pmu->lock);
12521272
hrtimer_init(&pmu->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
12531273
pmu->timer.function = i915_sample;

0 commit comments

Comments
 (0)