Skip to contentSkip to conversation

drm/i915: Track hw reported context runtime

Intel-gfx Chris Wilson 3 participants 4 messages Feb 15, 2020 – Feb 16, 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.c       |  6 +-
 drivers/gpu/drm/i915/gt/intel_context.h       | 18 ++++
 drivers/gpu/drm/i915/gt/intel_context_types.h | 11 +++
 drivers/gpu/drm/i915/gt/intel_lrc.c           | 42 ++++++++-
 drivers/gpu/drm/i915/gt/selftest_lrc.c        | 87 +++++++++++++++++++
 drivers/gpu/drm/i915/i915_gpu_error.c         | 11 ++-
 drivers/gpu/drm/i915/i915_gpu_error.h         |  4 +
 drivers/gpu/drm/i915/intel_device_info.c      |  6 ++
 drivers/gpu/drm/i915/intel_device_info.h      |  1 +
 9 files changed, 181 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.c +5 -1
index e4f89341d17c..8bb444cda14f 100644
@@ -220,7 +220,9 @@ static void __intel_context_retire(struct i915_active *active)
 {
 	struct intel_context *ce = container_of(active, typeof(*ce), active);
 
-	CE_TRACE(ce, "retire\n");
+	CE_TRACE(ce, "retire runtime: { total:%lluns, avg:%lluns }\n",
+		 intel_context_get_total_runtime_ns(ce),
+		 intel_context_get_avg_runtime_ns(ce));
 
 	set_bit(CONTEXT_VALID_BIT, &ce->flags);
 	if (ce->state)
@@ -281,6 +283,8 @@ intel_context_init(struct intel_context *ce,
 	ce->sseu = engine->sseu;
 	ce->ring = __intel_context_ring_size(SZ_4K);
 
+	ewma_runtime_init(&ce->runtime.avg);
+
 	ce->vm = i915_vm_get(engine->gt->vm);
 
 	INIT_LIST_HEAD(&ce->signal_link);
drivers/gpu/drm/i915/gt/intel_context.h +18 -0
index 604d5cfc46ba..e58da0938dcb 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,21 @@ intel_context_clear_nopreempt(struct intel_context *ce)
 	clear_bit(CONTEXT_NOPREEMPT, &ce->flags);
 }
 
+static inline u64 intel_context_get_total_runtime_ns(struct intel_context *ce)
+{
+	const u32 period =
+		RUNTIME_INFO(ce->engine->i915)->cs_timestamp_period_ns;
+
+	return ce->runtime.total * period;
+}
+
+static inline u64 intel_context_get_avg_runtime_ns(struct intel_context *ce)
+{
+	const u32 period =
+		RUNTIME_INFO(ce->engine->i915)->cs_timestamp_period_ns;
+
+	return mul_u32_u32(ewma_runtime_read(&ce->runtime.avg), period);
+}
+
+
 #endif /* __INTEL_CONTEXT_H__ */
drivers/gpu/drm/i915/gt/intel_context_types.h +11 -0
index ca1420fb8b53..6112ec97fbdf 100644
@@ -7,6 +7,7 @@
 #ifndef __INTEL_CONTEXT_TYPES__
 #define __INTEL_CONTEXT_TYPES__
 
+#include <linux/average.h>
 #include <linux/kref.h>
 #include <linux/list.h>
 #include <linux/mutex.h>
@@ -19,6 +20,8 @@
 
 #define CONTEXT_REDZONE POISON_INUSE
 
+DECLARE_EWMA(runtime, 3, 4);
+
 struct i915_gem_context;
 struct i915_vma;
 struct intel_context;
@@ -68,6 +71,14 @@ 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 {
+		struct ewma_runtime avg;
+		u64 total;
+		u32 last;
+		I915_SELFTEST_DECLARE(u32 underflow);
+	} runtime;
+
 	unsigned int active_count; /* protected by timeline->mutex */
 
 	atomic_t pin_count;
drivers/gpu/drm/i915/gt/intel_lrc.c +40 -2

60 lines not on this page · raw message

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

99 lines not on this page · raw message

drivers/gpu/drm/i915/i915_gpu_error.c +9 -2
index b2ed977ed971..3052c4eaf9f6 100644
@@ -481,9 +481,13 @@ static void error_print_context(struct drm_i915_error_state_buf *m,
 				const char *header,
 				const struct i915_gem_context_coredump *ctx)
 {
-	err_printf(m, "%s%s[%d] prio %d, guilty %d active %d\n",
+	const u32 period = RUNTIME_INFO(m->i915)->cs_timestamp_period_ns;
+
+	err_printf(m, "%s%s[%d] prio %d, guilty %d active %d, runtime total %lluns, avg %lluns\n",
 		   header, ctx->comm, ctx->pid, ctx->sched_attr.priority,
-		   ctx->guilty, ctx->active);
+		   ctx->guilty, ctx->active,
+		   ctx->total_runtime * period,
+		   mul_u32_u32(ctx->avg_runtime, period));
 }
 
 static struct i915_vma_coredump *
@@ -1260,6 +1264,9 @@ static bool record_context(struct i915_gem_context_coredump *e,
 	e->guilty = atomic_read(&ctx->guilty_count);
 	e->active = atomic_read(&ctx->active_count);
 
+	e->total_runtime = rq->context->runtime.total;
+	e->avg_runtime = ewma_runtime_read(&rq->context->runtime.avg);
+
 	simulated = i915_gem_context_no_error_capture(ctx);
 
 	i915_gem_context_put(ctx);
drivers/gpu/drm/i915/i915_gpu_error.h +4 -0
index b35bc9edd733..0d1f6c8ff355 100644
@@ -88,6 +88,10 @@ struct intel_engine_coredump {
 
 	struct i915_gem_context_coredump {
 		char comm[TASK_COMM_LEN];
+
+		u64 total_runtime;
+		u32 avg_runtime;
+
 		pid_t pid;
 		int active;
 		int guilty;
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
#1 lore raw

[Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/i915: Track hw reported context runtime (rev2)

== Series Details ==

== Series Details ==

Series: drm/i915: Track hw reported context runtime (rev2)
URL : https://patchwork.freedesktop.org/series/73499/
State : warning

== Summary ==

$ dim checkpatch origin/drm-tip
2171c7e5dc4e drm/i915: Track hw reported context runtime
-:78: CHECK:LINE_SPACING: Please don't use multiple blank lines
#78: FILE: drivers/gpu/drm/i915/gt/intel_context.h:247:
+
+

-:110: WARNING:LINE_SPACING: Missing a blank line after declarations #110: FILE: drivers/gpu/drm/i915/gt/intel_context_types.h:79:
+ u32 last;
+ I915_SELFTEST_DECLARE(u32 underflow);

-:195: WARNING:LINE_SPACING: Missing a blank line after declarations #195: FILE: drivers/gpu/drm/i915/gt/selftest_lrc.c:4457:
+ struct i915_request *rq;
+ IGT_TIMEOUT(end_time);

total: 0 errors, 2 warnings, 1 checks, 287 lines checked

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

#2 lore raw

[Intel-gfx] ✗ Fi.CI.BAT: failure for drm/i915: Track hw reported context runtime (rev2)

In reply to Chris Wilson
== Series Details ==

== Series Details ==

Series: drm/i915: Track hw reported context runtime (rev2)
URL : https://patchwork.freedesktop.org/series/73499/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_7948 -> Patchwork_16583
====================================================

Summary
-------

**FAILURE**

Serious unknown changes coming with Patchwork_16583 absolutely need to be verified manually.

If you think the reported changes have nothing to do with the changes introduced in Patchwork_16583, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/index.html

Possible new issues
-------------------

Here are the unknown changes that may have been introduced in Patchwork_16583:

### IGT changes ###

#### Possible regressions ####

* igt@gem_exec_create@basic:
- fi-icl-u3: [PASS][1] -> [INCOMPLETE][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-icl-u3/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-icl-u3/igt@[email protected]
- fi-icl-y: [PASS][3] -> [INCOMPLETE][4]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-icl-y/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-icl-y/igt@[email protected]
- fi-kbl-guc: [PASS][5] -> [INCOMPLETE][6]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-kbl-guc/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-kbl-guc/igt@[email protected]
- fi-skl-6600u: [PASS][7] -> [INCOMPLETE][8]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-skl-6600u/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-skl-6600u/igt@[email protected]
- fi-icl-u2: [PASS][9] -> [INCOMPLETE][10]
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-icl-u2/igt@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-icl-u2/igt@[email protected]
- fi-skl-6700k2: [PASS][11] -> [INCOMPLETE][12]
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-skl-6700k2/igt@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-skl-6700k2/igt@[email protected]

* igt@gem_exec_gttfill@basic:
- fi-kbl-x1275: [PASS][13] -> [INCOMPLETE][14]
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-kbl-x1275/igt@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-kbl-x1275/igt@[email protected]
- fi-cfl-8109u: [PASS][15] -> [INCOMPLETE][16]
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-cfl-8109u/igt@[email protected]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-cfl-8109u/igt@[email protected]
- fi-bdw-5557u: [PASS][17] -> [INCOMPLETE][18]
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-bdw-5557u/igt@[email protected]
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-bdw-5557u/igt@[email protected]
- fi-cfl-guc: [PASS][19] -> [INCOMPLETE][20]
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-cfl-guc/igt@[email protected]
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-cfl-guc/igt@[email protected]
- fi-icl-guc: [PASS][21] -> [INCOMPLETE][22]
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-icl-guc/igt@[email protected]
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-icl-guc/igt@[email protected]

* igt@gem_exec_parallel@basic:
- fi-icl-dsi: [PASS][23] -> [INCOMPLETE][24]
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-icl-dsi/igt@[email protected]
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-icl-dsi/igt@[email protected]
- fi-skl-guc: [PASS][25] -> [INCOMPLETE][26]
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-skl-guc/igt@[email protected]
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-skl-guc/igt@[email protected]
- fi-kbl-r: [PASS][27] -> [INCOMPLETE][28]
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-kbl-r/igt@[email protected]
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-kbl-r/igt@[email protected]

* igt@gem_exec_parallel@fds:
- fi-cfl-8700k: [PASS][29] -> [INCOMPLETE][30]
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-cfl-8700k/igt@[email protected]
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-cfl-8700k/igt@[email protected]

* igt@gem_sync@basic-each:
- fi-kbl-8809g: [PASS][31] -> [INCOMPLETE][32]
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-kbl-8809g/igt@[email protected]
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-kbl-8809g/igt@[email protected]

* igt@runner@aborted:
- fi-kbl-x1275: NOTRUN -> [FAIL][33]
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-kbl-x1275/igt@[email protected]
- fi-cfl-8700k: NOTRUN -> [FAIL][34]
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-cfl-8700k/igt@[email protected]
- fi-cfl-8109u: NOTRUN -> [FAIL][35]
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-cfl-8109u/igt@[email protected]
- fi-apl-guc: NOTRUN -> [FAIL][36]
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-apl-guc/igt@[email protected]
- fi-kbl-r: NOTRUN -> [FAIL][37]
[37]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-kbl-r/igt@[email protected]
- fi-kbl-guc: NOTRUN -> [FAIL][38]
[38]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-kbl-guc/igt@[email protected]
- fi-cfl-guc: NOTRUN -> [FAIL][39]
[39]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-cfl-guc/igt@[email protected]

#### Warnings ####

* igt@runner@aborted:
- fi-kbl-8809g: [FAIL][40] ([i915#1209]) -> [FAIL][41]
[40]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-kbl-8809g/igt@[email protected]
[41]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-kbl-8809g/igt@[email protected]

#### Suppressed ####

The following results come from untrusted machines, tests, or statuses. They do not affect the overall result.

* igt@gem_close_race@basic-threads:
- {fi-tgl-u}: [PASS][42] -> [INCOMPLETE][43]
[42]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-tgl-u/igt@[email protected]
[43]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-tgl-u/igt@[email protected]

* igt@gem_exec_create@basic:
- {fi-kbl-7560u}: NOTRUN -> [INCOMPLETE][44]
[44]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-kbl-7560u/igt@[email protected]

* igt@runner@aborted:
- {fi-ehl-1}: NOTRUN -> [FAIL][45]
[45]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-ehl-1/igt@[email protected]
- {fi-kbl-7560u}: NOTRUN -> [FAIL][46]
[46]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-kbl-7560u/igt@[email protected]

Known issues
------------

Here are the changes found in Patchwork_16583 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@gem_exec_create@basic:
- fi-cml-u2: [PASS][47] -> [INCOMPLETE][48] ([i915#283])
[47]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-cml-u2/igt@[email protected]
[48]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-cml-u2/igt@[email protected]

* igt@gem_exec_gttfill@basic:
- fi-cml-s: [PASS][49] -> [INCOMPLETE][50] ([i915#283])
[49]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-cml-s/igt@[email protected]
[50]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-cml-s/igt@[email protected]

* igt@gem_exec_parallel@basic:
- fi-apl-guc: [PASS][51] -> [INCOMPLETE][52] ([fdo#103927])
[51]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-apl-guc/igt@[email protected]
[52]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-apl-guc/igt@[email protected]

* igt@i915_selftest@live_workarounds:
- fi-glk-dsi: [PASS][53] -> [INCOMPLETE][54] ([i915#58] / [k.org#198133])
[53]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-glk-dsi/igt@i915_selftest@live_workarounds.html
[54]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-glk-dsi/igt@i915_selftest@live_workarounds.html
- fi-bxt-dsi: [PASS][55] -> [INCOMPLETE][56] ([fdo#103927])
[55]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-bxt-dsi/igt@i915_selftest@live_workarounds.html
[56]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-bxt-dsi/igt@i915_selftest@live_workarounds.html

* igt@kms_frontbuffer_tracking@basic:
- fi-hsw-peppy: [PASS][57] -> [DMESG-WARN][58] ([i915#44])
[57]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-hsw-peppy/igt@[email protected]
[58]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-hsw-peppy/igt@[email protected]

#### Possible fixes ####

* igt@gem_close_race@basic-threads:
- fi-byt-n2820: [INCOMPLETE][59] ([i915#45]) -> [PASS][60]
[59]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7948/fi-byt-n2820/igt@[email protected]
[60]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/fi-byt-n2820/igt@[email protected]

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[fdo#103927]: https://bugs.freedesktop.org/show_bug.cgi?id=103927
[fdo#111593]: https://bugs.freedesktop.org/show_bug.cgi?id=111593
[i915#1209]: https://gitlab.freedesktop.org/drm/intel/issues/1209
[i915#283]: https://gitlab.freedesktop.org/drm/intel/issues/283
[i915#44]: https://gitlab.freedesktop.org/drm/intel/issues/44
[i915#45]: https://gitlab.freedesktop.org/drm/intel/issues/45
[i915#58]: https://gitlab.freedesktop.org/drm/intel/issues/58
[i915#937]: https://gitlab.freedesktop.org/drm/intel/issues/937
[k.org#198133]: https://bugzilla.kernel.org/show_bug.cgi?id=198133

Participating hosts (46 -> 34)
------------------------------

Additional (3): fi-bsw-kefka fi-kbl-7560u fi-snb-2520m
Missing (15): fi-bsw-n3050 fi-hsw-4200u fi-byt-squawks fi-bwr-2160 fi-kbl-7500u fi-ctg-p8600 fi-hsw-4770 fi-ivb-3770 fi-elk-e7500 fi-skl-lmem fi-blb-e6850 fi-byt-clapper fi-bsw-nick fi-bdw-samus fi-snb-2600

Build changes
-------------

* CI: CI-20190529 -> None
* Linux: CI_DRM_7948 -> Patchwork_16583

CI-20190529: 20190529
CI_DRM_7948: 129a4630a618fee5d2eaa4290cd367e24893bc91 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_5444: c46bae259d427f53fcfcd5f05de0181a9e82d6fe @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_16583: 2171c7e5dc4ed7eaafd7c6e8fcc3648e00d1d935 @ git://anongit.freedesktop.org/gfx-ci/linux

== Linux commits ==

2171c7e5dc4e drm/i915: Track hw reported context runtime

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_16583/index.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#3 lore raw
In reply to Chris Wilson
Quoted 128 lines · Chris Wilson

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.c       |  6 +-
  drivers/gpu/drm/i915/gt/intel_context.h       | 18 ++++
  drivers/gpu/drm/i915/gt/intel_context_types.h | 11 +++
  drivers/gpu/drm/i915/gt/intel_lrc.c           | 42 ++++++++-
  drivers/gpu/drm/i915/gt/selftest_lrc.c        | 87 +++++++++++++++++++
  drivers/gpu/drm/i915/i915_gpu_error.c         | 11 ++-
  drivers/gpu/drm/i915/i915_gpu_error.h         |  4 +
  drivers/gpu/drm/i915/intel_device_info.c      |  6 ++
  drivers/gpu/drm/i915/intel_device_info.h      |  1 +
  9 files changed, 181 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.c +5 -1
index e4f89341d17c..8bb444cda14f 100644
@@ -220,7 +220,9 @@ static void __intel_context_retire(struct i915_active *active)
  {
  	struct intel_context *ce = container_of(active, typeof(*ce), active);
 
-	CE_TRACE(ce, "retire\n");
+	CE_TRACE(ce, "retire runtime: { total:%lluns, avg:%lluns }\n",
+		 intel_context_get_total_runtime_ns(ce),
+		 intel_context_get_avg_runtime_ns(ce));
 
  	set_bit(CONTEXT_VALID_BIT, &ce->flags);
  	if (ce->state)
@@ -281,6 +283,8 @@ intel_context_init(struct intel_context *ce,
  	ce->sseu = engine->sseu;
  	ce->ring = __intel_context_ring_size(SZ_4K);
 
+	ewma_runtime_init(&ce->runtime.avg);
+
  	ce->vm = i915_vm_get(engine->gt->vm);
 
  	INIT_LIST_HEAD(&ce->signal_link);
drivers/gpu/drm/i915/gt/intel_context.h +18 -0
index 604d5cfc46ba..e58da0938dcb 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,21 @@ intel_context_clear_nopreempt(struct intel_context *ce)
  	clear_bit(CONTEXT_NOPREEMPT, &ce->flags);
  }
 
+static inline u64 intel_context_get_total_runtime_ns(struct intel_context *ce)
+{
+	const u32 period =
+		RUNTIME_INFO(ce->engine->i915)->cs_timestamp_period_ns;
+
+	return ce->runtime.total * period;
+}
+
+static inline u64 intel_context_get_avg_runtime_ns(struct intel_context *ce)
+{
+	const u32 period =
+		RUNTIME_INFO(ce->engine->i915)->cs_timestamp_period_ns;
+
+	return mul_u32_u32(ewma_runtime_read(&ce->runtime.avg), period);
+}
+
+
  #endif /* __INTEL_CONTEXT_H__ */
drivers/gpu/drm/i915/gt/intel_context_types.h +11 -0
index ca1420fb8b53..6112ec97fbdf 100644
@@ -7,6 +7,7 @@
  #ifndef __INTEL_CONTEXT_TYPES__
  #define __INTEL_CONTEXT_TYPES__
 
+#include <linux/average.h>
  #include <linux/kref.h>
  #include <linux/list.h>
  #include <linux/mutex.h>
@@ -19,6 +20,8 @@
 
  #define CONTEXT_REDZONE POISON_INUSE
 
+DECLARE_EWMA(runtime, 3, 4);
+
  struct i915_gem_context;
  struct i915_vma;
  struct intel_context;
@@ -68,6 +71,14 @@ 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 {
+		struct ewma_runtime avg;
+		u64 total;
+		u32 last;
+		I915_SELFTEST_DECLARE(u32 underflow);
+	} runtime;
+
  	unsigned int active_count; /* protected by timeline->mutex */
 
  	atomic_t pin_count;
drivers/gpu/drm/i915/gt/intel_lrc.c +0 -0
index c3d7727021db..c09079c93345 100644

drivers/gpu/drm/i915/gt/intel_lrc.c static void reset_active(struct i915_request *rq, · line 1203

Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_lrc.c +6 -0
@@ -1195,6 +1195,38 @@ static void reset_active(struct i915_request *rq,
  	ce->lrc_desc |= CTX_DESC_FORCE_RESTORE;
  }
 
+static u32 intel_context_get_runtime(const struct intel_context *ce)
+{
+	/*
+	 * PPHWSP is one page before the lrc state page and in it at
+	 * dword 16 we have cumulative context runtime in CS timestamp ticks.
+	 */

I read somewhere this accumulated runtime was incremented only every 8th CS timestamp tick.

-Lionel

Quoted 225 lines
drivers/gpu/drm/i915/gt/intel_lrc.c +34 -2
+	BUILD_BUG_ON((LRC_STATE_PN - LRC_PPHWSP_PN) != 1);
+	return ce->lrc_reg_state[-1024 + 16];
+}
+
+static void intel_context_update_runtime(struct intel_context *ce)
+{
+	u32 new, old;
+
+	if (intel_context_is_barrier(ce))
+		return;
+
+	old = ce->runtime.last;
+	new = intel_context_get_runtime(ce);
+	if ((s32)(new - old) <= 0) {
+		CE_TRACE(ce, "runtime underflow: last=%u, new=%u, delta=%d\n",
+			 old, new, new - old);
+		I915_SELFTEST_ONLY(ce->runtime.underflow++);
+		GEM_TRACE_DUMP();
+		return;
+	}
+
+	ewma_runtime_add(&ce->runtime.avg, new - old);
+	ce->runtime.total += new - old;
+	ce->runtime.last = new;
+}
+
  static inline struct intel_engine_cs *
  __execlists_schedule_in(struct i915_request *rq)
  {
@@ -1278,6 +1310,7 @@ __execlists_schedule_out(struct i915_request *rq,
  	    i915_request_completed(rq))
  		intel_engine_add_retire(engine, ce->timeline);
 
+	intel_context_update_runtime(ce);
  	intel_engine_context_out(engine);
  	execlists_context_status_change(rq, INTEL_CONTEXT_SCHEDULE_OUT);
  	intel_gt_pm_put_async(engine->gt);
@@ -4607,8 +4640,13 @@ populate_lr_context(struct intel_context *ce,
  		inhibit = false;
  	}
 
-	/* The second page of the context object contains some fields which must
-	 * be set up prior to the first execution. */
+	/* Clear the ppHWSP (inc. per-context counters) */
+	memset(vaddr, 0, PAGE_SIZE);
+
+	/*
+	 * The second page of the context object contains some registers which
+	 * must be set up prior to the first execution.
+	 */
  	execlists_init_reg_state(vaddr + LRC_STATE_PN * PAGE_SIZE,
  				 ce, engine, ring, inhibit);
 
drivers/gpu/drm/i915/gt/selftest_lrc.c +87 -0
index 64761e619876..8c6edb6904cd 100644
@@ -4450,6 +4450,92 @@ static int live_gpr_clear(void *arg)
  	return err;
  }
 
+static int __live_pphwsp_runtime(struct intel_engine_cs *engine)
+{
+	struct intel_context *ce;
+	struct i915_request *rq;
+	IGT_TIMEOUT(end_time);
+	bool timeout = false;
+	int err;
+
+	ce = intel_context_create(engine);
+	if (IS_ERR(ce))
+		return PTR_ERR(ce);
+
+	ce->runtime.underflow = 0;
+
+	while (!timeout) {
+		unsigned int loop = 1024;
+
+		while (loop) {
+			rq = intel_context_create_request(ce);
+			if (IS_ERR(rq)) {
+				err = PTR_ERR(rq);
+				goto err_rq;
+			}
+
+			if (--loop == 0)
+				i915_request_get(rq);
+
+			i915_request_add(rq);
+		}
+		timeout = __igt_timeout(end_time, NULL);
+		if (!timeout)
+			i915_request_put(rq);
+	}
+
+	err = i915_request_wait(rq, 0, HZ / 5);
+	if (err < 0) {
+		pr_err("%s: request not completed! (err=%d)\n",
+		       engine->name, err);
+		goto err_wait;
+	}
+
+	igt_flush_test(engine->i915);
+
+	pr_info("%s: pphwsp runtime %lluns, average %llu\n",
+		engine->name,
+		intel_context_get_total_runtime_ns(ce),
+		intel_context_get_avg_runtime_ns(ce));
+
+	err = 0;
+	if (ce->runtime.underflow) {
+		pr_err("%s: pphwsp underflow %u time(s)!\n",
+		       engine->name, ce->runtime.underflow);
+		err = -EOVERFLOW;
+	}
+
+err_wait:
+	i915_request_put(rq);
+err_rq:
+	intel_context_put(ce);
+	return err;
+}
+
+static int live_pphwsp_runtime(void *arg)
+{
+	struct intel_gt *gt = arg;
+	struct intel_engine_cs *engine;
+	enum intel_engine_id id;
+	int err = 0;
+
+	/*
+	 * Check that cumulative context runtime as stored in the pphwsp[16]
+	 * is monotonic.
+	 */
+
+	for_each_engine(engine, gt, id) {
+		err = __live_pphwsp_runtime(engine);
+		if (err)
+			break;
+	}
+
+	if (igt_flush_test(gt->i915))
+		err = -EIO;
+
+	return err;
+}
+
  int intel_lrc_live_selftests(struct drm_i915_private *i915)
  {
  	static const struct i915_subtest tests[] = {
@@ -4457,6 +4543,7 @@ int intel_lrc_live_selftests(struct drm_i915_private *i915)
  		SUBTEST(live_lrc_fixed),
  		SUBTEST(live_lrc_state),
  		SUBTEST(live_gpr_clear),
+		SUBTEST(live_pphwsp_runtime),
  	};
 
  	if (!HAS_LOGICAL_RING_CONTEXTS(i915))
drivers/gpu/drm/i915/i915_gpu_error.c +9 -2
index b2ed977ed971..3052c4eaf9f6 100644
@@ -481,9 +481,13 @@ static void error_print_context(struct drm_i915_error_state_buf *m,
  				const char *header,
  				const struct i915_gem_context_coredump *ctx)
  {
-	err_printf(m, "%s%s[%d] prio %d, guilty %d active %d\n",
+	const u32 period = RUNTIME_INFO(m->i915)->cs_timestamp_period_ns;
+
+	err_printf(m, "%s%s[%d] prio %d, guilty %d active %d, runtime total %lluns, avg %lluns\n",
  		   header, ctx->comm, ctx->pid, ctx->sched_attr.priority,
-		   ctx->guilty, ctx->active);
+		   ctx->guilty, ctx->active,
+		   ctx->total_runtime * period,
+		   mul_u32_u32(ctx->avg_runtime, period));
  }
 
  static struct i915_vma_coredump *
@@ -1260,6 +1264,9 @@ static bool record_context(struct i915_gem_context_coredump *e,
  	e->guilty = atomic_read(&ctx->guilty_count);
  	e->active = atomic_read(&ctx->active_count);
 
+	e->total_runtime = rq->context->runtime.total;
+	e->avg_runtime = ewma_runtime_read(&rq->context->runtime.avg);
+
  	simulated = i915_gem_context_no_error_capture(ctx);
 
  	i915_gem_context_put(ctx);
drivers/gpu/drm/i915/i915_gpu_error.h +4 -0
index b35bc9edd733..0d1f6c8ff355 100644
@@ -88,6 +88,10 @@ struct intel_engine_coredump {
 
  	struct i915_gem_context_coredump {
  		char comm[TASK_COMM_LEN];
+
+		u64 total_runtime;
+		u32 avg_runtime;
+
  		pid_t pid;
  		int active;
  		int guilty;
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 +0 -0
index 7d4d122d2182..f8bfa26388c1 100644

drivers/gpu/drm/i915/intel_device_info.h struct intel_runtime_info { · line 223

Quoted 7 lines
drivers/gpu/drm/i915/intel_device_info.h +1 -0
@@ -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;

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