Skip to content

Commit 54a9adc

Browse files
arndbjlahtine-intel
authored andcommitted
drm/i915/pmu: avoid an maybe-uninitialized warning
Conditional spinlocks make it hard for gcc and for lockdep to follow the code flow. This one causes a warning with at least gcc-9 and higher: In file included from include/linux/irq.h:14, from drivers/gpu/drm/i915/i915_pmu.c:7: drivers/gpu/drm/i915/i915_pmu.c: In function 'i915_sample': include/linux/spinlock.h:289:3: error: 'flags' may be used uninitialized in this function [-Werror=maybe-uninitialized] 289 | _raw_spin_unlock_irqrestore(lock, flags); \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/i915_pmu.c:288:17: note: 'flags' was declared here 288 | unsigned long flags; | ^~~~~ Split out the part between the locks into a separate function for readability and to let the compiler figure out what the logic actually is. Fixes: d79e1bd ("drm/i915/pmu: Only use exclusive mmio access for gen7") Signed-off-by: Arnd Bergmann <[email protected]> Reviewed-by: Chris Wilson <[email protected]> Signed-off-by: Chris Wilson <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] (cherry picked from commit 6ec81b8) Signed-off-by: Joonas Lahtinen <[email protected]>
1 parent 8497376 commit 54a9adc

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

drivers/gpu/drm/i915/i915_pmu.c

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,48 @@ static bool exclusive_mmio_access(const struct drm_i915_private *i915)
269269
return IS_GEN(i915, 7);
270270
}
271271

272+
static void engine_sample(struct intel_engine_cs *engine, unsigned int period_ns)
273+
{
274+
struct intel_engine_pmu *pmu = &engine->pmu;
275+
bool busy;
276+
u32 val;
277+
278+
val = ENGINE_READ_FW(engine, RING_CTL);
279+
if (val == 0) /* powerwell off => engine idle */
280+
return;
281+
282+
if (val & RING_WAIT)
283+
add_sample(&pmu->sample[I915_SAMPLE_WAIT], period_ns);
284+
if (val & RING_WAIT_SEMAPHORE)
285+
add_sample(&pmu->sample[I915_SAMPLE_SEMA], period_ns);
286+
287+
/* No need to sample when busy stats are supported. */
288+
if (intel_engine_supports_stats(engine))
289+
return;
290+
291+
/*
292+
* While waiting on a semaphore or event, MI_MODE reports the
293+
* ring as idle. However, previously using the seqno, and with
294+
* execlists sampling, we account for the ring waiting as the
295+
* engine being busy. Therefore, we record the sample as being
296+
* busy if either waiting or !idle.
297+
*/
298+
busy = val & (RING_WAIT_SEMAPHORE | RING_WAIT);
299+
if (!busy) {
300+
val = ENGINE_READ_FW(engine, RING_MI_MODE);
301+
busy = !(val & MODE_IDLE);
302+
}
303+
if (busy)
304+
add_sample(&pmu->sample[I915_SAMPLE_BUSY], period_ns);
305+
}
306+
272307
static void
273308
engines_sample(struct intel_gt *gt, unsigned int period_ns)
274309
{
275310
struct drm_i915_private *i915 = gt->i915;
276311
struct intel_engine_cs *engine;
277312
enum intel_engine_id id;
313+
unsigned long flags;
278314

279315
if ((i915->pmu.enable & ENGINE_SAMPLE_MASK) == 0)
280316
return;
@@ -283,53 +319,17 @@ engines_sample(struct intel_gt *gt, unsigned int period_ns)
283319
return;
284320

285321
for_each_engine(engine, gt, id) {
286-
struct intel_engine_pmu *pmu = &engine->pmu;
287-
spinlock_t *mmio_lock;
288-
unsigned long flags;
289-
bool busy;
290-
u32 val;
291-
292322
if (!intel_engine_pm_get_if_awake(engine))
293323
continue;
294324

295-
mmio_lock = NULL;
296-
if (exclusive_mmio_access(i915))
297-
mmio_lock = &engine->uncore->lock;
298-
299-
if (unlikely(mmio_lock))
300-
spin_lock_irqsave(mmio_lock, flags);
301-
302-
val = ENGINE_READ_FW(engine, RING_CTL);
303-
if (val == 0) /* powerwell off => engine idle */
304-
goto skip;
305-
306-
if (val & RING_WAIT)
307-
add_sample(&pmu->sample[I915_SAMPLE_WAIT], period_ns);
308-
if (val & RING_WAIT_SEMAPHORE)
309-
add_sample(&pmu->sample[I915_SAMPLE_SEMA], period_ns);
310-
311-
/* No need to sample when busy stats are supported. */
312-
if (intel_engine_supports_stats(engine))
313-
goto skip;
314-
315-
/*
316-
* While waiting on a semaphore or event, MI_MODE reports the
317-
* ring as idle. However, previously using the seqno, and with
318-
* execlists sampling, we account for the ring waiting as the
319-
* engine being busy. Therefore, we record the sample as being
320-
* busy if either waiting or !idle.
321-
*/
322-
busy = val & (RING_WAIT_SEMAPHORE | RING_WAIT);
323-
if (!busy) {
324-
val = ENGINE_READ_FW(engine, RING_MI_MODE);
325-
busy = !(val & MODE_IDLE);
325+
if (exclusive_mmio_access(i915)) {
326+
spin_lock_irqsave(&engine->uncore->lock, flags);
327+
engine_sample(engine, period_ns);
328+
spin_unlock_irqrestore(&engine->uncore->lock, flags);
329+
} else {
330+
engine_sample(engine, period_ns);
326331
}
327-
if (busy)
328-
add_sample(&pmu->sample[I915_SAMPLE_BUSY], period_ns);
329332

330-
skip:
331-
if (unlikely(mmio_lock))
332-
spin_unlock_irqrestore(mmio_lock, flags);
333333
intel_engine_pm_put_async(engine);
334334
}
335335
}

0 commit comments

Comments
 (0)