Skip to contentSkip to conversation

drm/i915: Track hw reported context runtime

Intel-gfx Chris Wilson 1 participant 1 message Feb 15, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

From: Tvrtko Ursulin <[email protected]>

GPU saves accumulated context runtime (in CS timestamp units) in PPHWSP which will be useful for us in cases when we are not able to track context busyness ourselves (like with GuC). Keep a copy of this in struct intel_context from where it can be easily read even if the context is not pinned.

QQQ: Do we want to make this accounting conditional / able to turn on/off?

v2:
(Chris)
* Do not store pphwsp address in intel_context.
* Log CS wrap-around.
* Simplify calculation by relying on integer wraparound.

---
 drivers/gpu/drm/i915/gt/intel_context.h       |  9 ++
 drivers/gpu/drm/i915/gt/intel_context_types.h |  7 ++
 drivers/gpu/drm/i915/gt/intel_lrc.c           | 41 ++++++++-
 drivers/gpu/drm/i915/gt/selftest_lrc.c        | 85 +++++++++++++++++++
 drivers/gpu/drm/i915/intel_device_info.c      |  6 ++
 drivers/gpu/drm/i915/intel_device_info.h      |  1 +
 6 files changed, 147 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.h +9 -0
index 604d5cfc46ba..502cf7361a29 100644
@@ -12,6 +12,7 @@
 #include <linux/types.h>
 
 #include "i915_active.h"
+#include "i915_drv.h"
 #include "intel_context_types.h"
 #include "intel_engine_types.h"
 #include "intel_ring_types.h"
@@ -227,4 +228,12 @@ intel_context_clear_nopreempt(struct intel_context *ce)
 	clear_bit(CONTEXT_NOPREEMPT, &ce->flags);
 }
 
+static inline u64 intel_context_get_hw_runtime_ns(struct intel_context *ce)
+{
+	const u32 period =
+		RUNTIME_INFO(ce->engine->i915)->cs_timestamp_period_ns;
+
+	return mul_u32_u32(ce->runtime.total, period);
+}
+
 #endif /* __INTEL_CONTEXT_H__ */
drivers/gpu/drm/i915/gt/intel_context_types.h +7 -0
index ca1420fb8b53..3100823b16c3 100644
@@ -68,6 +68,13 @@ struct intel_context {
 	u64 lrc_desc;
 	u32 tag; /* cookie passed to HW to track this context on submission */
 
+	/* Time on GPU as tracked by the hw. */
+	struct {
+		u64 total;
+		u32 last;
+		I915_SELFTEST_DECLARE(unsigned long underflow);
+	} runtime;
+
 	unsigned int active_count; /* protected by timeline->mutex */
 
 	atomic_t pin_count;
drivers/gpu/drm/i915/gt/intel_lrc.c +39 -2

59 lines not on this page · raw message

drivers/gpu/drm/i915/gt/selftest_lrc.c +85 -0

97 lines not on this page · raw message

drivers/gpu/drm/i915/intel_device_info.c +6 -0
index fcdacd6d4aa5..113decd59b40 100644
@@ -1045,6 +1045,12 @@ void intel_device_info_runtime_init(struct drm_i915_private *dev_priv)
 
 	/* Initialize command stream timestamp frequency */
 	runtime->cs_timestamp_frequency_khz = read_timestamp_frequency(dev_priv);
+	runtime->cs_timestamp_period_ns =
+		div_u64(1e6, runtime->cs_timestamp_frequency_khz);
+	drm_dbg(&dev_priv->drm,
+		"CS timestamp wraparound in %lldms\n",
+		div_u64(mul_u32_u32(runtime->cs_timestamp_period_ns, U32_MAX),
+			USEC_PER_SEC));
 }
 
 void intel_driver_caps_print(const struct intel_driver_caps *caps,
drivers/gpu/drm/i915/intel_device_info.h +1 -0
index 7d4d122d2182..f8bfa26388c1 100644
@@ -217,6 +217,7 @@ struct intel_runtime_info {
 	struct sseu_dev_info sseu;
 
 	u32 cs_timestamp_frequency_khz;
+	u32 cs_timestamp_period_ns;
 
 	/* Media engine access to SFC per instance */
 	u8 vdbox_sfc_access;
Signature · 6 lines
2.25.0

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