From: Tvrtko Ursulin <[email protected]>

Sagar noticed the check can be consolidated between the engine stats
implementation and the PMU.

My first choice was a static inline helper but that got into include
ordering mess quickly fast so I went with a macro instead. At some point
we should perhaps looking into taking out the non-ringubffer bits from
intel_ringbuffer.h into a new intel_engine.h or something.

v2: Use engine->flags. (Chris Wilson)

Signed-off-by: Tvrtko Ursulin <[email protected]>
Suggested-by: Sagar Arun Kamble <[email protected]>
Cc: Sagar Arun Kamble <[email protected]>
---
 drivers/gpu/drm/i915/i915_pmu.c         | 11 ++++-------
 drivers/gpu/drm/i915/intel_engine_cs.c  |  7 +++++--
 drivers/gpu/drm/i915/intel_ringbuffer.h |  6 ++++++
 3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_pmu.c b/drivers/gpu/drm/i915/i915_pmu.c
index 685aef1d81b9..ccce9c84add1 100644
--- a/drivers/gpu/drm/i915/i915_pmu.c
+++ b/drivers/gpu/drm/i915/i915_pmu.c
@@ -90,11 +90,6 @@ static unsigned int event_enabled_bit(struct perf_event 
*event)
        return config_enabled_bit(event->attr.config);
 }
 
-static bool supports_busy_stats(struct drm_i915_private *i915)
-{
-       return INTEL_GEN(i915) >= 8;
-}
-
 static bool pmu_needs_timer(struct drm_i915_private *i915, bool gpu_active)
 {
        u64 enable;
@@ -123,8 +118,10 @@ static bool pmu_needs_timer(struct drm_i915_private *i915, 
bool gpu_active)
        /*
         * Also there is software busyness tracking available we do not
         * need the timer for I915_SAMPLE_BUSY counter.
+        *
+        * Use RCS as proxy for all engines.
         */
-       else if (supports_busy_stats(i915))
+       else if (intel_engine_supports_stats(i915->engine[RCS]))
                enable &= ~BIT(I915_SAMPLE_BUSY);
 
        /*
@@ -458,7 +455,7 @@ static void i915_pmu_event_read(struct perf_event *event)
 
 static bool engine_needs_busy_stats(struct intel_engine_cs *engine)
 {
-       return supports_busy_stats(engine->i915) &&
+       return intel_engine_supports_stats(engine) &&
               (engine->pmu.enable & BIT(I915_SAMPLE_BUSY));
 }
 
diff --git a/drivers/gpu/drm/i915/intel_engine_cs.c 
b/drivers/gpu/drm/i915/intel_engine_cs.c
index fede62daf3e1..1ee8c8dcc2c7 100644
--- a/drivers/gpu/drm/i915/intel_engine_cs.c
+++ b/drivers/gpu/drm/i915/intel_engine_cs.c
@@ -420,6 +420,9 @@ static void intel_engine_init_execlist(struct 
intel_engine_cs *engine)
 
        execlists->queue = RB_ROOT;
        execlists->first = NULL;
+
+       if (INTEL_GEN(engine->i915) >=8)
+               engine->flags |= I915_ENGINE_SUPPORTS_STATS;
 }
 
 /**
@@ -1863,7 +1866,7 @@ int intel_enable_engine_stats(struct intel_engine_cs 
*engine)
 {
        unsigned long flags;
 
-       if (INTEL_GEN(engine->i915) < 8)
+       if (!intel_engine_supports_stats(engine))
                return -ENODEV;
 
        spin_lock_irqsave(&engine->stats.lock, flags);
@@ -1924,7 +1927,7 @@ void intel_disable_engine_stats(struct intel_engine_cs 
*engine)
 {
        unsigned long flags;
 
-       if (INTEL_GEN(engine->i915) < 8)
+       if (!intel_engine_supports_stats(engine))
                return;
 
        spin_lock_irqsave(&engine->stats.lock, flags);
diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.h 
b/drivers/gpu/drm/i915/intel_ringbuffer.h
index a91ce63b88b6..c68ab3ead83c 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.h
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.h
@@ -540,6 +540,7 @@ struct intel_engine_cs {
        struct intel_engine_hangcheck hangcheck;
 
 #define I915_ENGINE_NEEDS_CMD_PARSER BIT(0)
+#define I915_ENGINE_SUPPORTS_STATS   BIT(1)
        unsigned int flags;
 
        /*
@@ -604,6 +605,11 @@ static inline bool intel_engine_needs_cmd_parser(struct 
intel_engine_cs *engine)
        return engine->flags & I915_ENGINE_NEEDS_CMD_PARSER;
 }
 
+static inline bool intel_engine_supports_stats(struct intel_engine_cs *engine)
+{
+       return engine->flags & I915_ENGINE_SUPPORTS_STATS;
+}
+
 static inline void
 execlists_set_active(struct intel_engine_execlists *execlists,
                     unsigned int bit)
-- 
2.14.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to