Skip to contentSkip to conversation

Remaining patches for basic GuC submission

PATCH In review Matthew Brost 8 participants 51 messages Jul 27, 2021 – Jun 7, 2022

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

cover Remaining patches for basic GuC submission

The remaining patches for basic GuC submission [1]. Need 1 more RB and CI results to get this merged.

v2:
(Checkpatch)
- Fix checkpatch warning (1 remaining overrulled) (Daniele)
- Use an outer lock in guc_context_block / unblock

[1] https://patchwork.freedesktop.org/series/91840/

Daniele Ceraolo Spurio (1):
drm/i915/guc: Unblock GuC submission on Gen11+

Daniele Ceraolo Spurio (1):
drm/i915/guc: Unblock GuC submission on Gen11+

John Harrison (12):
drm/i915/guc: Make hangcheck work with GuC virtual engines drm/i915/guc: Provide mmio list to be saved/restored on engine reset drm/i915/guc: Don't complain about reset races drm/i915/guc: Enable GuC engine reset
drm/i915/guc: Fix for error capture after full GPU reset with GuC drm/i915/guc: Hook GuC scheduling policies up drm/i915/guc: Connect reset modparam updates to GuC policy flags drm/i915/guc: Include scheduling policies in the debugfs state dump drm/i915/guc: Add golden context to GuC ADS drm/i915/selftest: Better error reporting from hangcheck selftest drm/i915/selftest: Fix hangcheck self test for GuC submission drm/i915/selftest: Bump selftest timeouts for hangcheck

Matthew Brost (18):
drm/i915/guc: GuC virtual engines
drm/i915: Hold reference to intel_context over life of i915_request drm/i915/guc: Disable bonding extension with GuC submission drm/i915/guc: Direct all breadcrumbs for a class to single breadcrumbs drm/i915: Add i915_sched_engine destroy vfunc
drm/i915: Move active request tracking to a vfunc drm/i915/guc: Reset implementation for new GuC interface drm/i915: Reset GPU immediately if submission is disabled drm/i915/guc: Add disable interrupts to guc sanitize drm/i915/guc: Suspend/resume implementation for new interface drm/i915/guc: Handle context reset notification drm/i915/guc: Handle engine reset failure notification drm/i915/guc: Enable the timer expired interrupt for GuC drm/i915/guc: Capture error state on context reset drm/i915/guc: Implement banned contexts for GuC submission drm/i915/guc: Support request cancellation drm/i915/selftest: Increase some timeouts in live_requests drm/i915/guc: Implement GuC priority management

Rahul Kumar Singh (2):
drm/i915/selftest: Fix workarounds selftest for GuC submission drm/i915/selftest: Fix MOCS selftest for GuC submission

 drivers/gpu/drm/i915/Makefile                 |    1 +
 drivers/gpu/drm/i915/gem/i915_gem_context.c   |   15 +-
 drivers/gpu/drm/i915/gt/intel_breadcrumbs.c   |   44 +-
 drivers/gpu/drm/i915/gt/intel_breadcrumbs.h   |   16 +-
 .../gpu/drm/i915/gt/intel_breadcrumbs_types.h |    7 +
 drivers/gpu/drm/i915/gt/intel_context.c       |   36 +
 drivers/gpu/drm/i915/gt/intel_context.h       |   23 +
 drivers/gpu/drm/i915/gt/intel_context_types.h |   33 +-
 drivers/gpu/drm/i915/gt/intel_engine.h        |   57 +-
 drivers/gpu/drm/i915/gt/intel_engine_cs.c     |  183 +-
 .../gpu/drm/i915/gt/intel_engine_heartbeat.c  |   70 +-
 .../gpu/drm/i915/gt/intel_engine_heartbeat.h  |    4 +
 drivers/gpu/drm/i915/gt/intel_engine_types.h  |   13 +-
 drivers/gpu/drm/i915/gt/intel_engine_user.c   |    4 +
 .../drm/i915/gt/intel_execlists_submission.c  |   89 +-
 .../drm/i915/gt/intel_execlists_submission.h  |    4 -
 drivers/gpu/drm/i915/gt/intel_gt.c            |    2 +
 drivers/gpu/drm/i915/gt/intel_gt_pm.c         |    6 +-
 drivers/gpu/drm/i915/gt/intel_reset.c         |   50 +-
 .../gpu/drm/i915/gt/intel_ring_submission.c   |   58 +
 drivers/gpu/drm/i915/gt/intel_rps.c           |    4 +
 drivers/gpu/drm/i915/gt/intel_workarounds.c   |   46 +-
 .../gpu/drm/i915/gt/intel_workarounds_types.h |    1 +
 drivers/gpu/drm/i915/gt/mock_engine.c         |   34 +-
 .../drm/i915/gt/selftest_engine_heartbeat.c   |   22 +
 .../drm/i915/gt/selftest_engine_heartbeat.h   |    2 +
 drivers/gpu/drm/i915/gt/selftest_execlists.c  |   12 +-
 drivers/gpu/drm/i915/gt/selftest_hangcheck.c  |  322 +++-
 drivers/gpu/drm/i915/gt/selftest_mocs.c       |   50 +-
 .../gpu/drm/i915/gt/selftest_workarounds.c    |  132 +-
 .../gpu/drm/i915/gt/uc/abi/guc_actions_abi.h  |    1 +
 drivers/gpu/drm/i915/gt/uc/intel_guc.c        |   82 +-
 drivers/gpu/drm/i915/gt/uc/intel_guc.h        |   38 +-
 drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c    |  464 ++++-
 drivers/gpu/drm/i915/gt/uc/intel_guc_ads.h    |    4 +
 drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c     |   11 +-
 .../gpu/drm/i915/gt/uc/intel_guc_debugfs.c    |    2 +
 .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 1611 +++++++++++++++--
 .../gpu/drm/i915/gt/uc/intel_guc_submission.h |   13 +-
 drivers/gpu/drm/i915/gt/uc/intel_uc.c         |  101 +-
 drivers/gpu/drm/i915/gt/uc/intel_uc.h         |    6 +
 drivers/gpu/drm/i915/i915_debugfs_params.c    |   32 +
 drivers/gpu/drm/i915/i915_gpu_error.c         |   25 +-
 drivers/gpu/drm/i915/i915_reg.h               |    1 +
 drivers/gpu/drm/i915/i915_request.c           |  162 +-
 drivers/gpu/drm/i915/i915_request.h           |   21 +
 drivers/gpu/drm/i915/i915_scheduler.c         |   16 +-
 drivers/gpu/drm/i915/i915_scheduler.h         |   10 +-
 drivers/gpu/drm/i915/i915_scheduler_types.h   |   22 +
 drivers/gpu/drm/i915/i915_trace.h             |   37 +-
 drivers/gpu/drm/i915/selftests/i915_request.c |    4 +-
 .../gpu/drm/i915/selftests/igt_flush_test.c   |    2 +-
 .../i915/selftests/intel_scheduler_helpers.c  |   88 +
 .../i915/selftests/intel_scheduler_helpers.h  |   33 +
 include/uapi/drm/i915_drm.h                   |    9 +
 55 files changed, 3501 insertions(+), 634 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/selftests/intel_scheduler_helpers.c
 create mode 100644 drivers/gpu/drm/i915/selftests/intel_scheduler_helpers.h
Signature · 6 lines
2.28.0

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

PATCH 1/33 drm/i915/guc: GuC virtual engines

Implement GuC virtual engines. Rather simple implementation, basically just allocate an engine, setup context enter / exit function to virtual engine specific functions, set all other variables / functions to guc versions, and set the engine mask to that of all the siblings.

v2: Update to work with proto-ctx
v3:
(Daniele)
- Drop include, add comment to intel_virtual_engine_has_heartbeat

---
 drivers/gpu/drm/i915/gem/i915_gem_context.c   |   8 +-
 drivers/gpu/drm/i915/gt/intel_context_types.h |   6 +
 drivers/gpu/drm/i915/gt/intel_engine.h        |  30 ++-
 drivers/gpu/drm/i915/gt/intel_engine_cs.c     |  14 +
 .../drm/i915/gt/intel_execlists_submission.c  |  29 ++-
 .../drm/i915/gt/intel_execlists_submission.h  |   4 -
 drivers/gpu/drm/i915/gt/selftest_execlists.c  |  12 +-
 .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 242 +++++++++++++++++-
 .../gpu/drm/i915/gt/uc/intel_guc_submission.h |   2 +
 9 files changed, 311 insertions(+), 36 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +2 -6
index 89ca401bf9ae..bc52eeed782a 100644
@@ -74,7 +74,6 @@
 #include "gt/intel_context_param.h"
 #include "gt/intel_engine_heartbeat.h"
 #include "gt/intel_engine_user.h"
-#include "gt/intel_execlists_submission.h" /* virtual_engine */
 #include "gt/intel_gpu_commands.h"
 #include "gt/intel_ring.h"
 
@@ -363,9 +362,6 @@ set_proto_ctx_engines_balance(struct i915_user_extension __user *base,
 	if (!HAS_EXECLISTS(i915))
 		return -ENODEV;
 
-	if (intel_uc_uses_guc_submission(&i915->gt.uc))
-		return -ENODEV; /* not implement yet */
-
 	if (get_user(idx, &ext->engine_index))
 		return -EFAULT;
 
@@ -950,8 +946,8 @@ static struct i915_gem_engines *user_engines(struct i915_gem_context *ctx,
 			break;
 
 		case I915_GEM_ENGINE_TYPE_BALANCED:
-			ce = intel_execlists_create_virtual(pe[n].siblings,
-							    pe[n].num_siblings);
+			ce = intel_engine_create_virtual(pe[n].siblings,
+							 pe[n].num_siblings);
 			break;
 
 		case I915_GEM_ENGINE_TYPE_INVALID:
drivers/gpu/drm/i915/gt/intel_context_types.h +6 -0
index 4a5518d295c2..542c98418771 100644
@@ -47,6 +47,12 @@ struct intel_context_ops {
 
 	void (*reset)(struct intel_context *ce);
 	void (*destroy)(struct kref *kref);
+
+	/* virtual engine/context interface */
+	struct intel_context *(*create_virtual)(struct intel_engine_cs **engine,
+						unsigned int count);
+	struct intel_engine_cs *(*get_sibling)(struct intel_engine_cs *engine,
+					       unsigned int sibling);
 };
 
 struct intel_context {
drivers/gpu/drm/i915/gt/intel_engine.h +29 -1
index f911c1224ab2..13bfb7ec33b2 100644
@@ -273,13 +273,41 @@ intel_engine_has_preempt_reset(const struct intel_engine_cs *engine)
 	return intel_engine_has_preemption(engine);
 }
 
+struct intel_context *
+intel_engine_create_virtual(struct intel_engine_cs **siblings,
+			    unsigned int count);
+
+static inline bool
+intel_virtual_engine_has_heartbeat(const struct intel_engine_cs *engine)
+{
+	/*
+	 * For non-GuC submission we expect the back-end to look at the
+	 * heartbeat status of the actual physical engine that the work
+	 * has been (or is being) scheduled on, so we should only reach
+	 * here with GuC submission enabled.
+	 */
+	GEM_BUG_ON(!intel_engine_uses_guc(engine));
+
+	return intel_guc_virtual_engine_has_heartbeat(engine);
+}
+
 static inline bool
 intel_engine_has_heartbeat(const struct intel_engine_cs *engine)
 {
 	if (!IS_ACTIVE(CONFIG_DRM_I915_HEARTBEAT_INTERVAL))
 		return false;
 
-	return READ_ONCE(engine->props.heartbeat_interval_ms);
+	if (intel_engine_is_virtual(engine))
+		return intel_virtual_engine_has_heartbeat(engine);
+	else
+		return READ_ONCE(engine->props.heartbeat_interval_ms);
+}
+
+static inline struct intel_engine_cs *
+intel_engine_get_sibling(struct intel_engine_cs *engine, unsigned int sibling)
+{
+	GEM_BUG_ON(!intel_engine_is_virtual(engine));
+	return engine->cops->get_sibling(engine, sibling);
 }
 
 #endif /* _INTEL_RINGBUFFER_H_ */
drivers/gpu/drm/i915/gt/intel_engine_cs.c +14 -0
index 43c3fb2aeb13..6a7edc839a2c 100644
@@ -1796,6 +1796,20 @@ ktime_t intel_engine_get_busy_time(struct intel_engine_cs *engine, ktime_t *now)
 	return total;
 }
 
+struct intel_context *
+intel_engine_create_virtual(struct intel_engine_cs **siblings,
+			    unsigned int count)
+{
+	if (count == 0)
+		return ERR_PTR(-EINVAL);
+
+	if (count == 1)
+		return intel_context_create(siblings[0]);
+
+	GEM_BUG_ON(!siblings[0]->cops->create_virtual);
+	return siblings[0]->cops->create_virtual(siblings, count);
+}
+
 static bool match_ring(struct i915_request *rq)
 {
 	u32 ring = ENGINE_READ(rq->engine, RING_START);
drivers/gpu/drm/i915/gt/intel_execlists_submission.c +20 -9
index be99a74e6e09..1e76768dc5e9 100644
@@ -199,6 +199,9 @@ static struct virtual_engine *to_virtual_engine(struct intel_engine_cs *engine)
 	return container_of(engine, struct virtual_engine, base);
 }
 
+static struct intel_context *
+execlists_create_virtual(struct intel_engine_cs **siblings, unsigned int count);
+
 static struct i915_request *
 __active_request(const struct intel_timeline * const tl,
 		 struct i915_request *rq,
@@ -2599,6 +2602,8 @@ static const struct intel_context_ops execlists_context_ops = {
 
 	.reset = lrc_reset,
 	.destroy = lrc_destroy,
+
+	.create_virtual = execlists_create_virtual,
 };
 
 static int emit_pdps(struct i915_request *rq)
@@ -3549,6 +3554,17 @@ static void virtual_context_exit(struct intel_context *ce)
 		intel_engine_pm_put(ve->siblings[n]);
 }
 
+static struct intel_engine_cs *
+virtual_get_sibling(struct intel_engine_cs *engine, unsigned int sibling)
+{
+	struct virtual_engine *ve = to_virtual_engine(engine);
+
+	if (sibling >= ve->num_siblings)
+		return NULL;
+
+	return ve->siblings[sibling];
+}
+
 static const struct intel_context_ops virtual_context_ops = {
 	.flags = COPS_HAS_INFLIGHT,
 
@@ -3563,6 +3579,8 @@ static const struct intel_context_ops virtual_context_ops = {
 	.exit = virtual_context_exit,
 
 	.destroy = virtual_context_destroy,
+
+	.get_sibling = virtual_get_sibling,
 };
 
 static intel_engine_mask_t virtual_submission_mask(struct virtual_engine *ve)
@@ -3711,20 +3729,13 @@ static void virtual_submit_request(struct i915_request *rq)
 	spin_unlock_irqrestore(&ve->base.sched_engine->lock, flags);
 }
 
-struct intel_context *
-intel_execlists_create_virtual(struct intel_engine_cs **siblings,
-			       unsigned int count)
+static struct intel_context *
+execlists_create_virtual(struct intel_engine_cs **siblings, unsigned int count)
 {
 	struct virtual_engine *ve;
 	unsigned int n;
 	int err;
 
-	if (count == 0)
-		return ERR_PTR(-EINVAL);
-
-	if (count == 1)
-		return intel_context_create(siblings[0]);
-
 	ve = kzalloc(struct_size(ve, siblings, count), GFP_KERNEL);
 	if (!ve)
 		return ERR_PTR(-ENOMEM);
drivers/gpu/drm/i915/gt/intel_execlists_submission.h +0 -4
index ad4f3e1a0fde..a1aa92c983a5 100644
@@ -32,10 +32,6 @@ void intel_execlists_show_requests(struct intel_engine_cs *engine,
 							int indent),
 				   unsigned int max);
 
-struct intel_context *
-intel_execlists_create_virtual(struct intel_engine_cs **siblings,
-			       unsigned int count);
-
 bool
 intel_engine_in_execlists_submission_mode(const struct intel_engine_cs *engine);
 
drivers/gpu/drm/i915/gt/selftest_execlists.c +6 -6
index 22a124b134b6..f12ffe797639 100644
@@ -3733,7 +3733,7 @@ static int nop_virtual_engine(struct intel_gt *gt,
 	GEM_BUG_ON(!nctx || nctx > ARRAY_SIZE(ve));
 
 	for (n = 0; n < nctx; n++) {
-		ve[n] = intel_execlists_create_virtual(siblings, nsibling);
+		ve[n] = intel_engine_create_virtual(siblings, nsibling);
 		if (IS_ERR(ve[n])) {
 			err = PTR_ERR(ve[n]);
 			nctx = n;
@@ -3929,7 +3929,7 @@ static int mask_virtual_engine(struct intel_gt *gt,
 	 * restrict it to our desired engine within the virtual engine.
 	 */
 
-	ve = intel_execlists_create_virtual(siblings, nsibling);
+	ve = intel_engine_create_virtual(siblings, nsibling);
 	if (IS_ERR(ve)) {
 		err = PTR_ERR(ve);
 		goto out_close;
@@ -4060,7 +4060,7 @@ static int slicein_virtual_engine(struct intel_gt *gt,
 		i915_request_add(rq);
 	}
 
-	ce = intel_execlists_create_virtual(siblings, nsibling);
+	ce = intel_engine_create_virtual(siblings, nsibling);
 	if (IS_ERR(ce)) {
 		err = PTR_ERR(ce);
 		goto out;
@@ -4112,7 +4112,7 @@ static int sliceout_virtual_engine(struct intel_gt *gt,
 
 	/* XXX We do not handle oversubscription and fairness with normal rq */
 	for (n = 0; n < nsibling; n++) {
-		ce = intel_execlists_create_virtual(siblings, nsibling);
+		ce = intel_engine_create_virtual(siblings, nsibling);
 		if (IS_ERR(ce)) {
 			err = PTR_ERR(ce);
 			goto out;
@@ -4214,7 +4214,7 @@ static int preserved_virtual_engine(struct intel_gt *gt,
 	if (err)
 		goto out_scratch;
 
-	ve = intel_execlists_create_virtual(siblings, nsibling);
+	ve = intel_engine_create_virtual(siblings, nsibling);
 	if (IS_ERR(ve)) {
 		err = PTR_ERR(ve);
 		goto out_scratch;
@@ -4354,7 +4354,7 @@ static int reset_virtual_engine(struct intel_gt *gt,
 	if (igt_spinner_init(&spin, gt))
 		return -ENOMEM;
 
-	ve = intel_execlists_create_virtual(siblings, nsibling);
+	ve = intel_engine_create_virtual(siblings, nsibling);
 	if (IS_ERR(ve)) {
 		err = PTR_ERR(ve);
 		goto out_spin;
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +232 -10

305 lines not on this page · raw message

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.h +2 -0
index 2b9470c90558..5f263ac4f46a 100644
@@ -26,6 +26,8 @@ void intel_guc_submission_print_info(struct intel_guc *guc,
 void intel_guc_submission_print_context_info(struct intel_guc *guc,
 					     struct drm_printer *p);
 
+bool intel_guc_virtual_engine_has_heartbeat(const struct intel_engine_cs *ve);
+
 static inline bool intel_guc_submission_is_supported(struct intel_guc *guc)
 {
 	/* XXX: GuC submission is unavailable for now */
Signature · 1 line
2.28.0
#2 lore raw

PATCH 2/33 drm/i915/guc: Make hangcheck work with GuC virtual engines

In reply to Matthew Brost

From: John Harrison <[email protected]>

The serial number tracking of engines happens at the backend of request submission and was expecting to only be given physical engines. However, in GuC submission mode, the decomposition of virtual to physical engines does not happen in i915. Instead, requests are submitted to their virtual engine mask all the way through to the hardware (i.e. to GuC). This would mean that the heart beat code thinks the physical engines are idle due to the serial number not incrementing. Which in turns means hangcheck does not work for GuC virtual engines.

This patch updates the tracking to decompose virtual engines into their physical constituents and tracks the request against each. This is not entirely accurate as the GuC will only be issuing the request to one physical engine. However, it is the best that i915 can do given that it has no knowledge of the GuC's scheduling decisions.

Downside of this is that all physical engines constituting a GuC virtual engine will be periodically unparked (even during just a single context executing) in order to be pinged with a heartbeat request. However the power and performance cost of this is not expected to be measurable (due low frequency of heartbeat pulses) and it is considered an easier option than trying to make changes to GuC firmware.

v2:
(Tvrtko)
- Update commit message
- Have default behavior if no vfunc present

---
 drivers/gpu/drm/i915/gt/intel_engine_types.h      |  2 ++
 drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c | 10 ++++++++++
 drivers/gpu/drm/i915/i915_request.c               |  6 +++++-
 3 files changed, 17 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/gt/intel_engine_types.h +2 -0
index 3f308a920b50..75a34cd3f1c2 100644
@@ -382,6 +382,8 @@ struct intel_engine_cs {
 	void		(*park)(struct intel_engine_cs *engine);
 	void		(*unpark)(struct intel_engine_cs *engine);
 
+	void		(*bump_serial)(struct intel_engine_cs *engine);
+
 	void		(*set_default_submission)(struct intel_engine_cs *engine);
 
 	const struct intel_context_ops *cops;
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10 -0
index 8b3ae5f65cd5..6b08221df143 100644
@@ -1492,6 +1492,15 @@ static void guc_release(struct intel_engine_cs *engine)
 	lrc_fini_wa_ctx(engine);
 }
 
+static void virtual_guc_bump_serial(struct intel_engine_cs *engine)
+{
+	struct intel_engine_cs *e;
+	intel_engine_mask_t tmp, mask = engine->mask;
+
+	for_each_engine_masked(e, engine->gt, mask, tmp)
+		e->serial++;
+}
+
 static void guc_default_vfuncs(struct intel_engine_cs *engine)
 {
 	/* Default vfuncs which can be overridden by each engine. */
@@ -1835,6 +1844,7 @@ guc_create_virtual(struct intel_engine_cs **siblings, unsigned int count)
 
 	ve->base.cops = &virtual_guc_context_ops;
 	ve->base.request_alloc = guc_request_alloc;
+	ve->base.bump_serial = virtual_guc_bump_serial;
 
 	ve->base.submit_request = guc_submit_request;
 
drivers/gpu/drm/i915/i915_request.c +5 -1
index 6594cb2f8ebd..39a21d96577e 100644
@@ -669,7 +669,11 @@ bool __i915_request_submit(struct i915_request *request)
 				     request->ring->vaddr + request->postfix);
 
 	trace_i915_request_execute(request);
-	engine->serial++;
+	if (engine->bump_serial)
+		engine->bump_serial(engine);
+	else
+		engine->serial++;
+
 	result = true;
 
 	GEM_BUG_ON(test_bit(I915_FENCE_FLAG_ACTIVE, &request->fence.flags));
Signature · 6 lines
2.28.0

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

PATCH 3/33 drm/i915: Hold reference to intel_context over life of i915_request

In reply to Matthew Brost

Hold a reference to the intel_context over life of an i915_request. Without this an i915_request can exist after the context has been destroyed (e.g. request retired, context closed, but user space holds a reference to the request from an out fence). In the case of GuC submission + virtual engine, the engine that the request references is also destroyed which can trigger bad pointer dref in fence ops (e.g. i915_fence_get_driver_name). We could likely change i915_fence_get_driver_name to avoid touching the engine but let's just be safe and hold the intel_context reference.

v2:
(John Harrison)
- Update comment explaining how GuC mode and execlists mode deal with virtual engines differently

---
 drivers/gpu/drm/i915/i915_request.c | 55 ++++++++++++-----------------
 1 file changed, 23 insertions(+), 32 deletions(-)
drivers/gpu/drm/i915/i915_request.c +23 -32
index 39a21d96577e..57c9187aff74 100644
@@ -125,39 +125,17 @@ static void i915_fence_release(struct dma_fence *fence)
 	i915_sw_fence_fini(&rq->semaphore);
 
 	/*
-	 * Keep one request on each engine for reserved use under mempressure
-	 *
-	 * We do not hold a reference to the engine here and so have to be
-	 * very careful in what rq->engine we poke. The virtual engine is
-	 * referenced via the rq->context and we released that ref during
-	 * i915_request_retire(), ergo we must not dereference a virtual
-	 * engine here. Not that we would want to, as the only consumer of
-	 * the reserved engine->request_pool is the power management parking,
-	 * which must-not-fail, and that is only run on the physical engines.
-	 *
-	 * Since the request must have been executed to be have completed,
-	 * we know that it will have been processed by the HW and will
-	 * not be unsubmitted again, so rq->engine and rq->execution_mask
-	 * at this point is stable. rq->execution_mask will be a single
-	 * bit if the last and _only_ engine it could execution on was a
-	 * physical engine, if it's multiple bits then it started on and
-	 * could still be on a virtual engine. Thus if the mask is not a
-	 * power-of-two we assume that rq->engine may still be a virtual
-	 * engine and so a dangling invalid pointer that we cannot dereference
-	 *
-	 * For example, consider the flow of a bonded request through a virtual
-	 * engine. The request is created with a wide engine mask (all engines
-	 * that we might execute on). On processing the bond, the request mask
-	 * is reduced to one or more engines. If the request is subsequently
-	 * bound to a single engine, it will then be constrained to only
-	 * execute on that engine and never returned to the virtual engine
-	 * after timeslicing away, see __unwind_incomplete_requests(). Thus we
-	 * know that if the rq->execution_mask is a single bit, rq->engine
-	 * can be a physical engine with the exact corresponding mask.
+	 * Keep one request on each engine for reserved use under mempressure,
+	 * do not use with virtual engines as this really is only needed for
+	 * kernel contexts.
 	 */
-	if (is_power_of_2(rq->execution_mask) &&
-	    !cmpxchg(&rq->engine->request_pool, NULL, rq))
+	if (!intel_engine_is_virtual(rq->engine) &&
+	    !cmpxchg(&rq->engine->request_pool, NULL, rq)) {
+		intel_context_put(rq->context);
 		return;
+	}
+
+	intel_context_put(rq->context);
 
 	kmem_cache_free(global.slab_requests, rq);
 }
@@ -956,7 +934,19 @@ __i915_request_create(struct intel_context *ce, gfp_t gfp)
 		}
 	}
 
-	rq->context = ce;
+	/*
+	 * Hold a reference to the intel_context over life of an i915_request.
+	 * Without this an i915_request can exist after the context has been
+	 * destroyed (e.g. request retired, context closed, but user space holds
+	 * a reference to the request from an out fence). In the case of GuC
+	 * submission + virtual engine, the engine that the request references
+	 * is also destroyed which can trigger bad pointer dref in fence ops
+	 * (e.g. i915_fence_get_driver_name). We could likely change these
+	 * functions to avoid touching the engine but let's just be safe and
+	 * hold the intel_context reference. In execlist mode the request always
+	 * eventually points to a physical engine so this isn't an issue.
+	 */
+	rq->context = intel_context_get(ce);
 	rq->engine = ce->engine;
 	rq->ring = ce->ring;
 	rq->execution_mask = ce->engine->mask;
@@ -1033,6 +1023,7 @@ __i915_request_create(struct intel_context *ce, gfp_t gfp)
 	GEM_BUG_ON(!list_empty(&rq->sched.waiters_list));
 
 err_free:
+	intel_context_put(ce);
 	kmem_cache_free(global.slab_requests, rq);
 err_unreserve:
 	intel_context_unpin(ce);
Signature · 6 lines
2.28.0

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

Re: [Intel-gfx] [PATCH 03/33] drm/i915: Hold reference to intel_context over life of i915_request

Quoted 10 lines · Matthew Brost

Hold a reference to the intel_context over life of an i915_request. Without this an i915_request can exist after the context has been destroyed (e.g. request retired, context closed, but user space holds a reference to the request from an out fence). In the case of GuC submission + virtual engine, the engine that the request references is also destroyed which can trigger bad pointer dref in fence ops (e.g. i915_fence_get_driver_name). We could likely change i915_fence_get_driver_name to avoid touching the engine but let's just be safe and hold the intel_context reference.

Quoted 7 lines

v2:
(John Harrison)
- Update comment explaining how GuC mode and execlists mode deal with virtual engines differently

Please also update the comment in the header for i915_request. That is back from 2016 or so, when the context was actually fully refcounted
...

It would also be good to record a bit more the history here and all the back&forth (and maybe why).

Don't ask why I've stumbled over this.
-Daniel

Quoted 93 lines
---
 drivers/gpu/drm/i915/i915_request.c | 55 ++++++++++++-----------------
 1 file changed, 23 insertions(+), 32 deletions(-)
drivers/gpu/drm/i915/i915_request.c +23 -33
index 39a21d96577e..57c9187aff74 100644
@@ -125,39 +125,17 @@ static void i915_fence_release(struct dma_fence *fence)
        i915_sw_fence_fini(&rq->semaphore);
 
        /*
-        * Keep one request on each engine for reserved use under mempressure
-        *
-        * We do not hold a reference to the engine here and so have to be
-        * very careful in what rq->engine we poke. The virtual engine is
-        * referenced via the rq->context and we released that ref during
-        * i915_request_retire(), ergo we must not dereference a virtual
-        * engine here. Not that we would want to, as the only consumer of
-        * the reserved engine->request_pool is the power management parking,
-        * which must-not-fail, and that is only run on the physical engines.
-        *
-        * Since the request must have been executed to be have completed,
-        * we know that it will have been processed by the HW and will
-        * not be unsubmitted again, so rq->engine and rq->execution_mask
-        * at this point is stable. rq->execution_mask will be a single
-        * bit if the last and _only_ engine it could execution on was a
-        * physical engine, if it's multiple bits then it started on and
-        * could still be on a virtual engine. Thus if the mask is not a
-        * power-of-two we assume that rq->engine may still be a virtual
-        * engine and so a dangling invalid pointer that we cannot dereference
-        *
-        * For example, consider the flow of a bonded request through a virtual
-        * engine. The request is created with a wide engine mask (all engines
-        * that we might execute on). On processing the bond, the request mask
-        * is reduced to one or more engines. If the request is subsequently
-        * bound to a single engine, it will then be constrained to only
-        * execute on that engine and never returned to the virtual engine
-        * after timeslicing away, see __unwind_incomplete_requests(). Thus we
-        * know that if the rq->execution_mask is a single bit, rq->engine
-        * can be a physical engine with the exact corresponding mask.
+        * Keep one request on each engine for reserved use under mempressure,
+        * do not use with virtual engines as this really is only needed for
+        * kernel contexts.
         */
-       if (is_power_of_2(rq->execution_mask) &&
-           !cmpxchg(&rq->engine->request_pool, NULL, rq))
+       if (!intel_engine_is_virtual(rq->engine) &&
+           !cmpxchg(&rq->engine->request_pool, NULL, rq)) {
+               intel_context_put(rq->context);
                return;
+       }
+
+       intel_context_put(rq->context);
 
        kmem_cache_free(global.slab_requests, rq);
 }
@@ -956,7 +934,19 @@ __i915_request_create(struct intel_context *ce, gfp_t gfp)
                }
        }
 
-       rq->context = ce;
+       /*
+        * Hold a reference to the intel_context over life of an i915_request.
+        * Without this an i915_request can exist after the context has been
+        * destroyed (e.g. request retired, context closed, but user space holds
+        * a reference to the request from an out fence). In the case of GuC
+        * submission + virtual engine, the engine that the request references
+        * is also destroyed which can trigger bad pointer dref in fence ops
+        * (e.g. i915_fence_get_driver_name). We could likely change these
+        * functions to avoid touching the engine but let's just be safe and
+        * hold the intel_context reference. In execlist mode the request always
+        * eventually points to a physical engine so this isn't an issue.
+        */
+       rq->context = intel_context_get(ce);
        rq->engine = ce->engine;
        rq->ring = ce->ring;
        rq->execution_mask = ce->engine->mask;
@@ -1033,6 +1023,7 @@ __i915_request_create(struct intel_context *ce, gfp_t gfp)
        GEM_BUG_ON(!list_empty(&rq->sched.waiters_list));
 
 err_free:
+       intel_context_put(ce);
        kmem_cache_free(global.slab_requests, rq);
 err_unreserve:
        intel_context_unpin(ce);
--

2.28.0

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

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#5 lore raw

PATCH 4/33 drm/i915/guc: Disable bonding extension with GuC submission

In reply to Matthew Brost

Update the bonding extension to return -ENODEV when using GuC submission as this extension fundamentally will not work with the GuC submission interface.

---
 drivers/gpu/drm/i915/gem/i915_gem_context.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/i915/gem/i915_gem_context.c +5 -0
index bc52eeed782a..e3df01a201d7 100644
@@ -491,6 +491,11 @@ set_proto_ctx_engines_bond(struct i915_user_extension __user *base, void *data)
 		return -EINVAL;
 	}
 
+	if (intel_engine_uses_guc(master)) {
+		DRM_DEBUG("bonding extension not supported with GuC submission");
+		return -ENODEV;
+	}
+
 	if (get_user(num_bonds, &ext->num_bonds))
 		return -EFAULT;
 
Signature · 1 line
2.28.0
#6 lore raw

PATCH 5/33 drm/i915/guc: Direct all breadcrumbs for a class to single breadcrumbs

In reply to Matthew Brost

With GuC virtual engines the physical engine which a request executes and completes on isn't known to the i915. Therefore we can't attach a request to a physical engines breadcrumbs. To work around this we create a single breadcrumbs per engine class when using GuC submission and direct all physical engine interrupts to this breadcrumbs.

v2:
(John H)
- Rework header file structure so intel_engine_mask_t can be in intel_engine_types.h

---
 drivers/gpu/drm/i915/gt/intel_breadcrumbs.c   | 41 +++++-------
 drivers/gpu/drm/i915/gt/intel_breadcrumbs.h   | 16 ++++-
 .../gpu/drm/i915/gt/intel_breadcrumbs_types.h |  7 ++
 drivers/gpu/drm/i915/gt/intel_engine.h        |  3 +
 drivers/gpu/drm/i915/gt/intel_engine_cs.c     | 28 +++++++-
 drivers/gpu/drm/i915/gt/intel_engine_types.h  |  2 +-
 .../drm/i915/gt/intel_execlists_submission.c  |  2 +-
 drivers/gpu/drm/i915/gt/mock_engine.c         |  4 +-
 .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 67 +++++++++++++++++--
 9 files changed, 133 insertions(+), 37 deletions(-)
drivers/gpu/drm/i915/gt/intel_breadcrumbs.c +17 -24
index 38cc42783dfb..2007dc6f6b99 100644
@@ -15,28 +15,14 @@
 #include "intel_gt_pm.h"
 #include "intel_gt_requests.h"
 
-static bool irq_enable(struct intel_engine_cs *engine)
+static bool irq_enable(struct intel_breadcrumbs *b)
 {
-	if (!engine->irq_enable)
-		return false;
-
-	/* Caller disables interrupts */
-	spin_lock(&engine->gt->irq_lock);
-	engine->irq_enable(engine);
-	spin_unlock(&engine->gt->irq_lock);
-
-	return true;
+	return intel_engine_irq_enable(b->irq_engine);
 }
 
-static void irq_disable(struct intel_engine_cs *engine)
+static void irq_disable(struct intel_breadcrumbs *b)
 {
-	if (!engine->irq_disable)
-		return;
-
-	/* Caller disables interrupts */
-	spin_lock(&engine->gt->irq_lock);
-	engine->irq_disable(engine);
-	spin_unlock(&engine->gt->irq_lock);
+	intel_engine_irq_disable(b->irq_engine);
 }
 
 static void __intel_breadcrumbs_arm_irq(struct intel_breadcrumbs *b)
@@ -57,7 +43,7 @@ static void __intel_breadcrumbs_arm_irq(struct intel_breadcrumbs *b)
 	WRITE_ONCE(b->irq_armed, true);
 
 	/* Requests may have completed before we could enable the interrupt. */
-	if (!b->irq_enabled++ && irq_enable(b->irq_engine))
+	if (!b->irq_enabled++ && b->irq_enable(b))
 		irq_work_queue(&b->irq_work);
 }
 
@@ -76,7 +62,7 @@ static void __intel_breadcrumbs_disarm_irq(struct intel_breadcrumbs *b)
 {
 	GEM_BUG_ON(!b->irq_enabled);
 	if (!--b->irq_enabled)
-		irq_disable(b->irq_engine);
+		b->irq_disable(b);
 
 	WRITE_ONCE(b->irq_armed, false);
 	intel_gt_pm_put_async(b->irq_engine->gt);
@@ -281,7 +267,7 @@ intel_breadcrumbs_create(struct intel_engine_cs *irq_engine)
 	if (!b)
 		return NULL;
 
-	b->irq_engine = irq_engine;
+	kref_init(&b->ref);
 
 	spin_lock_init(&b->signalers_lock);
 	INIT_LIST_HEAD(&b->signalers);
@@ -290,6 +276,10 @@ intel_breadcrumbs_create(struct intel_engine_cs *irq_engine)
 	spin_lock_init(&b->irq_lock);
 	init_irq_work(&b->irq_work, signal_irq_work);
 
+	b->irq_engine = irq_engine;
+	b->irq_enable = irq_enable;
+	b->irq_disable = irq_disable;
+
 	return b;
 }
 
@@ -303,9 +293,9 @@ void intel_breadcrumbs_reset(struct intel_breadcrumbs *b)
 	spin_lock_irqsave(&b->irq_lock, flags);
 
 	if (b->irq_enabled)
-		irq_enable(b->irq_engine);
+		b->irq_enable(b);
 	else
-		irq_disable(b->irq_engine);
+		b->irq_disable(b);
 
 	spin_unlock_irqrestore(&b->irq_lock, flags);
 }
@@ -325,11 +315,14 @@ void __intel_breadcrumbs_park(struct intel_breadcrumbs *b)
 	}
 }
 
-void intel_breadcrumbs_free(struct intel_breadcrumbs *b)
+void intel_breadcrumbs_free(struct kref *kref)
 {
+	struct intel_breadcrumbs *b = container_of(kref, typeof(*b), ref);
+
 	irq_work_sync(&b->irq_work);
 	GEM_BUG_ON(!list_empty(&b->signalers));
 	GEM_BUG_ON(b->irq_armed);
+
 	kfree(b);
 }
 
drivers/gpu/drm/i915/gt/intel_breadcrumbs.h +14 -2
index 3ce5ce270b04..be0d4f379a85 100644
@@ -9,7 +9,7 @@
 #include <linux/atomic.h>
 #include <linux/irq_work.h>
 
-#include "intel_engine_types.h"
+#include "intel_breadcrumbs_types.h"
 
 struct drm_printer;
 struct i915_request;
@@ -17,7 +17,7 @@ struct intel_breadcrumbs;
 
 struct intel_breadcrumbs *
 intel_breadcrumbs_create(struct intel_engine_cs *irq_engine);
-void intel_breadcrumbs_free(struct intel_breadcrumbs *b);
+void intel_breadcrumbs_free(struct kref *kref);
 
 void intel_breadcrumbs_reset(struct intel_breadcrumbs *b);
 void __intel_breadcrumbs_park(struct intel_breadcrumbs *b);
@@ -48,4 +48,16 @@ void i915_request_cancel_breadcrumb(struct i915_request *request);
 void intel_context_remove_breadcrumbs(struct intel_context *ce,
 				      struct intel_breadcrumbs *b);
 
+static inline struct intel_breadcrumbs *
+intel_breadcrumbs_get(struct intel_breadcrumbs *b)
+{
+	kref_get(&b->ref);
+	return b;
+}
+
+static inline void intel_breadcrumbs_put(struct intel_breadcrumbs *b)
+{
+	kref_put(&b->ref, intel_breadcrumbs_free);
+}
+
 #endif /* __INTEL_BREADCRUMBS__ */
drivers/gpu/drm/i915/gt/intel_breadcrumbs_types.h +7 -0
index 3a084ce8ff5e..72dfd3748c4c 100644
@@ -7,10 +7,13 @@
 #define __INTEL_BREADCRUMBS_TYPES__
 
 #include <linux/irq_work.h>
+#include <linux/kref.h>
 #include <linux/list.h>
 #include <linux/spinlock.h>
 #include <linux/types.h>
 
+#include "intel_engine_types.h"
+
 /*
  * Rather than have every client wait upon all user interrupts,
  * with the herd waking after every interrupt and each doing the
@@ -29,6 +32,7 @@
  * the overhead of waking that client is much preferred.
  */
 struct intel_breadcrumbs {
+	struct kref ref;
 	atomic_t active;
 
 	spinlock_t signalers_lock; /* protects the list of signalers */
@@ -42,7 +46,10 @@ struct intel_breadcrumbs {
 	bool irq_armed;
 
 	/* Not all breadcrumbs are attached to physical HW */
+	intel_engine_mask_t	engine_mask;
 	struct intel_engine_cs *irq_engine;
+	bool	(*irq_enable)(struct intel_breadcrumbs *b);
+	void	(*irq_disable)(struct intel_breadcrumbs *b);
 };
 
 #endif /* __INTEL_BREADCRUMBS_TYPES__ */
drivers/gpu/drm/i915/gt/intel_engine.h +3 -0
index 13bfb7ec33b2..8fc76dc8bf98 100644
@@ -212,6 +212,9 @@ void intel_engine_get_instdone(const struct intel_engine_cs *engine,
 
 void intel_engine_init_execlists(struct intel_engine_cs *engine);
 
+bool intel_engine_irq_enable(struct intel_engine_cs *engine);
+void intel_engine_irq_disable(struct intel_engine_cs *engine);
+
 static inline void __intel_engine_reset(struct intel_engine_cs *engine,
 					bool stalled)
 {
drivers/gpu/drm/i915/gt/intel_engine_cs.c +26 -2
index 6a7edc839a2c..1eaa658507e1 100644
@@ -798,7 +798,7 @@ static int engine_setup_common(struct intel_engine_cs *engine)
 err_cmd_parser:
 	i915_sched_engine_put(engine->sched_engine);
 err_sched_engine:
-	intel_breadcrumbs_free(engine->breadcrumbs);
+	intel_breadcrumbs_put(engine->breadcrumbs);
 err_status:
 	cleanup_status_page(engine);
 	return err;
@@ -1007,7 +1007,7 @@ void intel_engine_cleanup_common(struct intel_engine_cs *engine)
 	GEM_BUG_ON(!list_empty(&engine->sched_engine->requests));
 
 	i915_sched_engine_put(engine->sched_engine);
-	intel_breadcrumbs_free(engine->breadcrumbs);
+	intel_breadcrumbs_put(engine->breadcrumbs);
 
 	intel_engine_fini_retire(engine);
 	intel_engine_cleanup_cmd_parser(engine);
@@ -1324,6 +1324,30 @@ bool intel_engines_are_idle(struct intel_gt *gt)
 	return true;
 }
 
+bool intel_engine_irq_enable(struct intel_engine_cs *engine)
+{
+	if (!engine->irq_enable)
+		return false;
+
+	/* Caller disables interrupts */
+	spin_lock(&engine->gt->irq_lock);
+	engine->irq_enable(engine);
+	spin_unlock(&engine->gt->irq_lock);
+
+	return true;
+}
+
+void intel_engine_irq_disable(struct intel_engine_cs *engine)
+{
+	if (!engine->irq_disable)
+		return;
+
+	/* Caller disables interrupts */
+	spin_lock(&engine->gt->irq_lock);
+	engine->irq_disable(engine);
+	spin_unlock(&engine->gt->irq_lock);
+}
+
 void intel_engines_reset_default_submission(struct intel_gt *gt)
 {
 	struct intel_engine_cs *engine;
drivers/gpu/drm/i915/gt/intel_engine_types.h +1 -1
index 75a34cd3f1c2..e55776e27a2a 100644
@@ -21,7 +21,6 @@
 #include "i915_pmu.h"
 #include "i915_priolist_types.h"
 #include "i915_selftest.h"
-#include "intel_breadcrumbs_types.h"
 #include "intel_sseu.h"
 #include "intel_timeline_types.h"
 #include "intel_uncore.h"
@@ -52,6 +51,7 @@ struct i915_sched_engine;
 struct intel_gt;
 struct intel_ring;
 struct intel_uncore;
+struct intel_breadcrumbs;
 
 typedef u32 intel_engine_mask_t;
 #define ALL_ENGINES ((intel_engine_mask_t)~0ul)
drivers/gpu/drm/i915/gt/intel_execlists_submission.c +1 -1
index 1e76768dc5e9..6e4959ee5065 100644
@@ -3457,7 +3457,7 @@ static void rcu_virtual_context_destroy(struct work_struct *wrk)
 	intel_context_fini(&ve->context);
 
 	if (ve->base.breadcrumbs)
-		intel_breadcrumbs_free(ve->base.breadcrumbs);
+		intel_breadcrumbs_put(ve->base.breadcrumbs);
 	if (ve->base.sched_engine)
 		i915_sched_engine_put(ve->base.sched_engine);
 	intel_engine_free_request_pool(&ve->base);
drivers/gpu/drm/i915/gt/mock_engine.c +2 -2
index 68970398e4ef..2ddaacb4e753 100644
@@ -284,7 +284,7 @@ static void mock_engine_release(struct intel_engine_cs *engine)
 	GEM_BUG_ON(timer_pending(&mock->hw_delay));
 
 	i915_sched_engine_put(engine->sched_engine);
-	intel_breadcrumbs_free(engine->breadcrumbs);
+	intel_breadcrumbs_put(engine->breadcrumbs);
 
 	intel_context_unpin(engine->kernel_context);
 	intel_context_put(engine->kernel_context);
@@ -370,7 +370,7 @@ int mock_engine_init(struct intel_engine_cs *engine)
 	return 0;
 
 err_breadcrumbs:
-	intel_breadcrumbs_free(engine->breadcrumbs);
+	intel_breadcrumbs_put(engine->breadcrumbs);
 err_schedule:
 	i915_sched_engine_put(engine->sched_engine);
 	return -ENOMEM;
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +62 -5

97 lines not on this page · raw message

Signature · 1 line
2.28.0
#7 lore raw

PATCH 6/33 drm/i915: Add i915_sched_engine destroy vfunc

In reply to Matthew Brost

This is required to allow backend specific cleanup

v2:
(John H)
- Rework commit message

---
 drivers/gpu/drm/i915/i915_scheduler.c       | 3 ++-
 drivers/gpu/drm/i915/i915_scheduler.h       | 4 +---
 drivers/gpu/drm/i915/i915_scheduler_types.h | 5 +++++
 3 files changed, 8 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/i915_scheduler.c +2 -1
index 561c649e59f7..2804fd5b660b 100644
@@ -431,7 +431,7 @@ void i915_request_show_with_schedule(struct drm_printer *m,
 	rcu_read_unlock();
 }
 
-void i915_sched_engine_free(struct kref *kref)
+static void default_destroy(struct kref *kref)
 {
 	struct i915_sched_engine *sched_engine =
 		container_of(kref, typeof(*sched_engine), ref);
@@ -453,6 +453,7 @@ i915_sched_engine_create(unsigned int subclass)
 
 	sched_engine->queue = RB_ROOT_CACHED;
 	sched_engine->queue_priority_hint = INT_MIN;
+	sched_engine->destroy = default_destroy;
 
 	INIT_LIST_HEAD(&sched_engine->requests);
 	INIT_LIST_HEAD(&sched_engine->hold);
drivers/gpu/drm/i915/i915_scheduler.h +1 -3
index 650ab8e0db9f..3c9504e9f409 100644
@@ -51,8 +51,6 @@ static inline void i915_priolist_free(struct i915_priolist *p)
 struct i915_sched_engine *
 i915_sched_engine_create(unsigned int subclass);
 
-void i915_sched_engine_free(struct kref *kref);
-
 static inline struct i915_sched_engine *
 i915_sched_engine_get(struct i915_sched_engine *sched_engine)
 {
@@ -63,7 +61,7 @@ i915_sched_engine_get(struct i915_sched_engine *sched_engine)
 static inline void
 i915_sched_engine_put(struct i915_sched_engine *sched_engine)
 {
-	kref_put(&sched_engine->ref, i915_sched_engine_free);
+	kref_put(&sched_engine->ref, sched_engine->destroy);
 }
 
 static inline bool
drivers/gpu/drm/i915/i915_scheduler_types.h +5 -0
index 5935c3152bdc..00384e2c5273 100644
@@ -163,6 +163,11 @@ struct i915_sched_engine {
 	 */
 	void *private_data;
 
+	/**
+	 * @destroy: destroy schedule engine / cleanup in backend
+	 */
+	void	(*destroy)(struct kref *kref);
+
 	/**
 	 * @kick_backend: kick backend after a request's priority has changed
 	 */
Signature · 1 line
2.28.0
#8 lore raw

PATCH 7/33 drm/i915: Move active request tracking to a vfunc

In reply to Matthew Brost

Move active request tracking to a backend vfunc rather than assuming all backends want to do this in the manner. In the of case execlists / ring submission the tracking is on the physical engine while with GuC submission it is on the context.

---
 drivers/gpu/drm/i915/gt/intel_context.c       |  3 ++
 drivers/gpu/drm/i915/gt/intel_context_types.h |  7 ++++
 drivers/gpu/drm/i915/gt/intel_engine_types.h  |  6 +++
 .../drm/i915/gt/intel_execlists_submission.c  | 40 ++++++++++++++++++
 .../gpu/drm/i915/gt/intel_ring_submission.c   | 22 ++++++++++
 drivers/gpu/drm/i915/gt/mock_engine.c         | 30 ++++++++++++++
 .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 33 +++++++++++++++
 drivers/gpu/drm/i915/i915_request.c           | 41 ++-----------------
 drivers/gpu/drm/i915/i915_request.h           |  2 +
 9 files changed, 147 insertions(+), 37 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.c +3 -0
index baa05fddd690..0bf4a13e9759 100644
@@ -393,6 +393,9 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)
 	spin_lock_init(&ce->guc_state.lock);
 	INIT_LIST_HEAD(&ce->guc_state.fences);
 
+	spin_lock_init(&ce->guc_active.lock);
+	INIT_LIST_HEAD(&ce->guc_active.requests);
+
 	ce->guc_id = GUC_INVALID_LRC_ID;
 	INIT_LIST_HEAD(&ce->guc_id_link);
 
drivers/gpu/drm/i915/gt/intel_context_types.h +7 -0
index 542c98418771..035108c10b2c 100644
@@ -162,6 +162,13 @@ struct intel_context {
 		struct list_head fences;
 	} guc_state;
 
+	struct {
+		/** lock: protects everything in guc_active */
+		spinlock_t lock;
+		/** requests: active requests on this context */
+		struct list_head requests;
+	} guc_active;
+
 	/* GuC scheduling state flags that do not require a lock. */
 	atomic_t guc_sched_state_no_lock;
 
drivers/gpu/drm/i915/gt/intel_engine_types.h +6 -0
index e55776e27a2a..1c7e2724cdae 100644
@@ -414,6 +414,12 @@ struct intel_engine_cs {
 
 	void		(*release)(struct intel_engine_cs *engine);
 
+	/*
+	 * Add / remove request from engine active tracking
+	 */
+	void		(*add_active_request)(struct i915_request *rq);
+	void		(*remove_active_request)(struct i915_request *rq);
+
 	struct intel_engine_execlists execlists;
 
 	/*
drivers/gpu/drm/i915/gt/intel_execlists_submission.c +40 -0
index 6e4959ee5065..b4a876736074 100644
@@ -3157,6 +3157,42 @@ static void execlists_park(struct intel_engine_cs *engine)
 	cancel_timer(&engine->execlists.preempt);
 }
 
+static void add_to_engine(struct i915_request *rq)
+{
+	lockdep_assert_held(&rq->engine->sched_engine->lock);
+	list_move_tail(&rq->sched.link, &rq->engine->sched_engine->requests);
+}
+
+static void remove_from_engine(struct i915_request *rq)
+{
+	struct intel_engine_cs *engine, *locked;
+
+	/*
+	 * Virtual engines complicate acquiring the engine timeline lock,
+	 * as their rq->engine pointer is not stable until under that
+	 * engine lock. The simple ploy we use is to take the lock then
+	 * check that the rq still belongs to the newly locked engine.
+	 */
+	locked = READ_ONCE(rq->engine);
+	spin_lock_irq(&locked->sched_engine->lock);
+	while (unlikely(locked != (engine = READ_ONCE(rq->engine)))) {
+		spin_unlock(&locked->sched_engine->lock);
+		spin_lock(&engine->sched_engine->lock);
+		locked = engine;
+	}
+	list_del_init(&rq->sched.link);
+
+	clear_bit(I915_FENCE_FLAG_PQUEUE, &rq->fence.flags);
+	clear_bit(I915_FENCE_FLAG_HOLD, &rq->fence.flags);
+
+	/* Prevent further __await_execution() registering a cb, then flush */
+	set_bit(I915_FENCE_FLAG_ACTIVE, &rq->fence.flags);
+
+	spin_unlock_irq(&locked->sched_engine->lock);
+
+	i915_request_notify_execute_cb_imm(rq);
+}
+
 static bool can_preempt(struct intel_engine_cs *engine)
 {
 	if (GRAPHICS_VER(engine->i915) > 8)
@@ -3251,6 +3287,8 @@ logical_ring_default_vfuncs(struct intel_engine_cs *engine)
 
 	engine->cops = &execlists_context_ops;
 	engine->request_alloc = execlists_request_alloc;
+	engine->add_active_request = add_to_engine;
+	engine->remove_active_request = remove_from_engine;
 
 	engine->reset.prepare = execlists_reset_prepare;
 	engine->reset.rewind = execlists_reset_rewind;
@@ -3847,6 +3885,8 @@ execlists_create_virtual(struct intel_engine_cs **siblings, unsigned int count)
 			 "v%dx%d", ve->base.class, count);
 		ve->base.context_size = sibling->context_size;
 
+		ve->base.add_active_request = sibling->add_active_request;
+		ve->base.remove_active_request = sibling->remove_active_request;
 		ve->base.emit_bb_start = sibling->emit_bb_start;
 		ve->base.emit_flush = sibling->emit_flush;
 		ve->base.emit_init_breadcrumb = sibling->emit_init_breadcrumb;
drivers/gpu/drm/i915/gt/intel_ring_submission.c +22 -0
index 5c4d204d07cc..a5404c7b600f 100644
@@ -1047,6 +1047,25 @@ static void setup_irq(struct intel_engine_cs *engine)
 	}
 }
 
+static void add_to_engine(struct i915_request *rq)
+{
+	lockdep_assert_held(&rq->engine->sched_engine->lock);
+	list_move_tail(&rq->sched.link, &rq->engine->sched_engine->requests);
+}
+
+static void remove_from_engine(struct i915_request *rq)
+{
+	spin_lock_irq(&rq->engine->sched_engine->lock);
+	list_del_init(&rq->sched.link);
+
+	/* Prevent further __await_execution() registering a cb, then flush */
+	set_bit(I915_FENCE_FLAG_ACTIVE, &rq->fence.flags);
+
+	spin_unlock_irq(&rq->engine->sched_engine->lock);
+
+	i915_request_notify_execute_cb_imm(rq);
+}
+
 static void setup_common(struct intel_engine_cs *engine)
 {
 	struct drm_i915_private *i915 = engine->i915;
@@ -1064,6 +1083,9 @@ static void setup_common(struct intel_engine_cs *engine)
 	engine->reset.cancel = reset_cancel;
 	engine->reset.finish = reset_finish;
 
+	engine->add_active_request = add_to_engine;
+	engine->remove_active_request = remove_from_engine;
+
 	engine->cops = &ring_context_ops;
 	engine->request_alloc = ring_request_alloc;
 
drivers/gpu/drm/i915/gt/mock_engine.c +30 -0
index 2ddaacb4e753..2c1af030310c 100644
@@ -235,6 +235,34 @@ static void mock_submit_request(struct i915_request *request)
 	spin_unlock_irqrestore(&engine->hw_lock, flags);
 }
 
+static void mock_add_to_engine(struct i915_request *rq)
+{
+	lockdep_assert_held(&rq->engine->sched_engine->lock);
+	list_move_tail(&rq->sched.link, &rq->engine->sched_engine->requests);
+}
+
+static void mock_remove_from_engine(struct i915_request *rq)
+{
+	struct intel_engine_cs *engine, *locked;
+
+	/*
+	 * Virtual engines complicate acquiring the engine timeline lock,
+	 * as their rq->engine pointer is not stable until under that
+	 * engine lock. The simple ploy we use is to take the lock then
+	 * check that the rq still belongs to the newly locked engine.
+	 */
+
+	locked = READ_ONCE(rq->engine);
+	spin_lock_irq(&locked->sched_engine->lock);
+	while (unlikely(locked != (engine = READ_ONCE(rq->engine)))) {
+		spin_unlock(&locked->sched_engine->lock);
+		spin_lock(&engine->sched_engine->lock);
+		locked = engine;
+	}
+	list_del_init(&rq->sched.link);
+	spin_unlock_irq(&locked->sched_engine->lock);
+}
+
 static void mock_reset_prepare(struct intel_engine_cs *engine)
 {
 }
@@ -321,6 +349,8 @@ struct intel_engine_cs *mock_engine(struct drm_i915_private *i915,
 	engine->base.emit_flush = mock_emit_flush;
 	engine->base.emit_fini_breadcrumb = mock_emit_breadcrumb;
 	engine->base.submit_request = mock_submit_request;
+	engine->base.add_active_request = mock_add_to_engine;
+	engine->base.remove_active_request = mock_remove_from_engine;
 
 	engine->base.reset.prepare = mock_reset_prepare;
 	engine->base.reset.rewind = mock_reset_rewind;
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +33 -0
index 60a73d9a00f6..2d49fbcfb88b 100644
@@ -1159,6 +1159,33 @@ static int guc_context_alloc(struct intel_context *ce)
 	return lrc_alloc(ce, ce->engine);
 }
 
+static void add_to_context(struct i915_request *rq)
+{
+	struct intel_context *ce = rq->context;
+
+	spin_lock(&ce->guc_active.lock);
+	list_move_tail(&rq->sched.link, &ce->guc_active.requests);
+	spin_unlock(&ce->guc_active.lock);
+}
+
+static void remove_from_context(struct i915_request *rq)
+{
+	struct intel_context *ce = rq->context;
+
+	spin_lock_irq(&ce->guc_active.lock);
+
+	list_del_init(&rq->sched.link);
+	clear_bit(I915_FENCE_FLAG_PQUEUE, &rq->fence.flags);
+
+	/* Prevent further __await_execution() registering a cb, then flush */
+	set_bit(I915_FENCE_FLAG_ACTIVE, &rq->fence.flags);
+
+	spin_unlock_irq(&ce->guc_active.lock);
+
+	atomic_dec(&ce->guc_id_ref);
+	i915_request_notify_execute_cb_imm(rq);
+}
+
 static const struct intel_context_ops guc_context_ops = {
 	.alloc = guc_context_alloc,
 
@@ -1568,6 +1595,8 @@ static void guc_default_vfuncs(struct intel_engine_cs *engine)
 
 	engine->cops = &guc_context_ops;
 	engine->request_alloc = guc_request_alloc;
+	engine->add_active_request = add_to_context;
+	engine->remove_active_request = remove_from_context;
 
 	engine->sched_engine->schedule = i915_schedule;
 
@@ -1932,6 +1961,10 @@ guc_create_virtual(struct intel_engine_cs **siblings, unsigned int count)
 				 "v%dx%d", ve->base.class, count);
 			ve->base.context_size = sibling->context_size;
 
+			ve->base.add_active_request =
+				sibling->add_active_request;
+			ve->base.remove_active_request =
+				sibling->remove_active_request;
 			ve->base.emit_bb_start = sibling->emit_bb_start;
 			ve->base.emit_flush = sibling->emit_flush;
 			ve->base.emit_init_breadcrumb =
drivers/gpu/drm/i915/i915_request.c +4 -37

71 lines not on this page · raw message

drivers/gpu/drm/i915/i915_request.h +2 -0
index 717e5b292046..128030f43bbf 100644
@@ -647,4 +647,6 @@ bool
 i915_request_active_engine(struct i915_request *rq,
 			   struct intel_engine_cs **active);
 
+void i915_request_notify_execute_cb_imm(struct i915_request *rq);
+
 #endif /* I915_REQUEST_H */
Signature · 1 line
2.28.0
#9 lore raw

PATCH 8/33 drm/i915/guc: Reset implementation for new GuC interface

In reply to Matthew Brost

Reset implementation for new GuC interface. This is the legacy reset implementation which is called when the i915 owns the engine hang check. Future patches will offload the engine hang check to GuC but we will continue to maintain this legacy path as a fallback and this code path is also required if the GuC dies.

With the new GuC interface it is not possible to reset individual engines - it is only possible to reset the GPU entirely. This patch forces an entire chip reset if any engine hangs.

v2:
(Michal)
- Check for -EPIPE rather than -EIO (CT deadlock/corrupt check)
v3:
(John H)
- Split into a series of smaller patches
v4:
(John H)
- Fix typo
- Add braces around if statements in reset code
v5:
(Checkpatch)
- Fix warnings

---
 drivers/gpu/drm/i915/gt/intel_gt_pm.c         |   6 +-
 drivers/gpu/drm/i915/gt/intel_reset.c         |  18 +-
 drivers/gpu/drm/i915/gt/uc/intel_guc.c        |  13 -
 drivers/gpu/drm/i915/gt/uc/intel_guc.h        |   8 +-
 .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 562 ++++++++++++++----
 drivers/gpu/drm/i915/gt/uc/intel_uc.c         |  38 +-
 drivers/gpu/drm/i915/gt/uc/intel_uc.h         |   3 +
 7 files changed, 516 insertions(+), 132 deletions(-)
drivers/gpu/drm/i915/gt/intel_gt_pm.c +4 -2
index d86825437516..cd7b96005d29 100644
@@ -170,8 +170,6 @@ static void gt_sanitize(struct intel_gt *gt, bool force)
 	if (intel_gt_is_wedged(gt))
 		intel_gt_unset_wedged(gt);
 
-	intel_uc_sanitize(&gt->uc);
-
 	for_each_engine(engine, gt, id)
 		if (engine->reset.prepare)
 			engine->reset.prepare(engine);
@@ -187,6 +185,8 @@ static void gt_sanitize(struct intel_gt *gt, bool force)
 			__intel_engine_reset(engine, false);
 	}
 
+	intel_uc_reset(&gt->uc, false);
+
 	for_each_engine(engine, gt, id)
 		if (engine->reset.finish)
 			engine->reset.finish(engine);
@@ -239,6 +239,8 @@ int intel_gt_resume(struct intel_gt *gt)
 		goto err_wedged;
 	}
 
+	intel_uc_reset_finish(&gt->uc);
+
 	intel_rps_enable(&gt->rps);
 	intel_llc_enable(&gt->llc);
 
drivers/gpu/drm/i915/gt/intel_reset.c +12 -6
index 9586613ee399..721a10e2215e 100644
@@ -832,6 +832,8 @@ static int gt_reset(struct intel_gt *gt, intel_engine_mask_t stalled_mask)
 		__intel_engine_reset(engine, stalled_mask & engine->mask);
 	local_bh_enable();
 
+	intel_uc_reset(&gt->uc, true);
+
 	intel_ggtt_restore_fences(gt->ggtt);
 
 	return err;
@@ -856,6 +858,8 @@ static void reset_finish(struct intel_gt *gt, intel_engine_mask_t awake)
 		if (awake & engine->mask)
 			intel_engine_pm_put(engine);
 	}
+
+	intel_uc_reset_finish(&gt->uc);
 }
 
 static void nop_submit_request(struct i915_request *request)
@@ -909,6 +913,7 @@ static void __intel_gt_set_wedged(struct intel_gt *gt)
 	for_each_engine(engine, gt, id)
 		if (engine->reset.cancel)
 			engine->reset.cancel(engine);
+	intel_uc_cancel_requests(&gt->uc);
 	local_bh_enable();
 
 	reset_finish(gt, awake);
@@ -1197,6 +1202,9 @@ int __intel_engine_reset_bh(struct intel_engine_cs *engine, const char *msg)
 	ENGINE_TRACE(engine, "flags=%lx\n", gt->reset.flags);
 	GEM_BUG_ON(!test_bit(I915_RESET_ENGINE + engine->id, &gt->reset.flags));
 
+	if (intel_engine_uses_guc(engine))
+		return -ENODEV;
+
 	if (!intel_engine_pm_get_if_awake(engine))
 		return 0;
 
@@ -1207,13 +1215,10 @@ int __intel_engine_reset_bh(struct intel_engine_cs *engine, const char *msg)
 			   "Resetting %s for %s\n", engine->name, msg);
 	atomic_inc(&engine->i915->gpu_error.reset_engine_count[engine->uabi_class]);
 
-	if (intel_engine_uses_guc(engine))
-		ret = intel_guc_reset_engine(&engine->gt->uc.guc, engine);
-	else
-		ret = intel_gt_reset_engine(engine);
+	ret = intel_gt_reset_engine(engine);
 	if (ret) {
 		/* If we fail here, we expect to fallback to a global reset */
-		ENGINE_TRACE(engine, "Failed to reset, err: %d\n", ret);
+		ENGINE_TRACE(engine, "Failed to reset %s, err: %d\n", engine->name, ret);
 		goto out;
 	}
 
@@ -1347,7 +1352,8 @@ void intel_gt_handle_error(struct intel_gt *gt,
 	 * Try engine reset when available. We fall back to full reset if
 	 * single reset fails.
 	 */
-	if (intel_has_reset_engine(gt) && !intel_gt_is_wedged(gt)) {
+	if (!intel_uc_uses_guc_submission(&gt->uc) &&
+	    intel_has_reset_engine(gt) && !intel_gt_is_wedged(gt)) {
 		local_bh_disable();
 		for_each_engine_masked(engine, gt, engine_mask, tmp) {
 			BUILD_BUG_ON(I915_RESET_MODESET >= I915_RESET_ENGINE);
drivers/gpu/drm/i915/gt/uc/intel_guc.c +0 -13
index 6661dcb02239..9b09395b998f 100644
@@ -572,19 +572,6 @@ int intel_guc_suspend(struct intel_guc *guc)
 	return 0;
 }
 
-/**
- * intel_guc_reset_engine() - ask GuC to reset an engine
- * @guc:	intel_guc structure
- * @engine:	engine to be reset
- */
-int intel_guc_reset_engine(struct intel_guc *guc,
-			   struct intel_engine_cs *engine)
-{
-	/* XXX: to be implemented with submission interface rework */
-
-	return -ENODEV;
-}
-
 /**
  * intel_guc_resume() - notify GuC resuming from suspend state
  * @guc:	the guc
drivers/gpu/drm/i915/gt/uc/intel_guc.h +5 -3
index d4987cd789ea..a068e3262676 100644
@@ -249,14 +249,16 @@ static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)
 
 int intel_guc_wait_for_idle(struct intel_guc *guc, long timeout);
 
-int intel_guc_reset_engine(struct intel_guc *guc,
-			   struct intel_engine_cs *engine);
-
 int intel_guc_deregister_done_process_msg(struct intel_guc *guc,
 					  const u32 *msg, u32 len);
 int intel_guc_sched_done_process_msg(struct intel_guc *guc,
 				     const u32 *msg, u32 len);
 
+void intel_guc_submission_reset_prepare(struct intel_guc *guc);
+void intel_guc_submission_reset(struct intel_guc *guc, bool stalled);
+void intel_guc_submission_reset_finish(struct intel_guc *guc);
+void intel_guc_submission_cancel_requests(struct intel_guc *guc);
+
 void intel_guc_load_status(struct intel_guc *guc, struct drm_printer *p);
 
 #endif
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +455 -107

853 lines not on this page · raw message

drivers/gpu/drm/i915/gt/uc/intel_uc.c +37 -1
index 6d8b9233214e..9a5ef1dca022 100644
@@ -565,12 +565,48 @@ void intel_uc_reset_prepare(struct intel_uc *uc)
 {
 	struct intel_guc *guc = &uc->guc;
 
-	if (!intel_guc_is_ready(guc))
+	/* Nothing to do if GuC isn't supported */
+	if (!intel_uc_supports_guc(uc))
 		return;
 
+	/* Firmware expected to be running when this function is called */
+	if (!intel_guc_is_ready(guc))
+		goto sanitize;
+
+	if (intel_uc_uses_guc_submission(uc))
+		intel_guc_submission_reset_prepare(guc);
+
+sanitize:
 	__uc_sanitize(uc);
 }
 
+void intel_uc_reset(struct intel_uc *uc, bool stalled)
+{
+	struct intel_guc *guc = &uc->guc;
+
+	/* Firmware can not be running when this function is called  */
+	if (intel_uc_uses_guc_submission(uc))
+		intel_guc_submission_reset(guc, stalled);
+}
+
+void intel_uc_reset_finish(struct intel_uc *uc)
+{
+	struct intel_guc *guc = &uc->guc;
+
+	/* Firmware expected to be running when this function is called */
+	if (intel_guc_is_fw_running(guc) && intel_uc_uses_guc_submission(uc))
+		intel_guc_submission_reset_finish(guc);
+}
+
+void intel_uc_cancel_requests(struct intel_uc *uc)
+{
+	struct intel_guc *guc = &uc->guc;
+
+	/* Firmware can not be running when this function is called  */
+	if (intel_uc_uses_guc_submission(uc))
+		intel_guc_submission_cancel_requests(guc);
+}
+
 void intel_uc_runtime_suspend(struct intel_uc *uc)
 {
 	struct intel_guc *guc = &uc->guc;
drivers/gpu/drm/i915/gt/uc/intel_uc.h +3 -0
index c4cef885e984..eaa3202192ac 100644
@@ -37,6 +37,9 @@ void intel_uc_driver_late_release(struct intel_uc *uc);
 void intel_uc_driver_remove(struct intel_uc *uc);
 void intel_uc_init_mmio(struct intel_uc *uc);
 void intel_uc_reset_prepare(struct intel_uc *uc);
+void intel_uc_reset(struct intel_uc *uc, bool stalled);
+void intel_uc_reset_finish(struct intel_uc *uc);
+void intel_uc_cancel_requests(struct intel_uc *uc);
 void intel_uc_suspend(struct intel_uc *uc);
 void intel_uc_runtime_suspend(struct intel_uc *uc);
 int intel_uc_resume(struct intel_uc *uc);
Signature · 1 line
2.28.0
#10 lore raw

PATCH 9/33 drm/i915: Reset GPU immediately if submission is disabled

In reply to Matthew Brost

If submission is disabled by the backend for any reason, reset the GPU immediately in the heartbeat code as the backend can't be reenabled until the GPU is reset.

---
 .../gpu/drm/i915/gt/intel_engine_heartbeat.c  | 62 +++++++++++++++----
 .../gpu/drm/i915/gt/intel_engine_heartbeat.h  |  4 ++
 .../gpu/drm/i915/gt/uc/intel_guc_submission.c |  9 +++
 drivers/gpu/drm/i915/i915_scheduler.c         |  6 ++
 drivers/gpu/drm/i915/i915_scheduler.h         |  6 ++
 drivers/gpu/drm/i915/i915_scheduler_types.h   |  5 ++
 6 files changed, 79 insertions(+), 13 deletions(-)
drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c +49 -13
index b6a305e6a974..0b16f19c384e 100644
@@ -70,12 +70,30 @@ static void show_heartbeat(const struct i915_request *rq,
 {
 	struct drm_printer p = drm_debug_printer("heartbeat");
 
-	intel_engine_dump(engine, &p,
-			  "%s heartbeat {seqno:%llx:%lld, prio:%d} not ticking\n",
-			  engine->name,
-			  rq->fence.context,
-			  rq->fence.seqno,
-			  rq->sched.attr.priority);
+	if (!rq) {
+		intel_engine_dump(engine, &p,
+				  "%s heartbeat not ticking\n",
+				  engine->name);
+	} else {
+		intel_engine_dump(engine, &p,
+				  "%s heartbeat {seqno:%llx:%lld, prio:%d} not ticking\n",
+				  engine->name,
+				  rq->fence.context,
+				  rq->fence.seqno,
+				  rq->sched.attr.priority);
+	}
+}
+
+static void
+reset_engine(struct intel_engine_cs *engine, struct i915_request *rq)
+{
+	if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM))
+		show_heartbeat(rq, engine);
+
+	intel_gt_handle_error(engine->gt, engine->mask,
+			      I915_ERROR_CAPTURE,
+			      "stopped heartbeat on %s",
+			      engine->name);
 }
 
 static void heartbeat(struct work_struct *wrk)
@@ -102,6 +120,11 @@ static void heartbeat(struct work_struct *wrk)
 	if (intel_gt_is_wedged(engine->gt))
 		goto out;
 
+	if (i915_sched_engine_disabled(engine->sched_engine)) {
+		reset_engine(engine, engine->heartbeat.systole);
+		goto out;
+	}
+
 	if (engine->heartbeat.systole) {
 		long delay = READ_ONCE(engine->props.heartbeat_interval_ms);
 
@@ -139,13 +162,7 @@ static void heartbeat(struct work_struct *wrk)
 			engine->sched_engine->schedule(rq, &attr);
 			local_bh_enable();
 		} else {
-			if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM))
-				show_heartbeat(rq, engine);
-
-			intel_gt_handle_error(engine->gt, engine->mask,
-					      I915_ERROR_CAPTURE,
-					      "stopped heartbeat on %s",
-					      engine->name);
+			reset_engine(engine, rq);
 		}
 
 		rq->emitted_jiffies = jiffies;
@@ -194,6 +211,25 @@ void intel_engine_park_heartbeat(struct intel_engine_cs *engine)
 		i915_request_put(fetch_and_zero(&engine->heartbeat.systole));
 }
 
+void intel_gt_unpark_heartbeats(struct intel_gt *gt)
+{
+	struct intel_engine_cs *engine;
+	enum intel_engine_id id;
+
+	for_each_engine(engine, gt, id)
+		if (intel_engine_pm_is_awake(engine))
+			intel_engine_unpark_heartbeat(engine);
+}
+
+void intel_gt_park_heartbeats(struct intel_gt *gt)
+{
+	struct intel_engine_cs *engine;
+	enum intel_engine_id id;
+
+	for_each_engine(engine, gt, id)
+		intel_engine_park_heartbeat(engine);
+}
+
 void intel_engine_init_heartbeat(struct intel_engine_cs *engine)
 {
 	INIT_DELAYED_WORK(&engine->heartbeat.work, heartbeat);
drivers/gpu/drm/i915/gt/intel_engine_heartbeat.h +4 -0
index a488ea3e84a3..5da6d809a87a 100644
@@ -7,6 +7,7 @@
 #define INTEL_ENGINE_HEARTBEAT_H
 
 struct intel_engine_cs;
+struct intel_gt;
 
 void intel_engine_init_heartbeat(struct intel_engine_cs *engine);
 
@@ -16,6 +17,9 @@ int intel_engine_set_heartbeat(struct intel_engine_cs *engine,
 void intel_engine_park_heartbeat(struct intel_engine_cs *engine);
 void intel_engine_unpark_heartbeat(struct intel_engine_cs *engine);
 
+void intel_gt_park_heartbeats(struct intel_gt *gt);
+void intel_gt_unpark_heartbeats(struct intel_gt *gt);
+
 int intel_engine_pulse(struct intel_engine_cs *engine);
 int intel_engine_flush_barriers(struct intel_engine_cs *engine);
 
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +9 -0
index be13a33ef17e..dd4ea1ef5731 100644
@@ -10,6 +10,7 @@
 #include "gt/intel_breadcrumbs.h"
 #include "gt/intel_context.h"
 #include "gt/intel_engine_pm.h"
+#include "gt/intel_engine_heartbeat.h"
 #include "gt/intel_gt.h"
 #include "gt/intel_gt_irq.h"
 #include "gt/intel_gt_pm.h"
@@ -603,6 +604,7 @@ void intel_guc_submission_reset_prepare(struct intel_guc *guc)
 		return;
 	}
 
+	intel_gt_park_heartbeats(guc_to_gt(guc));
 	disable_submission(guc);
 	guc->interrupts.disable(guc);
 
@@ -890,6 +892,7 @@ void intel_guc_submission_reset_finish(struct intel_guc *guc)
 	atomic_set(&guc->outstanding_submission_g2h, 0);
 
 	enable_submission(guc);
+	intel_gt_unpark_heartbeats(guc_to_gt(guc));
 }
 
 /*
@@ -1866,6 +1869,11 @@ static int guc_resume(struct intel_engine_cs *engine)
 	return 0;
 }
 
+static bool guc_sched_engine_disabled(struct i915_sched_engine *sched_engine)
+{
+	return !sched_engine->tasklet.callback;
+}
+
 static void guc_set_default_submission(struct intel_engine_cs *engine)
 {
 	engine->submit_request = guc_submit_request;
@@ -2016,6 +2024,7 @@ int intel_guc_submission_setup(struct intel_engine_cs *engine)
 			return -ENOMEM;
 
 		guc->sched_engine->schedule = i915_schedule;
+		guc->sched_engine->disabled = guc_sched_engine_disabled;
 		guc->sched_engine->private_data = guc;
 		guc->sched_engine->destroy = guc_sched_engine_destroy;
 		tasklet_setup(&guc->sched_engine->tasklet,
drivers/gpu/drm/i915/i915_scheduler.c +6 -0
index 2804fd5b660b..28dd887eb1be 100644
@@ -440,6 +440,11 @@ static void default_destroy(struct kref *kref)
 	kfree(sched_engine);
 }
 
+static bool default_disabled(struct i915_sched_engine *sched_engine)
+{
+	return false;
+}
+
 struct i915_sched_engine *
 i915_sched_engine_create(unsigned int subclass)
 {
@@ -454,6 +459,7 @@ i915_sched_engine_create(unsigned int subclass)
 	sched_engine->queue = RB_ROOT_CACHED;
 	sched_engine->queue_priority_hint = INT_MIN;
 	sched_engine->destroy = default_destroy;
+	sched_engine->disabled = default_disabled;
 
 	INIT_LIST_HEAD(&sched_engine->requests);
 	INIT_LIST_HEAD(&sched_engine->hold);
drivers/gpu/drm/i915/i915_scheduler.h +6 -0
index 3c9504e9f409..f4d9811ade5b 100644
@@ -96,4 +96,10 @@ void i915_request_show_with_schedule(struct drm_printer *m,
 				     const char *prefix,
 				     int indent);
 
+static inline bool
+i915_sched_engine_disabled(struct i915_sched_engine *sched_engine)
+{
+	return sched_engine->disabled(sched_engine);
+}
+
 #endif /* _I915_SCHEDULER_H_ */
drivers/gpu/drm/i915/i915_scheduler_types.h +5 -0
index 00384e2c5273..eaef233e9080 100644
@@ -168,6 +168,11 @@ struct i915_sched_engine {
 	 */
 	void	(*destroy)(struct kref *kref);
 
+	/**
+	 * @disabled: check if backend has disabled submission
+	 */
+	bool	(*disabled)(struct i915_sched_engine *sched_engine);
+
 	/**
 	 * @kick_backend: kick backend after a request's priority has changed
 	 */
Signature · 6 lines
2.28.0

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

PATCH 10/33 drm/i915/guc: Add disable interrupts to guc sanitize

In reply to Matthew Brost

Add disable GuC interrupts to intel_guc_sanitize(). Part of this requires moving the guc_*_interrupt wrapper function into header file intel_guc.h.

---
 drivers/gpu/drm/i915/gt/uc/intel_guc.h | 16 ++++++++++++++++
 drivers/gpu/drm/i915/gt/uc/intel_uc.c  | 21 +++------------------
 2 files changed, 19 insertions(+), 18 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +16 -0
index a068e3262676..7b871f675e48 100644
@@ -224,9 +224,25 @@ static inline bool intel_guc_is_ready(struct intel_guc *guc)
 	return intel_guc_is_fw_running(guc) && intel_guc_ct_enabled(&guc->ct);
 }
 
+static inline void intel_guc_reset_interrupts(struct intel_guc *guc)
+{
+	guc->interrupts.reset(guc);
+}
+
+static inline void intel_guc_enable_interrupts(struct intel_guc *guc)
+{
+	guc->interrupts.enable(guc);
+}
+
+static inline void intel_guc_disable_interrupts(struct intel_guc *guc)
+{
+	guc->interrupts.disable(guc);
+}
+
 static inline int intel_guc_sanitize(struct intel_guc *guc)
 {
 	intel_uc_fw_sanitize(&guc->fw);
+	intel_guc_disable_interrupts(guc);
 	intel_guc_ct_sanitize(&guc->ct);
 	guc->mmio_msg = 0;
 
drivers/gpu/drm/i915/gt/uc/intel_uc.c +3 -18
index 9a5ef1dca022..05a2001afde9 100644
@@ -207,21 +207,6 @@ static void guc_handle_mmio_msg(struct intel_guc *guc)
 	spin_unlock_irq(&guc->irq_lock);
 }
 
-static void guc_reset_interrupts(struct intel_guc *guc)
-{
-	guc->interrupts.reset(guc);
-}
-
-static void guc_enable_interrupts(struct intel_guc *guc)
-{
-	guc->interrupts.enable(guc);
-}
-
-static void guc_disable_interrupts(struct intel_guc *guc)
-{
-	guc->interrupts.disable(guc);
-}
-
 static int guc_enable_communication(struct intel_guc *guc)
 {
 	struct intel_gt *gt = guc_to_gt(guc);
@@ -242,7 +227,7 @@ static int guc_enable_communication(struct intel_guc *guc)
 	guc_get_mmio_msg(guc);
 	guc_handle_mmio_msg(guc);
 
-	guc_enable_interrupts(guc);
+	intel_guc_enable_interrupts(guc);
 
 	/* check for CT messages received before we enabled interrupts */
 	spin_lock_irq(&gt->irq_lock);
@@ -265,7 +250,7 @@ static void guc_disable_communication(struct intel_guc *guc)
 	 */
 	guc_clear_mmio_msg(guc);
 
-	guc_disable_interrupts(guc);
+	intel_guc_disable_interrupts(guc);
 
 	intel_guc_ct_disable(&guc->ct);
 
@@ -463,7 +448,7 @@ static int __uc_init_hw(struct intel_uc *uc)
 	if (ret)
 		goto err_out;
 
-	guc_reset_interrupts(guc);
+	intel_guc_reset_interrupts(guc);
 
 	/* WaEnableuKernelHeaderValidFix:skl */
 	/* WaEnableGuCBootHashCheckNotSet:skl,bxt,kbl */
Signature · 1 line
2.28.0
#12 lore raw

PATCH 11/33 drm/i915/guc: Suspend/resume implementation for new interface

In reply to Matthew Brost

The new GuC interface introduces an MMIO H2G command, INTEL_GUC_ACTION_RESET_CLIENT, which is used to implement suspend. This MMIO tears down any active contexts generating a context reset G2H CTB for each. Once that step completes the GuC tears down the CTB channels. It is safe to suspend once this MMIO H2G command completes and all G2H CTBs have been processed. In practice the i915 will likely never receive a G2H as suspend should only be called after the GPU is idle.

Resume is implemented in the same manner as before - simply reload the GuC firmware and reinitialize everything (e.g. CTB channels, contexts, etc..).

v2:
(Michel / John H)
- INTEL_GUC_ACTION_RESET_CLIENT 0x5B01 -> 0x5507

---
 .../gpu/drm/i915/gt/uc/abi/guc_actions_abi.h  |  1 +
 drivers/gpu/drm/i915/gt/uc/intel_guc.c        | 64 ++++++++-----------
 .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 15 +++--
 .../gpu/drm/i915/gt/uc/intel_guc_submission.h |  5 ++
 drivers/gpu/drm/i915/gt/uc/intel_uc.c         | 20 ++++--
 5 files changed, 54 insertions(+), 51 deletions(-)
drivers/gpu/drm/i915/gt/uc/abi/guc_actions_abi.h +1 -0
index 57e18babdf4b..d832c8f11c11 100644
@@ -142,6 +142,7 @@ enum intel_guc_action {
 	INTEL_GUC_ACTION_REGISTER_COMMAND_TRANSPORT_BUFFER = 0x4505,
 	INTEL_GUC_ACTION_DEREGISTER_COMMAND_TRANSPORT_BUFFER = 0x4506,
 	INTEL_GUC_ACTION_DEREGISTER_CONTEXT_DONE = 0x4600,
+	INTEL_GUC_ACTION_RESET_CLIENT = 0x5507,
 	INTEL_GUC_ACTION_LIMIT
 };
 
drivers/gpu/drm/i915/gt/uc/intel_guc.c +26 -38

84 lines not on this page · raw message

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +8 -7
index dd4ea1ef5731..d39a312e980a 100644
@@ -302,10 +302,10 @@ static int guc_submission_send_busy_loop(struct intel_guc *guc,
 	return err;
 }
 
-static int guc_wait_for_pending_msg(struct intel_guc *guc,
-				    atomic_t *wait_var,
-				    bool interruptible,
-				    long timeout)
+int intel_guc_wait_for_pending_msg(struct intel_guc *guc,
+				   atomic_t *wait_var,
+				   bool interruptible,
+				   long timeout)
 {
 	const int state = interruptible ?
 		TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE;
@@ -348,8 +348,9 @@ int intel_guc_wait_for_idle(struct intel_guc *guc, long timeout)
 	if (!intel_uc_uses_guc_submission(&guc_to_gt(guc)->uc))
 		return 0;
 
-	return guc_wait_for_pending_msg(guc, &guc->outstanding_submission_g2h,
-					true, timeout);
+	return intel_guc_wait_for_pending_msg(guc,
+					      &guc->outstanding_submission_g2h,
+					      true, timeout);
 }
 
 static int guc_lrc_desc_pin(struct intel_context *ce, bool loop);
@@ -623,7 +624,7 @@ void intel_guc_submission_reset_prepare(struct intel_guc *guc)
 	for (i = 0; i < 4 && atomic_read(&guc->outstanding_submission_g2h); ++i) {
 		intel_guc_to_host_event_handler(guc);
 #define wait_for_reset(guc, wait_var) \
-		guc_wait_for_pending_msg(guc, wait_var, false, (HZ / 20))
+		intel_guc_wait_for_pending_msg(guc, wait_var, false, (HZ / 20))
 		do {
 			wait_for_reset(guc, &guc->outstanding_submission_g2h);
 		} while (!list_empty(&guc->ct.requests.incoming));
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.h +5 -0
index 5f263ac4f46a..08ff77c5c50e 100644
@@ -28,6 +28,11 @@ void intel_guc_submission_print_context_info(struct intel_guc *guc,
 
 bool intel_guc_virtual_engine_has_heartbeat(const struct intel_engine_cs *ve);
 
+int intel_guc_wait_for_pending_msg(struct intel_guc *guc,
+				   atomic_t *wait_var,
+				   bool interruptible,
+				   long timeout);
+
 static inline bool intel_guc_submission_is_supported(struct intel_guc *guc)
 {
 	/* XXX: GuC submission is unavailable for now */
drivers/gpu/drm/i915/gt/uc/intel_uc.c +14 -6
index 05a2001afde9..e07c989968f9 100644
@@ -595,14 +595,18 @@ void intel_uc_cancel_requests(struct intel_uc *uc)
 void intel_uc_runtime_suspend(struct intel_uc *uc)
 {
 	struct intel_guc *guc = &uc->guc;
-	int err;
 
 	if (!intel_guc_is_ready(guc))
 		return;
 
-	err = intel_guc_suspend(guc);
-	if (err)
-		DRM_DEBUG_DRIVER("Failed to suspend GuC, err=%d", err);
+	/*
+	 * Wait for any outstanding CTB before tearing down communication /w the
+	 * GuC.
+	 */
+#define OUTSTANDING_CTB_TIMEOUT_PERIOD	(HZ / 5)
+	intel_guc_wait_for_pending_msg(guc, &guc->outstanding_submission_g2h,
+				       false, OUTSTANDING_CTB_TIMEOUT_PERIOD);
+	GEM_WARN_ON(atomic_read(&guc->outstanding_submission_g2h));
 
 	guc_disable_communication(guc);
 }
@@ -611,12 +615,16 @@ void intel_uc_suspend(struct intel_uc *uc)
 {
 	struct intel_guc *guc = &uc->guc;
 	intel_wakeref_t wakeref;
+	int err;
 
 	if (!intel_guc_is_ready(guc))
 		return;
 
-	with_intel_runtime_pm(uc_to_gt(uc)->uncore->rpm, wakeref)
-		intel_uc_runtime_suspend(uc);
+	with_intel_runtime_pm(&uc_to_gt(uc)->i915->runtime_pm, wakeref) {
+		err = intel_guc_suspend(guc);
+		if (err)
+			DRM_DEBUG_DRIVER("Failed to suspend GuC, err=%d", err);
+	}
 }
 
 static int __uc_resume(struct intel_uc *uc, bool enable_communication)
Signature · 6 lines
2.28.0

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

PATCH 12/33 drm/i915/guc: Handle context reset notification

In reply to Matthew Brost

GuC will issue a reset on detecting an engine hang and will notify the driver via a G2H message. The driver will service the notification by resetting the guilty context to a simple state or banning it completely.

v2:
(John Harrison)
- Move msg[0] lookup after length check
v3:
(John Harrison)
- s/drm_dbg/drm_err

---
 drivers/gpu/drm/i915/gt/uc/intel_guc.h        |  2 ++
 drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c     |  3 ++
 .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 36 +++++++++++++++++++
 drivers/gpu/drm/i915/i915_trace.h             | 10 ++++++
 4 files changed, 51 insertions(+)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2 -0
index 7b871f675e48..c79da154c16d 100644
@@ -269,6 +269,8 @@ int intel_guc_deregister_done_process_msg(struct intel_guc *guc,
 					  const u32 *msg, u32 len);
 int intel_guc_sched_done_process_msg(struct intel_guc *guc,
 				     const u32 *msg, u32 len);
+int intel_guc_context_reset_process_msg(struct intel_guc *guc,
+					const u32 *msg, u32 len);
 
 void intel_guc_submission_reset_prepare(struct intel_guc *guc);
 void intel_guc_submission_reset(struct intel_guc *guc, bool stalled);
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3 -0
index 8bb6b1bbcea1..231a42887675 100644
@@ -984,6 +984,9 @@ static int ct_process_request(struct intel_guc_ct *ct, struct ct_incoming_msg *r
 	case INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_DONE:
 		ret = intel_guc_sched_done_process_msg(guc, payload, len);
 		break;
+	case INTEL_GUC_ACTION_CONTEXT_RESET_NOTIFICATION:
+		ret = intel_guc_context_reset_process_msg(guc, payload, len);
+		break;
 	default:
 		ret = -EOPNOTSUPP;
 		break;
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +36 -0
index d39a312e980a..7be84b0761b5 100644
@@ -2201,6 +2201,42 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,
 	return 0;
 }
 
+static void guc_context_replay(struct intel_context *ce)
+{
+	struct i915_sched_engine *sched_engine = ce->engine->sched_engine;
+
+	__guc_reset_context(ce, true);
+	tasklet_hi_schedule(&sched_engine->tasklet);
+}
+
+static void guc_handle_context_reset(struct intel_guc *guc,
+				     struct intel_context *ce)
+{
+	trace_intel_context_reset(ce);
+	guc_context_replay(ce);
+}
+
+int intel_guc_context_reset_process_msg(struct intel_guc *guc,
+					const u32 *msg, u32 len)
+{
+	struct intel_context *ce;
+	int desc_idx;
+
+	if (unlikely(len != 1)) {
+		drm_err(&guc_to_gt(guc)->i915->drm, "Invalid length %u", len);
+		return -EPROTO;
+	}
+
+	desc_idx = msg[0];
+	ce = g2h_context_lookup(guc, desc_idx);
+	if (unlikely(!ce))
+		return -EPROTO;
+
+	guc_handle_context_reset(guc, ce);
+
+	return 0;
+}
+
 void intel_guc_submission_print_info(struct intel_guc *guc,
 				     struct drm_printer *p)
 {
drivers/gpu/drm/i915/i915_trace.h +10 -0
index 68b70626c3e2..3f43d904f043 100644
@@ -920,6 +920,11 @@ DECLARE_EVENT_CLASS(intel_context,
 			      __entry->guc_sched_state_no_lock)
 );
 
+DEFINE_EVENT(intel_context, intel_context_reset,
+	     TP_PROTO(struct intel_context *ce),
+	     TP_ARGS(ce)
+);
+
 DEFINE_EVENT(intel_context, intel_context_register,
 	     TP_PROTO(struct intel_context *ce),
 	     TP_ARGS(ce)
@@ -1007,6 +1012,11 @@ trace_i915_request_out(struct i915_request *rq)
 {
 }
 
+static inline void
+trace_intel_context_reset(struct intel_context *ce)
+{
+}
+
 static inline void
 trace_intel_context_register(struct intel_context *ce)
 {
Signature · 1 line
2.28.0
#14 lore raw

PATCH 13/33 drm/i915/guc: Handle engine reset failure notification

In reply to Matthew Brost

GuC will notify the driver, via G2H, if it fails to reset an engine. We recover by resorting to a full GPU reset.

v2:
(John Harrison):
- s/drm_dbg/drm_err

---
 drivers/gpu/drm/i915/gt/uc/intel_guc.h        |  2 +
 drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c     |  3 ++
 .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 43 +++++++++++++++++++
 3 files changed, 48 insertions(+)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2 -0
index c79da154c16d..9c8d53a32e0d 100644
@@ -271,6 +271,8 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,
 				     const u32 *msg, u32 len);
 int intel_guc_context_reset_process_msg(struct intel_guc *guc,
 					const u32 *msg, u32 len);
+int intel_guc_engine_failure_process_msg(struct intel_guc *guc,
+					 const u32 *msg, u32 len);
 
 void intel_guc_submission_reset_prepare(struct intel_guc *guc);
 void intel_guc_submission_reset(struct intel_guc *guc, bool stalled);
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3 -0
index 231a42887675..18917b443f05 100644
@@ -987,6 +987,9 @@ static int ct_process_request(struct intel_guc_ct *ct, struct ct_incoming_msg *r
 	case INTEL_GUC_ACTION_CONTEXT_RESET_NOTIFICATION:
 		ret = intel_guc_context_reset_process_msg(guc, payload, len);
 		break;
+	case INTEL_GUC_ACTION_ENGINE_FAILURE_NOTIFICATION:
+		ret = intel_guc_engine_failure_process_msg(guc, payload, len);
+		break;
 	default:
 		ret = -EOPNOTSUPP;
 		break;
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +43 -0

49 lines not on this page · raw message

Signature · 1 line
2.28.0
#15 lore raw

PATCH 14/33 drm/i915/guc: Enable the timer expired interrupt for GuC

In reply to Matthew Brost

The GuC can implement execution qunatums, detect hung contexts and other such things but it requires the timer expired interrupt to do so.

---
 drivers/gpu/drm/i915/gt/intel_rps.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/i915/gt/intel_rps.c +4 -0
index 06e9a8ed4e03..0c8e7f2b06f0 100644
@@ -1877,6 +1877,10 @@ void intel_rps_init(struct intel_rps *rps)
 
 	if (GRAPHICS_VER(i915) >= 8 && GRAPHICS_VER(i915) < 11)
 		rps->pm_intrmsk_mbz |= GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC;
+
+	/* GuC needs ARAT expired interrupt unmasked */
+	if (intel_uc_uses_guc_submission(&rps_to_gt(rps)->uc))
+		rps->pm_intrmsk_mbz |= ARAT_EXPIRED_INTRMSK;
 }
 
 void intel_rps_sanitize(struct intel_rps *rps)
Signature · 6 lines
2.28.0

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

PATCH 15/33 drm/i915/guc: Provide mmio list to be saved/restored on engine reset

In reply to Matthew Brost

From: John Harrison <[email protected]>

The driver must provide GuC with a list of mmio registers that should be saved/restored during a GuC-based engine reset. Unfortunately, the list must be dynamically allocated as its size is variable. That means the driver must generate the list twice - once to work out the size and a second time to actually save it.

v2:
(Alan / CI)
- GEN7_GT_MODE -> GEN6_GT_MODE to fix WA selftest failure

---
 drivers/gpu/drm/i915/gt/intel_workarounds.c   |  46 ++--
 .../gpu/drm/i915/gt/intel_workarounds_types.h |   1 +
 drivers/gpu/drm/i915/gt/uc/intel_guc.h        |   1 +
 drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c    | 199 +++++++++++++++++-
 drivers/gpu/drm/i915/i915_reg.h               |   1 +
 5 files changed, 222 insertions(+), 26 deletions(-)
drivers/gpu/drm/i915/gt/intel_workarounds.c +24 -22
index 3aa5ce3cda8b..9173df59821a 100644
@@ -150,13 +150,14 @@ static void _wa_add(struct i915_wa_list *wal, const struct i915_wa *wa)
 }
 
 static void wa_add(struct i915_wa_list *wal, i915_reg_t reg,
-		   u32 clear, u32 set, u32 read_mask)
+		   u32 clear, u32 set, u32 read_mask, bool masked_reg)
 {
 	struct i915_wa wa = {
 		.reg  = reg,
 		.clr  = clear,
 		.set  = set,
 		.read = read_mask,
+		.masked_reg = masked_reg,
 	};
 
 	_wa_add(wal, &wa);
@@ -165,7 +166,7 @@ static void wa_add(struct i915_wa_list *wal, i915_reg_t reg,
 static void
 wa_write_clr_set(struct i915_wa_list *wal, i915_reg_t reg, u32 clear, u32 set)
 {
-	wa_add(wal, reg, clear, set, clear);
+	wa_add(wal, reg, clear, set, clear, false);
 }
 
 static void
@@ -200,20 +201,20 @@ wa_write_clr(struct i915_wa_list *wal, i915_reg_t reg, u32 clr)
 static void
 wa_masked_en(struct i915_wa_list *wal, i915_reg_t reg, u32 val)
 {
-	wa_add(wal, reg, 0, _MASKED_BIT_ENABLE(val), val);
+	wa_add(wal, reg, 0, _MASKED_BIT_ENABLE(val), val, true);
 }
 
 static void
 wa_masked_dis(struct i915_wa_list *wal, i915_reg_t reg, u32 val)
 {
-	wa_add(wal, reg, 0, _MASKED_BIT_DISABLE(val), val);
+	wa_add(wal, reg, 0, _MASKED_BIT_DISABLE(val), val, true);
 }
 
 static void
 wa_masked_field_set(struct i915_wa_list *wal, i915_reg_t reg,
 		    u32 mask, u32 val)
 {
-	wa_add(wal, reg, 0, _MASKED_FIELD(mask, val), mask);
+	wa_add(wal, reg, 0, _MASKED_FIELD(mask, val), mask, true);
 }
 
 static void gen6_ctx_workarounds_init(struct intel_engine_cs *engine,
@@ -533,10 +534,10 @@ static void icl_ctx_workarounds_init(struct intel_engine_cs *engine,
 	wa_masked_en(wal, ICL_HDC_MODE, HDC_FORCE_NON_COHERENT);
 
 	/* WaEnableFloatBlendOptimization:icl */
-	wa_write_clr_set(wal,
-			 GEN10_CACHE_MODE_SS,
-			 0, /* write-only, so skip validation */
-			 _MASKED_BIT_ENABLE(FLOAT_BLEND_OPTIMIZATION_ENABLE));
+	wa_add(wal, GEN10_CACHE_MODE_SS, 0,
+	       _MASKED_BIT_ENABLE(FLOAT_BLEND_OPTIMIZATION_ENABLE),
+	       0 /* write-only, so skip validation */,
+	       true);
 
 	/* WaDisableGPGPUMidThreadPreemption:icl */
 	wa_masked_field_set(wal, GEN8_CS_CHICKEN1,
@@ -581,7 +582,7 @@ static void gen12_ctx_gt_tuning_init(struct intel_engine_cs *engine,
 	       FF_MODE2,
 	       FF_MODE2_TDS_TIMER_MASK,
 	       FF_MODE2_TDS_TIMER_128,
-	       0);
+	       0, false);
 }
 
 static void gen12_ctx_workarounds_init(struct intel_engine_cs *engine,
@@ -619,7 +620,7 @@ static void gen12_ctx_workarounds_init(struct intel_engine_cs *engine,
 	       FF_MODE2,
 	       FF_MODE2_GS_TIMER_MASK,
 	       FF_MODE2_GS_TIMER_224,
-	       0);
+	       0, false);
 
 	/*
 	 * Wa_14012131227:dg1
@@ -795,7 +796,7 @@ hsw_gt_workarounds_init(struct drm_i915_private *i915, struct i915_wa_list *wal)
 	wa_add(wal,
 	       HSW_ROW_CHICKEN3, 0,
 	       _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE),
-		0 /* XXX does this reg exist? */);
+	       0 /* XXX does this reg exist? */, true);
 
 	/* WaVSRefCountFullforceMissDisable:hsw */
 	wa_write_clr(wal, GEN7_FF_THREAD_MODE, GEN7_FF_VS_REF_CNT_FFME);
@@ -1824,10 +1825,10 @@ rcs_engine_wa_init(struct intel_engine_cs *engine, struct i915_wa_list *wal)
 		 * disable bit, which we don't touch here, but it's good
 		 * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
 		 */
-		wa_add(wal, GEN7_GT_MODE, 0,
-		       _MASKED_FIELD(GEN6_WIZ_HASHING_MASK,
-				     GEN6_WIZ_HASHING_16x4),
-		       GEN6_WIZ_HASHING_16x4);
+		wa_masked_field_set(wal,
+				    GEN7_GT_MODE,
+				    GEN6_WIZ_HASHING_MASK,
+				    GEN6_WIZ_HASHING_16x4);
 	}
 
 	if (IS_GRAPHICS_VER(i915, 6, 7))
@@ -1877,10 +1878,10 @@ rcs_engine_wa_init(struct intel_engine_cs *engine, struct i915_wa_list *wal)
 		 * disable bit, which we don't touch here, but it's good
 		 * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
 		 */
-		wa_add(wal,
-		       GEN6_GT_MODE, 0,
-		       _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4),
-		       GEN6_WIZ_HASHING_16x4);
+		wa_masked_field_set(wal,
+				    GEN6_GT_MODE,
+				    GEN6_WIZ_HASHING_MASK,
+				    GEN6_WIZ_HASHING_16x4);
 
 		/* WaDisable_RenderCache_OperationalFlush:snb */
 		wa_masked_dis(wal, CACHE_MODE_0, RC_OP_FLUSH_ENABLE);
@@ -1901,7 +1902,7 @@ rcs_engine_wa_init(struct intel_engine_cs *engine, struct i915_wa_list *wal)
 		wa_add(wal, MI_MODE,
 		       0, _MASKED_BIT_ENABLE(VS_TIMER_DISPATCH),
 		       /* XXX bit doesn't stick on Broadwater */
-		       IS_I965G(i915) ? 0 : VS_TIMER_DISPATCH);
+		       IS_I965G(i915) ? 0 : VS_TIMER_DISPATCH, true);
 
 	if (GRAPHICS_VER(i915) == 4)
 		/*
@@ -1916,7 +1917,8 @@ rcs_engine_wa_init(struct intel_engine_cs *engine, struct i915_wa_list *wal)
 		 */
 		wa_add(wal, ECOSKPD,
 		       0, _MASKED_BIT_ENABLE(ECO_CONSTANT_BUFFER_SR_DISABLE),
-		       0 /* XXX bit doesn't stick on Broadwater */);
+		       0 /* XXX bit doesn't stick on Broadwater */,
+		       true);
 }
 
 static void
drivers/gpu/drm/i915/gt/intel_workarounds_types.h +1 -0
index c214111ea367..1e873681795d 100644
@@ -15,6 +15,7 @@ struct i915_wa {
 	u32		clr;
 	u32		set;
 	u32		read;
+	bool		masked_reg;
 };
 
 struct i915_wa_list {
drivers/gpu/drm/i915/gt/uc/intel_guc.h +1 -0
index 9c8d53a32e0d..f3c69160cb7e 100644
@@ -59,6 +59,7 @@ struct intel_guc {
 
 	struct i915_vma *ads_vma;
 	struct __guc_ads_blob *ads_blob;
+	u32 ads_regset_size;
 
 	struct i915_vma *lrc_desc_pool;
 	void *lrc_desc_pool_vaddr;
drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c +195 -4

250 lines not on this page · raw message

drivers/gpu/drm/i915/i915_reg.h +1 -0
index f01821d70155..1cbe86b7bc3a 100644
@@ -12347,6 +12347,7 @@ enum skl_power_gate {
 
 /* MOCS (Memory Object Control State) registers */
 #define GEN9_LNCFCMOCS(i)	_MMIO(0xb020 + (i) * 4)	/* L3 Cache Control */
+#define GEN9_LNCFCMOCS_REG_COUNT	32
 
 #define __GEN9_RCS0_MOCS0	0xc800
 #define GEN9_GFX_MOCS(i)	_MMIO(__GEN9_RCS0_MOCS0 + (i) * 4)
Signature · 6 lines
2.28.0

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

PATCH 16/33 drm/i915/guc: Don't complain about reset races

In reply to Matthew Brost

From: John Harrison <[email protected]>

It is impossible to seal all race conditions of resets occurring concurrent to other operations. At least, not without introducing excesive mutex locking. Instead, don't complain if it occurs. In particular, don't complain if trying to send a H2G during a reset. Whatever the H2G was about should get redone once the reset is over.

---
 drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 5 ++++-
 drivers/gpu/drm/i915/gt/uc/intel_uc.c     | 4 ++++
 drivers/gpu/drm/i915/gt/uc/intel_uc.h     | 2 ++
 3 files changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4 -1
index 18917b443f05..22b4733b55e2 100644
@@ -760,7 +760,10 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,
 	int ret;
 
 	if (unlikely(!ct->enabled)) {
-		WARN(1, "Unexpected send: action=%#x\n", *action);
+		struct intel_guc *guc = ct_to_guc(ct);
+		struct intel_uc *uc = container_of(guc, struct intel_uc, guc);
+
+		WARN(!uc->reset_in_progress, "Unexpected send: action=%#x\n", *action);
 		return -ENODEV;
 	}
 
drivers/gpu/drm/i915/gt/uc/intel_uc.c +4 -0
index e07c989968f9..77c1fe2ed883 100644
@@ -550,6 +550,8 @@ void intel_uc_reset_prepare(struct intel_uc *uc)
 {
 	struct intel_guc *guc = &uc->guc;
 
+	uc->reset_in_progress = true;
+
 	/* Nothing to do if GuC isn't supported */
 	if (!intel_uc_supports_guc(uc))
 		return;
@@ -578,6 +580,8 @@ void intel_uc_reset_finish(struct intel_uc *uc)
 {
 	struct intel_guc *guc = &uc->guc;
 
+	uc->reset_in_progress = false;
+
 	/* Firmware expected to be running when this function is called */
 	if (intel_guc_is_fw_running(guc) && intel_uc_uses_guc_submission(uc))
 		intel_guc_submission_reset_finish(guc);
drivers/gpu/drm/i915/gt/uc/intel_uc.h +2 -0
index eaa3202192ac..91315e3f1c58 100644
@@ -30,6 +30,8 @@ struct intel_uc {
 
 	/* Snapshot of GuC log from last failed load */
 	struct drm_i915_gem_object *load_err_log;
+
+	bool reset_in_progress;
 };
 
 void intel_uc_init_early(struct intel_uc *uc);
Signature · 6 lines
2.28.0

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

PATCH 17/33 drm/i915/guc: Enable GuC engine reset

In reply to Matthew Brost

From: John Harrison <[email protected]>

Clear the 'disable resets' flag to allow GuC to reset hung contexts (detected via pre-emption timeout).

---
 drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c +1 -2
index fdac8a7805f5..97cfaaaf2397 100644
@@ -81,8 +81,7 @@ static void guc_policies_init(struct guc_policies *policies)
 {
 	policies->dpc_promote_time = GLOBAL_POLICY_DEFAULT_DPC_PROMOTE_TIME_US;
 	policies->max_num_work_items = GLOBAL_POLICY_MAX_NUM_WI;
-	/* Disable automatic resets as not yet supported. */
-	policies->global_flags = GLOBAL_POLICY_DISABLE_ENGINE_RESET;
+	policies->global_flags = 0;
 	policies->is_valid = 1;
 }
 
Signature · 6 lines
2.28.0

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

PATCH 18/33 drm/i915/guc: Capture error state on context reset

In reply to Matthew Brost

We receive notification of an engine reset from GuC at its completion. Meaning GuC has potentially cleared any HW state we may have been interested in capturing. GuC resumes scheduling on the engine post-reset, as the resets are meant to be transparent, further muddling our error state.

There is ongoing work to define an API for a GuC debug state dump. The suggestion for now is to manually disable FW initiated resets in cases where debug state is needed.

---
 drivers/gpu/drm/i915/gt/intel_context.c       | 20 +++++++++++
 drivers/gpu/drm/i915/gt/intel_context.h       |  3 ++
 drivers/gpu/drm/i915/gt/intel_engine.h        | 21 ++++++++++-
 drivers/gpu/drm/i915/gt/intel_engine_cs.c     | 11 ++++--
 drivers/gpu/drm/i915/gt/intel_engine_types.h  |  2 ++
 .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 35 +++++++++----------
 drivers/gpu/drm/i915/i915_gpu_error.c         | 25 ++++++++++---
 7 files changed, 91 insertions(+), 26 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.c +20 -0
index 0bf4a13e9759..237b70e98744 100644
@@ -509,6 +509,26 @@ struct i915_request *intel_context_create_request(struct intel_context *ce)
 	return rq;
 }
 
+struct i915_request *intel_context_find_active_request(struct intel_context *ce)
+{
+	struct i915_request *rq, *active = NULL;
+	unsigned long flags;
+
+	GEM_BUG_ON(!intel_engine_uses_guc(ce->engine));
+
+	spin_lock_irqsave(&ce->guc_active.lock, flags);
+	list_for_each_entry_reverse(rq, &ce->guc_active.requests,
+				    sched.link) {
+		if (i915_request_completed(rq))
+			break;
+
+		active = rq;
+	}
+	spin_unlock_irqrestore(&ce->guc_active.lock, flags);
+
+	return active;
+}
+
 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
 #include "selftest_context.c"
 #endif
drivers/gpu/drm/i915/gt/intel_context.h +3 -0
index 974ef85320c2..2ed9bf5f91a5 100644
@@ -200,6 +200,9 @@ int intel_context_prepare_remote_request(struct intel_context *ce,
 
 struct i915_request *intel_context_create_request(struct intel_context *ce);
 
+struct i915_request *
+intel_context_find_active_request(struct intel_context *ce);
+
 static inline bool intel_context_is_barrier(const struct intel_context *ce)
 {
 	return test_bit(CONTEXT_BARRIER_BIT, &ce->flags);
drivers/gpu/drm/i915/gt/intel_engine.h +20 -1
index 8fc76dc8bf98..1db2d3efc71f 100644
@@ -245,7 +245,7 @@ ktime_t intel_engine_get_busy_time(struct intel_engine_cs *engine,
 				   ktime_t *now);
 
 struct i915_request *
-intel_engine_find_active_request(struct intel_engine_cs *engine);
+intel_engine_execlist_find_hung_request(struct intel_engine_cs *engine);
 
 u32 intel_engine_context_size(struct intel_gt *gt, u8 class);
 struct intel_context *
@@ -313,4 +313,23 @@ intel_engine_get_sibling(struct intel_engine_cs *engine, unsigned int sibling)
 	return engine->cops->get_sibling(engine, sibling);
 }
 
+static inline void
+intel_engine_set_hung_context(struct intel_engine_cs *engine,
+			      struct intel_context *ce)
+{
+	engine->hung_ce = ce;
+}
+
+static inline void
+intel_engine_clear_hung_context(struct intel_engine_cs *engine)
+{
+	intel_engine_set_hung_context(engine, NULL);
+}
+
+static inline struct intel_context *
+intel_engine_get_hung_context(struct intel_engine_cs *engine)
+{
+	return engine->hung_ce;
+}
+
 #endif /* _INTEL_RINGBUFFER_H_ */
drivers/gpu/drm/i915/gt/intel_engine_cs.c +9 -2
index 1eaa658507e1..0da7868c5a13 100644
@@ -1731,7 +1731,7 @@ void intel_engine_dump(struct intel_engine_cs *engine,
 	drm_printf(m, "\tRequests:\n");
 
 	spin_lock_irqsave(&engine->sched_engine->lock, flags);
-	rq = intel_engine_find_active_request(engine);
+	rq = intel_engine_execlist_find_hung_request(engine);
 	if (rq) {
 		struct intel_timeline *tl = get_timeline(rq);
 
@@ -1842,10 +1842,17 @@ static bool match_ring(struct i915_request *rq)
 }
 
 struct i915_request *
-intel_engine_find_active_request(struct intel_engine_cs *engine)
+intel_engine_execlist_find_hung_request(struct intel_engine_cs *engine)
 {
 	struct i915_request *request, *active = NULL;
 
+	/*
+	 * This search does not work in GuC submission mode. However, the GuC
+	 * will report the hanging context directly to the driver itself. So
+	 * the driver should never get here when in GuC mode.
+	 */
+	GEM_BUG_ON(intel_uc_uses_guc_submission(&engine->gt->uc));
+
 	/*
 	 * We are called by the error capture, reset and to dump engine
 	 * state at random points in time. In particular, note that neither is
drivers/gpu/drm/i915/gt/intel_engine_types.h +2 -0
index 1c7e2724cdae..260cce15cb62 100644
@@ -298,6 +298,8 @@ struct intel_engine_cs {
 	/* keep a request in reserve for a [pm] barrier under oom */
 	struct i915_request *request_pool;
 
+	struct intel_context *hung_ce;
+
 	struct llist_head barrier_tasks;
 
 	struct intel_context *kernel_context; /* pinned */
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +16 -19
index d76494e3e271..7d6ca0d54f9e 100644
@@ -726,24 +726,6 @@ __unwind_incomplete_requests(struct intel_context *ce)
 	spin_unlock_irqrestore(&sched_engine->lock, flags);
 }
 
-static struct i915_request *context_find_active_request(struct intel_context *ce)
-{
-	struct i915_request *rq, *active = NULL;
-	unsigned long flags;
-
-	spin_lock_irqsave(&ce->guc_active.lock, flags);
-	list_for_each_entry_reverse(rq, &ce->guc_active.requests,
-				    sched.link) {
-		if (i915_request_completed(rq))
-			break;
-
-		active = rq;
-	}
-	spin_unlock_irqrestore(&ce->guc_active.lock, flags);
-
-	return active;
-}
-
 static void __guc_reset_context(struct intel_context *ce, bool stalled)
 {
 	struct i915_request *rq;
@@ -757,7 +739,7 @@ static void __guc_reset_context(struct intel_context *ce, bool stalled)
 	 */
 	clr_context_enabled(ce);
 
-	rq = context_find_active_request(ce);
+	rq = intel_context_find_active_request(ce);
 	if (!rq) {
 		head = ce->ring->tail;
 		stalled = false;
@@ -2201,6 +2183,20 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,
 	return 0;
 }
 
+static void capture_error_state(struct intel_guc *guc,
+				struct intel_context *ce)
+{
+	struct intel_gt *gt = guc_to_gt(guc);
+	struct drm_i915_private *i915 = gt->i915;
+	struct intel_engine_cs *engine = __context_to_physical_engine(ce);
+	intel_wakeref_t wakeref;
+
+	intel_engine_set_hung_context(engine, ce);
+	with_intel_runtime_pm(&i915->runtime_pm, wakeref)
+		i915_capture_error_state(gt, engine->mask);
+	atomic_inc(&i915->gpu_error.reset_engine_count[engine->uabi_class]);
+}
+
 static void guc_context_replay(struct intel_context *ce)
 {
 	struct i915_sched_engine *sched_engine = ce->engine->sched_engine;
@@ -2213,6 +2209,7 @@ static void guc_handle_context_reset(struct intel_guc *guc,
 				     struct intel_context *ce)
 {
 	trace_intel_context_reset(ce);
+	capture_error_state(guc, ce);
 	guc_context_replay(ce);
 }
 
drivers/gpu/drm/i915/i915_gpu_error.c +21 -4
index a2c58b54a592..0f08bcfbe964 100644
@@ -1429,20 +1429,37 @@ capture_engine(struct intel_engine_cs *engine,
 {
 	struct intel_engine_capture_vma *capture = NULL;
 	struct intel_engine_coredump *ee;
-	struct i915_request *rq;
+	struct intel_context *ce;
+	struct i915_request *rq = NULL;
 	unsigned long flags;
 
 	ee = intel_engine_coredump_alloc(engine, GFP_KERNEL);
 	if (!ee)
 		return NULL;
 
-	spin_lock_irqsave(&engine->sched_engine->lock, flags);
-	rq = intel_engine_find_active_request(engine);
+	ce = intel_engine_get_hung_context(engine);
+	if (ce) {
+		intel_engine_clear_hung_context(engine);
+		rq = intel_context_find_active_request(ce);
+		if (!rq || !i915_request_started(rq))
+			goto no_request_capture;
+	} else {
+		/*
+		 * Getting here with GuC enabled means it is a forced error capture
+		 * with no actual hang. So, no need to attempt the execlist search.
+		 */
+		if (!intel_uc_uses_guc_submission(&engine->gt->uc)) {
+			spin_lock_irqsave(&engine->sched_engine->lock, flags);
+			rq = intel_engine_execlist_find_hung_request(engine);
+			spin_unlock_irqrestore(&engine->sched_engine->lock,
+					       flags);
+		}
+	}
 	if (rq)
 		capture = intel_engine_coredump_add_request(ee, rq,
 							    ATOMIC_MAYFAIL);
-	spin_unlock_irqrestore(&engine->sched_engine->lock, flags);
 	if (!capture) {
+no_request_capture:
 		kfree(ee);
 		return NULL;
 	}
Signature · 1 line
2.28.0
#20 lore raw

PATCH 19/33 drm/i915/guc: Fix for error capture after full GPU reset with GuC

In reply to Matthew Brost

From: John Harrison <[email protected]>

In the case of a full GPU reset (e.g. because GuC has died or because GuC's hang detection has been disabled), the driver can't rely on GuC reporting the guilty context. Instead, the driver needs to scan all active contexts and find one that is currently executing, as per the execlist mode behaviour. In GuC mode, this scan is different to execlist mode as the active request list is handled very differently.

Similarly, the request state dump in debugfs needs to be handled differently when in GuC submission mode.

Also refactured some of the request scanning code to avoid duplication across the multiple code paths that are now replicating it.

---
 drivers/gpu/drm/i915/gt/intel_engine.h        |   3 +
 drivers/gpu/drm/i915/gt/intel_engine_cs.c     | 140 ++++++++++++------
 .../gpu/drm/i915/gt/intel_engine_heartbeat.c  |   8 +
 drivers/gpu/drm/i915/gt/intel_reset.c         |   2 +-
 drivers/gpu/drm/i915/gt/uc/intel_guc.h        |   2 +
 .../gpu/drm/i915/gt/uc/intel_guc_submission.c |  67 +++++++++
 .../gpu/drm/i915/gt/uc/intel_guc_submission.h |   3 +
 drivers/gpu/drm/i915/i915_request.c           |  41 +++++
 drivers/gpu/drm/i915/i915_request.h           |  10 ++
 9 files changed, 229 insertions(+), 47 deletions(-)
drivers/gpu/drm/i915/gt/intel_engine.h +3 -0
index 1db2d3efc71f..c2a5640ae055 100644
@@ -240,6 +240,9 @@ __printf(3, 4)
 void intel_engine_dump(struct intel_engine_cs *engine,
 		       struct drm_printer *m,
 		       const char *header, ...);
+void intel_engine_dump_active_requests(struct list_head *requests,
+				       struct i915_request *hung_rq,
+				       struct drm_printer *m);
 
 ktime_t intel_engine_get_busy_time(struct intel_engine_cs *engine,
 				   ktime_t *now);
drivers/gpu/drm/i915/gt/intel_engine_cs.c +94 -46

166 lines not on this page · raw message

drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c +8 -0
index 0b16f19c384e..74775ae961b2 100644
@@ -90,6 +90,14 @@ reset_engine(struct intel_engine_cs *engine, struct i915_request *rq)
 	if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM))
 		show_heartbeat(rq, engine);
 
+	if (intel_engine_uses_guc(engine))
+		/*
+		 * GuC itself is toast or GuC's hang detection
+		 * is disabled. Either way, need to find the
+		 * hang culprit manually.
+		 */
+		intel_guc_find_hung_context(engine);
+
 	intel_gt_handle_error(engine->gt, engine->mask,
 			      I915_ERROR_CAPTURE,
 			      "stopped heartbeat on %s",
drivers/gpu/drm/i915/gt/intel_reset.c +1 -1
index 721a10e2215e..4d281bc8a38c 100644
@@ -156,7 +156,7 @@ void __i915_request_reset(struct i915_request *rq, bool guilty)
 	if (guilty) {
 		i915_request_set_error_once(rq, -EIO);
 		__i915_request_skip(rq);
-		if (mark_guilty(rq))
+		if (mark_guilty(rq) && !intel_engine_uses_guc(rq->engine))
 			skip_context(rq);
 	} else {
 		i915_request_set_error_once(rq, -EAGAIN);
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2 -0
index f3c69160cb7e..f355a70bbec4 100644
@@ -275,6 +275,8 @@ int intel_guc_context_reset_process_msg(struct intel_guc *guc,
 int intel_guc_engine_failure_process_msg(struct intel_guc *guc,
 					 const u32 *msg, u32 len);
 
+void intel_guc_find_hung_context(struct intel_engine_cs *engine);
+
 void intel_guc_submission_reset_prepare(struct intel_guc *guc);
 void intel_guc_submission_reset(struct intel_guc *guc, bool stalled);
 void intel_guc_submission_reset_finish(struct intel_guc *guc);
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +67 -0

73 lines not on this page · raw message

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.h +3 -0
index 08ff77c5c50e..03bc1c83a4d2 100644
@@ -25,6 +25,9 @@ void intel_guc_submission_print_info(struct intel_guc *guc,
 				     struct drm_printer *p);
 void intel_guc_submission_print_context_info(struct intel_guc *guc,
 					     struct drm_printer *p);
+void intel_guc_dump_active_requests(struct intel_engine_cs *engine,
+				    struct i915_request *hung_rq,
+				    struct drm_printer *m);
 
 bool intel_guc_virtual_engine_has_heartbeat(const struct intel_engine_cs *ve);
 
drivers/gpu/drm/i915/i915_request.c +41 -0

47 lines not on this page · raw message

drivers/gpu/drm/i915/i915_request.h +10 -0
index 128030f43bbf..ac0e3326c067 100644
@@ -649,4 +649,14 @@ i915_request_active_engine(struct i915_request *rq,
 
 void i915_request_notify_execute_cb_imm(struct i915_request *rq);
 
+enum i915_request_state {
+	I915_REQUEST_UNKNOWN = 0,
+	I915_REQUEST_COMPLETE,
+	I915_REQUEST_PENDING,
+	I915_REQUEST_QUEUED,
+	I915_REQUEST_ACTIVE,
+};
+
+enum i915_request_state i915_test_request_state(struct i915_request *rq);
+
 #endif /* I915_REQUEST_H */
Signature · 6 lines
2.28.0

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

PATCH 20/33 drm/i915/guc: Hook GuC scheduling policies up

In reply to Matthew Brost

From: John Harrison <[email protected]>

Use the official driver default scheduling policies for configuring the GuC scheduler rather than a bunch of hardcoded values.

v2:
(Matthew Brost)
- Move I915_ENGINE_WANT_FORCED_PREEMPTION to later patch

---
 drivers/gpu/drm/i915/gt/uc/intel_guc.h        |  2 +
 drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c    | 44 ++++++++++++++++++-
 .../gpu/drm/i915/gt/uc/intel_guc_submission.c |  8 ++--
 3 files changed, 49 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2 -0
index f355a70bbec4..8c8cf842c29a 100644
@@ -277,6 +277,8 @@ int intel_guc_engine_failure_process_msg(struct intel_guc *guc,
 
 void intel_guc_find_hung_context(struct intel_engine_cs *engine);
 
+int intel_guc_global_policies_update(struct intel_guc *guc);
+
 void intel_guc_submission_reset_prepare(struct intel_guc *guc);
 void intel_guc_submission_reset(struct intel_guc *guc, bool stalled);
 void intel_guc_submission_reset_finish(struct intel_guc *guc);
drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c +42 -2

63 lines not on this page · raw message

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5 -3
index 76c2d927e1c3..cea3e3073a71 100644
@@ -874,6 +874,7 @@ void intel_guc_submission_reset_finish(struct intel_guc *guc)
 	GEM_WARN_ON(atomic_read(&guc->outstanding_submission_g2h));
 	atomic_set(&guc->outstanding_submission_g2h, 0);
 
+	intel_guc_global_policies_update(guc);
 	enable_submission(guc);
 	intel_gt_unpark_heartbeats(guc_to_gt(guc));
 }
@@ -1170,8 +1171,9 @@ static void guc_context_policy_init(struct intel_engine_cs *engine,
 {
 	desc->policy_flags = 0;
 
-	desc->execution_quantum = CONTEXT_POLICY_DEFAULT_EXECUTION_QUANTUM_US;
-	desc->preemption_timeout = CONTEXT_POLICY_DEFAULT_PREEMPTION_TIME_US;
+	/* NB: For both of these, zero means disabled. */
+	desc->execution_quantum = engine->props.timeslice_duration_ms * 1000;
+	desc->preemption_timeout = engine->props.preempt_timeout_ms * 1000;
 }
 
 static int guc_lrc_desc_pin(struct intel_context *ce, bool loop)
@@ -1942,13 +1944,13 @@ static void guc_default_vfuncs(struct intel_engine_cs *engine)
 	engine->set_default_submission = guc_set_default_submission;
 
 	engine->flags |= I915_ENGINE_HAS_PREEMPTION;
+	engine->flags |= I915_ENGINE_HAS_TIMESLICES;
 
 	/*
 	 * TODO: GuC supports timeslicing and semaphores as well, but they're
 	 * handled by the firmware so some minor tweaks are required before
 	 * enabling.
 	 *
-	 * engine->flags |= I915_ENGINE_HAS_TIMESLICES;
 	 * engine->flags |= I915_ENGINE_HAS_SEMAPHORES;
 	 */
 
Signature · 6 lines
2.28.0

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

PATCH 21/33 drm/i915/guc: Connect reset modparam updates to GuC policy flags

In reply to Matthew Brost

From: John Harrison <[email protected]>

Changing the reset module parameter has no effect on a running GuC. The corresponding entry in the ADS must be updated and then the GuC informed via a Host2GuC message.

The new debugfs interface to module parameters allows this to happen. However, connecting the parameter data address back to anything useful is messy. One option would be to pass a new private data structure address through instead of just the parameter pointer. However, that means having a new (and different) data structure for each parameter and a new (and different) write function for each parameter. This method keeps everything generic by instead using a string lookup on the directory entry name.

---
 drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c |  2 +-
 drivers/gpu/drm/i915/i915_debugfs_params.c | 32 ++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c +1 -1
index 60b73625f686..7797766c56a9 100644
@@ -99,7 +99,7 @@ static int guc_action_policies_update(struct intel_guc *guc, u32 policy_offset)
 		policy_offset
 	};
 
-	return intel_guc_send(guc, action, ARRAY_SIZE(action));
+	return intel_guc_send_busy_loop(guc, action, ARRAY_SIZE(action), 0, true);
 }
 
 int intel_guc_global_policies_update(struct intel_guc *guc)
drivers/gpu/drm/i915/i915_debugfs_params.c +32 -0
index 4e2b077692cb..20424275d41e 100644
@@ -6,9 +6,21 @@
 #include <linux/kernel.h>
 
 #include "i915_debugfs_params.h"
+#include "gt/intel_gt.h"
+#include "gt/uc/intel_guc.h"
 #include "i915_drv.h"
 #include "i915_params.h"
 
+#define MATCH_DEBUGFS_NODE_NAME(_file, _name) \
+	(strcmp((_file)->f_path.dentry->d_name.name, (_name)) == 0)
+
+#define GET_I915(i915, name, ptr)	\
+	do {	\
+		struct i915_params *params;	\
+		params = container_of(((void *)(ptr)), typeof(*params), name);	\
+		(i915) = container_of(params, typeof(*(i915)), params);	\
+	} while (0)
+
 /* int param */
 static int i915_param_int_show(struct seq_file *m, void *data)
 {
@@ -24,6 +36,16 @@ static int i915_param_int_open(struct inode *inode, struct file *file)
 	return single_open(file, i915_param_int_show, inode->i_private);
 }
 
+static int notify_guc(struct drm_i915_private *i915)
+{
+	int ret = 0;
+
+	if (intel_uc_uses_guc_submission(&i915->gt.uc))
+		ret = intel_guc_global_policies_update(&i915->gt.uc.guc);
+
+	return ret;
+}
+
 static ssize_t i915_param_int_write(struct file *file,
 				    const char __user *ubuf, size_t len,
 				    loff_t *offp)
@@ -81,8 +103,10 @@ static ssize_t i915_param_uint_write(struct file *file,
 				     const char __user *ubuf, size_t len,
 				     loff_t *offp)
 {
+	struct drm_i915_private *i915;
 	struct seq_file *m = file->private_data;
 	unsigned int *value = m->private;
+	unsigned int old = *value;
 	int ret;
 
 	ret = kstrtouint_from_user(ubuf, len, 0, value);
@@ -95,6 +119,14 @@ static ssize_t i915_param_uint_write(struct file *file,
 			*value = b;
 	}
 
+	if (!ret && MATCH_DEBUGFS_NODE_NAME(file, "reset")) {
+		GET_I915(i915, reset, value);
+
+		ret = notify_guc(i915);
+		if (ret)
+			*value = old;
+	}
+
 	return ret ?: len;
 }
 
Signature · 1 line
2.28.0
maintainer
#23 lore raw

Re: [PATCH 21/33] drm/i915/guc: Connect reset modparam updates to GuC policy flags

Quoted 91 lines · Matthew Brost

From: John Harrison <[email protected]>

Changing the reset module parameter has no effect on a running GuC. The corresponding entry in the ADS must be updated and then the GuC informed via a Host2GuC message.

The new debugfs interface to module parameters allows this to happen. However, connecting the parameter data address back to anything useful is messy. One option would be to pass a new private data structure address through instead of just the parameter pointer. However, that means having a new (and different) data structure for each parameter and a new (and different) write function for each parameter. This method keeps everything generic by instead using a string lookup on the directory entry name.

---
 drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c |  2 +-
 drivers/gpu/drm/i915/i915_debugfs_params.c | 32 ++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c +1 -1
index 60b73625f686..7797766c56a9 100644
@@ -99,7 +99,7 @@ static int guc_action_policies_update(struct intel_guc *guc, u32 policy_offset)
 		policy_offset
 	};
 
-	return intel_guc_send(guc, action, ARRAY_SIZE(action));
+	return intel_guc_send_busy_loop(guc, action, ARRAY_SIZE(action), 0, true);
 }
 
 int intel_guc_global_policies_update(struct intel_guc *guc)
drivers/gpu/drm/i915/i915_debugfs_params.c +24 -0
index 4e2b077692cb..20424275d41e 100644
@@ -6,9 +6,21 @@
 #include <linux/kernel.h>
 
 #include "i915_debugfs_params.h"
+#include "gt/intel_gt.h"
+#include "gt/uc/intel_guc.h"
 #include "i915_drv.h"
 #include "i915_params.h"
 
+#define MATCH_DEBUGFS_NODE_NAME(_file, _name) \
+	(strcmp((_file)->f_path.dentry->d_name.name, (_name)) == 0)
+
+#define GET_I915(i915, name, ptr)	\
+	do {	\
+		struct i915_params *params;	\
+		params = container_of(((void *)(ptr)), typeof(*params), name);	\
+		(i915) = container_of(params, typeof(*(i915)), params);	\
+	} while (0)
+
 /* int param */
 static int i915_param_int_show(struct seq_file *m, void *data)
 {
@@ -24,6 +36,16 @@ static int i915_param_int_open(struct inode *inode, struct file *file)
 	return single_open(file, i915_param_int_show, inode->i_private);
 }
 
+static int notify_guc(struct drm_i915_private *i915)
+{
+	int ret = 0;
+
+	if (intel_uc_uses_guc_submission(&i915->gt.uc))
+		ret = intel_guc_global_policies_update(&i915->gt.uc.guc);
+
+	return ret;
+}
+
 static ssize_t i915_param_int_write(struct file *file,
 				    const char __user *ubuf, size_t len,
 				    loff_t *offp)
@@ -81,8 +103,10 @@ static ssize_t i915_param_uint_write(struct file *file,
 				     const char __user *ubuf, size_t len,
 				     loff_t *offp)
 {
+	struct drm_i915_private *i915;
 	struct seq_file *m = file->private_data;
 	unsigned int *value = m->private;
+	unsigned int old = *value;
 	int ret;
 
 	ret = kstrtouint_from_user(ubuf, len, 0, value);

drivers/gpu/drm/i915/i915_debugfs_params.c static ssize_t i915_param_uint_write(struct file *file, · line 128

Quoted 10 lines
drivers/gpu/drm/i915/i915_debugfs_params.c +7 -0
@@ -95,6 +119,14 @@ static ssize_t i915_param_uint_write(struct file *file,
 			*value = b;
 	}
 
+	if (!ret && MATCH_DEBUGFS_NODE_NAME(file, "reset")) {
+		GET_I915(i915, reset, value);
+
+		ret = notify_guc(i915);
+		if (ret)
+			*value = old;
+	}

Only stumbled on this now. It was never the idea to add this kind of checks in the middle of the generic functions. What if the type was bool or ulong, where the generic function is a debugfs helper outside of i915?

See the comment in i915_debugfs_params() that I added there exactly because I envisioned someone was going to need this facility:

/*
* Note: We could create files for params needing special handling
* here. Set mode in params to 0 to skip the generic create file, or
* just let the generic create file fail silently with -EEXIST. */

The idea was that you create your own handlers for params that need special handling.

BR,
Jani.

Quoted 3 lines
drivers/gpu/drm/i915/i915_debugfs_params.c +1 -0
+
 	return ret ?: len;
 }
Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center
#24 lore raw

PATCH 22/33 drm/i915/guc: Include scheduling policies in the debugfs state dump

In reply to Matthew Brost

From: John Harrison <[email protected]>

Added the scheduling policy parameters to the 'guc_info' debugfs state dump.

---
 drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c     | 14 ++++++++++++++
 drivers/gpu/drm/i915/gt/uc/intel_guc_ads.h     |  3 +++
 drivers/gpu/drm/i915/gt/uc/intel_guc_debugfs.c |  2 ++
 3 files changed, 19 insertions(+)
drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c +14 -0
index 7797766c56a9..51fc14ee79cd 100644
@@ -92,6 +92,20 @@ static void guc_policies_init(struct intel_guc *guc, struct guc_policies *polici
 	policies->is_valid = 1;
 }
 
+void intel_guc_ads_print_policy_info(struct intel_guc *guc,
+				     struct drm_printer *dp)
+{
+	struct __guc_ads_blob *blob = guc->ads_blob;
+
+	if (unlikely(!blob))
+		return;
+
+	drm_printf(dp, "Global scheduling policies:\n");
+	drm_printf(dp, "  DPC promote time   = %u\n", blob->policies.dpc_promote_time);
+	drm_printf(dp, "  Max num work items = %u\n", blob->policies.max_num_work_items);
+	drm_printf(dp, "  Flags              = %u\n", blob->policies.global_flags);
+}
+
 static int guc_action_policies_update(struct intel_guc *guc, u32 policy_offset)
 {
 	u32 action[] = {
drivers/gpu/drm/i915/gt/uc/intel_guc_ads.h +3 -0
index b00d3ae1113a..bdcb339a5321 100644
@@ -7,9 +7,12 @@
 #define _INTEL_GUC_ADS_H_
 
 struct intel_guc;
+struct drm_printer;
 
 int intel_guc_ads_create(struct intel_guc *guc);
 void intel_guc_ads_destroy(struct intel_guc *guc);
 void intel_guc_ads_reset(struct intel_guc *guc);
+void intel_guc_ads_print_policy_info(struct intel_guc *guc,
+				     struct drm_printer *p);
 
 #endif
drivers/gpu/drm/i915/gt/uc/intel_guc_debugfs.c +2 -0
index 7a454c91a736..72ddfff42f7d 100644
@@ -10,6 +10,7 @@
 #include "intel_guc_debugfs.h"
 #include "intel_guc_log_debugfs.h"
 #include "gt/uc/intel_guc_ct.h"
+#include "gt/uc/intel_guc_ads.h"
 #include "gt/uc/intel_guc_submission.h"
 
 static int guc_info_show(struct seq_file *m, void *data)
@@ -29,6 +30,7 @@ static int guc_info_show(struct seq_file *m, void *data)
 
 	intel_guc_ct_print_info(&guc->ct, &p);
 	intel_guc_submission_print_info(guc, &p);
+	intel_guc_ads_print_policy_info(guc, &p);
 
 	return 0;
 }
Signature · 6 lines
2.28.0

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

PATCH 23/33 drm/i915/guc: Add golden context to GuC ADS

In reply to Matthew Brost

From: John Harrison <[email protected]>

The media watchdog mechanism involves GuC doing a silent reset and continue of the hung context. This requires the i915 driver provide a golden context to GuC in the ADS.

v2:
(Matthew Brost):
- Fix memory corruption in shmem_read
(John H)
- Use locals rather than defines for LR_* + SKIP_SIZE

---
 drivers/gpu/drm/i915/gt/intel_gt.c         |   2 +
 drivers/gpu/drm/i915/gt/uc/intel_guc.c     |   5 +
 drivers/gpu/drm/i915/gt/uc/intel_guc.h     |   2 +
 drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c | 216 ++++++++++++++++++---
 drivers/gpu/drm/i915/gt/uc/intel_guc_ads.h |   1 +
 drivers/gpu/drm/i915/gt/uc/intel_uc.c      |   5 +
 drivers/gpu/drm/i915/gt/uc/intel_uc.h      |   1 +
 7 files changed, 202 insertions(+), 30 deletions(-)
drivers/gpu/drm/i915/gt/intel_gt.c +2 -0
index 46441607d18b..a64aa43f7cd9 100644
@@ -654,6 +654,8 @@ int intel_gt_init(struct intel_gt *gt)
 	if (err)
 		goto err_gt;
 
+	intel_uc_init_late(&gt->uc);
+
 	err = i915_inject_probe_error(gt->i915, -EIO);
 	if (err)
 		goto err_gt;
drivers/gpu/drm/i915/gt/uc/intel_guc.c +5 -0
index 68266cbffd1f..979128e28372 100644
@@ -180,6 +180,11 @@ void intel_guc_init_early(struct intel_guc *guc)
 	}
 }
 
+void intel_guc_init_late(struct intel_guc *guc)
+{
+	intel_guc_ads_init_late(guc);
+}
+
 static u32 guc_ctl_debug_flags(struct intel_guc *guc)
 {
 	u32 level = intel_guc_log_get_level(&guc->log);
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2 -0
index 8c8cf842c29a..1875303c3bca 100644
@@ -60,6 +60,7 @@ struct intel_guc {
 	struct i915_vma *ads_vma;
 	struct __guc_ads_blob *ads_blob;
 	u32 ads_regset_size;
+	u32 ads_golden_ctxt_size;
 
 	struct i915_vma *lrc_desc_pool;
 	void *lrc_desc_pool_vaddr;
@@ -183,6 +184,7 @@ static inline u32 intel_guc_ggtt_offset(struct intel_guc *guc,
 }
 
 void intel_guc_init_early(struct intel_guc *guc);
+void intel_guc_init_late(struct intel_guc *guc);
 void intel_guc_init_send_regs(struct intel_guc *guc);
 void intel_guc_write_params(struct intel_guc *guc);
 int intel_guc_init(struct intel_guc *guc);
drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c +186 -30

287 lines not on this page · raw message

drivers/gpu/drm/i915/gt/uc/intel_guc_ads.h +1 -0
index bdcb339a5321..3d85051d57e4 100644
@@ -11,6 +11,7 @@ struct drm_printer;
 
 int intel_guc_ads_create(struct intel_guc *guc);
 void intel_guc_ads_destroy(struct intel_guc *guc);
+void intel_guc_ads_init_late(struct intel_guc *guc);
 void intel_guc_ads_reset(struct intel_guc *guc);
 void intel_guc_ads_print_policy_info(struct intel_guc *guc,
 				     struct drm_printer *p);
drivers/gpu/drm/i915/gt/uc/intel_uc.c +5 -0
index 77c1fe2ed883..7a69c3c027e9 100644
@@ -120,6 +120,11 @@ void intel_uc_init_early(struct intel_uc *uc)
 		uc->ops = &uc_ops_off;
 }
 
+void intel_uc_init_late(struct intel_uc *uc)
+{
+	intel_guc_init_late(&uc->guc);
+}
+
 void intel_uc_driver_late_release(struct intel_uc *uc)
 {
 }
drivers/gpu/drm/i915/gt/uc/intel_uc.h +1 -0
index 91315e3f1c58..e2da2b6e76e1 100644
@@ -35,6 +35,7 @@ struct intel_uc {
 };
 
 void intel_uc_init_early(struct intel_uc *uc);
+void intel_uc_init_late(struct intel_uc *uc);
 void intel_uc_driver_late_release(struct intel_uc *uc);
 void intel_uc_driver_remove(struct intel_uc *uc);
 void intel_uc_init_mmio(struct intel_uc *uc);
Signature · 1 line
2.28.0
#26 lore raw

PATCH 24/33 drm/i915/guc: Implement banned contexts for GuC submission

In reply to Matthew Brost

When using GuC submission, if a context gets banned disable scheduling and mark all inflight requests as complete.

---
 drivers/gpu/drm/i915/gem/i915_gem_context.c   |   2 +-
 drivers/gpu/drm/i915/gt/intel_context.h       |  13 ++
 drivers/gpu/drm/i915/gt/intel_context_types.h |   2 +
 drivers/gpu/drm/i915/gt/intel_reset.c         |  32 +---
 .../gpu/drm/i915/gt/intel_ring_submission.c   |  20 +++
 drivers/gpu/drm/i915/gt/uc/intel_guc.h        |   2 +
 .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 151 ++++++++++++++++--
 drivers/gpu/drm/i915/i915_trace.h             |  10 ++
 8 files changed, 195 insertions(+), 37 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +1 -1
index e3df01a201d7..05c3ee191710 100644
@@ -1084,7 +1084,7 @@ static void kill_engines(struct i915_gem_engines *engines, bool ban)
 	for_each_gem_engine(ce, engines, it) {
 		struct intel_engine_cs *engine;
 
-		if (ban && intel_context_set_banned(ce))
+		if (ban && intel_context_ban(ce, NULL))
 			continue;
 
 		/*
drivers/gpu/drm/i915/gt/intel_context.h +13 -0
index 2ed9bf5f91a5..814d9277096a 100644
@@ -16,6 +16,7 @@
 #include "intel_engine_types.h"
 #include "intel_ring_types.h"
 #include "intel_timeline_types.h"
+#include "i915_trace.h"
 
 #define CE_TRACE(ce, fmt, ...) do {					\
 	const struct intel_context *ce__ = (ce);			\
@@ -243,6 +244,18 @@ static inline bool intel_context_set_banned(struct intel_context *ce)
 	return test_and_set_bit(CONTEXT_BANNED, &ce->flags);
 }
 
+static inline bool intel_context_ban(struct intel_context *ce,
+				     struct i915_request *rq)
+{
+	bool ret = intel_context_set_banned(ce);
+
+	trace_intel_context_ban(ce);
+	if (ce->ops->ban)
+		ce->ops->ban(ce, rq);
+
+	return ret;
+}
+
 static inline bool
 intel_context_force_single_submission(const struct intel_context *ce)
 {
drivers/gpu/drm/i915/gt/intel_context_types.h +2 -0
index 035108c10b2c..57c19ee3e313 100644
@@ -35,6 +35,8 @@ struct intel_context_ops {
 
 	int (*alloc)(struct intel_context *ce);
 
+	void (*ban)(struct intel_context *ce, struct i915_request *rq);
+
 	int (*pre_pin)(struct intel_context *ce, struct i915_gem_ww_ctx *ww, void **vaddr);
 	int (*pin)(struct intel_context *ce, void *vaddr);
 	void (*unpin)(struct intel_context *ce);
drivers/gpu/drm/i915/gt/intel_reset.c +8 -24
index 4d281bc8a38c..91200c43951f 100644
@@ -22,7 +22,6 @@
 #include "intel_reset.h"
 
 #include "uc/intel_guc.h"
-#include "uc/intel_guc_submission.h"
 
 #define RESET_MAX_RETRIES 3
 
@@ -39,21 +38,6 @@ static void rmw_clear_fw(struct intel_uncore *uncore, i915_reg_t reg, u32 clr)
 	intel_uncore_rmw_fw(uncore, reg, clr, 0);
 }
 
-static void skip_context(struct i915_request *rq)
-{
-	struct intel_context *hung_ctx = rq->context;
-
-	list_for_each_entry_from_rcu(rq, &hung_ctx->timeline->requests, link) {
-		if (!i915_request_is_active(rq))
-			return;
-
-		if (rq->context == hung_ctx) {
-			i915_request_set_error_once(rq, -EIO);
-			__i915_request_skip(rq);
-		}
-	}
-}
-
 static void client_mark_guilty(struct i915_gem_context *ctx, bool banned)
 {
 	struct drm_i915_file_private *file_priv = ctx->file_priv;
@@ -88,10 +72,8 @@ static bool mark_guilty(struct i915_request *rq)
 	bool banned;
 	int i;
 
-	if (intel_context_is_closed(rq->context)) {
-		intel_context_set_banned(rq->context);
+	if (intel_context_is_closed(rq->context))
 		return true;
-	}
 
 	rcu_read_lock();
 	ctx = rcu_dereference(rq->context->gem_context);
@@ -123,11 +105,9 @@ static bool mark_guilty(struct i915_request *rq)
 	banned = !i915_gem_context_is_recoverable(ctx);
 	if (time_before(jiffies, prev_hang + CONTEXT_FAST_HANG_JIFFIES))
 		banned = true;
-	if (banned) {
+	if (banned)
 		drm_dbg(&ctx->i915->drm, "context %s: guilty %d, banned\n",
 			ctx->name, atomic_read(&ctx->guilty_count));
-		intel_context_set_banned(rq->context);
-	}
 
 	client_mark_guilty(ctx, banned);
 
@@ -149,6 +129,8 @@ static void mark_innocent(struct i915_request *rq)
 
 void __i915_request_reset(struct i915_request *rq, bool guilty)
 {
+	bool banned = false;
+
 	RQ_TRACE(rq, "guilty? %s\n", yesno(guilty));
 	GEM_BUG_ON(__i915_request_is_complete(rq));
 
@@ -156,13 +138,15 @@ void __i915_request_reset(struct i915_request *rq, bool guilty)
 	if (guilty) {
 		i915_request_set_error_once(rq, -EIO);
 		__i915_request_skip(rq);
-		if (mark_guilty(rq) && !intel_engine_uses_guc(rq->engine))
-			skip_context(rq);
+		banned = mark_guilty(rq);
 	} else {
 		i915_request_set_error_once(rq, -EAGAIN);
 		mark_innocent(rq);
 	}
 	rcu_read_unlock();
+
+	if (banned)
+		intel_context_ban(rq->context, rq);
 }
 
 static bool i915_in_reset(struct pci_dev *pdev)
drivers/gpu/drm/i915/gt/intel_ring_submission.c +20 -0
index a5404c7b600f..05bb9f449df1 100644
@@ -586,9 +586,29 @@ static void ring_context_reset(struct intel_context *ce)
 	clear_bit(CONTEXT_VALID_BIT, &ce->flags);
 }
 
+static void ring_context_ban(struct intel_context *ce,
+			     struct i915_request *rq)
+{
+	struct intel_engine_cs *engine;
+
+	if (!rq || !i915_request_is_active(rq))
+		return;
+
+	engine = rq->engine;
+	lockdep_assert_held(&engine->sched_engine->lock);
+	list_for_each_entry_continue(rq, &engine->sched_engine->requests,
+				     sched.link)
+		if (rq->context == ce) {
+			i915_request_set_error_once(rq, -EIO);
+			__i915_request_skip(rq);
+		}
+}
+
 static const struct intel_context_ops ring_context_ops = {
 	.alloc = ring_context_alloc,
 
+	.ban = ring_context_ban,
+
 	.pre_pin = ring_context_pre_pin,
 	.pin = ring_context_pin,
 	.unpin = ring_context_unpin,
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2 -0
index 1875303c3bca..8ab70a2223b0 100644
@@ -281,6 +281,8 @@ void intel_guc_find_hung_context(struct intel_engine_cs *engine);
 
 int intel_guc_global_policies_update(struct intel_guc *guc);
 
+void intel_guc_context_ban(struct intel_context *ce, struct i915_request *rq);
+
 void intel_guc_submission_reset_prepare(struct intel_guc *guc);
 void intel_guc_submission_reset(struct intel_guc *guc, bool stalled);
 void intel_guc_submission_reset_finish(struct intel_guc *guc);
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +139 -12

289 lines not on this page · raw message

drivers/gpu/drm/i915/i915_trace.h +10 -0
index 3f43d904f043..9613a7c19661 100644
@@ -925,6 +925,11 @@ DEFINE_EVENT(intel_context, intel_context_reset,
 	     TP_ARGS(ce)
 );
 
+DEFINE_EVENT(intel_context, intel_context_ban,
+	     TP_PROTO(struct intel_context *ce),
+	     TP_ARGS(ce)
+);
+
 DEFINE_EVENT(intel_context, intel_context_register,
 	     TP_PROTO(struct intel_context *ce),
 	     TP_ARGS(ce)
@@ -1017,6 +1022,11 @@ trace_intel_context_reset(struct intel_context *ce)
 {
 }
 
+static inline void
+trace_intel_context_ban(struct intel_context *ce)
+{
+}
+
 static inline void
 trace_intel_context_register(struct intel_context *ce)
 {
Signature · 6 lines
2.28.0

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

Re: [Intel-gfx] [PATCH 24/33] drm/i915/guc: Implement banned contexts for GuC submission

Quoted 44 lines · Matthew Brost

When using GuC submission, if a context gets banned disable scheduling and mark all inflight requests as complete.

---
  drivers/gpu/drm/i915/gem/i915_gem_context.c   |   2 +-
  drivers/gpu/drm/i915/gt/intel_context.h       |  13 ++
  drivers/gpu/drm/i915/gt/intel_context_types.h |   2 +
  drivers/gpu/drm/i915/gt/intel_reset.c         |  32 +---
  .../gpu/drm/i915/gt/intel_ring_submission.c   |  20 +++
  drivers/gpu/drm/i915/gt/uc/intel_guc.h        |   2 +
  .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 151 ++++++++++++++++--
  drivers/gpu/drm/i915/i915_trace.h             |  10 ++
  8 files changed, 195 insertions(+), 37 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +1 -1
index e3df01a201d7..05c3ee191710 100644
@@ -1084,7 +1084,7 @@ static void kill_engines(struct i915_gem_engines *engines, bool ban)
  	for_each_gem_engine(ce, engines, it) {
  		struct intel_engine_cs *engine;
 
-		if (ban && intel_context_set_banned(ce))
+		if (ban && intel_context_ban(ce, NULL))
  			continue;
 
  		/*
drivers/gpu/drm/i915/gt/intel_context.h +1 -0
index 2ed9bf5f91a5..814d9277096a 100644
@@ -16,6 +16,7 @@
  #include "intel_engine_types.h"
  #include "intel_ring_types.h"
  #include "intel_timeline_types.h"
+#include "i915_trace.h"
 
  #define CE_TRACE(ce, fmt, ...) do {					\
  	const struct intel_context *ce__ = (ce);			\
@@ -243,6 +244,18 @@ static inline bool intel_context_set_banned(struct intel_context *ce)
  	return test_and_set_bit(CONTEXT_BANNED, &ce->flags);

drivers/gpu/drm/i915/gt/intel_context.h static inline bool intel_context_set_banned(struct intel_context *ce) · line 254

Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_context.h +8 -0
  }
 
+static inline bool intel_context_ban(struct intel_context *ce,
+				     struct i915_request *rq)
+{
+	bool ret = intel_context_set_banned(ce);
+
+	trace_intel_context_ban(ce);
+	if (ce->ops->ban)
+		ce->ops->ban(ce, rq);

Do you want to skip this call if already banned?

Quoted 40 lines
drivers/gpu/drm/i915/gt/intel_context.h +4 -0
+
+	return ret;
+}
+
  static inline bool
  intel_context_force_single_submission(const struct intel_context *ce)
  {
drivers/gpu/drm/i915/gt/intel_context_types.h +2 -0
index 035108c10b2c..57c19ee3e313 100644
@@ -35,6 +35,8 @@ struct intel_context_ops {
 
  	int (*alloc)(struct intel_context *ce);
 
+	void (*ban)(struct intel_context *ce, struct i915_request *rq);
+
  	int (*pre_pin)(struct intel_context *ce, struct i915_gem_ww_ctx *ww, void **vaddr);
  	int (*pin)(struct intel_context *ce, void *vaddr);
  	void (*unpin)(struct intel_context *ce);
drivers/gpu/drm/i915/gt/intel_reset.c +0 -5
index 4d281bc8a38c..91200c43951f 100644
@@ -22,7 +22,6 @@
  #include "intel_reset.h"
 
  #include "uc/intel_guc.h"
-#include "uc/intel_guc_submission.h"
 
  #define RESET_MAX_RETRIES 3
 
@@ -39,21 +38,6 @@ static void rmw_clear_fw(struct intel_uncore *uncore, i915_reg_t reg, u32 clr)
  	intel_uncore_rmw_fw(uncore, reg, clr, 0);
  }
 
-static void skip_context(struct i915_request *rq)
-{
-	struct intel_context *hung_ctx = rq->context;
-

drivers/gpu/drm/i915/gt/intel_reset.c static void rmw_clear_fw(struct intel_uncore *uncore, i915_reg_t reg, u32 clr) · line 55

Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_reset.c +0 -10
-	list_for_each_entry_from_rcu(rq, &hung_ctx->timeline->requests, link) {
-		if (!i915_request_is_active(rq))
-			return;
-
-		if (rq->context == hung_ctx) {
-			i915_request_set_error_once(rq, -EIO);
-			__i915_request_skip(rq);
-		}
-	}
-}

More importantly I must be missing something - this code has been moved to ring_context_ban - what am I not seeing on the execlists side of things?!

Regards,

Tvrtko

Quoted 444 lines
drivers/gpu/drm/i915/gt/intel_reset.c +8 -9
-
  static void client_mark_guilty(struct i915_gem_context *ctx, bool banned)
  {
  	struct drm_i915_file_private *file_priv = ctx->file_priv;
@@ -88,10 +72,8 @@ static bool mark_guilty(struct i915_request *rq)
  	bool banned;
  	int i;
 
-	if (intel_context_is_closed(rq->context)) {
-		intel_context_set_banned(rq->context);
+	if (intel_context_is_closed(rq->context))
  		return true;
-	}
 
  	rcu_read_lock();
  	ctx = rcu_dereference(rq->context->gem_context);
@@ -123,11 +105,9 @@ static bool mark_guilty(struct i915_request *rq)
  	banned = !i915_gem_context_is_recoverable(ctx);
  	if (time_before(jiffies, prev_hang + CONTEXT_FAST_HANG_JIFFIES))
  		banned = true;
-	if (banned) {
+	if (banned)
  		drm_dbg(&ctx->i915->drm, "context %s: guilty %d, banned\n",
  			ctx->name, atomic_read(&ctx->guilty_count));
-		intel_context_set_banned(rq->context);
-	}
 
  	client_mark_guilty(ctx, banned);
 
@@ -149,6 +129,8 @@ static void mark_innocent(struct i915_request *rq)
 
  void __i915_request_reset(struct i915_request *rq, bool guilty)
  {
+	bool banned = false;
+
  	RQ_TRACE(rq, "guilty? %s\n", yesno(guilty));
  	GEM_BUG_ON(__i915_request_is_complete(rq));
 
@@ -156,13 +138,15 @@ void __i915_request_reset(struct i915_request *rq, bool guilty)
  	if (guilty) {
  		i915_request_set_error_once(rq, -EIO);
  		__i915_request_skip(rq);
-		if (mark_guilty(rq) && !intel_engine_uses_guc(rq->engine))
-			skip_context(rq);
+		banned = mark_guilty(rq);
  	} else {
  		i915_request_set_error_once(rq, -EAGAIN);
  		mark_innocent(rq);
  	}
  	rcu_read_unlock();
+
+	if (banned)
+		intel_context_ban(rq->context, rq);
  }
 
  static bool i915_in_reset(struct pci_dev *pdev)
drivers/gpu/drm/i915/gt/intel_ring_submission.c +20 -0
index a5404c7b600f..05bb9f449df1 100644
@@ -586,9 +586,29 @@ static void ring_context_reset(struct intel_context *ce)
  	clear_bit(CONTEXT_VALID_BIT, &ce->flags);
  }
 
+static void ring_context_ban(struct intel_context *ce,
+			     struct i915_request *rq)
+{
+	struct intel_engine_cs *engine;
+
+	if (!rq || !i915_request_is_active(rq))
+		return;
+
+	engine = rq->engine;
+	lockdep_assert_held(&engine->sched_engine->lock);
+	list_for_each_entry_continue(rq, &engine->sched_engine->requests,
+				     sched.link)
+		if (rq->context == ce) {
+			i915_request_set_error_once(rq, -EIO);
+			__i915_request_skip(rq);
+		}
+}
+
  static const struct intel_context_ops ring_context_ops = {
  	.alloc = ring_context_alloc,
 
+	.ban = ring_context_ban,
+
  	.pre_pin = ring_context_pre_pin,
  	.pin = ring_context_pin,
  	.unpin = ring_context_unpin,
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2 -0
index 1875303c3bca..8ab70a2223b0 100644
@@ -281,6 +281,8 @@ void intel_guc_find_hung_context(struct intel_engine_cs *engine);
 
  int intel_guc_global_policies_update(struct intel_guc *guc);
 
+void intel_guc_context_ban(struct intel_context *ce, struct i915_request *rq);
+
  void intel_guc_submission_reset_prepare(struct intel_guc *guc);
  void intel_guc_submission_reset(struct intel_guc *guc, bool stalled);
  void intel_guc_submission_reset_finish(struct intel_guc *guc);
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +139 -12
index cea3e3073a71..ad9a38a861df 100644
@@ -125,6 +125,7 @@ static inline void clr_context_pending_enable(struct intel_context *ce)
  #define SCHED_STATE_WAIT_FOR_DEREGISTER_TO_REGISTER	BIT(0)
  #define SCHED_STATE_DESTROYED				BIT(1)
  #define SCHED_STATE_PENDING_DISABLE			BIT(2)
+#define SCHED_STATE_BANNED				BIT(3)
  static inline void init_sched_state(struct intel_context *ce)
  {
  	/* Only should be called from guc_lrc_desc_pin() */
@@ -185,6 +186,23 @@ static inline void clr_context_pending_disable(struct intel_context *ce)
  	ce->guc_state.sched_state &= ~SCHED_STATE_PENDING_DISABLE;
  }
 
+static inline bool context_banned(struct intel_context *ce)
+{
+	return ce->guc_state.sched_state & SCHED_STATE_BANNED;
+}
+
+static inline void set_context_banned(struct intel_context *ce)
+{
+	lockdep_assert_held(&ce->guc_state.lock);
+	ce->guc_state.sched_state |= SCHED_STATE_BANNED;
+}
+
+static inline void clr_context_banned(struct intel_context *ce)
+{
+	lockdep_assert_held(&ce->guc_state.lock);
+	ce->guc_state.sched_state &= ~SCHED_STATE_BANNED;
+}
+
  static inline bool context_guc_id_invalid(struct intel_context *ce)
  {
  	return ce->guc_id == GUC_INVALID_LRC_ID;
@@ -357,13 +375,23 @@ static int guc_lrc_desc_pin(struct intel_context *ce, bool loop);
 
  static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)
  {
-	int err;
+	int err = 0;
  	struct intel_context *ce = rq->context;
  	u32 action[3];
  	int len = 0;
  	u32 g2h_len_dw = 0;
  	bool enabled;
 
+	/*
+	 * Corner case where requests were sitting in the priority list or a
+	 * request resubmitted after the context was banned.
+	 */
+	if (unlikely(intel_context_is_banned(ce))) {
+		i915_request_put(i915_request_mark_eio(rq));
+		intel_engine_signal_breadcrumbs(ce->engine);
+		goto out;
+	}
+
  	GEM_BUG_ON(!atomic_read(&ce->guc_id_ref));
  	GEM_BUG_ON(context_guc_id_invalid(ce));
 
@@ -399,6 +427,8 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)
  		clr_context_pending_enable(ce);
  		intel_context_put(ce);
  	}
+	if (likely(!err))
+		trace_i915_request_guc_submit(rq);
 
  out:
  	return err;
@@ -463,7 +493,6 @@ static int guc_dequeue_one_context(struct intel_guc *guc)
  			guc->stalled_request = last;
  			return false;
  		}
-		trace_i915_request_guc_submit(last);
  	}
 
  	guc->stalled_request = NULL;
@@ -502,12 +531,13 @@ static void cs_irq_handler(struct intel_engine_cs *engine, u16 iir)
  static void __guc_context_destroy(struct intel_context *ce);
  static void release_guc_id(struct intel_guc *guc, struct intel_context *ce);
  static void guc_signal_context_fence(struct intel_context *ce);
+static void guc_cancel_context_requests(struct intel_context *ce);
 
  static void scrub_guc_desc_for_outstanding_g2h(struct intel_guc *guc)
  {
  	struct intel_context *ce;
  	unsigned long index, flags;
-	bool pending_disable, pending_enable, deregister, destroyed;
+	bool pending_disable, pending_enable, deregister, destroyed, banned;
 
  	xa_for_each(&guc->context_lookup, index, ce) {
  		/* Flush context */
@@ -525,6 +555,7 @@ static void scrub_guc_desc_for_outstanding_g2h(struct intel_guc *guc)
  		pending_enable = context_pending_enable(ce);
  		pending_disable = context_pending_disable(ce);
  		deregister = context_wait_for_deregister_to_register(ce);
+		banned = context_banned(ce);
  		init_sched_state(ce);
 
  		if (pending_enable || destroyed || deregister) {
@@ -542,6 +573,10 @@ static void scrub_guc_desc_for_outstanding_g2h(struct intel_guc *guc)
  		/* Not mutualy exclusive with above if statement. */
  		if (pending_disable) {
  			guc_signal_context_fence(ce);
+			if (banned) {
+				guc_cancel_context_requests(ce);
+				intel_engine_signal_breadcrumbs(ce->engine);
+			}
  			intel_context_sched_disable_unpin(ce);
  			atomic_dec(&guc->outstanding_submission_g2h);
  			intel_context_put(ce);
@@ -661,6 +696,9 @@ static void guc_reset_state(struct intel_context *ce, u32 head, bool scrub)
  {
  	struct intel_engine_cs *engine = __context_to_physical_engine(ce);
 
+	if (intel_context_is_banned(ce))
+		return;
+
  	GEM_BUG_ON(!intel_context_is_pinned(ce));
 
  	/*
@@ -731,6 +769,8 @@ static void __guc_reset_context(struct intel_context *ce, bool stalled)
  	struct i915_request *rq;
  	u32 head;
 
+	intel_context_get(ce);
+
  	/*
  	 * GuC will implicitly mark the context as non-schedulable
  	 * when it sends the reset notification. Make sure our state
@@ -756,6 +796,7 @@ static void __guc_reset_context(struct intel_context *ce, bool stalled)
  out_replay:
  	guc_reset_state(ce, head, stalled);
  	__unwind_incomplete_requests(ce);
+	intel_context_put(ce);
  }
 
  void intel_guc_submission_reset(struct intel_guc *guc, bool stalled)
@@ -940,8 +981,6 @@ static int guc_bypass_tasklet_submit(struct intel_guc *guc,
  	ret = guc_add_request(guc, rq);
  	if (ret == -EBUSY)
  		guc->stalled_request = rq;
-	else
-		trace_i915_request_guc_submit(rq);
 
  	if (unlikely(ret == -EPIPE))
  		disable_submission(guc);
@@ -1344,13 +1383,77 @@ static u16 prep_context_pending_disable(struct intel_context *ce)
  	return ce->guc_id;
  }
 
+static void __guc_context_set_preemption_timeout(struct intel_guc *guc,
+						 u16 guc_id,
+						 u32 preemption_timeout)
+{
+	u32 action[] = {
+		INTEL_GUC_ACTION_SET_CONTEXT_PREEMPTION_TIMEOUT,
+		guc_id,
+		preemption_timeout
+	};
+
+	intel_guc_send_busy_loop(guc, action, ARRAY_SIZE(action), 0, true);
+}
+
+static void guc_context_ban(struct intel_context *ce, struct i915_request *rq)
+{
+	struct intel_guc *guc = ce_to_guc(ce);
+	struct intel_runtime_pm *runtime_pm =
+		&ce->engine->gt->i915->runtime_pm;
+	intel_wakeref_t wakeref;
+	unsigned long flags;
+
+	guc_flush_submissions(guc);
+
+	spin_lock_irqsave(&ce->guc_state.lock, flags);
+	set_context_banned(ce);
+
+	if (submission_disabled(guc) ||
+	    (!context_enabled(ce) && !context_pending_disable(ce))) {
+		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+
+		guc_cancel_context_requests(ce);
+		intel_engine_signal_breadcrumbs(ce->engine);
+	} else if (!context_pending_disable(ce)) {
+		u16 guc_id;
+
+		/*
+		 * We add +2 here as the schedule disable complete CTB handler
+		 * calls intel_context_sched_disable_unpin (-2 to pin_count).
+		 */
+		atomic_add(2, &ce->pin_count);
+
+		guc_id = prep_context_pending_disable(ce);
+		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+
+		/*
+		 * In addition to disabling scheduling, set the preemption
+		 * timeout to the minimum value (1 us) so the banned context
+		 * gets kicked off the HW ASAP.
+		 */
+		with_intel_runtime_pm(runtime_pm, wakeref) {
+			__guc_context_set_preemption_timeout(guc, guc_id, 1);
+			__guc_context_sched_disable(guc, ce, guc_id);
+		}
+	} else {
+		if (!context_guc_id_invalid(ce))
+			with_intel_runtime_pm(runtime_pm, wakeref)
+				__guc_context_set_preemption_timeout(guc,
+								     ce->guc_id,
+								     1);
+		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+	}
+}
+
  static void guc_context_sched_disable(struct intel_context *ce)
  {
  	struct intel_guc *guc = ce_to_guc(ce);
-	struct intel_runtime_pm *runtime_pm = &ce->engine->gt->i915->runtime_pm;
  	unsigned long flags;
-	u16 guc_id;
+	struct intel_runtime_pm *runtime_pm = &ce->engine->gt->i915->runtime_pm;
  	intel_wakeref_t wakeref;
+	u16 guc_id;
+	bool enabled;
 
  	if (submission_disabled(guc) || context_guc_id_invalid(ce) ||
  	    !lrc_desc_registered(guc, ce->guc_id)) {
@@ -1364,14 +1467,22 @@ static void guc_context_sched_disable(struct intel_context *ce)
  	spin_lock_irqsave(&ce->guc_state.lock, flags);
 
  	/*
-	 * We have to check if the context has been pinned again as another pin
-	 * operation is allowed to pass this function. Checking the pin count,
-	 * within ce->guc_state.lock, synchronizes this function with
+	 * We have to check if the context has been disabled by another thread.
+	 * We also have to check if the context has been pinned again as another
+	 * pin operation is allowed to pass this function. Checking the pin
+	 * count, within ce->guc_state.lock, synchronizes this function with
  	 * guc_request_alloc ensuring a request doesn't slip through the
  	 * 'context_pending_disable' fence. Checking within the spin lock (can't
  	 * sleep) ensures another process doesn't pin this context and generate
  	 * a request before we set the 'context_pending_disable' flag here.
  	 */
+	enabled = context_enabled(ce);
+	if (unlikely(!enabled || submission_disabled(guc))) {
+		if (enabled)
+			clr_context_enabled(ce);
+		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+		goto unpin;
+	}
  	if (unlikely(atomic_add_unless(&ce->pin_count, -2, 2))) {
  		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
  		return;
@@ -1529,6 +1640,8 @@ static const struct intel_context_ops guc_context_ops = {
  	.unpin = guc_context_unpin,
  	.post_unpin = guc_context_post_unpin,
 
+	.ban = guc_context_ban,
+
  	.enter = intel_context_enter_engine,
  	.exit = intel_context_exit_engine,
 
@@ -1722,6 +1835,8 @@ static const struct intel_context_ops virtual_guc_context_ops = {
  	.unpin = guc_context_unpin,
  	.post_unpin = guc_context_post_unpin,
 
+	.ban = guc_context_ban,
+
  	.enter = guc_virtual_context_enter,
  	.exit = guc_virtual_context_exit,
 
@@ -2164,6 +2279,8 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,
  	if (context_pending_enable(ce)) {
  		clr_context_pending_enable(ce);
  	} else if (context_pending_disable(ce)) {
+		bool banned;
+
  		/*
  		 * Unpin must be done before __guc_signal_context_fence,
  		 * otherwise a race exists between the requests getting
@@ -2174,9 +2291,16 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,
  		intel_context_sched_disable_unpin(ce);
 
  		spin_lock_irqsave(&ce->guc_state.lock, flags);
+		banned = context_banned(ce);
+		clr_context_banned(ce);
  		clr_context_pending_disable(ce);
  		__guc_signal_context_fence(ce);
  		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+
+		if (banned) {
+			guc_cancel_context_requests(ce);
+			intel_engine_signal_breadcrumbs(ce->engine);
+		}
  	}
 
  	decr_outstanding_submission_g2h(guc);
@@ -2211,8 +2335,11 @@ static void guc_handle_context_reset(struct intel_guc *guc,
  				     struct intel_context *ce)
  {
  	trace_intel_context_reset(ce);
-	capture_error_state(guc, ce);
-	guc_context_replay(ce);
+
+	if (likely(!intel_context_is_banned(ce))) {
+		capture_error_state(guc, ce);
+		guc_context_replay(ce);
+	}
  }
 
  int intel_guc_context_reset_process_msg(struct intel_guc *guc,
drivers/gpu/drm/i915/i915_trace.h +10 -0
index 3f43d904f043..9613a7c19661 100644
@@ -925,6 +925,11 @@ DEFINE_EVENT(intel_context, intel_context_reset,
  	     TP_ARGS(ce)
  );
 
+DEFINE_EVENT(intel_context, intel_context_ban,
+	     TP_PROTO(struct intel_context *ce),
+	     TP_ARGS(ce)
+);
+
  DEFINE_EVENT(intel_context, intel_context_register,
  	     TP_PROTO(struct intel_context *ce),
  	     TP_ARGS(ce)
@@ -1017,6 +1022,11 @@ trace_intel_context_reset(struct intel_context *ce)
  {
  }
 
+static inline void
+trace_intel_context_ban(struct intel_context *ce)
+{
+}
+
  static inline void
  trace_intel_context_register(struct intel_context *ce)
  {
#28 lore raw

Re: [Intel-gfx] [PATCH 24/33] drm/i915/guc: Implement banned contexts for GuC submission

In reply to Matthew Brost
Quoted 165 lines · Matthew Brost

When using GuC submission, if a context gets banned disable scheduling and mark all inflight requests as complete.

---
  drivers/gpu/drm/i915/gem/i915_gem_context.c   |   2 +-
  drivers/gpu/drm/i915/gt/intel_context.h       |  13 ++
  drivers/gpu/drm/i915/gt/intel_context_types.h |   2 +
  drivers/gpu/drm/i915/gt/intel_reset.c         |  32 +---
  .../gpu/drm/i915/gt/intel_ring_submission.c   |  20 +++
  drivers/gpu/drm/i915/gt/uc/intel_guc.h        |   2 +
  .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 151 ++++++++++++++++--
  drivers/gpu/drm/i915/i915_trace.h             |  10 ++
  8 files changed, 195 insertions(+), 37 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +1 -1
index e3df01a201d7..05c3ee191710 100644
@@ -1084,7 +1084,7 @@ static void kill_engines(struct i915_gem_engines *engines, bool ban)
  	for_each_gem_engine(ce, engines, it) {
  		struct intel_engine_cs *engine;
 
-		if (ban && intel_context_set_banned(ce))
+		if (ban && intel_context_ban(ce, NULL))
  			continue;
 
  		/*
drivers/gpu/drm/i915/gt/intel_context.h +13 -0
index 2ed9bf5f91a5..814d9277096a 100644
@@ -16,6 +16,7 @@
  #include "intel_engine_types.h"
  #include "intel_ring_types.h"
  #include "intel_timeline_types.h"
+#include "i915_trace.h"
 
  #define CE_TRACE(ce, fmt, ...) do {					\
  	const struct intel_context *ce__ = (ce);			\
@@ -243,6 +244,18 @@ static inline bool intel_context_set_banned(struct intel_context *ce)
  	return test_and_set_bit(CONTEXT_BANNED, &ce->flags);
  }
 
+static inline bool intel_context_ban(struct intel_context *ce,
+				     struct i915_request *rq)
+{
+	bool ret = intel_context_set_banned(ce);
+
+	trace_intel_context_ban(ce);
+	if (ce->ops->ban)
+		ce->ops->ban(ce, rq);
+
+	return ret;
+}
+
  static inline bool
  intel_context_force_single_submission(const struct intel_context *ce)
  {
drivers/gpu/drm/i915/gt/intel_context_types.h +2 -0
index 035108c10b2c..57c19ee3e313 100644
@@ -35,6 +35,8 @@ struct intel_context_ops {
 
  	int (*alloc)(struct intel_context *ce);
 
+	void (*ban)(struct intel_context *ce, struct i915_request *rq);
+
  	int (*pre_pin)(struct intel_context *ce, struct i915_gem_ww_ctx *ww, void **vaddr);
  	int (*pin)(struct intel_context *ce, void *vaddr);
  	void (*unpin)(struct intel_context *ce);
drivers/gpu/drm/i915/gt/intel_reset.c +8 -24
index 4d281bc8a38c..91200c43951f 100644
@@ -22,7 +22,6 @@
  #include "intel_reset.h"
 
  #include "uc/intel_guc.h"
-#include "uc/intel_guc_submission.h"
 
  #define RESET_MAX_RETRIES 3
 
@@ -39,21 +38,6 @@ static void rmw_clear_fw(struct intel_uncore *uncore, i915_reg_t reg, u32 clr)
  	intel_uncore_rmw_fw(uncore, reg, clr, 0);
  }
 
-static void skip_context(struct i915_request *rq)
-{
-	struct intel_context *hung_ctx = rq->context;
-
-	list_for_each_entry_from_rcu(rq, &hung_ctx->timeline->requests, link) {
-		if (!i915_request_is_active(rq))
-			return;
-
-		if (rq->context == hung_ctx) {
-			i915_request_set_error_once(rq, -EIO);
-			__i915_request_skip(rq);
-		}
-	}
-}
-
  static void client_mark_guilty(struct i915_gem_context *ctx, bool banned)
  {
  	struct drm_i915_file_private *file_priv = ctx->file_priv;
@@ -88,10 +72,8 @@ static bool mark_guilty(struct i915_request *rq)
  	bool banned;
  	int i;
 
-	if (intel_context_is_closed(rq->context)) {
-		intel_context_set_banned(rq->context);
+	if (intel_context_is_closed(rq->context))
  		return true;
-	}
 
  	rcu_read_lock();
  	ctx = rcu_dereference(rq->context->gem_context);
@@ -123,11 +105,9 @@ static bool mark_guilty(struct i915_request *rq)
  	banned = !i915_gem_context_is_recoverable(ctx);
  	if (time_before(jiffies, prev_hang + CONTEXT_FAST_HANG_JIFFIES))
  		banned = true;
-	if (banned) {
+	if (banned)
  		drm_dbg(&ctx->i915->drm, "context %s: guilty %d, banned\n",
  			ctx->name, atomic_read(&ctx->guilty_count));
-		intel_context_set_banned(rq->context);
-	}
 
  	client_mark_guilty(ctx, banned);
 
@@ -149,6 +129,8 @@ static void mark_innocent(struct i915_request *rq)
 
  void __i915_request_reset(struct i915_request *rq, bool guilty)
  {
+	bool banned = false;
+
  	RQ_TRACE(rq, "guilty? %s\n", yesno(guilty));
  	GEM_BUG_ON(__i915_request_is_complete(rq));
 
@@ -156,13 +138,15 @@ void __i915_request_reset(struct i915_request *rq, bool guilty)
  	if (guilty) {
  		i915_request_set_error_once(rq, -EIO);
  		__i915_request_skip(rq);
-		if (mark_guilty(rq) && !intel_engine_uses_guc(rq->engine))
-			skip_context(rq);
+		banned = mark_guilty(rq);
  	} else {
  		i915_request_set_error_once(rq, -EAGAIN);
  		mark_innocent(rq);
  	}
  	rcu_read_unlock();
+
+	if (banned)
+		intel_context_ban(rq->context, rq);
  }
 
  static bool i915_in_reset(struct pci_dev *pdev)
drivers/gpu/drm/i915/gt/intel_ring_submission.c +0 -0
index a5404c7b600f..05bb9f449df1 100644

drivers/gpu/drm/i915/gt/intel_ring_submission.c static void ring_context_reset(struct intel_context *ce) · line 595

Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_ring_submission.c +7 -0
@@ -586,9 +586,29 @@ static void ring_context_reset(struct intel_context *ce)
  	clear_bit(CONTEXT_VALID_BIT, &ce->flags);
  }
 
+static void ring_context_ban(struct intel_context *ce,
+			     struct i915_request *rq)
+{
+	struct intel_engine_cs *engine;
+
+	if (!rq || !i915_request_is_active(rq))
+		return;

When this gets called from context close, via intel_context_ban, rq will be always NULL - so the below loop which skips a line of executing requests never gets to run.

This appears a functional change versus previous state of the codebase, where skip_context() would run in any case.

I had this observation from a patch I am working on (https://intel-gfx-ci.01.org/tree/drm-tip/Trybot_7950/shard-snb6/igt@[email protected] - so a long line of executing requests which did not get zapped post reset), but may be wrong. Maybe I am missing something since I don't yet understand why would I be first to hit this issue. So take it with a grain of salt for now.

Ah.. maybe the key is that in my patch I made intel_context_ban not call ce->ops->"ban" (I renamed it to revoke) unconditionally. Hence there may be a path there intel_context_ban is first called wo/ a rq, then from within __i915_request_reset it gets called with rq, which now fails to call the vfunc. Hm that's clunky and fragile which ever way I look at it. I'll trybot one more experiment..

Regards,

Tvrtko

Quoted 373 lines
drivers/gpu/drm/i915/gt/intel_ring_submission.c +13 -0
+
+	engine = rq->engine;
+	lockdep_assert_held(&engine->sched_engine->lock);
+	list_for_each_entry_continue(rq, &engine->sched_engine->requests,
+				     sched.link)
+		if (rq->context == ce) {
+			i915_request_set_error_once(rq, -EIO);
+			__i915_request_skip(rq);
+		}
+}
+
  static const struct intel_context_ops ring_context_ops = {
  	.alloc = ring_context_alloc,
 
+	.ban = ring_context_ban,
+
  	.pre_pin = ring_context_pre_pin,
  	.pin = ring_context_pin,
  	.unpin = ring_context_unpin,
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2 -0
index 1875303c3bca..8ab70a2223b0 100644
@@ -281,6 +281,8 @@ void intel_guc_find_hung_context(struct intel_engine_cs *engine);
 
  int intel_guc_global_policies_update(struct intel_guc *guc);
 
+void intel_guc_context_ban(struct intel_context *ce, struct i915_request *rq);
+
  void intel_guc_submission_reset_prepare(struct intel_guc *guc);
  void intel_guc_submission_reset(struct intel_guc *guc, bool stalled);
  void intel_guc_submission_reset_finish(struct intel_guc *guc);
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +139 -12
index cea3e3073a71..ad9a38a861df 100644
@@ -125,6 +125,7 @@ static inline void clr_context_pending_enable(struct intel_context *ce)
  #define SCHED_STATE_WAIT_FOR_DEREGISTER_TO_REGISTER	BIT(0)
  #define SCHED_STATE_DESTROYED				BIT(1)
  #define SCHED_STATE_PENDING_DISABLE			BIT(2)
+#define SCHED_STATE_BANNED				BIT(3)
  static inline void init_sched_state(struct intel_context *ce)
  {
  	/* Only should be called from guc_lrc_desc_pin() */
@@ -185,6 +186,23 @@ static inline void clr_context_pending_disable(struct intel_context *ce)
  	ce->guc_state.sched_state &= ~SCHED_STATE_PENDING_DISABLE;
  }
 
+static inline bool context_banned(struct intel_context *ce)
+{
+	return ce->guc_state.sched_state & SCHED_STATE_BANNED;
+}
+
+static inline void set_context_banned(struct intel_context *ce)
+{
+	lockdep_assert_held(&ce->guc_state.lock);
+	ce->guc_state.sched_state |= SCHED_STATE_BANNED;
+}
+
+static inline void clr_context_banned(struct intel_context *ce)
+{
+	lockdep_assert_held(&ce->guc_state.lock);
+	ce->guc_state.sched_state &= ~SCHED_STATE_BANNED;
+}
+
  static inline bool context_guc_id_invalid(struct intel_context *ce)
  {
  	return ce->guc_id == GUC_INVALID_LRC_ID;
@@ -357,13 +375,23 @@ static int guc_lrc_desc_pin(struct intel_context *ce, bool loop);
 
  static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)
  {
-	int err;
+	int err = 0;
  	struct intel_context *ce = rq->context;
  	u32 action[3];
  	int len = 0;
  	u32 g2h_len_dw = 0;
  	bool enabled;
 
+	/*
+	 * Corner case where requests were sitting in the priority list or a
+	 * request resubmitted after the context was banned.
+	 */
+	if (unlikely(intel_context_is_banned(ce))) {
+		i915_request_put(i915_request_mark_eio(rq));
+		intel_engine_signal_breadcrumbs(ce->engine);
+		goto out;
+	}
+
  	GEM_BUG_ON(!atomic_read(&ce->guc_id_ref));
  	GEM_BUG_ON(context_guc_id_invalid(ce));
 
@@ -399,6 +427,8 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)
  		clr_context_pending_enable(ce);
  		intel_context_put(ce);
  	}
+	if (likely(!err))
+		trace_i915_request_guc_submit(rq);
 
  out:
  	return err;
@@ -463,7 +493,6 @@ static int guc_dequeue_one_context(struct intel_guc *guc)
  			guc->stalled_request = last;
  			return false;
  		}
-		trace_i915_request_guc_submit(last);
  	}
 
  	guc->stalled_request = NULL;
@@ -502,12 +531,13 @@ static void cs_irq_handler(struct intel_engine_cs *engine, u16 iir)
  static void __guc_context_destroy(struct intel_context *ce);
  static void release_guc_id(struct intel_guc *guc, struct intel_context *ce);
  static void guc_signal_context_fence(struct intel_context *ce);
+static void guc_cancel_context_requests(struct intel_context *ce);
 
  static void scrub_guc_desc_for_outstanding_g2h(struct intel_guc *guc)
  {
  	struct intel_context *ce;
  	unsigned long index, flags;
-	bool pending_disable, pending_enable, deregister, destroyed;
+	bool pending_disable, pending_enable, deregister, destroyed, banned;
 
  	xa_for_each(&guc->context_lookup, index, ce) {
  		/* Flush context */
@@ -525,6 +555,7 @@ static void scrub_guc_desc_for_outstanding_g2h(struct intel_guc *guc)
  		pending_enable = context_pending_enable(ce);
  		pending_disable = context_pending_disable(ce);
  		deregister = context_wait_for_deregister_to_register(ce);
+		banned = context_banned(ce);
  		init_sched_state(ce);
 
  		if (pending_enable || destroyed || deregister) {
@@ -542,6 +573,10 @@ static void scrub_guc_desc_for_outstanding_g2h(struct intel_guc *guc)
  		/* Not mutualy exclusive with above if statement. */
  		if (pending_disable) {
  			guc_signal_context_fence(ce);
+			if (banned) {
+				guc_cancel_context_requests(ce);
+				intel_engine_signal_breadcrumbs(ce->engine);
+			}
  			intel_context_sched_disable_unpin(ce);
  			atomic_dec(&guc->outstanding_submission_g2h);
  			intel_context_put(ce);
@@ -661,6 +696,9 @@ static void guc_reset_state(struct intel_context *ce, u32 head, bool scrub)
  {
  	struct intel_engine_cs *engine = __context_to_physical_engine(ce);
 
+	if (intel_context_is_banned(ce))
+		return;
+
  	GEM_BUG_ON(!intel_context_is_pinned(ce));
 
  	/*
@@ -731,6 +769,8 @@ static void __guc_reset_context(struct intel_context *ce, bool stalled)
  	struct i915_request *rq;
  	u32 head;
 
+	intel_context_get(ce);
+
  	/*
  	 * GuC will implicitly mark the context as non-schedulable
  	 * when it sends the reset notification. Make sure our state
@@ -756,6 +796,7 @@ static void __guc_reset_context(struct intel_context *ce, bool stalled)
  out_replay:
  	guc_reset_state(ce, head, stalled);
  	__unwind_incomplete_requests(ce);
+	intel_context_put(ce);
  }
 
  void intel_guc_submission_reset(struct intel_guc *guc, bool stalled)
@@ -940,8 +981,6 @@ static int guc_bypass_tasklet_submit(struct intel_guc *guc,
  	ret = guc_add_request(guc, rq);
  	if (ret == -EBUSY)
  		guc->stalled_request = rq;
-	else
-		trace_i915_request_guc_submit(rq);
 
  	if (unlikely(ret == -EPIPE))
  		disable_submission(guc);
@@ -1344,13 +1383,77 @@ static u16 prep_context_pending_disable(struct intel_context *ce)
  	return ce->guc_id;
  }
 
+static void __guc_context_set_preemption_timeout(struct intel_guc *guc,
+						 u16 guc_id,
+						 u32 preemption_timeout)
+{
+	u32 action[] = {
+		INTEL_GUC_ACTION_SET_CONTEXT_PREEMPTION_TIMEOUT,
+		guc_id,
+		preemption_timeout
+	};
+
+	intel_guc_send_busy_loop(guc, action, ARRAY_SIZE(action), 0, true);
+}
+
+static void guc_context_ban(struct intel_context *ce, struct i915_request *rq)
+{
+	struct intel_guc *guc = ce_to_guc(ce);
+	struct intel_runtime_pm *runtime_pm =
+		&ce->engine->gt->i915->runtime_pm;
+	intel_wakeref_t wakeref;
+	unsigned long flags;
+
+	guc_flush_submissions(guc);
+
+	spin_lock_irqsave(&ce->guc_state.lock, flags);
+	set_context_banned(ce);
+
+	if (submission_disabled(guc) ||
+	    (!context_enabled(ce) && !context_pending_disable(ce))) {
+		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+
+		guc_cancel_context_requests(ce);
+		intel_engine_signal_breadcrumbs(ce->engine);
+	} else if (!context_pending_disable(ce)) {
+		u16 guc_id;
+
+		/*
+		 * We add +2 here as the schedule disable complete CTB handler
+		 * calls intel_context_sched_disable_unpin (-2 to pin_count).
+		 */
+		atomic_add(2, &ce->pin_count);
+
+		guc_id = prep_context_pending_disable(ce);
+		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+
+		/*
+		 * In addition to disabling scheduling, set the preemption
+		 * timeout to the minimum value (1 us) so the banned context
+		 * gets kicked off the HW ASAP.
+		 */
+		with_intel_runtime_pm(runtime_pm, wakeref) {
+			__guc_context_set_preemption_timeout(guc, guc_id, 1);
+			__guc_context_sched_disable(guc, ce, guc_id);
+		}
+	} else {
+		if (!context_guc_id_invalid(ce))
+			with_intel_runtime_pm(runtime_pm, wakeref)
+				__guc_context_set_preemption_timeout(guc,
+								     ce->guc_id,
+								     1);
+		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+	}
+}
+
  static void guc_context_sched_disable(struct intel_context *ce)
  {
  	struct intel_guc *guc = ce_to_guc(ce);
-	struct intel_runtime_pm *runtime_pm = &ce->engine->gt->i915->runtime_pm;
  	unsigned long flags;
-	u16 guc_id;
+	struct intel_runtime_pm *runtime_pm = &ce->engine->gt->i915->runtime_pm;
  	intel_wakeref_t wakeref;
+	u16 guc_id;
+	bool enabled;
 
  	if (submission_disabled(guc) || context_guc_id_invalid(ce) ||
  	    !lrc_desc_registered(guc, ce->guc_id)) {
@@ -1364,14 +1467,22 @@ static void guc_context_sched_disable(struct intel_context *ce)
  	spin_lock_irqsave(&ce->guc_state.lock, flags);
 
  	/*
-	 * We have to check if the context has been pinned again as another pin
-	 * operation is allowed to pass this function. Checking the pin count,
-	 * within ce->guc_state.lock, synchronizes this function with
+	 * We have to check if the context has been disabled by another thread.
+	 * We also have to check if the context has been pinned again as another
+	 * pin operation is allowed to pass this function. Checking the pin
+	 * count, within ce->guc_state.lock, synchronizes this function with
  	 * guc_request_alloc ensuring a request doesn't slip through the
  	 * 'context_pending_disable' fence. Checking within the spin lock (can't
  	 * sleep) ensures another process doesn't pin this context and generate
  	 * a request before we set the 'context_pending_disable' flag here.
  	 */
+	enabled = context_enabled(ce);
+	if (unlikely(!enabled || submission_disabled(guc))) {
+		if (enabled)
+			clr_context_enabled(ce);
+		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+		goto unpin;
+	}
  	if (unlikely(atomic_add_unless(&ce->pin_count, -2, 2))) {
  		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
  		return;
@@ -1529,6 +1640,8 @@ static const struct intel_context_ops guc_context_ops = {
  	.unpin = guc_context_unpin,
  	.post_unpin = guc_context_post_unpin,
 
+	.ban = guc_context_ban,
+
  	.enter = intel_context_enter_engine,
  	.exit = intel_context_exit_engine,
 
@@ -1722,6 +1835,8 @@ static const struct intel_context_ops virtual_guc_context_ops = {
  	.unpin = guc_context_unpin,
  	.post_unpin = guc_context_post_unpin,
 
+	.ban = guc_context_ban,
+
  	.enter = guc_virtual_context_enter,
  	.exit = guc_virtual_context_exit,
 
@@ -2164,6 +2279,8 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,
  	if (context_pending_enable(ce)) {
  		clr_context_pending_enable(ce);
  	} else if (context_pending_disable(ce)) {
+		bool banned;
+
  		/*
  		 * Unpin must be done before __guc_signal_context_fence,
  		 * otherwise a race exists between the requests getting
@@ -2174,9 +2291,16 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,
  		intel_context_sched_disable_unpin(ce);
 
  		spin_lock_irqsave(&ce->guc_state.lock, flags);
+		banned = context_banned(ce);
+		clr_context_banned(ce);
  		clr_context_pending_disable(ce);
  		__guc_signal_context_fence(ce);
  		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+
+		if (banned) {
+			guc_cancel_context_requests(ce);
+			intel_engine_signal_breadcrumbs(ce->engine);
+		}
  	}
 
  	decr_outstanding_submission_g2h(guc);
@@ -2211,8 +2335,11 @@ static void guc_handle_context_reset(struct intel_guc *guc,
  				     struct intel_context *ce)
  {
  	trace_intel_context_reset(ce);
-	capture_error_state(guc, ce);
-	guc_context_replay(ce);
+
+	if (likely(!intel_context_is_banned(ce))) {
+		capture_error_state(guc, ce);
+		guc_context_replay(ce);
+	}
  }
 
  int intel_guc_context_reset_process_msg(struct intel_guc *guc,
drivers/gpu/drm/i915/i915_trace.h +10 -0
index 3f43d904f043..9613a7c19661 100644
@@ -925,6 +925,11 @@ DEFINE_EVENT(intel_context, intel_context_reset,
  	     TP_ARGS(ce)
  );
 
+DEFINE_EVENT(intel_context, intel_context_ban,
+	     TP_PROTO(struct intel_context *ce),
+	     TP_ARGS(ce)
+);
+
  DEFINE_EVENT(intel_context, intel_context_register,
  	     TP_PROTO(struct intel_context *ce),
  	     TP_ARGS(ce)
@@ -1017,6 +1022,11 @@ trace_intel_context_reset(struct intel_context *ce)
  {
  }
 
+static inline void
+trace_intel_context_ban(struct intel_context *ce)
+{
+}
+
  static inline void
  trace_intel_context_register(struct intel_context *ce)
  {
#29 lore raw

Re: [Intel-gfx] [PATCH 24/33] drm/i915/guc: Implement banned contexts for GuC submission

Quoted 163 lines · Tvrtko Ursulin
Quoted 148 lines · Matthew Brost

When using GuC submission, if a context gets banned disable scheduling and mark all inflight requests as complete.

---
  drivers/gpu/drm/i915/gem/i915_gem_context.c   |   2 +-
  drivers/gpu/drm/i915/gt/intel_context.h       |  13 ++
  drivers/gpu/drm/i915/gt/intel_context_types.h |   2 +
  drivers/gpu/drm/i915/gt/intel_reset.c         |  32 +---
  .../gpu/drm/i915/gt/intel_ring_submission.c   |  20 +++
  drivers/gpu/drm/i915/gt/uc/intel_guc.h        |   2 +
  .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 151 ++++++++++++++++--
  drivers/gpu/drm/i915/i915_trace.h             |  10 ++
  8 files changed, 195 insertions(+), 37 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +1 -1
index e3df01a201d7..05c3ee191710 100644
@@ -1084,7 +1084,7 @@ static void kill_engines(struct i915_gem_engines *engines, bool ban)
  	for_each_gem_engine(ce, engines, it) {
  		struct intel_engine_cs *engine;
-		if (ban && intel_context_set_banned(ce))
+		if (ban && intel_context_ban(ce, NULL))
  			continue;
  		/*
drivers/gpu/drm/i915/gt/intel_context.h +13 -0
index 2ed9bf5f91a5..814d9277096a 100644
@@ -16,6 +16,7 @@
  #include "intel_engine_types.h"
  #include "intel_ring_types.h"
  #include "intel_timeline_types.h"
+#include "i915_trace.h"
  #define CE_TRACE(ce, fmt, ...) do {					\
  	const struct intel_context *ce__ = (ce);			\
@@ -243,6 +244,18 @@ static inline bool intel_context_set_banned(struct intel_context *ce)
  	return test_and_set_bit(CONTEXT_BANNED, &ce->flags);
  }
+static inline bool intel_context_ban(struct intel_context *ce,
+				     struct i915_request *rq)
+{
+	bool ret = intel_context_set_banned(ce);
+
+	trace_intel_context_ban(ce);
+	if (ce->ops->ban)
+		ce->ops->ban(ce, rq);
+
+	return ret;
+}
+
  static inline bool
  intel_context_force_single_submission(const struct intel_context *ce)
  {
drivers/gpu/drm/i915/gt/intel_context_types.h +2 -0
index 035108c10b2c..57c19ee3e313 100644
@@ -35,6 +35,8 @@ struct intel_context_ops {
  	int (*alloc)(struct intel_context *ce);
+	void (*ban)(struct intel_context *ce, struct i915_request *rq);
+
  	int (*pre_pin)(struct intel_context *ce, struct i915_gem_ww_ctx *ww, void **vaddr);
  	int (*pin)(struct intel_context *ce, void *vaddr);
  	void (*unpin)(struct intel_context *ce);
drivers/gpu/drm/i915/gt/intel_reset.c +8 -24
index 4d281bc8a38c..91200c43951f 100644
@@ -22,7 +22,6 @@
  #include "intel_reset.h"
  #include "uc/intel_guc.h"
-#include "uc/intel_guc_submission.h"
  #define RESET_MAX_RETRIES 3
@@ -39,21 +38,6 @@ static void rmw_clear_fw(struct intel_uncore *uncore, i915_reg_t reg, u32 clr)
  	intel_uncore_rmw_fw(uncore, reg, clr, 0);
  }
-static void skip_context(struct i915_request *rq)
-{
-	struct intel_context *hung_ctx = rq->context;
-
-	list_for_each_entry_from_rcu(rq, &hung_ctx->timeline->requests, link) {
-		if (!i915_request_is_active(rq))
-			return;
-
-		if (rq->context == hung_ctx) {
-			i915_request_set_error_once(rq, -EIO);
-			__i915_request_skip(rq);
-		}
-	}
-}
-
  static void client_mark_guilty(struct i915_gem_context *ctx, bool banned)
  {
  	struct drm_i915_file_private *file_priv = ctx->file_priv;
@@ -88,10 +72,8 @@ static bool mark_guilty(struct i915_request *rq)
  	bool banned;
  	int i;
-	if (intel_context_is_closed(rq->context)) {
-		intel_context_set_banned(rq->context);
+	if (intel_context_is_closed(rq->context))
  		return true;
-	}
  	rcu_read_lock();
  	ctx = rcu_dereference(rq->context->gem_context);
@@ -123,11 +105,9 @@ static bool mark_guilty(struct i915_request *rq)
  	banned = !i915_gem_context_is_recoverable(ctx);
  	if (time_before(jiffies, prev_hang + CONTEXT_FAST_HANG_JIFFIES))
  		banned = true;
-	if (banned) {
+	if (banned)
  		drm_dbg(&ctx->i915->drm, "context %s: guilty %d, banned\n",
  			ctx->name, atomic_read(&ctx->guilty_count));
-		intel_context_set_banned(rq->context);
-	}
  	client_mark_guilty(ctx, banned);
@@ -149,6 +129,8 @@ static void mark_innocent(struct i915_request *rq)
  void __i915_request_reset(struct i915_request *rq, bool guilty)
  {
+	bool banned = false;
+
  	RQ_TRACE(rq, "guilty? %s\n", yesno(guilty));
  	GEM_BUG_ON(__i915_request_is_complete(rq));
@@ -156,13 +138,15 @@ void __i915_request_reset(struct i915_request *rq, bool guilty)
  	if (guilty) {
  		i915_request_set_error_once(rq, -EIO);
  		__i915_request_skip(rq);
-		if (mark_guilty(rq) && !intel_engine_uses_guc(rq->engine))
-			skip_context(rq);
+		banned = mark_guilty(rq);
  	} else {
  		i915_request_set_error_once(rq, -EAGAIN);
  		mark_innocent(rq);
  	}
  	rcu_read_unlock();
+
+	if (banned)
+		intel_context_ban(rq->context, rq);
  }
  static bool i915_in_reset(struct pci_dev *pdev)
drivers/gpu/drm/i915/gt/intel_ring_submission.c +0 -0
index a5404c7b600f..05bb9f449df1 100644

drivers/gpu/drm/i915/gt/intel_ring_submission.c static void ring_context_reset(struct intel_context *ce) · line 594

Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_ring_submission.c +7 -0
@@ -586,9 +586,29 @@ static void ring_context_reset(struct intel_context *ce)
  	clear_bit(CONTEXT_VALID_BIT, &ce->flags);
  }
+static void ring_context_ban(struct intel_context *ce,
+			     struct i915_request *rq)
+{
+	struct intel_engine_cs *engine;
+
+	if (!rq || !i915_request_is_active(rq))
+		return;

When this gets called from context close, via intel_context_ban, rq will be always NULL - so the below loop which skips a line of executing requests never gets to run.

Quoted 3 lines

This appears a functional change versus previous state of the codebase, where skip_context() would run in any case.

Hmm, not so sure about this being a functional change. When called from __i915_request_reset, intel_context_ban (previously skip_context there) always has a non-NULL request argument. When called from kill_engines the request is NULL (short circuiting ring function), but we never hooked into the ring backend before.

Quoted 6 lines

I had this observation from a patch I am working on (https://intel-gfx-ci.01.org/tree/drm-tip/Trybot_7950/shard-snb6/igt@[email protected]
- so a long line of executing requests which did not get zapped post reset),
but may be wrong. Maybe I am missing something since I don't yet understand
why would I be first to hit this issue. So take it with a grain of salt for
now.

CI was green on my series but CI doesn't always catch everything...

Do you have link to your series that I can look at?

Quoted 7 lines

Ah.. maybe the key is that in my patch I made intel_context_ban not call ce->ops->"ban" (I renamed it to revoke) unconditionally. Hence there may be a path there intel_context_ban is first called wo/ a rq, then from within __i915_request_reset it gets called with rq, which now fails to call the vfunc. Hm that's clunky and fragile which ever way I look at it. I'll trybot one more experiment..

I'm open to suggestions on how to change this, to make it makes sense to call into the function unconditionally with a correct arguments and the backend handles the rest (i.e. the way it is currently).

Matt

Quoted 348 lines

Regards,

Tvrtko

Quoted 344 lines
drivers/gpu/drm/i915/gt/intel_ring_submission.c +13 -0
+
+	engine = rq->engine;
+	lockdep_assert_held(&engine->sched_engine->lock);
+	list_for_each_entry_continue(rq, &engine->sched_engine->requests,
+				     sched.link)
+		if (rq->context == ce) {
+			i915_request_set_error_once(rq, -EIO);
+			__i915_request_skip(rq);
+		}
+}
+
  static const struct intel_context_ops ring_context_ops = {
  	.alloc = ring_context_alloc,
+	.ban = ring_context_ban,
+
  	.pre_pin = ring_context_pre_pin,
  	.pin = ring_context_pin,
  	.unpin = ring_context_unpin,
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2 -0
index 1875303c3bca..8ab70a2223b0 100644
@@ -281,6 +281,8 @@ void intel_guc_find_hung_context(struct intel_engine_cs *engine);
  int intel_guc_global_policies_update(struct intel_guc *guc);
+void intel_guc_context_ban(struct intel_context *ce, struct i915_request *rq);
+
  void intel_guc_submission_reset_prepare(struct intel_guc *guc);
  void intel_guc_submission_reset(struct intel_guc *guc, bool stalled);
  void intel_guc_submission_reset_finish(struct intel_guc *guc);
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +139 -12
index cea3e3073a71..ad9a38a861df 100644
@@ -125,6 +125,7 @@ static inline void clr_context_pending_enable(struct intel_context *ce)
  #define SCHED_STATE_WAIT_FOR_DEREGISTER_TO_REGISTER	BIT(0)
  #define SCHED_STATE_DESTROYED				BIT(1)
  #define SCHED_STATE_PENDING_DISABLE			BIT(2)
+#define SCHED_STATE_BANNED				BIT(3)
  static inline void init_sched_state(struct intel_context *ce)
  {
  	/* Only should be called from guc_lrc_desc_pin() */
@@ -185,6 +186,23 @@ static inline void clr_context_pending_disable(struct intel_context *ce)
  	ce->guc_state.sched_state &= ~SCHED_STATE_PENDING_DISABLE;
  }
+static inline bool context_banned(struct intel_context *ce)
+{
+	return ce->guc_state.sched_state & SCHED_STATE_BANNED;
+}
+
+static inline void set_context_banned(struct intel_context *ce)
+{
+	lockdep_assert_held(&ce->guc_state.lock);
+	ce->guc_state.sched_state |= SCHED_STATE_BANNED;
+}
+
+static inline void clr_context_banned(struct intel_context *ce)
+{
+	lockdep_assert_held(&ce->guc_state.lock);
+	ce->guc_state.sched_state &= ~SCHED_STATE_BANNED;
+}
+
  static inline bool context_guc_id_invalid(struct intel_context *ce)
  {
  	return ce->guc_id == GUC_INVALID_LRC_ID;
@@ -357,13 +375,23 @@ static int guc_lrc_desc_pin(struct intel_context *ce, bool loop);
  static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)
  {
-	int err;
+	int err = 0;
  	struct intel_context *ce = rq->context;
  	u32 action[3];
  	int len = 0;
  	u32 g2h_len_dw = 0;
  	bool enabled;
+	/*
+	 * Corner case where requests were sitting in the priority list or a
+	 * request resubmitted after the context was banned.
+	 */
+	if (unlikely(intel_context_is_banned(ce))) {
+		i915_request_put(i915_request_mark_eio(rq));
+		intel_engine_signal_breadcrumbs(ce->engine);
+		goto out;
+	}
+
  	GEM_BUG_ON(!atomic_read(&ce->guc_id_ref));
  	GEM_BUG_ON(context_guc_id_invalid(ce));
@@ -399,6 +427,8 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)
  		clr_context_pending_enable(ce);
  		intel_context_put(ce);
  	}
+	if (likely(!err))
+		trace_i915_request_guc_submit(rq);
  out:
  	return err;
@@ -463,7 +493,6 @@ static int guc_dequeue_one_context(struct intel_guc *guc)
  			guc->stalled_request = last;
  			return false;
  		}
-		trace_i915_request_guc_submit(last);
  	}
  	guc->stalled_request = NULL;
@@ -502,12 +531,13 @@ static void cs_irq_handler(struct intel_engine_cs *engine, u16 iir)
  static void __guc_context_destroy(struct intel_context *ce);
  static void release_guc_id(struct intel_guc *guc, struct intel_context *ce);
  static void guc_signal_context_fence(struct intel_context *ce);
+static void guc_cancel_context_requests(struct intel_context *ce);
  static void scrub_guc_desc_for_outstanding_g2h(struct intel_guc *guc)
  {
  	struct intel_context *ce;
  	unsigned long index, flags;
-	bool pending_disable, pending_enable, deregister, destroyed;
+	bool pending_disable, pending_enable, deregister, destroyed, banned;
  	xa_for_each(&guc->context_lookup, index, ce) {
  		/* Flush context */
@@ -525,6 +555,7 @@ static void scrub_guc_desc_for_outstanding_g2h(struct intel_guc *guc)
  		pending_enable = context_pending_enable(ce);
  		pending_disable = context_pending_disable(ce);
  		deregister = context_wait_for_deregister_to_register(ce);
+		banned = context_banned(ce);
  		init_sched_state(ce);
  		if (pending_enable || destroyed || deregister) {
@@ -542,6 +573,10 @@ static void scrub_guc_desc_for_outstanding_g2h(struct intel_guc *guc)
  		/* Not mutualy exclusive with above if statement. */
  		if (pending_disable) {
  			guc_signal_context_fence(ce);
+			if (banned) {
+				guc_cancel_context_requests(ce);
+				intel_engine_signal_breadcrumbs(ce->engine);
+			}
  			intel_context_sched_disable_unpin(ce);
  			atomic_dec(&guc->outstanding_submission_g2h);
  			intel_context_put(ce);
@@ -661,6 +696,9 @@ static void guc_reset_state(struct intel_context *ce, u32 head, bool scrub)
  {
  	struct intel_engine_cs *engine = __context_to_physical_engine(ce);
+	if (intel_context_is_banned(ce))
+		return;
+
  	GEM_BUG_ON(!intel_context_is_pinned(ce));
  	/*
@@ -731,6 +769,8 @@ static void __guc_reset_context(struct intel_context *ce, bool stalled)
  	struct i915_request *rq;
  	u32 head;
+	intel_context_get(ce);
+
  	/*
  	 * GuC will implicitly mark the context as non-schedulable
  	 * when it sends the reset notification. Make sure our state
@@ -756,6 +796,7 @@ static void __guc_reset_context(struct intel_context *ce, bool stalled)
  out_replay:
  	guc_reset_state(ce, head, stalled);
  	__unwind_incomplete_requests(ce);
+	intel_context_put(ce);
  }
  void intel_guc_submission_reset(struct intel_guc *guc, bool stalled)
@@ -940,8 +981,6 @@ static int guc_bypass_tasklet_submit(struct intel_guc *guc,
  	ret = guc_add_request(guc, rq);
  	if (ret == -EBUSY)
  		guc->stalled_request = rq;
-	else
-		trace_i915_request_guc_submit(rq);
  	if (unlikely(ret == -EPIPE))
  		disable_submission(guc);
@@ -1344,13 +1383,77 @@ static u16 prep_context_pending_disable(struct intel_context *ce)
  	return ce->guc_id;
  }
+static void __guc_context_set_preemption_timeout(struct intel_guc *guc,
+						 u16 guc_id,
+						 u32 preemption_timeout)
+{
+	u32 action[] = {
+		INTEL_GUC_ACTION_SET_CONTEXT_PREEMPTION_TIMEOUT,
+		guc_id,
+		preemption_timeout
+	};
+
+	intel_guc_send_busy_loop(guc, action, ARRAY_SIZE(action), 0, true);
+}
+
+static void guc_context_ban(struct intel_context *ce, struct i915_request *rq)
+{
+	struct intel_guc *guc = ce_to_guc(ce);
+	struct intel_runtime_pm *runtime_pm =
+		&ce->engine->gt->i915->runtime_pm;
+	intel_wakeref_t wakeref;
+	unsigned long flags;
+
+	guc_flush_submissions(guc);
+
+	spin_lock_irqsave(&ce->guc_state.lock, flags);
+	set_context_banned(ce);
+
+	if (submission_disabled(guc) ||
+	    (!context_enabled(ce) && !context_pending_disable(ce))) {
+		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+
+		guc_cancel_context_requests(ce);
+		intel_engine_signal_breadcrumbs(ce->engine);
+	} else if (!context_pending_disable(ce)) {
+		u16 guc_id;
+
+		/*
+		 * We add +2 here as the schedule disable complete CTB handler
+		 * calls intel_context_sched_disable_unpin (-2 to pin_count).
+		 */
+		atomic_add(2, &ce->pin_count);
+
+		guc_id = prep_context_pending_disable(ce);
+		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+
+		/*
+		 * In addition to disabling scheduling, set the preemption
+		 * timeout to the minimum value (1 us) so the banned context
+		 * gets kicked off the HW ASAP.
+		 */
+		with_intel_runtime_pm(runtime_pm, wakeref) {
+			__guc_context_set_preemption_timeout(guc, guc_id, 1);
+			__guc_context_sched_disable(guc, ce, guc_id);
+		}
+	} else {
+		if (!context_guc_id_invalid(ce))
+			with_intel_runtime_pm(runtime_pm, wakeref)
+				__guc_context_set_preemption_timeout(guc,
+								     ce->guc_id,
+								     1);
+		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+	}
+}
+
  static void guc_context_sched_disable(struct intel_context *ce)
  {
  	struct intel_guc *guc = ce_to_guc(ce);
-	struct intel_runtime_pm *runtime_pm = &ce->engine->gt->i915->runtime_pm;
  	unsigned long flags;
-	u16 guc_id;
+	struct intel_runtime_pm *runtime_pm = &ce->engine->gt->i915->runtime_pm;
  	intel_wakeref_t wakeref;
+	u16 guc_id;
+	bool enabled;
  	if (submission_disabled(guc) || context_guc_id_invalid(ce) ||
  	    !lrc_desc_registered(guc, ce->guc_id)) {
@@ -1364,14 +1467,22 @@ static void guc_context_sched_disable(struct intel_context *ce)
  	spin_lock_irqsave(&ce->guc_state.lock, flags);
  	/*
-	 * We have to check if the context has been pinned again as another pin
-	 * operation is allowed to pass this function. Checking the pin count,
-	 * within ce->guc_state.lock, synchronizes this function with
+	 * We have to check if the context has been disabled by another thread.
+	 * We also have to check if the context has been pinned again as another
+	 * pin operation is allowed to pass this function. Checking the pin
+	 * count, within ce->guc_state.lock, synchronizes this function with
  	 * guc_request_alloc ensuring a request doesn't slip through the
  	 * 'context_pending_disable' fence. Checking within the spin lock (can't
  	 * sleep) ensures another process doesn't pin this context and generate
  	 * a request before we set the 'context_pending_disable' flag here.
  	 */
+	enabled = context_enabled(ce);
+	if (unlikely(!enabled || submission_disabled(guc))) {
+		if (enabled)
+			clr_context_enabled(ce);
+		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+		goto unpin;
+	}
  	if (unlikely(atomic_add_unless(&ce->pin_count, -2, 2))) {
  		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
  		return;
@@ -1529,6 +1640,8 @@ static const struct intel_context_ops guc_context_ops = {
  	.unpin = guc_context_unpin,
  	.post_unpin = guc_context_post_unpin,
+	.ban = guc_context_ban,
+
  	.enter = intel_context_enter_engine,
  	.exit = intel_context_exit_engine,
@@ -1722,6 +1835,8 @@ static const struct intel_context_ops virtual_guc_context_ops = {
  	.unpin = guc_context_unpin,
  	.post_unpin = guc_context_post_unpin,
+	.ban = guc_context_ban,
+
  	.enter = guc_virtual_context_enter,
  	.exit = guc_virtual_context_exit,
@@ -2164,6 +2279,8 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,
  	if (context_pending_enable(ce)) {
  		clr_context_pending_enable(ce);
  	} else if (context_pending_disable(ce)) {
+		bool banned;
+
  		/*
  		 * Unpin must be done before __guc_signal_context_fence,
  		 * otherwise a race exists between the requests getting
@@ -2174,9 +2291,16 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,
  		intel_context_sched_disable_unpin(ce);
  		spin_lock_irqsave(&ce->guc_state.lock, flags);
+		banned = context_banned(ce);
+		clr_context_banned(ce);
  		clr_context_pending_disable(ce);
  		__guc_signal_context_fence(ce);
  		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+
+		if (banned) {
+			guc_cancel_context_requests(ce);
+			intel_engine_signal_breadcrumbs(ce->engine);
+		}
  	}
  	decr_outstanding_submission_g2h(guc);
@@ -2211,8 +2335,11 @@ static void guc_handle_context_reset(struct intel_guc *guc,
  				     struct intel_context *ce)
  {
  	trace_intel_context_reset(ce);
-	capture_error_state(guc, ce);
-	guc_context_replay(ce);
+
+	if (likely(!intel_context_is_banned(ce))) {
+		capture_error_state(guc, ce);
+		guc_context_replay(ce);
+	}
  }
  int intel_guc_context_reset_process_msg(struct intel_guc *guc,
drivers/gpu/drm/i915/i915_trace.h +10 -0
index 3f43d904f043..9613a7c19661 100644
@@ -925,6 +925,11 @@ DEFINE_EVENT(intel_context, intel_context_reset,
  	     TP_ARGS(ce)
  );
+DEFINE_EVENT(intel_context, intel_context_ban,
+	     TP_PROTO(struct intel_context *ce),
+	     TP_ARGS(ce)
+);
+
  DEFINE_EVENT(intel_context, intel_context_register,
  	     TP_PROTO(struct intel_context *ce),
  	     TP_ARGS(ce)
@@ -1017,6 +1022,11 @@ trace_intel_context_reset(struct intel_context *ce)
  {
  }
+static inline void
+trace_intel_context_ban(struct intel_context *ce)
+{
+}
+
  static inline void
  trace_intel_context_register(struct intel_context *ce)
  {
 
#30 lore raw

Re: [Intel-gfx] [PATCH 24/33] drm/i915/guc: Implement banned contexts for GuC submission

Quoted 168 lines · Matthew Brost
Quoted 163 lines · Tvrtko Ursulin
Quoted 148 lines · Matthew Brost

When using GuC submission, if a context gets banned disable scheduling and mark all inflight requests as complete.

---
   drivers/gpu/drm/i915/gem/i915_gem_context.c   |   2 +-
   drivers/gpu/drm/i915/gt/intel_context.h       |  13 ++
   drivers/gpu/drm/i915/gt/intel_context_types.h |   2 +
   drivers/gpu/drm/i915/gt/intel_reset.c         |  32 +---
   .../gpu/drm/i915/gt/intel_ring_submission.c   |  20 +++
   drivers/gpu/drm/i915/gt/uc/intel_guc.h        |   2 +
   .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 151 ++++++++++++++++--
   drivers/gpu/drm/i915/i915_trace.h             |  10 ++
   8 files changed, 195 insertions(+), 37 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +1 -1
index e3df01a201d7..05c3ee191710 100644
@@ -1084,7 +1084,7 @@ static void kill_engines(struct i915_gem_engines *engines, bool ban)
   	for_each_gem_engine(ce, engines, it) {
   		struct intel_engine_cs *engine;
-		if (ban && intel_context_set_banned(ce))
+		if (ban && intel_context_ban(ce, NULL))
   			continue;
   		/*
drivers/gpu/drm/i915/gt/intel_context.h +13 -0
index 2ed9bf5f91a5..814d9277096a 100644
@@ -16,6 +16,7 @@
   #include "intel_engine_types.h"
   #include "intel_ring_types.h"
   #include "intel_timeline_types.h"
+#include "i915_trace.h"
   #define CE_TRACE(ce, fmt, ...) do {					\
   	const struct intel_context *ce__ = (ce);			\
@@ -243,6 +244,18 @@ static inline bool intel_context_set_banned(struct intel_context *ce)
   	return test_and_set_bit(CONTEXT_BANNED, &ce->flags);
   }
+static inline bool intel_context_ban(struct intel_context *ce,
+				     struct i915_request *rq)
+{
+	bool ret = intel_context_set_banned(ce);
+
+	trace_intel_context_ban(ce);
+	if (ce->ops->ban)
+		ce->ops->ban(ce, rq);
+
+	return ret;
+}
+
   static inline bool
   intel_context_force_single_submission(const struct intel_context *ce)
   {
drivers/gpu/drm/i915/gt/intel_context_types.h +2 -0
index 035108c10b2c..57c19ee3e313 100644
@@ -35,6 +35,8 @@ struct intel_context_ops {
   	int (*alloc)(struct intel_context *ce);
+	void (*ban)(struct intel_context *ce, struct i915_request *rq);
+
   	int (*pre_pin)(struct intel_context *ce, struct i915_gem_ww_ctx *ww, void **vaddr);
   	int (*pin)(struct intel_context *ce, void *vaddr);
   	void (*unpin)(struct intel_context *ce);
drivers/gpu/drm/i915/gt/intel_reset.c +8 -24
index 4d281bc8a38c..91200c43951f 100644
@@ -22,7 +22,6 @@
   #include "intel_reset.h"
   #include "uc/intel_guc.h"
-#include "uc/intel_guc_submission.h"
   #define RESET_MAX_RETRIES 3
@@ -39,21 +38,6 @@ static void rmw_clear_fw(struct intel_uncore *uncore, i915_reg_t reg, u32 clr)
   	intel_uncore_rmw_fw(uncore, reg, clr, 0);
   }
-static void skip_context(struct i915_request *rq)
-{
-	struct intel_context *hung_ctx = rq->context;
-
-	list_for_each_entry_from_rcu(rq, &hung_ctx->timeline->requests, link) {
-		if (!i915_request_is_active(rq))
-			return;
-
-		if (rq->context == hung_ctx) {
-			i915_request_set_error_once(rq, -EIO);
-			__i915_request_skip(rq);
-		}
-	}
-}
-
   static void client_mark_guilty(struct i915_gem_context *ctx, bool banned)
   {
   	struct drm_i915_file_private *file_priv = ctx->file_priv;
@@ -88,10 +72,8 @@ static bool mark_guilty(struct i915_request *rq)
   	bool banned;
   	int i;
-	if (intel_context_is_closed(rq->context)) {
-		intel_context_set_banned(rq->context);
+	if (intel_context_is_closed(rq->context))
   		return true;
-	}
   	rcu_read_lock();
   	ctx = rcu_dereference(rq->context->gem_context);
@@ -123,11 +105,9 @@ static bool mark_guilty(struct i915_request *rq)
   	banned = !i915_gem_context_is_recoverable(ctx);
   	if (time_before(jiffies, prev_hang + CONTEXT_FAST_HANG_JIFFIES))
   		banned = true;
-	if (banned) {
+	if (banned)
   		drm_dbg(&ctx->i915->drm, "context %s: guilty %d, banned\n",
   			ctx->name, atomic_read(&ctx->guilty_count));
-		intel_context_set_banned(rq->context);
-	}
   	client_mark_guilty(ctx, banned);
@@ -149,6 +129,8 @@ static void mark_innocent(struct i915_request *rq)
   void __i915_request_reset(struct i915_request *rq, bool guilty)
   {
+	bool banned = false;
+
   	RQ_TRACE(rq, "guilty? %s\n", yesno(guilty));
   	GEM_BUG_ON(__i915_request_is_complete(rq));
@@ -156,13 +138,15 @@ void __i915_request_reset(struct i915_request *rq, bool guilty)
   	if (guilty) {
   		i915_request_set_error_once(rq, -EIO);
   		__i915_request_skip(rq);
-		if (mark_guilty(rq) && !intel_engine_uses_guc(rq->engine))
-			skip_context(rq);
+		banned = mark_guilty(rq);
   	} else {
   		i915_request_set_error_once(rq, -EAGAIN);
   		mark_innocent(rq);
   	}
   	rcu_read_unlock();
+
+	if (banned)
+		intel_context_ban(rq->context, rq);
   }
   static bool i915_in_reset(struct pci_dev *pdev)
drivers/gpu/drm/i915/gt/intel_ring_submission.c +0 -0
index a5404c7b600f..05bb9f449df1 100644

drivers/gpu/drm/i915/gt/intel_ring_submission.c static void ring_context_reset(struct intel_context *ce) · line 594

Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_ring_submission.c +7 -0
@@ -586,9 +586,29 @@ static void ring_context_reset(struct intel_context *ce)
   	clear_bit(CONTEXT_VALID_BIT, &ce->flags);
   }
+static void ring_context_ban(struct intel_context *ce,
+			     struct i915_request *rq)
+{
+	struct intel_engine_cs *engine;
+
+	if (!rq || !i915_request_is_active(rq))
+		return;

When this gets called from context close, via intel_context_ban, rq will be always NULL - so the below loop which skips a line of executing requests never gets to run.

Quoted 3 lines

This appears a functional change versus previous state of the codebase, where skip_context() would run in any case.

Quoted 5 lines

Hmm, not so sure about this being a functional change. When called from __i915_request_reset, intel_context_ban (previously skip_context there) always has a non-NULL request argument. When called from kill_engines the request is NULL (short circuiting ring function), but we never hooked into the ring backend before.

Yeah that's the area of confusion. You have defined the interface as "intel_context_ban(ce, rq)" and it is called two times during a common flow. It is true there is no functional change, but it is confusing what the purpose of intel_context_ban then is, given how absence of the rq parameter on the context close path makes it do almost nothing (apart in the case of GuC), plus on top, the flow actually relies on it being called 2nd time from deeper in the stack in case of ringbuf (other backend do not care).

Quoted 11 lines
Quoted 7 lines

I had this observation from a patch I am working on (https://intel-gfx-ci.01.org/tree/drm-tip/Trybot_7950/shard-snb6/igt@[email protected]
- so a long line of executing requests which did not get zapped post reset),
but may be wrong. Maybe I am missing something since I don't yet understand
why would I be first to hit this issue. So take it with a grain of salt for
now.

CI was green on my series but CI doesn't always catch everything...

Do you have link to your series that I can look at?

It was on trybot, thought you'll figure it out, but now I have sent it to intel-gfx as well so please have a look. To be clear I am not too happy with the current state of that patch..

Quoted 9 lines
Quoted 8 lines

Ah.. maybe the key is that in my patch I made intel_context_ban not call ce->ops->"ban" (I renamed it to revoke) unconditionally. Hence there may be a path there intel_context_ban is first called wo/ a rq, then from within __i915_request_reset it gets called with rq, which now fails to call the vfunc. Hm that's clunky and fragile which ever way I look at it. I'll trybot one more experiment..

Quoted 3 lines

I'm open to suggestions on how to change this, to make it makes sense to call into the function unconditionally with a correct arguments and the backend handles the rest (i.e. the way it is currently).

.. given what I wrote in the first paragraph. And I presently have no suggestions how to improve it, since it seems complicated enough to require quite a bit of thinking.

The issues as I see them now, intel_context_ban, when called from the context close path:

Guc:
* Does not use the rq parameter even if it was available.
* Deals with the list of queued requests.
(Although why does guc_cancel_context_requests isn't doing any
skipping, contrary to the comment inside?)

Execlists:
* Does not use the vfunc at all, remains to be just a set_bit call.

Ringbuffer:
* Just sets the bit.

When called from the reset path:

Guc:
* Same as on context close path - redundant?

Execlists:
* Nothing, sets the same already set bit potentially.

Ringbuf:
* Deals with cancelling queued requests - like GuC does in the 1st
invocation already.
* Does not use appear to use the rq argument meanigfully. Isn't the
"is not active" check redundant to sched_engine->requests only having active request on the list?

Most obvious open is whether the rq paramenter is even needed.

Then is the redundant call to the same func in case of GuC needed? If not, which one should remain - first or the second call?

Regards,

Tvrtko

Quoted 350 lines

Matt

Quoted 348 lines

Regards,

Tvrtko

Quoted 344 lines
drivers/gpu/drm/i915/gt/intel_ring_submission.c +13 -0
+
+	engine = rq->engine;
+	lockdep_assert_held(&engine->sched_engine->lock);
+	list_for_each_entry_continue(rq, &engine->sched_engine->requests,
+				     sched.link)
+		if (rq->context == ce) {
+			i915_request_set_error_once(rq, -EIO);
+			__i915_request_skip(rq);
+		}
+}
+
   static const struct intel_context_ops ring_context_ops = {
   	.alloc = ring_context_alloc,
+	.ban = ring_context_ban,
+
   	.pre_pin = ring_context_pre_pin,
   	.pin = ring_context_pin,
   	.unpin = ring_context_unpin,
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2 -0
index 1875303c3bca..8ab70a2223b0 100644
@@ -281,6 +281,8 @@ void intel_guc_find_hung_context(struct intel_engine_cs *engine);
   int intel_guc_global_policies_update(struct intel_guc *guc);
+void intel_guc_context_ban(struct intel_context *ce, struct i915_request *rq);
+
   void intel_guc_submission_reset_prepare(struct intel_guc *guc);
   void intel_guc_submission_reset(struct intel_guc *guc, bool stalled);
   void intel_guc_submission_reset_finish(struct intel_guc *guc);
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +139 -12
index cea3e3073a71..ad9a38a861df 100644
@@ -125,6 +125,7 @@ static inline void clr_context_pending_enable(struct intel_context *ce)
   #define SCHED_STATE_WAIT_FOR_DEREGISTER_TO_REGISTER	BIT(0)
   #define SCHED_STATE_DESTROYED				BIT(1)
   #define SCHED_STATE_PENDING_DISABLE			BIT(2)
+#define SCHED_STATE_BANNED				BIT(3)
   static inline void init_sched_state(struct intel_context *ce)
   {
   	/* Only should be called from guc_lrc_desc_pin() */
@@ -185,6 +186,23 @@ static inline void clr_context_pending_disable(struct intel_context *ce)
   	ce->guc_state.sched_state &= ~SCHED_STATE_PENDING_DISABLE;
   }
+static inline bool context_banned(struct intel_context *ce)
+{
+	return ce->guc_state.sched_state & SCHED_STATE_BANNED;
+}
+
+static inline void set_context_banned(struct intel_context *ce)
+{
+	lockdep_assert_held(&ce->guc_state.lock);
+	ce->guc_state.sched_state |= SCHED_STATE_BANNED;
+}
+
+static inline void clr_context_banned(struct intel_context *ce)
+{
+	lockdep_assert_held(&ce->guc_state.lock);
+	ce->guc_state.sched_state &= ~SCHED_STATE_BANNED;
+}
+
   static inline bool context_guc_id_invalid(struct intel_context *ce)
   {
   	return ce->guc_id == GUC_INVALID_LRC_ID;
@@ -357,13 +375,23 @@ static int guc_lrc_desc_pin(struct intel_context *ce, bool loop);
   static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)
   {
-	int err;
+	int err = 0;
   	struct intel_context *ce = rq->context;
   	u32 action[3];
   	int len = 0;
   	u32 g2h_len_dw = 0;
   	bool enabled;
+	/*
+	 * Corner case where requests were sitting in the priority list or a
+	 * request resubmitted after the context was banned.
+	 */
+	if (unlikely(intel_context_is_banned(ce))) {
+		i915_request_put(i915_request_mark_eio(rq));
+		intel_engine_signal_breadcrumbs(ce->engine);
+		goto out;
+	}
+
   	GEM_BUG_ON(!atomic_read(&ce->guc_id_ref));
   	GEM_BUG_ON(context_guc_id_invalid(ce));
@@ -399,6 +427,8 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)
   		clr_context_pending_enable(ce);
   		intel_context_put(ce);
   	}
+	if (likely(!err))
+		trace_i915_request_guc_submit(rq);
   out:
   	return err;
@@ -463,7 +493,6 @@ static int guc_dequeue_one_context(struct intel_guc *guc)
   			guc->stalled_request = last;
   			return false;
   		}
-		trace_i915_request_guc_submit(last);
   	}
   	guc->stalled_request = NULL;
@@ -502,12 +531,13 @@ static void cs_irq_handler(struct intel_engine_cs *engine, u16 iir)
   static void __guc_context_destroy(struct intel_context *ce);
   static void release_guc_id(struct intel_guc *guc, struct intel_context *ce);
   static void guc_signal_context_fence(struct intel_context *ce);
+static void guc_cancel_context_requests(struct intel_context *ce);
   static void scrub_guc_desc_for_outstanding_g2h(struct intel_guc *guc)
   {
   	struct intel_context *ce;
   	unsigned long index, flags;
-	bool pending_disable, pending_enable, deregister, destroyed;
+	bool pending_disable, pending_enable, deregister, destroyed, banned;
   	xa_for_each(&guc->context_lookup, index, ce) {
   		/* Flush context */
@@ -525,6 +555,7 @@ static void scrub_guc_desc_for_outstanding_g2h(struct intel_guc *guc)
   		pending_enable = context_pending_enable(ce);
   		pending_disable = context_pending_disable(ce);
   		deregister = context_wait_for_deregister_to_register(ce);
+		banned = context_banned(ce);
   		init_sched_state(ce);
   		if (pending_enable || destroyed || deregister) {
@@ -542,6 +573,10 @@ static void scrub_guc_desc_for_outstanding_g2h(struct intel_guc *guc)
   		/* Not mutualy exclusive with above if statement. */
   		if (pending_disable) {
   			guc_signal_context_fence(ce);
+			if (banned) {
+				guc_cancel_context_requests(ce);
+				intel_engine_signal_breadcrumbs(ce->engine);
+			}
   			intel_context_sched_disable_unpin(ce);
   			atomic_dec(&guc->outstanding_submission_g2h);
   			intel_context_put(ce);
@@ -661,6 +696,9 @@ static void guc_reset_state(struct intel_context *ce, u32 head, bool scrub)
   {
   	struct intel_engine_cs *engine = __context_to_physical_engine(ce);
+	if (intel_context_is_banned(ce))
+		return;
+
   	GEM_BUG_ON(!intel_context_is_pinned(ce));
   	/*
@@ -731,6 +769,8 @@ static void __guc_reset_context(struct intel_context *ce, bool stalled)
   	struct i915_request *rq;
   	u32 head;
+	intel_context_get(ce);
+
   	/*
   	 * GuC will implicitly mark the context as non-schedulable
   	 * when it sends the reset notification. Make sure our state
@@ -756,6 +796,7 @@ static void __guc_reset_context(struct intel_context *ce, bool stalled)
   out_replay:
   	guc_reset_state(ce, head, stalled);
   	__unwind_incomplete_requests(ce);
+	intel_context_put(ce);
   }
   void intel_guc_submission_reset(struct intel_guc *guc, bool stalled)
@@ -940,8 +981,6 @@ static int guc_bypass_tasklet_submit(struct intel_guc *guc,
   	ret = guc_add_request(guc, rq);
   	if (ret == -EBUSY)
   		guc->stalled_request = rq;
-	else
-		trace_i915_request_guc_submit(rq);
   	if (unlikely(ret == -EPIPE))
   		disable_submission(guc);
@@ -1344,13 +1383,77 @@ static u16 prep_context_pending_disable(struct intel_context *ce)
   	return ce->guc_id;
   }
+static void __guc_context_set_preemption_timeout(struct intel_guc *guc,
+						 u16 guc_id,
+						 u32 preemption_timeout)
+{
+	u32 action[] = {
+		INTEL_GUC_ACTION_SET_CONTEXT_PREEMPTION_TIMEOUT,
+		guc_id,
+		preemption_timeout
+	};
+
+	intel_guc_send_busy_loop(guc, action, ARRAY_SIZE(action), 0, true);
+}
+
+static void guc_context_ban(struct intel_context *ce, struct i915_request *rq)
+{
+	struct intel_guc *guc = ce_to_guc(ce);
+	struct intel_runtime_pm *runtime_pm =
+		&ce->engine->gt->i915->runtime_pm;
+	intel_wakeref_t wakeref;
+	unsigned long flags;
+
+	guc_flush_submissions(guc);
+
+	spin_lock_irqsave(&ce->guc_state.lock, flags);
+	set_context_banned(ce);
+
+	if (submission_disabled(guc) ||
+	    (!context_enabled(ce) && !context_pending_disable(ce))) {
+		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+
+		guc_cancel_context_requests(ce);
+		intel_engine_signal_breadcrumbs(ce->engine);
+	} else if (!context_pending_disable(ce)) {
+		u16 guc_id;
+
+		/*
+		 * We add +2 here as the schedule disable complete CTB handler
+		 * calls intel_context_sched_disable_unpin (-2 to pin_count).
+		 */
+		atomic_add(2, &ce->pin_count);
+
+		guc_id = prep_context_pending_disable(ce);
+		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+
+		/*
+		 * In addition to disabling scheduling, set the preemption
+		 * timeout to the minimum value (1 us) so the banned context
+		 * gets kicked off the HW ASAP.
+		 */
+		with_intel_runtime_pm(runtime_pm, wakeref) {
+			__guc_context_set_preemption_timeout(guc, guc_id, 1);
+			__guc_context_sched_disable(guc, ce, guc_id);
+		}
+	} else {
+		if (!context_guc_id_invalid(ce))
+			with_intel_runtime_pm(runtime_pm, wakeref)
+				__guc_context_set_preemption_timeout(guc,
+								     ce->guc_id,
+								     1);
+		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+	}
+}
+
   static void guc_context_sched_disable(struct intel_context *ce)
   {
   	struct intel_guc *guc = ce_to_guc(ce);
-	struct intel_runtime_pm *runtime_pm = &ce->engine->gt->i915->runtime_pm;
   	unsigned long flags;
-	u16 guc_id;
+	struct intel_runtime_pm *runtime_pm = &ce->engine->gt->i915->runtime_pm;
   	intel_wakeref_t wakeref;
+	u16 guc_id;
+	bool enabled;
   	if (submission_disabled(guc) || context_guc_id_invalid(ce) ||
   	    !lrc_desc_registered(guc, ce->guc_id)) {
@@ -1364,14 +1467,22 @@ static void guc_context_sched_disable(struct intel_context *ce)
   	spin_lock_irqsave(&ce->guc_state.lock, flags);
   	/*
-	 * We have to check if the context has been pinned again as another pin
-	 * operation is allowed to pass this function. Checking the pin count,
-	 * within ce->guc_state.lock, synchronizes this function with
+	 * We have to check if the context has been disabled by another thread.
+	 * We also have to check if the context has been pinned again as another
+	 * pin operation is allowed to pass this function. Checking the pin
+	 * count, within ce->guc_state.lock, synchronizes this function with
   	 * guc_request_alloc ensuring a request doesn't slip through the
   	 * 'context_pending_disable' fence. Checking within the spin lock (can't
   	 * sleep) ensures another process doesn't pin this context and generate
   	 * a request before we set the 'context_pending_disable' flag here.
   	 */
+	enabled = context_enabled(ce);
+	if (unlikely(!enabled || submission_disabled(guc))) {
+		if (enabled)
+			clr_context_enabled(ce);
+		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+		goto unpin;
+	}
   	if (unlikely(atomic_add_unless(&ce->pin_count, -2, 2))) {
   		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
   		return;
@@ -1529,6 +1640,8 @@ static const struct intel_context_ops guc_context_ops = {
   	.unpin = guc_context_unpin,
   	.post_unpin = guc_context_post_unpin,
+	.ban = guc_context_ban,
+
   	.enter = intel_context_enter_engine,
   	.exit = intel_context_exit_engine,
@@ -1722,6 +1835,8 @@ static const struct intel_context_ops virtual_guc_context_ops = {
   	.unpin = guc_context_unpin,
   	.post_unpin = guc_context_post_unpin,
+	.ban = guc_context_ban,
+
   	.enter = guc_virtual_context_enter,
   	.exit = guc_virtual_context_exit,
@@ -2164,6 +2279,8 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,
   	if (context_pending_enable(ce)) {
   		clr_context_pending_enable(ce);
   	} else if (context_pending_disable(ce)) {
+		bool banned;
+
   		/*
   		 * Unpin must be done before __guc_signal_context_fence,
   		 * otherwise a race exists between the requests getting
@@ -2174,9 +2291,16 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,
   		intel_context_sched_disable_unpin(ce);
   		spin_lock_irqsave(&ce->guc_state.lock, flags);
+		banned = context_banned(ce);
+		clr_context_banned(ce);
   		clr_context_pending_disable(ce);
   		__guc_signal_context_fence(ce);
   		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+
+		if (banned) {
+			guc_cancel_context_requests(ce);
+			intel_engine_signal_breadcrumbs(ce->engine);
+		}
   	}
   	decr_outstanding_submission_g2h(guc);
@@ -2211,8 +2335,11 @@ static void guc_handle_context_reset(struct intel_guc *guc,
   				     struct intel_context *ce)
   {
   	trace_intel_context_reset(ce);
-	capture_error_state(guc, ce);
-	guc_context_replay(ce);
+
+	if (likely(!intel_context_is_banned(ce))) {
+		capture_error_state(guc, ce);
+		guc_context_replay(ce);
+	}
   }
   int intel_guc_context_reset_process_msg(struct intel_guc *guc,
drivers/gpu/drm/i915/i915_trace.h +10 -0
index 3f43d904f043..9613a7c19661 100644
@@ -925,6 +925,11 @@ DEFINE_EVENT(intel_context, intel_context_reset,
   	     TP_ARGS(ce)
   );
+DEFINE_EVENT(intel_context, intel_context_ban,
+	     TP_PROTO(struct intel_context *ce),
+	     TP_ARGS(ce)
+);
+
   DEFINE_EVENT(intel_context, intel_context_register,
   	     TP_PROTO(struct intel_context *ce),
   	     TP_ARGS(ce)
@@ -1017,6 +1022,11 @@ trace_intel_context_reset(struct intel_context *ce)
   {
   }
+static inline void
+trace_intel_context_ban(struct intel_context *ce)
+{
+}
+
   static inline void
   trace_intel_context_register(struct intel_context *ce)
   {
 
#31 lore raw

Re: [Intel-gfx] [PATCH 24/33] drm/i915/guc: Implement banned contexts for GuC submission

Quoted 176 lines · Tvrtko Ursulin
Quoted 168 lines · Matthew Brost
Quoted 163 lines · Tvrtko Ursulin
Quoted 148 lines · Matthew Brost

When using GuC submission, if a context gets banned disable scheduling and mark all inflight requests as complete.

---
   drivers/gpu/drm/i915/gem/i915_gem_context.c   |   2 +-
   drivers/gpu/drm/i915/gt/intel_context.h       |  13 ++
   drivers/gpu/drm/i915/gt/intel_context_types.h |   2 +
   drivers/gpu/drm/i915/gt/intel_reset.c         |  32 +---
   .../gpu/drm/i915/gt/intel_ring_submission.c   |  20 +++
   drivers/gpu/drm/i915/gt/uc/intel_guc.h        |   2 +
   .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 151 ++++++++++++++++--
   drivers/gpu/drm/i915/i915_trace.h             |  10 ++
   8 files changed, 195 insertions(+), 37 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +1 -1
index e3df01a201d7..05c3ee191710 100644
@@ -1084,7 +1084,7 @@ static void kill_engines(struct i915_gem_engines *engines, bool ban)
   	for_each_gem_engine(ce, engines, it) {
   		struct intel_engine_cs *engine;
-		if (ban && intel_context_set_banned(ce))
+		if (ban && intel_context_ban(ce, NULL))
   			continue;
   		/*
drivers/gpu/drm/i915/gt/intel_context.h +13 -0
index 2ed9bf5f91a5..814d9277096a 100644
@@ -16,6 +16,7 @@
   #include "intel_engine_types.h"
   #include "intel_ring_types.h"
   #include "intel_timeline_types.h"
+#include "i915_trace.h"
   #define CE_TRACE(ce, fmt, ...) do {					\
   	const struct intel_context *ce__ = (ce);			\
@@ -243,6 +244,18 @@ static inline bool intel_context_set_banned(struct intel_context *ce)
   	return test_and_set_bit(CONTEXT_BANNED, &ce->flags);
   }
+static inline bool intel_context_ban(struct intel_context *ce,
+				     struct i915_request *rq)
+{
+	bool ret = intel_context_set_banned(ce);
+
+	trace_intel_context_ban(ce);
+	if (ce->ops->ban)
+		ce->ops->ban(ce, rq);
+
+	return ret;
+}
+
   static inline bool
   intel_context_force_single_submission(const struct intel_context *ce)
   {
drivers/gpu/drm/i915/gt/intel_context_types.h +2 -0
index 035108c10b2c..57c19ee3e313 100644
@@ -35,6 +35,8 @@ struct intel_context_ops {
   	int (*alloc)(struct intel_context *ce);
+	void (*ban)(struct intel_context *ce, struct i915_request *rq);
+
   	int (*pre_pin)(struct intel_context *ce, struct i915_gem_ww_ctx *ww, void **vaddr);
   	int (*pin)(struct intel_context *ce, void *vaddr);
   	void (*unpin)(struct intel_context *ce);
drivers/gpu/drm/i915/gt/intel_reset.c +8 -24
index 4d281bc8a38c..91200c43951f 100644
@@ -22,7 +22,6 @@
   #include "intel_reset.h"
   #include "uc/intel_guc.h"
-#include "uc/intel_guc_submission.h"
   #define RESET_MAX_RETRIES 3
@@ -39,21 +38,6 @@ static void rmw_clear_fw(struct intel_uncore *uncore, i915_reg_t reg, u32 clr)
   	intel_uncore_rmw_fw(uncore, reg, clr, 0);
   }
-static void skip_context(struct i915_request *rq)
-{
-	struct intel_context *hung_ctx = rq->context;
-
-	list_for_each_entry_from_rcu(rq, &hung_ctx->timeline->requests, link) {
-		if (!i915_request_is_active(rq))
-			return;
-
-		if (rq->context == hung_ctx) {
-			i915_request_set_error_once(rq, -EIO);
-			__i915_request_skip(rq);
-		}
-	}
-}
-
   static void client_mark_guilty(struct i915_gem_context *ctx, bool banned)
   {
   	struct drm_i915_file_private *file_priv = ctx->file_priv;
@@ -88,10 +72,8 @@ static bool mark_guilty(struct i915_request *rq)
   	bool banned;
   	int i;
-	if (intel_context_is_closed(rq->context)) {
-		intel_context_set_banned(rq->context);
+	if (intel_context_is_closed(rq->context))
   		return true;
-	}
   	rcu_read_lock();
   	ctx = rcu_dereference(rq->context->gem_context);
@@ -123,11 +105,9 @@ static bool mark_guilty(struct i915_request *rq)
   	banned = !i915_gem_context_is_recoverable(ctx);
   	if (time_before(jiffies, prev_hang + CONTEXT_FAST_HANG_JIFFIES))
   		banned = true;
-	if (banned) {
+	if (banned)
   		drm_dbg(&ctx->i915->drm, "context %s: guilty %d, banned\n",
   			ctx->name, atomic_read(&ctx->guilty_count));
-		intel_context_set_banned(rq->context);
-	}
   	client_mark_guilty(ctx, banned);
@@ -149,6 +129,8 @@ static void mark_innocent(struct i915_request *rq)
   void __i915_request_reset(struct i915_request *rq, bool guilty)
   {
+	bool banned = false;
+
   	RQ_TRACE(rq, "guilty? %s\n", yesno(guilty));
   	GEM_BUG_ON(__i915_request_is_complete(rq));
@@ -156,13 +138,15 @@ void __i915_request_reset(struct i915_request *rq, bool guilty)
   	if (guilty) {
   		i915_request_set_error_once(rq, -EIO);
   		__i915_request_skip(rq);
-		if (mark_guilty(rq) && !intel_engine_uses_guc(rq->engine))
-			skip_context(rq);
+		banned = mark_guilty(rq);
   	} else {
   		i915_request_set_error_once(rq, -EAGAIN);
   		mark_innocent(rq);
   	}
   	rcu_read_unlock();
+
+	if (banned)
+		intel_context_ban(rq->context, rq);
   }
   static bool i915_in_reset(struct pci_dev *pdev)
drivers/gpu/drm/i915/gt/intel_ring_submission.c +0 -0
index a5404c7b600f..05bb9f449df1 100644

drivers/gpu/drm/i915/gt/intel_ring_submission.c static void ring_context_reset(struct intel_context *ce) · line 594

Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_ring_submission.c +7 -0
@@ -586,9 +586,29 @@ static void ring_context_reset(struct intel_context *ce)
   	clear_bit(CONTEXT_VALID_BIT, &ce->flags);
   }
+static void ring_context_ban(struct intel_context *ce,
+			     struct i915_request *rq)
+{
+	struct intel_engine_cs *engine;
+
+	if (!rq || !i915_request_is_active(rq))
+		return;

When this gets called from context close, via intel_context_ban, rq will be always NULL - so the below loop which skips a line of executing requests never gets to run.

Quoted 3 lines

This appears a functional change versus previous state of the codebase, where skip_context() would run in any case.

Quoted 5 lines

Hmm, not so sure about this being a functional change. When called from __i915_request_reset, intel_context_ban (previously skip_context there) always has a non-NULL request argument. When called from kill_engines the request is NULL (short circuiting ring function), but we never hooked into the ring backend before.

Quoted 8 lines

Yeah that's the area of confusion. You have defined the interface as "intel_context_ban(ce, rq)" and it is called two times during a common flow. It is true there is no functional change, but it is confusing what the purpose of intel_context_ban then is, given how absence of the rq parameter on the context close path makes it do almost nothing (apart in the case of GuC), plus on top, the flow actually relies on it being called 2nd time from deeper in the stack in case of ringbuf (other backend do not care).

This was an attempt to pull backend specific behavior (i.e skip_context prior to my patch) into the backend.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

I had this observation from a patch I am working on (https://intel-gfx-ci.01.org/tree/drm-tip/Trybot_7950/shard-snb6/igt@[email protected]
- so a long line of executing requests which did not get zapped post reset),
but may be wrong. Maybe I am missing something since I don't yet understand
why would I be first to hit this issue. So take it with a grain of salt for
now.

Quoted 8 lines
Quoted 3 lines

CI was green on my series but CI doesn't always catch everything...

Do you have link to your series that I can look at?

It was on trybot, thought you'll figure it out, but now I have sent it to intel-gfx as well so please have a look. To be clear I am not too happy with the current state of that patch..

I found it, almost certainly your problem is short circuiting it on the state of the ban bit.

Quoted 17 lines
Quoted 9 lines
Quoted 8 lines

Ah.. maybe the key is that in my patch I made intel_context_ban not call ce->ops->"ban" (I renamed it to revoke) unconditionally. Hence there may be a path there intel_context_ban is first called wo/ a rq, then from within __i915_request_reset it gets called with rq, which now fails to call the vfunc. Hm that's clunky and fragile which ever way I look at it. I'll trybot one more experiment..

Quoted 3 lines

I'm open to suggestions on how to change this, to make it makes sense to call into the function unconditionally with a correct arguments and the backend handles the rest (i.e. the way it is currently).

.. given what I wrote in the first paragraph. And I presently have no suggestions how to improve it, since it seems complicated enough to require quite a bit of thinking.

Quoted 9 lines

The issues as I see them now, intel_context_ban, when called from the context close path:

Guc:
* Does not use the rq parameter even if it was available.
* Deals with the list of queued requests.
(Although why does guc_cancel_context_requests isn't doing any skipping,
contrary to the comment inside?)

It calls i915_request_mark_eio which skips a request without putting in back on the HW. The context is banned thus we can't / shouldn't put that context on the HW ever again.

Quoted 3 lines

Execlists:
* Does not use the vfunc at all, remains to be just a set_bit call.

Chris pulled the execlists vfunc out but isn't the point of having a vfunc, it can be present or not.

Quoted 8 lines

Ringbuffer:
* Just sets the bit.

When called from the reset path:

Guc:
* Same as on context close path - redundant?

Not redundant, in both cases we need to ban context in the GuC. Scheduling is likely disabled in this path so we can cancel the requests straight away.

Quoted 9 lines

Execlists:
* Nothing, sets the same already set bit potentially.

Ringbuf:
* Deals with cancelling queued requests - like GuC does in the 1st
invocation already.
* Does not use appear to use the rq argument meanigfully. Isn't the "is not
active" check redundant to sched_engine->requests only having active request on the list?

Not sure. This is why added the request argument, perhaps it could be removed? It being present / NULL also has a meaning (post-reset, pre-reset).

Quoted 3 lines

Most obvious open is whether the rq paramenter is even needed.

Maybe, see above.

Quoted 3 lines

Then is the redundant call to the same func in case of GuC needed? If not, which one should remain - first or the second call?

In the case of the GuC we need both calls.

Matt

Quoted 354 lines

Regards,

Tvrtko

Quoted 350 lines

Matt

Quoted 348 lines

Regards,

Tvrtko

Quoted 344 lines
drivers/gpu/drm/i915/gt/intel_ring_submission.c +13 -0
+
+	engine = rq->engine;
+	lockdep_assert_held(&engine->sched_engine->lock);
+	list_for_each_entry_continue(rq, &engine->sched_engine->requests,
+				     sched.link)
+		if (rq->context == ce) {
+			i915_request_set_error_once(rq, -EIO);
+			__i915_request_skip(rq);
+		}
+}
+
   static const struct intel_context_ops ring_context_ops = {
   	.alloc = ring_context_alloc,
+	.ban = ring_context_ban,
+
   	.pre_pin = ring_context_pre_pin,
   	.pin = ring_context_pin,
   	.unpin = ring_context_unpin,
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2 -0
index 1875303c3bca..8ab70a2223b0 100644
@@ -281,6 +281,8 @@ void intel_guc_find_hung_context(struct intel_engine_cs *engine);
   int intel_guc_global_policies_update(struct intel_guc *guc);
+void intel_guc_context_ban(struct intel_context *ce, struct i915_request *rq);
+
   void intel_guc_submission_reset_prepare(struct intel_guc *guc);
   void intel_guc_submission_reset(struct intel_guc *guc, bool stalled);
   void intel_guc_submission_reset_finish(struct intel_guc *guc);
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +139 -12
index cea3e3073a71..ad9a38a861df 100644
@@ -125,6 +125,7 @@ static inline void clr_context_pending_enable(struct intel_context *ce)
   #define SCHED_STATE_WAIT_FOR_DEREGISTER_TO_REGISTER	BIT(0)
   #define SCHED_STATE_DESTROYED				BIT(1)
   #define SCHED_STATE_PENDING_DISABLE			BIT(2)
+#define SCHED_STATE_BANNED				BIT(3)
   static inline void init_sched_state(struct intel_context *ce)
   {
   	/* Only should be called from guc_lrc_desc_pin() */
@@ -185,6 +186,23 @@ static inline void clr_context_pending_disable(struct intel_context *ce)
   	ce->guc_state.sched_state &= ~SCHED_STATE_PENDING_DISABLE;
   }
+static inline bool context_banned(struct intel_context *ce)
+{
+	return ce->guc_state.sched_state & SCHED_STATE_BANNED;
+}
+
+static inline void set_context_banned(struct intel_context *ce)
+{
+	lockdep_assert_held(&ce->guc_state.lock);
+	ce->guc_state.sched_state |= SCHED_STATE_BANNED;
+}
+
+static inline void clr_context_banned(struct intel_context *ce)
+{
+	lockdep_assert_held(&ce->guc_state.lock);
+	ce->guc_state.sched_state &= ~SCHED_STATE_BANNED;
+}
+
   static inline bool context_guc_id_invalid(struct intel_context *ce)
   {
   	return ce->guc_id == GUC_INVALID_LRC_ID;
@@ -357,13 +375,23 @@ static int guc_lrc_desc_pin(struct intel_context *ce, bool loop);
   static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)
   {
-	int err;
+	int err = 0;
   	struct intel_context *ce = rq->context;
   	u32 action[3];
   	int len = 0;
   	u32 g2h_len_dw = 0;
   	bool enabled;
+	/*
+	 * Corner case where requests were sitting in the priority list or a
+	 * request resubmitted after the context was banned.
+	 */
+	if (unlikely(intel_context_is_banned(ce))) {
+		i915_request_put(i915_request_mark_eio(rq));
+		intel_engine_signal_breadcrumbs(ce->engine);
+		goto out;
+	}
+
   	GEM_BUG_ON(!atomic_read(&ce->guc_id_ref));
   	GEM_BUG_ON(context_guc_id_invalid(ce));
@@ -399,6 +427,8 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)
   		clr_context_pending_enable(ce);
   		intel_context_put(ce);
   	}
+	if (likely(!err))
+		trace_i915_request_guc_submit(rq);
   out:
   	return err;
@@ -463,7 +493,6 @@ static int guc_dequeue_one_context(struct intel_guc *guc)
   			guc->stalled_request = last;
   			return false;
   		}
-		trace_i915_request_guc_submit(last);
   	}
   	guc->stalled_request = NULL;
@@ -502,12 +531,13 @@ static void cs_irq_handler(struct intel_engine_cs *engine, u16 iir)
   static void __guc_context_destroy(struct intel_context *ce);
   static void release_guc_id(struct intel_guc *guc, struct intel_context *ce);
   static void guc_signal_context_fence(struct intel_context *ce);
+static void guc_cancel_context_requests(struct intel_context *ce);
   static void scrub_guc_desc_for_outstanding_g2h(struct intel_guc *guc)
   {
   	struct intel_context *ce;
   	unsigned long index, flags;
-	bool pending_disable, pending_enable, deregister, destroyed;
+	bool pending_disable, pending_enable, deregister, destroyed, banned;
   	xa_for_each(&guc->context_lookup, index, ce) {
   		/* Flush context */
@@ -525,6 +555,7 @@ static void scrub_guc_desc_for_outstanding_g2h(struct intel_guc *guc)
   		pending_enable = context_pending_enable(ce);
   		pending_disable = context_pending_disable(ce);
   		deregister = context_wait_for_deregister_to_register(ce);
+		banned = context_banned(ce);
   		init_sched_state(ce);
   		if (pending_enable || destroyed || deregister) {
@@ -542,6 +573,10 @@ static void scrub_guc_desc_for_outstanding_g2h(struct intel_guc *guc)
   		/* Not mutualy exclusive with above if statement. */
   		if (pending_disable) {
   			guc_signal_context_fence(ce);
+			if (banned) {
+				guc_cancel_context_requests(ce);
+				intel_engine_signal_breadcrumbs(ce->engine);
+			}
   			intel_context_sched_disable_unpin(ce);
   			atomic_dec(&guc->outstanding_submission_g2h);
   			intel_context_put(ce);
@@ -661,6 +696,9 @@ static void guc_reset_state(struct intel_context *ce, u32 head, bool scrub)
   {
   	struct intel_engine_cs *engine = __context_to_physical_engine(ce);
+	if (intel_context_is_banned(ce))
+		return;
+
   	GEM_BUG_ON(!intel_context_is_pinned(ce));
   	/*
@@ -731,6 +769,8 @@ static void __guc_reset_context(struct intel_context *ce, bool stalled)
   	struct i915_request *rq;
   	u32 head;
+	intel_context_get(ce);
+
   	/*
   	 * GuC will implicitly mark the context as non-schedulable
   	 * when it sends the reset notification. Make sure our state
@@ -756,6 +796,7 @@ static void __guc_reset_context(struct intel_context *ce, bool stalled)
   out_replay:
   	guc_reset_state(ce, head, stalled);
   	__unwind_incomplete_requests(ce);
+	intel_context_put(ce);
   }
   void intel_guc_submission_reset(struct intel_guc *guc, bool stalled)
@@ -940,8 +981,6 @@ static int guc_bypass_tasklet_submit(struct intel_guc *guc,
   	ret = guc_add_request(guc, rq);
   	if (ret == -EBUSY)
   		guc->stalled_request = rq;
-	else
-		trace_i915_request_guc_submit(rq);
   	if (unlikely(ret == -EPIPE))
   		disable_submission(guc);
@@ -1344,13 +1383,77 @@ static u16 prep_context_pending_disable(struct intel_context *ce)
   	return ce->guc_id;
   }
+static void __guc_context_set_preemption_timeout(struct intel_guc *guc,
+						 u16 guc_id,
+						 u32 preemption_timeout)
+{
+	u32 action[] = {
+		INTEL_GUC_ACTION_SET_CONTEXT_PREEMPTION_TIMEOUT,
+		guc_id,
+		preemption_timeout
+	};
+
+	intel_guc_send_busy_loop(guc, action, ARRAY_SIZE(action), 0, true);
+}
+
+static void guc_context_ban(struct intel_context *ce, struct i915_request *rq)
+{
+	struct intel_guc *guc = ce_to_guc(ce);
+	struct intel_runtime_pm *runtime_pm =
+		&ce->engine->gt->i915->runtime_pm;
+	intel_wakeref_t wakeref;
+	unsigned long flags;
+
+	guc_flush_submissions(guc);
+
+	spin_lock_irqsave(&ce->guc_state.lock, flags);
+	set_context_banned(ce);
+
+	if (submission_disabled(guc) ||
+	    (!context_enabled(ce) && !context_pending_disable(ce))) {
+		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+
+		guc_cancel_context_requests(ce);
+		intel_engine_signal_breadcrumbs(ce->engine);
+	} else if (!context_pending_disable(ce)) {
+		u16 guc_id;
+
+		/*
+		 * We add +2 here as the schedule disable complete CTB handler
+		 * calls intel_context_sched_disable_unpin (-2 to pin_count).
+		 */
+		atomic_add(2, &ce->pin_count);
+
+		guc_id = prep_context_pending_disable(ce);
+		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+
+		/*
+		 * In addition to disabling scheduling, set the preemption
+		 * timeout to the minimum value (1 us) so the banned context
+		 * gets kicked off the HW ASAP.
+		 */
+		with_intel_runtime_pm(runtime_pm, wakeref) {
+			__guc_context_set_preemption_timeout(guc, guc_id, 1);
+			__guc_context_sched_disable(guc, ce, guc_id);
+		}
+	} else {
+		if (!context_guc_id_invalid(ce))
+			with_intel_runtime_pm(runtime_pm, wakeref)
+				__guc_context_set_preemption_timeout(guc,
+								     ce->guc_id,
+								     1);
+		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+	}
+}
+
   static void guc_context_sched_disable(struct intel_context *ce)
   {
   	struct intel_guc *guc = ce_to_guc(ce);
-	struct intel_runtime_pm *runtime_pm = &ce->engine->gt->i915->runtime_pm;
   	unsigned long flags;
-	u16 guc_id;
+	struct intel_runtime_pm *runtime_pm = &ce->engine->gt->i915->runtime_pm;
   	intel_wakeref_t wakeref;
+	u16 guc_id;
+	bool enabled;
   	if (submission_disabled(guc) || context_guc_id_invalid(ce) ||
   	    !lrc_desc_registered(guc, ce->guc_id)) {
@@ -1364,14 +1467,22 @@ static void guc_context_sched_disable(struct intel_context *ce)
   	spin_lock_irqsave(&ce->guc_state.lock, flags);
   	/*
-	 * We have to check if the context has been pinned again as another pin
-	 * operation is allowed to pass this function. Checking the pin count,
-	 * within ce->guc_state.lock, synchronizes this function with
+	 * We have to check if the context has been disabled by another thread.
+	 * We also have to check if the context has been pinned again as another
+	 * pin operation is allowed to pass this function. Checking the pin
+	 * count, within ce->guc_state.lock, synchronizes this function with
   	 * guc_request_alloc ensuring a request doesn't slip through the
   	 * 'context_pending_disable' fence. Checking within the spin lock (can't
   	 * sleep) ensures another process doesn't pin this context and generate
   	 * a request before we set the 'context_pending_disable' flag here.
   	 */
+	enabled = context_enabled(ce);
+	if (unlikely(!enabled || submission_disabled(guc))) {
+		if (enabled)
+			clr_context_enabled(ce);
+		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+		goto unpin;
+	}
   	if (unlikely(atomic_add_unless(&ce->pin_count, -2, 2))) {
   		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
   		return;
@@ -1529,6 +1640,8 @@ static const struct intel_context_ops guc_context_ops = {
   	.unpin = guc_context_unpin,
   	.post_unpin = guc_context_post_unpin,
+	.ban = guc_context_ban,
+
   	.enter = intel_context_enter_engine,
   	.exit = intel_context_exit_engine,
@@ -1722,6 +1835,8 @@ static const struct intel_context_ops virtual_guc_context_ops = {
   	.unpin = guc_context_unpin,
   	.post_unpin = guc_context_post_unpin,
+	.ban = guc_context_ban,
+
   	.enter = guc_virtual_context_enter,
   	.exit = guc_virtual_context_exit,
@@ -2164,6 +2279,8 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,
   	if (context_pending_enable(ce)) {
   		clr_context_pending_enable(ce);
   	} else if (context_pending_disable(ce)) {
+		bool banned;
+
   		/*
   		 * Unpin must be done before __guc_signal_context_fence,
   		 * otherwise a race exists between the requests getting
@@ -2174,9 +2291,16 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,
   		intel_context_sched_disable_unpin(ce);
   		spin_lock_irqsave(&ce->guc_state.lock, flags);
+		banned = context_banned(ce);
+		clr_context_banned(ce);
   		clr_context_pending_disable(ce);
   		__guc_signal_context_fence(ce);
   		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+
+		if (banned) {
+			guc_cancel_context_requests(ce);
+			intel_engine_signal_breadcrumbs(ce->engine);
+		}
   	}
   	decr_outstanding_submission_g2h(guc);
@@ -2211,8 +2335,11 @@ static void guc_handle_context_reset(struct intel_guc *guc,
   				     struct intel_context *ce)
   {
   	trace_intel_context_reset(ce);
-	capture_error_state(guc, ce);
-	guc_context_replay(ce);
+
+	if (likely(!intel_context_is_banned(ce))) {
+		capture_error_state(guc, ce);
+		guc_context_replay(ce);
+	}
   }
   int intel_guc_context_reset_process_msg(struct intel_guc *guc,
drivers/gpu/drm/i915/i915_trace.h +10 -0
index 3f43d904f043..9613a7c19661 100644
@@ -925,6 +925,11 @@ DEFINE_EVENT(intel_context, intel_context_reset,
   	     TP_ARGS(ce)
   );
+DEFINE_EVENT(intel_context, intel_context_ban,
+	     TP_PROTO(struct intel_context *ce),
+	     TP_ARGS(ce)
+);
+
   DEFINE_EVENT(intel_context, intel_context_register,
   	     TP_PROTO(struct intel_context *ce),
   	     TP_ARGS(ce)
@@ -1017,6 +1022,11 @@ trace_intel_context_reset(struct intel_context *ce)
   {
   }
+static inline void
+trace_intel_context_ban(struct intel_context *ce)
+{
+}
+
   static inline void
   trace_intel_context_register(struct intel_context *ce)
   {
 
#32 lore raw

PATCH 25/33 drm/i915/guc: Support request cancellation

In reply to Matthew Brost

This adds GuC backend support for i915_request_cancel(), which in turn makes CONFIG_DRM_I915_REQUEST_TIMEOUT work.

This implementation makes use of fence while there are likely simplier options. A fence was chosen because of another feature coming soon which requires a user to block on a context until scheduling is disabled. In that case we return the fence to the user and the user can wait on that fence.

v2:
(Daniele)
- A comment about locking the blocked incr / decr
- A comments about the use of the fence
- Update commit message explaining why fence
- Delete redundant check blocked count in unblock function
- Ring buffer implementation
- Comment about blocked in submission path
- Shorter rpm path
v3:
(Checkpatch)
- Fix typos in commit message
(Daniel)
- Rework to simplier locking structure in guc_context_block / unblock

---
 drivers/gpu/drm/i915/gt/intel_context.c       |  13 ++
 drivers/gpu/drm/i915/gt/intel_context.h       |   7 +
 drivers/gpu/drm/i915/gt/intel_context_types.h |   9 +-
 .../drm/i915/gt/intel_execlists_submission.c  |  18 ++
 .../gpu/drm/i915/gt/intel_ring_submission.c   |  16 ++
 .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 188 ++++++++++++++++++
 drivers/gpu/drm/i915/i915_request.c           |  14 +-
 7 files changed, 251 insertions(+), 14 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.c +13 -0
index 237b70e98744..477c42d7d693 100644
@@ -366,6 +366,12 @@ static int __intel_context_active(struct i915_active *active)
 	return 0;
 }
 
+static int sw_fence_dummy_notify(struct i915_sw_fence *sf,
+				 enum i915_sw_fence_notify state)
+{
+	return NOTIFY_DONE;
+}
+
 void
 intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)
 {
@@ -399,6 +405,13 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)
 	ce->guc_id = GUC_INVALID_LRC_ID;
 	INIT_LIST_HEAD(&ce->guc_id_link);
 
+	/*
+	 * Initialize fence to be complete as this is expected to be complete
+	 * unless there is a pending schedule disable outstanding.
+	 */
+	i915_sw_fence_init(&ce->guc_blocked, sw_fence_dummy_notify);
+	i915_sw_fence_commit(&ce->guc_blocked);
+
 	i915_active_init(&ce->active,
 			 __intel_context_active, __intel_context_retire, 0);
 }
drivers/gpu/drm/i915/gt/intel_context.h +7 -0
index 814d9277096a..876bdb08303c 100644
@@ -70,6 +70,13 @@ intel_context_is_pinned(struct intel_context *ce)
 	return atomic_read(&ce->pin_count);
 }
 
+static inline void intel_context_cancel_request(struct intel_context *ce,
+						struct i915_request *rq)
+{
+	GEM_BUG_ON(!ce->ops->cancel_request);
+	return ce->ops->cancel_request(ce, rq);
+}
+
 /**
  * intel_context_unlock_pinned - Releases the earlier locking of 'pinned' status
  * @ce - the context
drivers/gpu/drm/i915/gt/intel_context_types.h +8 -1
index 57c19ee3e313..a5bc876face7 100644
@@ -13,6 +13,7 @@
 #include <linux/types.h>
 
 #include "i915_active_types.h"
+#include "i915_sw_fence.h"
 #include "i915_utils.h"
 #include "intel_engine_types.h"
 #include "intel_sseu.h"
@@ -42,6 +43,9 @@ struct intel_context_ops {
 	void (*unpin)(struct intel_context *ce);
 	void (*post_unpin)(struct intel_context *ce);
 
+	void (*cancel_request)(struct intel_context *ce,
+			       struct i915_request *rq);
+
 	void (*enter)(struct intel_context *ce);
 	void (*exit)(struct intel_context *ce);
 
@@ -156,7 +160,7 @@ struct intel_context {
 		 * sched_state: scheduling state of this context using GuC
 		 * submission
 		 */
-		u8 sched_state;
+		u16 sched_state;
 		/*
 		 * fences: maintains of list of requests that have a submit
 		 * fence related to GuC submission
@@ -184,6 +188,9 @@ struct intel_context {
 	 * GuC ID link - in list when unpinned but guc_id still valid in GuC
 	 */
 	struct list_head guc_id_link;
+
+	/* GuC context blocked fence */
+	struct i915_sw_fence guc_blocked;
 };
 
 #endif /* __INTEL_CONTEXT_TYPES__ */
drivers/gpu/drm/i915/gt/intel_execlists_submission.c +18 -0
index b4a876736074..de5f9c86b9a4 100644
@@ -114,6 +114,7 @@
 #include "gen8_engine_cs.h"
 #include "intel_breadcrumbs.h"
 #include "intel_context.h"
+#include "intel_engine_heartbeat.h"
 #include "intel_engine_pm.h"
 #include "intel_engine_stats.h"
 #include "intel_execlists_submission.h"
@@ -2587,11 +2588,26 @@ static int execlists_context_alloc(struct intel_context *ce)
 	return lrc_alloc(ce, ce->engine);
 }
 
+static void execlists_context_cancel_request(struct intel_context *ce,
+					     struct i915_request *rq)
+{
+	struct intel_engine_cs *engine = NULL;
+
+	i915_request_active_engine(rq, &engine);
+
+	if (engine && intel_engine_pulse(engine))
+		intel_gt_handle_error(engine->gt, engine->mask, 0,
+				      "request cancellation by %s",
+				      current->comm);
+}
+
 static const struct intel_context_ops execlists_context_ops = {
 	.flags = COPS_HAS_INFLIGHT,
 
 	.alloc = execlists_context_alloc,
 
+	.cancel_request = execlists_context_cancel_request,
+
 	.pre_pin = execlists_context_pre_pin,
 	.pin = execlists_context_pin,
 	.unpin = lrc_unpin,
@@ -3608,6 +3624,8 @@ static const struct intel_context_ops virtual_context_ops = {
 
 	.alloc = virtual_context_alloc,
 
+	.cancel_request = execlists_context_cancel_request,
+
 	.pre_pin = virtual_context_pre_pin,
 	.pin = virtual_context_pin,
 	.unpin = lrc_unpin,
drivers/gpu/drm/i915/gt/intel_ring_submission.c +16 -0
index 05bb9f449df1..2958e2fae380 100644
@@ -16,6 +16,7 @@
 #include "intel_reset.h"
 #include "intel_ring.h"
 #include "shmem_utils.h"
+#include "intel_engine_heartbeat.h"
 
 /* Rough estimate of the typical request size, performing a flush,
  * set-context and then emitting the batch.
@@ -604,9 +605,24 @@ static void ring_context_ban(struct intel_context *ce,
 		}
 }
 
+static void ring_context_cancel_request(struct intel_context *ce,
+					struct i915_request *rq)
+{
+	struct intel_engine_cs *engine = NULL;
+
+	i915_request_active_engine(rq, &engine);
+
+	if (engine && intel_engine_pulse(engine))
+		intel_gt_handle_error(engine->gt, engine->mask, 0,
+				      "request cancellation by %s",
+				      current->comm);
+}
+
 static const struct intel_context_ops ring_context_ops = {
 	.alloc = ring_context_alloc,
 
+	.cancel_request = ring_context_cancel_request,
+
 	.ban = ring_context_ban,
 
 	.pre_pin = ring_context_pre_pin,
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +188 -0

259 lines not on this page · raw message

drivers/gpu/drm/i915/i915_request.c +1 -13
index 28f38b02a5d2..541a20371502 100644
@@ -710,18 +710,6 @@ void i915_request_unsubmit(struct i915_request *request)
 	spin_unlock_irqrestore(&engine->sched_engine->lock, flags);
 }
 
-static void __cancel_request(struct i915_request *rq)
-{
-	struct intel_engine_cs *engine = NULL;
-
-	i915_request_active_engine(rq, &engine);
-
-	if (engine && intel_engine_pulse(engine))
-		intel_gt_handle_error(engine->gt, engine->mask, 0,
-				      "request cancellation by %s",
-				      current->comm);
-}
-
 void i915_request_cancel(struct i915_request *rq, int error)
 {
 	if (!i915_request_set_error_once(rq, error))
@@ -729,7 +717,7 @@ void i915_request_cancel(struct i915_request *rq, int error)
 
 	set_bit(I915_FENCE_FLAG_SENTINEL, &rq->fence.flags);
 
-	__cancel_request(rq);
+	intel_context_cancel_request(rq->context, rq);
 }
 
 static int __i915_sw_fence_call
Signature · 1 line
2.28.0
Reviewed-by on v1 25/33
#33 lore raw

Re: [PATCH 25/33] drm/i915/guc: Support request cancellation

Quoted 24 lines · Matthew Brost

This adds GuC backend support for i915_request_cancel(), which in turn makes CONFIG_DRM_I915_REQUEST_TIMEOUT work.

This implementation makes use of fence while there are likely simplier options. A fence was chosen because of another feature coming soon which requires a user to block on a context until scheduling is disabled. In that case we return the fence to the user and the user can wait on that fence.

v2:
(Daniele)
- A comment about locking the blocked incr / decr
- A comments about the use of the fence
- Update commit message explaining why fence
- Delete redundant check blocked count in unblock function
- Ring buffer implementation
- Comment about blocked in submission path
- Shorter rpm path
v3:
(Checkpatch)
- Fix typos in commit message
(Daniel)
- Rework to simplier locking structure in guc_context_block / unblock

Quoted 2 lines

Daniele

Quoted 482 lines
---
  drivers/gpu/drm/i915/gt/intel_context.c       |  13 ++
  drivers/gpu/drm/i915/gt/intel_context.h       |   7 +
  drivers/gpu/drm/i915/gt/intel_context_types.h |   9 +-
  .../drm/i915/gt/intel_execlists_submission.c  |  18 ++
  .../gpu/drm/i915/gt/intel_ring_submission.c   |  16 ++
  .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 188 ++++++++++++++++++
  drivers/gpu/drm/i915/i915_request.c           |  14 +-
  7 files changed, 251 insertions(+), 14 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.c +13 -0
index 237b70e98744..477c42d7d693 100644
@@ -366,6 +366,12 @@ static int __intel_context_active(struct i915_active *active)
  	return 0;
  }
 
+static int sw_fence_dummy_notify(struct i915_sw_fence *sf,
+				 enum i915_sw_fence_notify state)
+{
+	return NOTIFY_DONE;
+}
+
  void
  intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)
  {
@@ -399,6 +405,13 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)
  	ce->guc_id = GUC_INVALID_LRC_ID;
  	INIT_LIST_HEAD(&ce->guc_id_link);
 
+	/*
+	 * Initialize fence to be complete as this is expected to be complete
+	 * unless there is a pending schedule disable outstanding.
+	 */
+	i915_sw_fence_init(&ce->guc_blocked, sw_fence_dummy_notify);
+	i915_sw_fence_commit(&ce->guc_blocked);
+
  	i915_active_init(&ce->active,
  			 __intel_context_active, __intel_context_retire, 0);
  }
drivers/gpu/drm/i915/gt/intel_context.h +7 -0
index 814d9277096a..876bdb08303c 100644
@@ -70,6 +70,13 @@ intel_context_is_pinned(struct intel_context *ce)
  	return atomic_read(&ce->pin_count);
  }
 
+static inline void intel_context_cancel_request(struct intel_context *ce,
+						struct i915_request *rq)
+{
+	GEM_BUG_ON(!ce->ops->cancel_request);
+	return ce->ops->cancel_request(ce, rq);
+}
+
  /**
   * intel_context_unlock_pinned - Releases the earlier locking of 'pinned' status
   * @ce - the context
drivers/gpu/drm/i915/gt/intel_context_types.h +8 -1
index 57c19ee3e313..a5bc876face7 100644
@@ -13,6 +13,7 @@
  #include <linux/types.h>
 
  #include "i915_active_types.h"
+#include "i915_sw_fence.h"
  #include "i915_utils.h"
  #include "intel_engine_types.h"
  #include "intel_sseu.h"
@@ -42,6 +43,9 @@ struct intel_context_ops {
  	void (*unpin)(struct intel_context *ce);
  	void (*post_unpin)(struct intel_context *ce);
 
+	void (*cancel_request)(struct intel_context *ce,
+			       struct i915_request *rq);
+
  	void (*enter)(struct intel_context *ce);
  	void (*exit)(struct intel_context *ce);
 
@@ -156,7 +160,7 @@ struct intel_context {
  		 * sched_state: scheduling state of this context using GuC
  		 * submission
  		 */
-		u8 sched_state;
+		u16 sched_state;
  		/*
  		 * fences: maintains of list of requests that have a submit
  		 * fence related to GuC submission
@@ -184,6 +188,9 @@ struct intel_context {
  	 * GuC ID link - in list when unpinned but guc_id still valid in GuC
  	 */
  	struct list_head guc_id_link;
+
+	/* GuC context blocked fence */
+	struct i915_sw_fence guc_blocked;
  };
 
  #endif /* __INTEL_CONTEXT_TYPES__ */
drivers/gpu/drm/i915/gt/intel_execlists_submission.c +18 -0
index b4a876736074..de5f9c86b9a4 100644
@@ -114,6 +114,7 @@
  #include "gen8_engine_cs.h"
  #include "intel_breadcrumbs.h"
  #include "intel_context.h"
+#include "intel_engine_heartbeat.h"
  #include "intel_engine_pm.h"
  #include "intel_engine_stats.h"
  #include "intel_execlists_submission.h"
@@ -2587,11 +2588,26 @@ static int execlists_context_alloc(struct intel_context *ce)
  	return lrc_alloc(ce, ce->engine);
  }
 
+static void execlists_context_cancel_request(struct intel_context *ce,
+					     struct i915_request *rq)
+{
+	struct intel_engine_cs *engine = NULL;
+
+	i915_request_active_engine(rq, &engine);
+
+	if (engine && intel_engine_pulse(engine))
+		intel_gt_handle_error(engine->gt, engine->mask, 0,
+				      "request cancellation by %s",
+				      current->comm);
+}
+
  static const struct intel_context_ops execlists_context_ops = {
  	.flags = COPS_HAS_INFLIGHT,
 
  	.alloc = execlists_context_alloc,
 
+	.cancel_request = execlists_context_cancel_request,
+
  	.pre_pin = execlists_context_pre_pin,
  	.pin = execlists_context_pin,
  	.unpin = lrc_unpin,
@@ -3608,6 +3624,8 @@ static const struct intel_context_ops virtual_context_ops = {
 
  	.alloc = virtual_context_alloc,
 
+	.cancel_request = execlists_context_cancel_request,
+
  	.pre_pin = virtual_context_pre_pin,
  	.pin = virtual_context_pin,
  	.unpin = lrc_unpin,
drivers/gpu/drm/i915/gt/intel_ring_submission.c +16 -0
index 05bb9f449df1..2958e2fae380 100644
@@ -16,6 +16,7 @@
  #include "intel_reset.h"
  #include "intel_ring.h"
  #include "shmem_utils.h"
+#include "intel_engine_heartbeat.h"
 
  /* Rough estimate of the typical request size, performing a flush,
   * set-context and then emitting the batch.
@@ -604,9 +605,24 @@ static void ring_context_ban(struct intel_context *ce,
  		}
  }
 
+static void ring_context_cancel_request(struct intel_context *ce,
+					struct i915_request *rq)
+{
+	struct intel_engine_cs *engine = NULL;
+
+	i915_request_active_engine(rq, &engine);
+
+	if (engine && intel_engine_pulse(engine))
+		intel_gt_handle_error(engine->gt, engine->mask, 0,
+				      "request cancellation by %s",
+				      current->comm);
+}
+
  static const struct intel_context_ops ring_context_ops = {
  	.alloc = ring_context_alloc,
 
+	.cancel_request = ring_context_cancel_request,
+
  	.ban = ring_context_ban,
 
  	.pre_pin = ring_context_pre_pin,
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +188 -0
index ad9a38a861df..ee4f1f996efa 100644
@@ -126,6 +126,9 @@ static inline void clr_context_pending_enable(struct intel_context *ce)
  #define SCHED_STATE_DESTROYED				BIT(1)
  #define SCHED_STATE_PENDING_DISABLE			BIT(2)
  #define SCHED_STATE_BANNED				BIT(3)
+#define SCHED_STATE_BLOCKED_SHIFT			4
+#define SCHED_STATE_BLOCKED		BIT(SCHED_STATE_BLOCKED_SHIFT)
+#define SCHED_STATE_BLOCKED_MASK	(0xfff << SCHED_STATE_BLOCKED_SHIFT)
  static inline void init_sched_state(struct intel_context *ce)
  {
  	/* Only should be called from guc_lrc_desc_pin() */
@@ -203,6 +206,32 @@ static inline void clr_context_banned(struct intel_context *ce)
  	ce->guc_state.sched_state &= ~SCHED_STATE_BANNED;
  }
 
+static inline u32 context_blocked(struct intel_context *ce)
+{
+	return (ce->guc_state.sched_state & SCHED_STATE_BLOCKED_MASK) >>
+		SCHED_STATE_BLOCKED_SHIFT;
+}
+
+static inline void incr_context_blocked(struct intel_context *ce)
+{
+	lockdep_assert_held(&ce->engine->sched_engine->lock);
+	lockdep_assert_held(&ce->guc_state.lock);
+
+	ce->guc_state.sched_state += SCHED_STATE_BLOCKED;
+
+	GEM_BUG_ON(!context_blocked(ce));	/* Overflow check */
+}
+
+static inline void decr_context_blocked(struct intel_context *ce)
+{
+	lockdep_assert_held(&ce->engine->sched_engine->lock);
+	lockdep_assert_held(&ce->guc_state.lock);
+
+	GEM_BUG_ON(!context_blocked(ce));	/* Underflow check */
+
+	ce->guc_state.sched_state -= SCHED_STATE_BLOCKED;
+}
+
  static inline bool context_guc_id_invalid(struct intel_context *ce)
  {
  	return ce->guc_id == GUC_INVALID_LRC_ID;
@@ -404,6 +433,14 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)
  		if (unlikely(err))
  			goto out;
  	}
+
+	/*
+	 * The request / context will be run on the hardware when scheduling
+	 * gets enabled in the unblock.
+	 */
+	if (unlikely(context_blocked(ce)))
+		goto out;
+
  	enabled = context_enabled(ce);
 
  	if (!enabled) {
@@ -532,6 +569,7 @@ static void __guc_context_destroy(struct intel_context *ce);
  static void release_guc_id(struct intel_guc *guc, struct intel_context *ce);
  static void guc_signal_context_fence(struct intel_context *ce);
  static void guc_cancel_context_requests(struct intel_context *ce);
+static void guc_blocked_fence_complete(struct intel_context *ce);
 
  static void scrub_guc_desc_for_outstanding_g2h(struct intel_guc *guc)
  {
@@ -579,6 +617,10 @@ static void scrub_guc_desc_for_outstanding_g2h(struct intel_guc *guc)
  			}
  			intel_context_sched_disable_unpin(ce);
  			atomic_dec(&guc->outstanding_submission_g2h);
+			spin_lock_irqsave(&ce->guc_state.lock, flags);
+			guc_blocked_fence_complete(ce);
+			spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+
  			intel_context_put(ce);
  		}
  	}
@@ -1354,6 +1396,21 @@ static void guc_context_post_unpin(struct intel_context *ce)
  	lrc_post_unpin(ce);
  }
 
+static void __guc_context_sched_enable(struct intel_guc *guc,
+				       struct intel_context *ce)
+{
+	u32 action[] = {
+		INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_SET,
+		ce->guc_id,
+		GUC_CONTEXT_ENABLE
+	};
+
+	trace_intel_context_sched_enable(ce);
+
+	guc_submission_send_busy_loop(guc, action, ARRAY_SIZE(action),
+				      G2H_LEN_DW_SCHED_CONTEXT_MODE_SET, true);
+}
+
  static void __guc_context_sched_disable(struct intel_guc *guc,
  					struct intel_context *ce,
  					u16 guc_id)
@@ -1372,17 +1429,143 @@ static void __guc_context_sched_disable(struct intel_guc *guc,
  				      G2H_LEN_DW_SCHED_CONTEXT_MODE_SET, true);
  }
 
+static void guc_blocked_fence_complete(struct intel_context *ce)
+{
+	lockdep_assert_held(&ce->guc_state.lock);
+
+	if (!i915_sw_fence_done(&ce->guc_blocked))
+		i915_sw_fence_complete(&ce->guc_blocked);
+}
+
+static void guc_blocked_fence_reinit(struct intel_context *ce)
+{
+	lockdep_assert_held(&ce->guc_state.lock);
+	GEM_BUG_ON(!i915_sw_fence_done(&ce->guc_blocked));
+
+	/*
+	 * This fence is always complete unless a pending schedule disable is
+	 * outstanding. We arm the fence here and complete it when we receive
+	 * the pending schedule disable complete message.
+	 */
+	i915_sw_fence_fini(&ce->guc_blocked);
+	i915_sw_fence_reinit(&ce->guc_blocked);
+	i915_sw_fence_await(&ce->guc_blocked);
+	i915_sw_fence_commit(&ce->guc_blocked);
+}
+
  static u16 prep_context_pending_disable(struct intel_context *ce)
  {
  	lockdep_assert_held(&ce->guc_state.lock);
 
  	set_context_pending_disable(ce);
  	clr_context_enabled(ce);
+	guc_blocked_fence_reinit(ce);
  	intel_context_get(ce);
 
  	return ce->guc_id;
  }
 
+static struct i915_sw_fence *guc_context_block(struct intel_context *ce)
+{
+	struct intel_guc *guc = ce_to_guc(ce);
+	struct i915_sched_engine *sched_engine = ce->engine->sched_engine;
+	unsigned long flags;
+	struct intel_runtime_pm *runtime_pm = ce->engine->uncore->rpm;
+	intel_wakeref_t wakeref;
+	u16 guc_id;
+	bool enabled;
+
+	spin_lock_irqsave(&ce->guc_state.lock, flags);
+
+	/*
+	 * Sync with submission path, increment before below changes to context
+	 * state.
+	 */
+	spin_lock(&sched_engine->lock);
+	incr_context_blocked(ce);
+	spin_unlock(&sched_engine->lock);
+
+	enabled = context_enabled(ce);
+	if (unlikely(!enabled || submission_disabled(guc))) {
+		if (enabled)
+			clr_context_enabled(ce);
+		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+		return &ce->guc_blocked;
+	}
+
+	/*
+	 * We add +2 here as the schedule disable complete CTB handler calls
+	 * intel_context_sched_disable_unpin (-2 to pin_count).
+	 */
+	atomic_add(2, &ce->pin_count);
+
+	guc_id = prep_context_pending_disable(ce);
+
+	spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+
+	with_intel_runtime_pm(runtime_pm, wakeref)
+		__guc_context_sched_disable(guc, ce, guc_id);
+
+	return &ce->guc_blocked;
+}
+
+static void guc_context_unblock(struct intel_context *ce)
+{
+	struct intel_guc *guc = ce_to_guc(ce);
+	struct i915_sched_engine *sched_engine = ce->engine->sched_engine;
+	unsigned long flags;
+	struct intel_runtime_pm *runtime_pm = ce->engine->uncore->rpm;
+	intel_wakeref_t wakeref;
+	bool enable;
+
+	GEM_BUG_ON(context_enabled(ce));
+
+	spin_lock_irqsave(&ce->guc_state.lock, flags);
+
+	if (unlikely(submission_disabled(guc) ||
+		     !intel_context_is_pinned(ce) ||
+		     context_pending_disable(ce) ||
+		     context_blocked(ce) > 1)) {
+		enable = false;
+	} else {
+		enable = true;
+		set_context_pending_enable(ce);
+		set_context_enabled(ce);
+		intel_context_get(ce);
+	}
+
+	/*
+	 * Sync with submission path, decrement after above changes to context
+	 * state.
+	 */
+	spin_lock(&sched_engine->lock);
+	decr_context_blocked(ce);
+	spin_unlock(&sched_engine->lock);
+
+	spin_unlock_irqrestore(&ce->guc_state.lock, flags);
+
+	if (enable) {
+		with_intel_runtime_pm(runtime_pm, wakeref)
+			__guc_context_sched_enable(guc, ce);
+	}
+}
+
+static void guc_context_cancel_request(struct intel_context *ce,
+				       struct i915_request *rq)
+{
+	if (i915_sw_fence_signaled(&rq->submit)) {
+		struct i915_sw_fence *fence = guc_context_block(ce);
+
+		i915_sw_fence_wait(fence);
+		if (!i915_request_completed(rq)) {
+			__i915_request_skip(rq);
+			guc_reset_state(ce, intel_ring_wrap(ce->ring, rq->head),
+					true);
+		}
+		guc_context_unblock(ce);
+	}
+}
+
  static void __guc_context_set_preemption_timeout(struct intel_guc *guc,
  						 u16 guc_id,
  						 u32 preemption_timeout)
@@ -1642,6 +1825,8 @@ static const struct intel_context_ops guc_context_ops = {
 
  	.ban = guc_context_ban,
 
+	.cancel_request = guc_context_cancel_request,
+
  	.enter = intel_context_enter_engine,
  	.exit = intel_context_exit_engine,
 
@@ -1837,6 +2022,8 @@ static const struct intel_context_ops virtual_guc_context_ops = {
 
  	.ban = guc_context_ban,
 
+	.cancel_request = guc_context_cancel_request,
+
  	.enter = guc_virtual_context_enter,
  	.exit = guc_virtual_context_exit,
 
@@ -2295,6 +2482,7 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,
  		clr_context_banned(ce);
  		clr_context_pending_disable(ce);
  		__guc_signal_context_fence(ce);
+		guc_blocked_fence_complete(ce);
  		spin_unlock_irqrestore(&ce->guc_state.lock, flags);
 
  		if (banned) {
drivers/gpu/drm/i915/i915_request.c +0 -12
index 28f38b02a5d2..541a20371502 100644
@@ -710,18 +710,6 @@ void i915_request_unsubmit(struct i915_request *request)
  	spin_unlock_irqrestore(&engine->sched_engine->lock, flags);
  }
 
-static void __cancel_request(struct i915_request *rq)
-{
-	struct intel_engine_cs *engine = NULL;
-
-	i915_request_active_engine(rq, &engine);
-
-	if (engine && intel_engine_pulse(engine))
-		intel_gt_handle_error(engine->gt, engine->mask, 0,
-				      "request cancellation by %s",
-				      current->comm);
-}
-
  void i915_request_cancel(struct i915_request *rq, int error)
  {
  	if (!i915_request_set_error_once(rq, error))

drivers/gpu/drm/i915/i915_request.c void i915_request_cancel(struct i915_request *rq, int error) · line 723

Quoted 8 lines
drivers/gpu/drm/i915/i915_request.c +1 -1
@@ -729,7 +717,7 @@ void i915_request_cancel(struct i915_request *rq, int error)
 
  	set_bit(I915_FENCE_FLAG_SENTINEL, &rq->fence.flags);
 
-	__cancel_request(rq);
+	intel_context_cancel_request(rq->context, rq);
  }
 
  static int __i915_sw_fence_call

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

#34 lore raw

Re: [PATCH 25/33] drm/i915/guc: Support request cancellation

Quoted 5 lines · Daniele Ceraolo Spurio
Quoted 3 lines · Matthew Brost

This adds GuC backend support for i915_request_cancel(), which in turn makes CONFIG_DRM_I915_REQUEST_TIMEOUT work.

I have a few instances of ODEBUG warnings since this commit
62eaf0ae217d4 ("drm/i915/guc: Support request cancellation")

like:

| ------------[ cut here ]------------
| ODEBUG: init destroyed (active state 0) object type: i915_sw_fence hint: sw_fence_dummy_notify+0x0/0x10
| WARNING: CPU: 0 PID: 987 at lib/debugobjects.c:505 debug_print_object+0x6e/0x90
| Modules linked in:
| CPU: 0 PID: 987 Comm: Xorg Not tainted 5.15.0-rc4+ #67
| Hardware name: To Be Filled By O.E.M. To Be Filled By O.E.M./Z68 Pro3-M, BIOS P2.10 04/24/2012
| RIP: 0010:debug_print_object+0x6e/0x90
…
| Call Trace:
|  i915_sw_fence_reinit+0x10/0x40
|  intel_context_init+0x185/0x1e0
|  intel_context_create+0x2e/0x100
|  default_engines+0x9d/0x120
|  i915_gem_create_context+0x40a/0x5d0
|  ? trace_kmalloc+0x29/0xd0
|  ? kmem_cache_alloc_trace+0xdd/0x190
|  i915_gem_context_open+0x140/0x1c0
|  i915_gem_open+0x70/0xa0
|  drm_file_alloc+0x1af/0x270
|  drm_open+0xdc/0x270
|  drm_stub_open+0xa6/0x130
|  chrdev_open+0xbe/0x250
|  ? cdev_device_add+0x80/0x80
|  do_dentry_open+0x15e/0x390
|  path_openat+0x76b/0xa60
|  do_filp_open+0xa4/0x150
|  ? lock_release+0x149/0x2f0
|  ? _raw_spin_unlock+0x24/0x40
|  do_sys_openat2+0x92/0x160
|  __x64_sys_openat+0x4f/0x90
|  do_syscall_64+0x3b/0xc0
|  entry_SYSCALL_64_after_hwframe+0x44/0xae
| RIP: 0033:0x7f91b5cfdf07

and:

| ODEBUG: activate destroyed (active state 0) object type: i915_sw_fence hint: sw_fence_dummy_notify+0x0/0x10
| WARNING: CPU: 0 PID: 987 at lib/debugobjects.c:505 debug_print_object+0x6e/0x90
| 
| Call Trace:
|  debug_object_activate+0x174/0x200
|  i915_sw_fence_commit+0x10/0x20
|  intel_context_init+0x18d/0x1e0
|  intel_context_create+0x2e/0x100
|  default_engines+0x9d/0x120

---

| ODEBUG: active_state destroyed (active state 0) object type: i915_sw_fence hint: sw_fence_dummy_notify+0x0/0x10
| WARNING: CPU: 0 PID: 987 at lib/debugobjects.c:505 debug_print_object+0x6e/0x90
| Call Trace:
|  __i915_sw_fence_complete+0x6f/0x280
|  intel_context_init+0x18d/0x1e0
|  intel_context_create+0x2e/0x100
|  default_engines+0x9d/0x120

Is this known? This is yesterday's -rc4, I first noticed it in -rc3.

Quoted 1 line

Daniele

Sebastian

#35 lore raw

Re: [Intel-gfx] [PATCH 25/33] drm/i915/guc: Support request cancellation

Quoted 67 lines · Sebastian Andrzej Siewior
Quoted 5 lines · Daniele Ceraolo Spurio
Quoted 3 lines · Matthew Brost

This adds GuC backend support for i915_request_cancel(), which in turn makes CONFIG_DRM_I915_REQUEST_TIMEOUT work.

I have a few instances of ODEBUG warnings since this commit

    62eaf0ae217d4 ("drm/i915/guc: Support request cancellation")

like:

| ------------[ cut here ]------------
| ODEBUG: init destroyed (active state 0) object type: i915_sw_fence hint: sw_fence_dummy_notify+0x0/0x10
| WARNING: CPU: 0 PID: 987 at lib/debugobjects.c:505 debug_print_object+0x6e/0x90
| Modules linked in:
| CPU: 0 PID: 987 Comm: Xorg Not tainted 5.15.0-rc4+ #67
| Hardware name: To Be Filled By O.E.M. To Be Filled By O.E.M./Z68 Pro3-M, BIOS P2.10 04/24/2012
| RIP: 0010:debug_print_object+0x6e/0x90
…
| Call Trace:
|  i915_sw_fence_reinit+0x10/0x40
|  intel_context_init+0x185/0x1e0
|  intel_context_create+0x2e/0x100
|  default_engines+0x9d/0x120
|  i915_gem_create_context+0x40a/0x5d0
|  ? trace_kmalloc+0x29/0xd0
|  ? kmem_cache_alloc_trace+0xdd/0x190
|  i915_gem_context_open+0x140/0x1c0
|  i915_gem_open+0x70/0xa0
|  drm_file_alloc+0x1af/0x270
|  drm_open+0xdc/0x270
|  drm_stub_open+0xa6/0x130
|  chrdev_open+0xbe/0x250
|  ? cdev_device_add+0x80/0x80
|  do_dentry_open+0x15e/0x390
|  path_openat+0x76b/0xa60
|  do_filp_open+0xa4/0x150
|  ? lock_release+0x149/0x2f0
|  ? _raw_spin_unlock+0x24/0x40
|  do_sys_openat2+0x92/0x160
|  __x64_sys_openat+0x4f/0x90
|  do_syscall_64+0x3b/0xc0
|  entry_SYSCALL_64_after_hwframe+0x44/0xae
| RIP: 0033:0x7f91b5cfdf07

and:

| ODEBUG: activate destroyed (active state 0) object type: i915_sw_fence hint: sw_fence_dummy_notify+0x0/0x10
| WARNING: CPU: 0 PID: 987 at lib/debugobjects.c:505 debug_print_object+0x6e/0x90
|
| Call Trace:
|  debug_object_activate+0x174/0x200
|  i915_sw_fence_commit+0x10/0x20
|  intel_context_init+0x18d/0x1e0
|  intel_context_create+0x2e/0x100
|  default_engines+0x9d/0x120

---

| ODEBUG: active_state destroyed (active state 0) object type: i915_sw_fence hint: sw_fence_dummy_notify+0x0/0x10
| WARNING: CPU: 0 PID: 987 at lib/debugobjects.c:505 debug_print_object+0x6e/0x90
| Call Trace:
|  __i915_sw_fence_complete+0x6f/0x280
|  intel_context_init+0x18d/0x1e0
|  intel_context_create+0x2e/0x100
|  default_engines+0x9d/0x120
Quoted 1 line

Is this known? This is yesterday's -rc4, I first noticed it in -rc3.

Needs this fix:

commit d576b31bdece7b5034047cbe21170e948198d32f

Author: Matthew Auld <[email protected]>
Date:   Fri Sep 24 15:46:46 2021 +0100

drm/i915: remember to call i915_sw_fence_fini

But in the fix we forgot to add:

Fixes 62eaf0ae217d ("drm/i915/guc: Support request cancellation")

So not sure if it will appear on it's own. Adding Joonas and Rodrigo for maintainer level help.

Regards,

Tvrtko

#36 lore raw

Re: [Intel-gfx] [PATCH 25/33] drm/i915/guc: Support request cancellation

Quoted 7 lines · Tvrtko Ursulin

Needs this fix:

commit d576b31bdece7b5034047cbe21170e948198d32f

Author: Matthew Auld <[email protected]>
Date:   Fri Sep 24 15:46:46 2021 +0100

drm/i915: remember to call i915_sw_fence_fini

Thanks, works. Needed a tweak since it does not apply as-is.

Quoted 10 lines

But in the fix we forgot to add:

Fixes 62eaf0ae217d ("drm/i915/guc: Support request cancellation")

So not sure if it will appear on it's own. Adding Joonas and Rodrigo for maintainer level help.

Regards,

Tvrtko

Sebastian

#37 lore raw

PATCH 26/33 drm/i915/selftest: Better error reporting from hangcheck selftest

In reply to Matthew Brost

From: John Harrison <[email protected]>

There are many ways in which the hangcheck selftest can fail. Very few of them actually printed an error message to say what happened. So, fill in the missing messages.

---
 drivers/gpu/drm/i915/gt/selftest_hangcheck.c | 93 ++++++++++++++++----
 1 file changed, 75 insertions(+), 18 deletions(-)
drivers/gpu/drm/i915/gt/selftest_hangcheck.c +75 -18
index 7aea10aa1fb4..f93ba4076b2b 100644
@@ -378,6 +378,7 @@ static int igt_reset_nop(void *arg)
 			ce = intel_context_create(engine);
 			if (IS_ERR(ce)) {
 				err = PTR_ERR(ce);
+				pr_err("[%s] Create context failed: %d!\n", engine->name, err);
 				break;
 			}
 
@@ -387,6 +388,8 @@ static int igt_reset_nop(void *arg)
 				rq = intel_context_create_request(ce);
 				if (IS_ERR(rq)) {
 					err = PTR_ERR(rq);
+					pr_err("[%s] Create request failed: %d!\n",
+					       engine->name, err);
 					break;
 				}
 
@@ -401,24 +404,31 @@ static int igt_reset_nop(void *arg)
 		igt_global_reset_unlock(gt);
 
 		if (intel_gt_is_wedged(gt)) {
+			pr_err("[%s] GT is wedged!\n", engine->name);
 			err = -EIO;
 			break;
 		}
 
 		if (i915_reset_count(global) != reset_count + ++count) {
-			pr_err("Full GPU reset not recorded!\n");
+			pr_err("[%s] Reset not recorded: %d vs %d + %d!\n",
+			       engine->name, i915_reset_count(global), reset_count, count);
 			err = -EINVAL;
 			break;
 		}
 
 		err = igt_flush_test(gt->i915);
-		if (err)
+		if (err) {
+			pr_err("[%s] Flush failed: %d!\n", engine->name, err);
 			break;
+		}
 	} while (time_before(jiffies, end_time));
 	pr_info("%s: %d resets\n", __func__, count);
 
-	if (igt_flush_test(gt->i915))
+	if (igt_flush_test(gt->i915)) {
+		pr_err("Post flush failed: %d!\n", err);
 		err = -EIO;
+	}
+
 	return err;
 }
 
@@ -441,8 +451,10 @@ static int igt_reset_nop_engine(void *arg)
 		int err;
 
 		ce = intel_context_create(engine);
-		if (IS_ERR(ce))
+		if (IS_ERR(ce)) {
+			pr_err("[%s] Create context failed: %d!\n", engine->name, err);
 			return PTR_ERR(ce);
+		}
 
 		reset_count = i915_reset_count(global);
 		reset_engine_count = i915_reset_engine_count(global, engine);
@@ -550,8 +562,10 @@ static int igt_reset_fail_engine(void *arg)
 		int err;
 
 		ce = intel_context_create(engine);
-		if (IS_ERR(ce))
+		if (IS_ERR(ce)) {
+			pr_err("[%s] Create context failed: %d!\n", engine->name, err);
 			return PTR_ERR(ce);
+		}
 
 		st_engine_heartbeat_disable(engine);
 		set_bit(I915_RESET_ENGINE + id, &gt->reset.flags);
@@ -711,6 +725,8 @@ static int __igt_reset_engine(struct intel_gt *gt, bool active)
 				rq = hang_create_request(&h, engine);
 				if (IS_ERR(rq)) {
 					err = PTR_ERR(rq);
+					pr_err("[%s] Create hang request failed: %d!\n",
+					       engine->name, err);
 					break;
 				}
 
@@ -765,12 +781,16 @@ static int __igt_reset_engine(struct intel_gt *gt, bool active)
 			break;
 
 		err = igt_flush_test(gt->i915);
-		if (err)
+		if (err) {
+			pr_err("[%s] Flush failed: %d!\n", engine->name, err);
 			break;
+		}
 	}
 
-	if (intel_gt_is_wedged(gt))
+	if (intel_gt_is_wedged(gt)) {
+		pr_err("GT is wedged!\n");
 		err = -EIO;
+	}
 
 	if (active)
 		hang_fini(&h);
@@ -837,6 +857,7 @@ static int active_engine(void *data)
 		ce[count] = intel_context_create(engine);
 		if (IS_ERR(ce[count])) {
 			err = PTR_ERR(ce[count]);
+			pr_err("[%s] Create context #%ld failed: %d!\n", engine->name, count, err);
 			while (--count)
 				intel_context_put(ce[count]);
 			return err;
@@ -852,6 +873,7 @@ static int active_engine(void *data)
 		new = intel_context_create_request(ce[idx]);
 		if (IS_ERR(new)) {
 			err = PTR_ERR(new);
+			pr_err("[%s] Create request #%d failed: %d!\n", engine->name, idx, err);
 			break;
 		}
 
@@ -867,8 +889,10 @@ static int active_engine(void *data)
 		}
 
 		err = active_request_put(old);
-		if (err)
+		if (err) {
+			pr_err("[%s] Request put failed: %d!\n", engine->name, err);
 			break;
+		}
 
 		cond_resched();
 	}
@@ -876,6 +900,9 @@ static int active_engine(void *data)
 	for (count = 0; count < ARRAY_SIZE(rq); count++) {
 		int err__ = active_request_put(rq[count]);
 
+		if (err)
+			pr_err("[%s] Request put #%ld failed: %d!\n", engine->name, count, err);
+
 		/* Keep the first error */
 		if (!err)
 			err = err__;
@@ -949,6 +976,7 @@ static int __igt_reset_engines(struct intel_gt *gt,
 					  "igt/%s", other->name);
 			if (IS_ERR(tsk)) {
 				err = PTR_ERR(tsk);
+				pr_err("[%s] Thread spawn failed: %d!\n", engine->name, err);
 				goto unwind;
 			}
 
@@ -967,6 +995,8 @@ static int __igt_reset_engines(struct intel_gt *gt,
 				rq = hang_create_request(&h, engine);
 				if (IS_ERR(rq)) {
 					err = PTR_ERR(rq);
+					pr_err("[%s] Create hang request failed: %d!\n",
+					       engine->name, err);
 					break;
 				}
 
@@ -998,11 +1028,10 @@ static int __igt_reset_engines(struct intel_gt *gt,
 
 			if (rq) {
 				if (rq->fence.error != -EIO) {
-					pr_err("i915_reset_engine(%s:%s):"
-					       " failed to reset request %llx:%lld\n",
+					pr_err("i915_reset_engine(%s:%s): failed to reset request %lld:%lld [0x%04X]\n",
 					       engine->name, test_name,
 					       rq->fence.context,
-					       rq->fence.seqno);
+					       rq->fence.seqno, rq->context->guc_id);
 					i915_request_put(rq);
 
 					GEM_TRACE_DUMP();
@@ -1101,8 +1130,10 @@ static int __igt_reset_engines(struct intel_gt *gt,
 			break;
 
 		err = igt_flush_test(gt->i915);
-		if (err)
+		if (err) {
+			pr_err("[%s] Flush failed: %d!\n", engine->name, err);
 			break;
+		}
 	}
 
 	if (intel_gt_is_wedged(gt))
@@ -1180,12 +1211,15 @@ static int igt_reset_wait(void *arg)
 	igt_global_reset_lock(gt);
 
 	err = hang_init(&h, gt);
-	if (err)
+	if (err) {
+		pr_err("[%s] Hang init failed: %d!\n", engine->name, err);
 		goto unlock;
+	}
 
 	rq = hang_create_request(&h, engine);
 	if (IS_ERR(rq)) {
 		err = PTR_ERR(rq);
+		pr_err("[%s] Create hang request failed: %d!\n", engine->name, err);
 		goto fini;
 	}
 
@@ -1310,12 +1344,15 @@ static int __igt_reset_evict_vma(struct intel_gt *gt,
 	/* Check that we can recover an unbind stuck on a hanging request */
 
 	err = hang_init(&h, gt);
-	if (err)
+	if (err) {
+		pr_err("[%s] Hang init failed: %d!\n", engine->name, err);
 		return err;
+	}
 
 	obj = i915_gem_object_create_internal(gt->i915, SZ_1M);
 	if (IS_ERR(obj)) {
 		err = PTR_ERR(obj);
+		pr_err("[%s] Create object failed: %d!\n", engine->name, err);
 		goto fini;
 	}
 
@@ -1330,12 +1367,14 @@ static int __igt_reset_evict_vma(struct intel_gt *gt,
 	arg.vma = i915_vma_instance(obj, vm, NULL);
 	if (IS_ERR(arg.vma)) {
 		err = PTR_ERR(arg.vma);
+		pr_err("[%s] VMA instance failed: %d!\n", engine->name, err);
 		goto out_obj;
 	}
 
 	rq = hang_create_request(&h, engine);
 	if (IS_ERR(rq)) {
 		err = PTR_ERR(rq);
+		pr_err("[%s] Create hang request failed: %d!\n", engine->name, err);
 		goto out_obj;
 	}
 
@@ -1347,6 +1386,7 @@ static int __igt_reset_evict_vma(struct intel_gt *gt,
 	err = i915_vma_pin(arg.vma, 0, 0, pin_flags);
 	if (err) {
 		i915_request_add(rq);
+		pr_err("[%s] VMA pin failed: %d!\n", engine->name, err);
 		goto out_obj;
 	}
 
@@ -1363,8 +1403,14 @@ static int __igt_reset_evict_vma(struct intel_gt *gt,
 	i915_vma_lock(arg.vma);
 	err = i915_request_await_object(rq, arg.vma->obj,
 					flags & EXEC_OBJECT_WRITE);
-	if (err == 0)
+	if (err == 0) {
 		err = i915_vma_move_to_active(arg.vma, rq, flags);
+		if (err)
+			pr_err("[%s] Move to active failed: %d!\n", engine->name, err);
+	} else {
+		pr_err("[%s] Request await failed: %d!\n", engine->name, err);
+	}
+
 	i915_vma_unlock(arg.vma);
 
 	if (flags & EXEC_OBJECT_NEEDS_FENCE)
@@ -1392,6 +1438,7 @@ static int __igt_reset_evict_vma(struct intel_gt *gt,
 	tsk = kthread_run(fn, &arg, "igt/evict_vma");
 	if (IS_ERR(tsk)) {
 		err = PTR_ERR(tsk);
+		pr_err("[%s] Thread spawn failed: %d!\n", engine->name, err);
 		tsk = NULL;
 		goto out_reset;
 	}
@@ -1518,6 +1565,7 @@ static int igt_reset_queue(void *arg)
 		prev = hang_create_request(&h, engine);
 		if (IS_ERR(prev)) {
 			err = PTR_ERR(prev);
+			pr_err("[%s] Create 'prev' hang request failed: %d!\n", engine->name, err);
 			goto fini;
 		}
 
@@ -1532,6 +1580,7 @@ static int igt_reset_queue(void *arg)
 			rq = hang_create_request(&h, engine);
 			if (IS_ERR(rq)) {
 				err = PTR_ERR(rq);
+				pr_err("[%s] Create hang request failed: %d!\n", engine->name, err);
 				goto fini;
 			}
 
@@ -1619,8 +1668,10 @@ static int igt_reset_queue(void *arg)
 		i915_request_put(prev);
 
 		err = igt_flush_test(gt->i915);
-		if (err)
+		if (err) {
+			pr_err("[%s] Flush failed: %d!\n", engine->name, err);
 			break;
+		}
 	}
 
 fini:
@@ -1653,12 +1704,15 @@ static int igt_handle_error(void *arg)
 		return 0;
 
 	err = hang_init(&h, gt);
-	if (err)
+	if (err) {
+		pr_err("[%s] Hang init failed: %d!\n", engine->name, err);
 		return err;
+	}
 
 	rq = hang_create_request(&h, engine);
 	if (IS_ERR(rq)) {
 		err = PTR_ERR(rq);
+		pr_err("[%s] Create hang request failed: %d!\n", engine->name, err);
 		goto err_fini;
 	}
 
@@ -1743,12 +1797,15 @@ static int igt_atomic_reset_engine(struct intel_engine_cs *engine,
 		return err;
 
 	err = hang_init(&h, engine->gt);
-	if (err)
+	if (err) {
+		pr_err("[%s] Hang init failed: %d!\n", engine->name, err);
 		return err;
+	}
 
 	rq = hang_create_request(&h, engine);
 	if (IS_ERR(rq)) {
 		err = PTR_ERR(rq);
+		pr_err("[%s] Create hang request failed: %d!\n", engine->name, err);
 		goto out;
 	}
 
Signature · 6 lines
2.28.0

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

PATCH 27/33 drm/i915/selftest: Fix workarounds selftest for GuC submission

In reply to Matthew Brost

From: Rahul Kumar Singh <[email protected]>

When GuC submission is enabled, the GuC controls engine resets. Rather than explicitly triggering a reset, the driver must submit a hanging context to GuC and wait for the reset to occur.

---
 drivers/gpu/drm/i915/Makefile                 |   1 +
 drivers/gpu/drm/i915/gt/intel_engine_types.h  |   1 +
 .../gpu/drm/i915/gt/selftest_workarounds.c    | 130 +++++++++++++-----
 .../gpu/drm/i915/gt/uc/intel_guc_submission.c |   3 +
 .../i915/selftests/intel_scheduler_helpers.c  |  75 ++++++++++
 .../i915/selftests/intel_scheduler_helpers.h  |  27 ++++
 6 files changed, 203 insertions(+), 34 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/selftests/intel_scheduler_helpers.c
 create mode 100644 drivers/gpu/drm/i915/selftests/intel_scheduler_helpers.h
drivers/gpu/drm/i915/Makefile +1 -0
index 10b3bb6207ba..ab7679957623 100644
@@ -280,6 +280,7 @@ i915-$(CONFIG_DRM_I915_CAPTURE_ERROR) += i915_gpu_error.o
 i915-$(CONFIG_DRM_I915_SELFTEST) += \
 	gem/selftests/i915_gem_client_blt.o \
 	gem/selftests/igt_gem_utils.o \
+	selftests/intel_scheduler_helpers.o \
 	selftests/i915_random.o \
 	selftests/i915_selftest.o \
 	selftests/igt_atomic.o \
drivers/gpu/drm/i915/gt/intel_engine_types.h +1 -0
index 260cce15cb62..ed91bcff20eb 100644
@@ -443,6 +443,7 @@ struct intel_engine_cs {
 #define I915_ENGINE_IS_VIRTUAL       BIT(5)
 #define I915_ENGINE_HAS_RELATIVE_MMIO BIT(6)
 #define I915_ENGINE_REQUIRES_CMD_PARSER BIT(7)
+#define I915_ENGINE_WANT_FORCED_PREEMPTION BIT(8)
 	unsigned int flags;
 
 	/*
drivers/gpu/drm/i915/gt/selftest_workarounds.c +96 -34

214 lines not on this page · raw message

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +3 -0
index ee4f1f996efa..3ff42d6e934f 100644
@@ -1252,6 +1252,9 @@ static void guc_context_policy_init(struct intel_engine_cs *engine,
 {
 	desc->policy_flags = 0;
 
+	if (engine->flags & I915_ENGINE_WANT_FORCED_PREEMPTION)
+		desc->policy_flags |= CONTEXT_POLICY_FLAG_PREEMPT_TO_IDLE;
+
 	/* NB: For both of these, zero means disabled. */
 	desc->execution_quantum = engine->props.timeslice_duration_ms * 1000;
 	desc->preemption_timeout = engine->props.preempt_timeout_ms * 1000;
drivers/gpu/drm/i915/selftests/intel_scheduler_helpers.c new file +75 -0

75 lines not on this page · raw message

drivers/gpu/drm/i915/selftests/intel_scheduler_helpers.h new file +27 -0
new file mode 100644
index 000000000000..79605b14bc33
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2021 Intel Corporation
+ */
+
+#ifndef _INTEL_SELFTEST_SCHEDULER_HELPERS_H_
+#define _INTEL_SELFTEST_SCHEDULER_HELPERS_H_
+
+#include <linux/types.h>
+
+struct i915_request;
+struct intel_engine_cs;
+
+struct intel_selftest_saved_policy {
+	u32 flags;
+	u32 reset;
+	u64 timeslice;
+	u64 preempt_timeout;
+};
+
+int intel_selftest_modify_policy(struct intel_engine_cs *engine,
+				 struct intel_selftest_saved_policy *saved);
+int intel_selftest_restore_policy(struct intel_engine_cs *engine,
+				  struct intel_selftest_saved_policy *saved);
+int intel_selftest_wait_for_rq(struct i915_request *rq);
+
+#endif
Signature · 1 line
2.28.0
#39 lore raw

PATCH 28/33 drm/i915/selftest: Fix MOCS selftest for GuC submission

In reply to Matthew Brost

From: Rahul Kumar Singh <[email protected]>

When GuC submission is enabled, the GuC controls engine resets. Rather than explicitly triggering a reset, the driver must submit a hanging context to GuC and wait for the reset to occur.

---
 drivers/gpu/drm/i915/gt/selftest_mocs.c | 49 ++++++++++++++++++-------
 1 file changed, 35 insertions(+), 14 deletions(-)
drivers/gpu/drm/i915/gt/selftest_mocs.c +35 -14
index 8763bbeca0f7..b7314739ee40 100644
@@ -10,6 +10,7 @@
 #include "gem/selftests/mock_context.h"
 #include "selftests/igt_reset.h"
 #include "selftests/igt_spinner.h"
+#include "selftests/intel_scheduler_helpers.h"
 
 struct live_mocs {
 	struct drm_i915_mocs_table table;
@@ -318,7 +319,8 @@ static int live_mocs_clean(void *arg)
 }
 
 static int active_engine_reset(struct intel_context *ce,
-			       const char *reason)
+			       const char *reason,
+			       bool using_guc)
 {
 	struct igt_spinner spin;
 	struct i915_request *rq;
@@ -335,9 +337,13 @@ static int active_engine_reset(struct intel_context *ce,
 	}
 
 	err = request_add_spin(rq, &spin);
-	if (err == 0)
+	if (err == 0 && !using_guc)
 		err = intel_engine_reset(ce->engine, reason);
 
+	/* Ensure the reset happens and kills the engine */
+	if (err == 0)
+		err = intel_selftest_wait_for_rq(rq);
+
 	igt_spinner_end(&spin);
 	igt_spinner_fini(&spin);
 
@@ -345,21 +351,23 @@ static int active_engine_reset(struct intel_context *ce,
 }
 
 static int __live_mocs_reset(struct live_mocs *mocs,
-			     struct intel_context *ce)
+			     struct intel_context *ce, bool using_guc)
 {
 	struct intel_gt *gt = ce->engine->gt;
 	int err;
 
 	if (intel_has_reset_engine(gt)) {
-		err = intel_engine_reset(ce->engine, "mocs");
-		if (err)
-			return err;
-
-		err = check_mocs_engine(mocs, ce);
-		if (err)
-			return err;
+		if (!using_guc) {
+			err = intel_engine_reset(ce->engine, "mocs");
+			if (err)
+				return err;
+
+			err = check_mocs_engine(mocs, ce);
+			if (err)
+				return err;
+		}
 
-		err = active_engine_reset(ce, "mocs");
+		err = active_engine_reset(ce, "mocs", using_guc);
 		if (err)
 			return err;
 
@@ -395,19 +403,32 @@ static int live_mocs_reset(void *arg)
 
 	igt_global_reset_lock(gt);
 	for_each_engine(engine, gt, id) {
+		bool using_guc = intel_engine_uses_guc(engine);
+		struct intel_selftest_saved_policy saved;
 		struct intel_context *ce;
+		int err2;
+
+		err = intel_selftest_modify_policy(engine, &saved);
+		if (err)
+			break;
 
 		ce = mocs_context_create(engine);
 		if (IS_ERR(ce)) {
 			err = PTR_ERR(ce);
-			break;
+			goto restore;
 		}
 
 		intel_engine_pm_get(engine);
-		err = __live_mocs_reset(&mocs, ce);
-		intel_engine_pm_put(engine);
 
+		err = __live_mocs_reset(&mocs, ce, using_guc);
+
+		intel_engine_pm_put(engine);
 		intel_context_put(ce);
+
+restore:
+		err2 = intel_selftest_restore_policy(engine, &saved);
+		if (err == 0)
+			err = err2;
 		if (err)
 			break;
 	}
Signature · 6 lines
2.28.0

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

PATCH 29/33 drm/i915/selftest: Increase some timeouts in live_requests

In reply to Matthew Brost

Requests may take slightly longer with GuC submission, let's increase the timeouts in live_requests.

---
 drivers/gpu/drm/i915/selftests/i915_request.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/selftests/i915_request.c +2 -2
index bd5c96a77ba3..d67710d10615 100644
@@ -1313,7 +1313,7 @@ static int __live_parallel_engine1(void *arg)
 		i915_request_add(rq);
 
 		err = 0;
-		if (i915_request_wait(rq, 0, HZ / 5) < 0)
+		if (i915_request_wait(rq, 0, HZ) < 0)
 			err = -ETIME;
 		i915_request_put(rq);
 		if (err)
@@ -1419,7 +1419,7 @@ static int __live_parallel_spin(void *arg)
 	}
 	igt_spinner_end(&spin);
 
-	if (err == 0 && i915_request_wait(rq, 0, HZ / 5) < 0)
+	if (err == 0 && i915_request_wait(rq, 0, HZ) < 0)
 		err = -EIO;
 	i915_request_put(rq);
 
Signature · 1 line
2.28.0
Reviewed-by on v1 29/33
#41 lore raw

Re: [PATCH 29/33] drm/i915/selftest: Increase some timeouts in live_requests

Quoted 4 lines · Matthew Brost

Requests may take slightly longer with GuC submission, let's increase the timeouts in live_requests.

Was already reviewed in previous series. Repeating here for patchwork:

Quoted 26 lines
---
  drivers/gpu/drm/i915/selftests/i915_request.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/selftests/i915_request.c +2 -2
index bd5c96a77ba3..d67710d10615 100644
@@ -1313,7 +1313,7 @@ static int __live_parallel_engine1(void *arg)
  		i915_request_add(rq);
 
  		err = 0;
-		if (i915_request_wait(rq, 0, HZ / 5) < 0)
+		if (i915_request_wait(rq, 0, HZ) < 0)
  			err = -ETIME;
  		i915_request_put(rq);
  		if (err)
@@ -1419,7 +1419,7 @@ static int __live_parallel_spin(void *arg)
  	}
  	igt_spinner_end(&spin);
 
-	if (err == 0 && i915_request_wait(rq, 0, HZ / 5) < 0)
+	if (err == 0 && i915_request_wait(rq, 0, HZ) < 0)
  		err = -EIO;
  	i915_request_put(rq);
 
#42 lore raw

PATCH 30/33 drm/i915/selftest: Fix hangcheck self test for GuC submission

In reply to Matthew Brost

From: John Harrison <[email protected]>

When GuC submission is enabled, the GuC controls engine resets. Rather than explicitly triggering a reset, the driver must submit a hanging context to GuC and wait for the reset to occur.

Conversely, one of the tests specifically sends hanging batches to the engines but wants them to sit around until a manual reset of the full GT (including GuC itself). That means disabling GuC based engine resets to prevent those from killing the hanging batch too soon. So, add support to the scheduling policy helper for disabling resets as well as making them quicker!

In GuC submission mode, the 'is engine idle' test basically turns into 'is engine PM wakelock held'. Independently, there is a heartbeat disable helper function that the tests use. For unexplained reasons, this acquires the engine wakelock before disabling the heartbeat and only releases it when re-enabling the heartbeat. As one of the tests tries to do a wait for idle in the middle of a heartbeat disabled section, it is therefore guaranteed to always fail. Added a 'no_pm' variant of the heartbeat helper that allows the engine to be asleep while also having heartbeats disabled.

---
 .../drm/i915/gt/selftest_engine_heartbeat.c   |  22 ++
 .../drm/i915/gt/selftest_engine_heartbeat.h   |   2 +
 drivers/gpu/drm/i915/gt/selftest_hangcheck.c  | 227 +++++++++++++-----
 drivers/gpu/drm/i915/gt/selftest_mocs.c       |   3 +-
 .../gpu/drm/i915/gt/selftest_workarounds.c    |   6 +-
 .../i915/selftests/intel_scheduler_helpers.c  |  39 ++-
 .../i915/selftests/intel_scheduler_helpers.h  |   8 +-
 7 files changed, 236 insertions(+), 71 deletions(-)
drivers/gpu/drm/i915/gt/selftest_engine_heartbeat.c +22 -0
index 4896e4ccad50..317eebf086c3 100644
@@ -405,3 +405,25 @@ void st_engine_heartbeat_enable(struct intel_engine_cs *engine)
 	engine->props.heartbeat_interval_ms =
 		engine->defaults.heartbeat_interval_ms;
 }
+
+void st_engine_heartbeat_disable_no_pm(struct intel_engine_cs *engine)
+{
+	engine->props.heartbeat_interval_ms = 0;
+
+	/*
+	 * Park the heartbeat but without holding the PM lock as that
+	 * makes the engines appear not-idle. Note that if/when unpark
+	 * is called due to the PM lock being acquired later the
+	 * heartbeat still won't be enabled because of the above = 0.
+	 */
+	if (intel_engine_pm_get_if_awake(engine)) {
+		intel_engine_park_heartbeat(engine);
+		intel_engine_pm_put(engine);
+	}
+}
+
+void st_engine_heartbeat_enable_no_pm(struct intel_engine_cs *engine)
+{
+	engine->props.heartbeat_interval_ms =
+		engine->defaults.heartbeat_interval_ms;
+}
drivers/gpu/drm/i915/gt/selftest_engine_heartbeat.h +2 -0
index cd27113d5400..81da2cd8e406 100644
@@ -9,6 +9,8 @@
 struct intel_engine_cs;
 
 void st_engine_heartbeat_disable(struct intel_engine_cs *engine);
+void st_engine_heartbeat_disable_no_pm(struct intel_engine_cs *engine);
 void st_engine_heartbeat_enable(struct intel_engine_cs *engine);
+void st_engine_heartbeat_enable_no_pm(struct intel_engine_cs *engine);
 
 #endif /* SELFTEST_ENGINE_HEARTBEAT_H */
drivers/gpu/drm/i915/gt/selftest_hangcheck.c +173 -54

412 lines not on this page · raw message

drivers/gpu/drm/i915/gt/selftest_mocs.c +2 -1
index b7314739ee40..13d25bf2a94a 100644
@@ -408,7 +408,8 @@ static int live_mocs_reset(void *arg)
 		struct intel_context *ce;
 		int err2;
 
-		err = intel_selftest_modify_policy(engine, &saved);
+		err = intel_selftest_modify_policy(engine, &saved,
+						   SELFTEST_SCHEDULER_MODIFY_FAST_RESET);
 		if (err)
 			break;
 
drivers/gpu/drm/i915/gt/selftest_workarounds.c +4 -2
index ba7ee69414d5..e623ac45f4aa 100644
@@ -810,7 +810,8 @@ static int live_reset_whitelist(void *arg)
 				struct intel_selftest_saved_policy saved;
 				int err2;
 
-				err = intel_selftest_modify_policy(engine, &saved);
+				err = intel_selftest_modify_policy(engine, &saved,
+								   SELFTEST_SCHEDULER_MODIFY_FAST_RESET);
 				if (err)
 					goto out;
 
@@ -1278,7 +1279,8 @@ live_engine_reset_workarounds(void *arg)
 		int ret2;
 
 		pr_info("Verifying after %s reset...\n", engine->name);
-		ret = intel_selftest_modify_policy(engine, &saved);
+		ret = intel_selftest_modify_policy(engine, &saved,
+						   SELFTEST_SCHEDULER_MODIFY_FAST_RESET);
 		if (ret)
 			break;
 
drivers/gpu/drm/i915/selftests/intel_scheduler_helpers.c +26 -13
index 5cdee1378e98..dac275e835c4 100644
@@ -15,7 +15,8 @@
 #define WAIT_FOR_RESET_TIME	1000
 
 int intel_selftest_modify_policy(struct intel_engine_cs *engine,
-				 struct intel_selftest_saved_policy *saved)
+				 struct intel_selftest_saved_policy *saved,
+				 u32 modify_type)
 
 {
 	int err;
@@ -25,18 +26,30 @@ int intel_selftest_modify_policy(struct intel_engine_cs *engine,
 	saved->timeslice = engine->props.timeslice_duration_ms;
 	saved->preempt_timeout = engine->props.preempt_timeout_ms;
 
-	/*
-	 * Enable force pre-emption on time slice expiration
-	 * together with engine reset on pre-emption timeout.
-	 * This is required to make the GuC notice and reset
-	 * the single hanging context.
-	 * Also, reduce the preemption timeout to something
-	 * small to speed the test up.
-	 */
-	engine->i915->params.reset = 2;
-	engine->flags |= I915_ENGINE_WANT_FORCED_PREEMPTION;
-	engine->props.timeslice_duration_ms = REDUCED_TIMESLICE;
-	engine->props.preempt_timeout_ms = REDUCED_PREEMPT;
+	switch (modify_type) {
+	case SELFTEST_SCHEDULER_MODIFY_FAST_RESET:
+		/*
+		 * Enable force pre-emption on time slice expiration
+		 * together with engine reset on pre-emption timeout.
+		 * This is required to make the GuC notice and reset
+		 * the single hanging context.
+		 * Also, reduce the preemption timeout to something
+		 * small to speed the test up.
+		 */
+		engine->i915->params.reset = 2;
+		engine->flags |= I915_ENGINE_WANT_FORCED_PREEMPTION;
+		engine->props.timeslice_duration_ms = REDUCED_TIMESLICE;
+		engine->props.preempt_timeout_ms = REDUCED_PREEMPT;
+		break;
+
+	case SELFTEST_SCHEDULER_MODIFY_NO_HANGCHECK:
+		engine->props.preempt_timeout_ms = 0;
+		break;
+
+	default:
+		pr_err("Invalid scheduler policy modification type: %d!\n", modify_type);
+		return -EINVAL;
+	}
 
 	if (!intel_engine_uses_guc(engine))
 		return 0;
drivers/gpu/drm/i915/selftests/intel_scheduler_helpers.h +7 -1
index 79605b14bc33..35c098601ac0 100644
@@ -18,8 +18,14 @@ struct intel_selftest_saved_policy {
 	u64 preempt_timeout;
 };
 
+enum selftest_scheduler_modify {
+	SELFTEST_SCHEDULER_MODIFY_NO_HANGCHECK = 0,
+	SELFTEST_SCHEDULER_MODIFY_FAST_RESET,
+};
+
 int intel_selftest_modify_policy(struct intel_engine_cs *engine,
-				 struct intel_selftest_saved_policy *saved);
+				 struct intel_selftest_saved_policy *saved,
+				 enum selftest_scheduler_modify modify_type);
 int intel_selftest_restore_policy(struct intel_engine_cs *engine,
 				  struct intel_selftest_saved_policy *saved);
 int intel_selftest_wait_for_rq(struct i915_request *rq);
Signature · 1 line
2.28.0
#43 lore raw

PATCH 31/33 drm/i915/selftest: Bump selftest timeouts for hangcheck

In reply to Matthew Brost

From: John Harrison <[email protected]>

Some testing environments and some heavier tests are slower than previous limits allowed for. For example, it can take multiple seconds for the 'context has been reset' notification handler to reach the 'kill the requests' code in the 'active' version of the 'reset engines' test. During which time the selftest gets bored, gives up waiting and fails the test.

There is also an async thread that the selftest uses to pump work through the hardware in parallel to the context that is marked for reset. That also could get bored waiting for completions and kill the test off.

Lastly, the flush at the of various test sections can also see timeouts due to the large amount of work backed up. This is also true of the live_hwsp_read test.

---
 drivers/gpu/drm/i915/gt/selftest_hangcheck.c             | 2 +-
 drivers/gpu/drm/i915/selftests/igt_flush_test.c          | 2 +-
 drivers/gpu/drm/i915/selftests/intel_scheduler_helpers.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gt/selftest_hangcheck.c +1 -1
index e0e200ba77e9..08f011f893b2 100644
@@ -879,7 +879,7 @@ static int active_request_put(struct i915_request *rq)
 	if (!rq)
 		return 0;
 
-	if (i915_request_wait(rq, 0, 5 * HZ) < 0) {
+	if (i915_request_wait(rq, 0, 10 * HZ) < 0) {
 		GEM_TRACE("%s timed out waiting for completion of fence %llx:%lld\n",
 			  rq->engine->name,
 			  rq->fence.context,
drivers/gpu/drm/i915/selftests/igt_flush_test.c +1 -1
index 7b0939e3f007..a6c71fca61aa 100644
@@ -19,7 +19,7 @@ int igt_flush_test(struct drm_i915_private *i915)
 
 	cond_resched();
 
-	if (intel_gt_wait_for_idle(gt, HZ / 5) == -ETIME) {
+	if (intel_gt_wait_for_idle(gt, HZ) == -ETIME) {
 		pr_err("%pS timed out, cancelling all further testing.\n",
 		       __builtin_return_address(0));
 
drivers/gpu/drm/i915/selftests/intel_scheduler_helpers.c +1 -1
index dac275e835c4..4b328346b48a 100644
@@ -12,7 +12,7 @@
 
 #define REDUCED_TIMESLICE	5
 #define REDUCED_PREEMPT		10
-#define WAIT_FOR_RESET_TIME	1000
+#define WAIT_FOR_RESET_TIME	10000
 
 int intel_selftest_modify_policy(struct intel_engine_cs *engine,
 				 struct intel_selftest_saved_policy *saved,
Signature · 1 line
2.28.0
#44 lore raw

PATCH 32/33 drm/i915/guc: Implement GuC priority management

In reply to Matthew Brost

Implement a simple static mapping algorithm of the i915 priority levels (int, -1k to 1k exposed to user) to the 4 GuC levels. Mapping is as follows:

i915 level < 0          -> GuC low level     (3)
i915 level == 0         -> GuC normal level  (2)
i915 level < INT_MAX    -> GuC high level    (1)
i915 level == INT_MAX   -> GuC highest level (0)

We believe this mapping should cover the UMD use cases (3 distinct user levels + 1 kernel level).

In addition to static mapping, a simple counter system is attached to each context tracking the number of requests inflight on the context at each level. This is needed as the GuC levels are per context while in the i915 levels are per request.

v2:
(Daniele)
- Add BUILD_BUG_ON to enforce ordering of priority levels
- Add missing lockdep to guc_prio_fini
- Check for return before setting context registered flag
- Map DISPLAY priority or higher to highest guc prio
- Update comment for guc_prio

---
 drivers/gpu/drm/i915/gt/intel_breadcrumbs.c   |   3 +
 drivers/gpu/drm/i915/gt/intel_context_types.h |   9 +-
 drivers/gpu/drm/i915/gt/intel_engine_user.c   |   4 +
 .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 212 +++++++++++++++++-
 drivers/gpu/drm/i915/i915_request.c           |   5 +
 drivers/gpu/drm/i915/i915_request.h           |   9 +
 drivers/gpu/drm/i915/i915_scheduler.c         |   7 +
 drivers/gpu/drm/i915/i915_scheduler_types.h   |  12 +
 drivers/gpu/drm/i915/i915_trace.h             |  17 +-
 include/uapi/drm/i915_drm.h                   |   9 +
 10 files changed, 282 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/gt/intel_breadcrumbs.c +3 -0
index 2007dc6f6b99..209cf265bf74 100644
@@ -245,6 +245,9 @@ static void signal_irq_work(struct irq_work *work)
 			llist_entry(signal, typeof(*rq), signal_node);
 		struct list_head cb_list;
 
+		if (rq->engine->sched_engine->retire_inflight_request_prio)
+			rq->engine->sched_engine->retire_inflight_request_prio(rq);
+
 		spin_lock(&rq->lock);
 		list_replace(&rq->fence.cb_list, &cb_list);
 		__dma_fence_signal__timestamp(&rq->fence, timestamp);
drivers/gpu/drm/i915/gt/intel_context_types.h +8 -1
index a5bc876face7..e54351a170e2 100644
@@ -18,8 +18,9 @@
 #include "intel_engine_types.h"
 #include "intel_sseu.h"
 
-#define CONTEXT_REDZONE POISON_INUSE
+#include "uc/intel_guc_fwif.h"
 
+#define CONTEXT_REDZONE POISON_INUSE
 DECLARE_EWMA(runtime, 3, 8);
 
 struct i915_gem_context;
@@ -191,6 +192,12 @@ struct intel_context {
 
 	/* GuC context blocked fence */
 	struct i915_sw_fence guc_blocked;
+
+	/*
+	 * GuC priority management
+	 */
+	u8 guc_prio;
+	u32 guc_prio_count[GUC_CLIENT_PRIORITY_NUM];
 };
 
 #endif /* __INTEL_CONTEXT_TYPES__ */
drivers/gpu/drm/i915/gt/intel_engine_user.c +4 -0
index 84142127ebd8..8f8bea08e734 100644
@@ -11,6 +11,7 @@
 #include "intel_engine.h"
 #include "intel_engine_user.h"
 #include "intel_gt.h"
+#include "uc/intel_guc_submission.h"
 
 struct intel_engine_cs *
 intel_engine_lookup_user(struct drm_i915_private *i915, u8 class, u8 instance)
@@ -115,6 +116,9 @@ static void set_scheduler_caps(struct drm_i915_private *i915)
 			disabled |= (I915_SCHEDULER_CAP_ENABLED |
 				     I915_SCHEDULER_CAP_PRIORITY);
 
+		if (intel_uc_uses_guc_submission(&i915->gt.uc))
+			enabled |= I915_SCHEDULER_CAP_STATIC_PRIORITY_MAP;
+
 		for (i = 0; i < ARRAY_SIZE(map); i++) {
 			if (engine->flags & BIT(map[i].engine))
 				enabled |= BIT(map[i].sched);
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +210 -2

319 lines not on this page · raw message

drivers/gpu/drm/i915/i915_request.c +5 -0
index 541a20371502..1f1d4a6a0eff 100644
@@ -114,6 +114,9 @@ static void i915_fence_release(struct dma_fence *fence)
 {
 	struct i915_request *rq = to_request(fence);
 
+	GEM_BUG_ON(rq->guc_prio != GUC_PRIO_INIT &&
+		   rq->guc_prio != GUC_PRIO_FINI);
+
 	/*
 	 * The request is put onto a RCU freelist (i.e. the address
 	 * is immediately reused), mark the fences as being freed now.
@@ -924,6 +927,8 @@ __i915_request_create(struct intel_context *ce, gfp_t gfp)
 
 	rq->rcustate = get_state_synchronize_rcu(); /* acts as smp_mb() */
 
+	rq->guc_prio = GUC_PRIO_INIT;
+
 	/* We bump the ref for the fence chain */
 	i915_sw_fence_reinit(&i915_request_get(rq)->submit);
 	i915_sw_fence_reinit(&i915_request_get(rq)->semaphore);
drivers/gpu/drm/i915/i915_request.h +9 -0
index ac0e3326c067..e6a0e0ebc9aa 100644
@@ -293,6 +293,15 @@ struct i915_request {
 	 */
 	struct list_head guc_fence_link;
 
+	/**
+	 * Priority level while the request is inflight. Differs from i915
+	 * scheduler priority. See comment above
+	 * I915_SCHEDULER_CAP_STATIC_PRIORITY_MAP for details.
+	 */
+#define	GUC_PRIO_INIT	0xff
+#define	GUC_PRIO_FINI	0xfe
+	u8 guc_prio;
+
 	I915_SELFTEST_DECLARE(struct {
 		struct list_head link;
 		unsigned long delay;
drivers/gpu/drm/i915/i915_scheduler.c +7 -0
index 28dd887eb1be..17843c204356 100644
@@ -241,6 +241,9 @@ static void __i915_schedule(struct i915_sched_node *node,
 	/* Fifo and depth-first replacement ensure our deps execute before us */
 	sched_engine = lock_sched_engine(node, sched_engine, &cache);
 	list_for_each_entry_safe_reverse(dep, p, &dfs, dfs_link) {
+		struct i915_request *from = container_of(dep->signaler,
+							 struct i915_request,
+							 sched);
 		INIT_LIST_HEAD(&dep->dfs_link);
 
 		node = dep->signaler;
@@ -254,6 +257,10 @@ static void __i915_schedule(struct i915_sched_node *node,
 		GEM_BUG_ON(node_to_request(node)->engine->sched_engine !=
 			   sched_engine);
 
+		/* Must be called before changing the nodes priority */
+		if (sched_engine->bump_inflight_request_prio)
+			sched_engine->bump_inflight_request_prio(from, prio);
+
 		WRITE_ONCE(node->attr.priority, prio);
 
 		/*
drivers/gpu/drm/i915/i915_scheduler_types.h +12 -0
index eaef233e9080..b0a1b58c7893 100644
@@ -179,6 +179,18 @@ struct i915_sched_engine {
 	void	(*kick_backend)(const struct i915_request *rq,
 				int prio);
 
+	/**
+	 * @bump_inflight_request_prio: update priority of an inflight request
+	 */
+	void	(*bump_inflight_request_prio)(struct i915_request *rq,
+					      int prio);
+
+	/**
+	 * @retire_inflight_request_prio: indicate request is retired to
+	 * priority tracking
+	 */
+	void	(*retire_inflight_request_prio)(struct i915_request *rq);
+
 	/**
 	 * @schedule: adjust priority of request
 	 *
drivers/gpu/drm/i915/i915_trace.h +15 -2
index 9613a7c19661..806ad688274b 100644
@@ -904,6 +904,7 @@ DECLARE_EVENT_CLASS(intel_context,
 			     __field(int, pin_count)
 			     __field(u32, sched_state)
 			     __field(u32, guc_sched_state_no_lock)
+			     __field(u8, guc_prio)
 			     ),
 
 		    TP_fast_assign(
@@ -912,12 +913,19 @@ DECLARE_EVENT_CLASS(intel_context,
 			   __entry->sched_state = ce->guc_state.sched_state;
 			   __entry->guc_sched_state_no_lock =
 			   atomic_read(&ce->guc_sched_state_no_lock);
+			   __entry->guc_prio = ce->guc_prio;
 			   ),
 
-		    TP_printk("guc_id=%d, pin_count=%d sched_state=0x%x,0x%x",
+		    TP_printk("guc_id=%d, pin_count=%d sched_state=0x%x,0x%x, guc_prio=%u",
 			      __entry->guc_id, __entry->pin_count,
 			      __entry->sched_state,
-			      __entry->guc_sched_state_no_lock)
+			      __entry->guc_sched_state_no_lock,
+			      __entry->guc_prio)
+);
+
+DEFINE_EVENT(intel_context, intel_context_set_prio,
+	     TP_PROTO(struct intel_context *ce),
+	     TP_ARGS(ce)
 );
 
 DEFINE_EVENT(intel_context, intel_context_reset,
@@ -1017,6 +1025,11 @@ trace_i915_request_out(struct i915_request *rq)
 {
 }
 
+static inline void
+trace_intel_context_set_prio(struct intel_context *ce)
+{
+}
+
 static inline void
 trace_intel_context_reset(struct intel_context *ce)
 {
include/uapi/drm/i915_drm.h +9 -0
index 975087553ea0..7f13d241417f 100644
@@ -572,6 +572,15 @@ typedef struct drm_i915_irq_wait {
 #define   I915_SCHEDULER_CAP_PREEMPTION	(1ul << 2)
 #define   I915_SCHEDULER_CAP_SEMAPHORES	(1ul << 3)
 #define   I915_SCHEDULER_CAP_ENGINE_BUSY_STATS	(1ul << 4)
+/*
+ * Indicates the 2k user priority levels are statically mapped into 3 buckets as
+ * follows:
+ *
+ * -1k to -1	Low priority
+ * 0		Normal priority
+ * 1 to 1k	Highest priority
+ */
+#define   I915_SCHEDULER_CAP_STATIC_PRIORITY_MAP	(1ul << 5)
 
 #define I915_PARAM_HUC_STATUS		 42
 
Signature · 1 line
2.28.0
#45 lore raw

Re: [Intel-gfx] [PATCH 32/33] drm/i915/guc: Implement GuC priority management

A blast from the past..

Quoted 11 lines · Matthew Brost

Implement a simple static mapping algorithm of the i915 priority levels (int, -1k to 1k exposed to user) to the 4 GuC levels. Mapping is as follows:

i915 level < 0          -> GuC low level     (3)
i915 level == 0         -> GuC normal level  (2)
i915 level < INT_MAX    -> GuC high level    (1)
i915 level == INT_MAX   -> GuC highest level (0)

We believe this mapping should cover the UMD use cases (3 distinct user levels + 1 kernel level).

I've noticed Vulkan has VK_EXT_global_priority and AFAICT Mesa implementation maps those priorities to i915 uapi:

VK_QUEUE_GLOBAL_PRIORITY_LOW_KHR = -512
VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_KHR = 0
VK_QUEUE_GLOBAL_PRIORITY_HIGH_KHR = +512
VK_QUEUE_GLOBAL_PRIORITY_REALTIME_KHR = +1023

GuC as per this patch remaps to:

VK_QUEUE_GLOBAL_PRIORITY_LOW_KHR = GUC_CLIENT_PRIORITY_NORMAL VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_KHR = GUC_CLIENT_PRIORITY_KMD_NORMAL VK_QUEUE_GLOBAL_PRIORITY_HIGH_KHR = GUC_CLIENT_PRIORITY_HIGH VK_QUEUE_GLOBAL_PRIORITY_REALTIME_KHR = GUC_CLIENT_PRIORITY_HIGH

Last two being the same, so we lose one level. I don't think it is a problem according to VK spec, which is very loose, so considered fine for us and just unfortunate?

Also, given drm/sched has three priorities - what is the plan to connect GuC's four into those three? I ask because I noticed the fixed three levels does not really fit with some other drivers like msm for instance. There are up to four hardware priorities there and currently an odd mapping scheme is implemented. So I am getting a feeling drm/sched should rather be extended to allow more flexibility for drivers.

And finally a side question on this particular patch - shouldn't GuC map I915_PRIORITY_HEARTBEAT to GUC_CLIENT_PRIORITY_KMD_HIGH (highest)? I'd say yes - we certainly want heartbeats to preempt maximum user priority.

Regards,

Tvrtko

Quoted 588 lines

In addition to static mapping, a simple counter system is attached to each context tracking the number of requests inflight on the context at each level. This is needed as the GuC levels are per context while in the i915 levels are per request.

v2:
(Daniele)
- Add BUILD_BUG_ON to enforce ordering of priority levels
- Add missing lockdep to guc_prio_fini
- Check for return before setting context registered flag
- Map DISPLAY priority or higher to highest guc prio
- Update comment for guc_prio

---
  drivers/gpu/drm/i915/gt/intel_breadcrumbs.c   |   3 +
  drivers/gpu/drm/i915/gt/intel_context_types.h |   9 +-
  drivers/gpu/drm/i915/gt/intel_engine_user.c   |   4 +
  .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 212 +++++++++++++++++-
  drivers/gpu/drm/i915/i915_request.c           |   5 +
  drivers/gpu/drm/i915/i915_request.h           |   9 +
  drivers/gpu/drm/i915/i915_scheduler.c         |   7 +
  drivers/gpu/drm/i915/i915_scheduler_types.h   |  12 +
  drivers/gpu/drm/i915/i915_trace.h             |  17 +-
  include/uapi/drm/i915_drm.h                   |   9 +
  10 files changed, 282 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/gt/intel_breadcrumbs.c +3 -0
index 2007dc6f6b99..209cf265bf74 100644
@@ -245,6 +245,9 @@ static void signal_irq_work(struct irq_work *work)
  			llist_entry(signal, typeof(*rq), signal_node);
  		struct list_head cb_list;
 
+		if (rq->engine->sched_engine->retire_inflight_request_prio)
+			rq->engine->sched_engine->retire_inflight_request_prio(rq);
+
  		spin_lock(&rq->lock);
  		list_replace(&rq->fence.cb_list, &cb_list);
  		__dma_fence_signal__timestamp(&rq->fence, timestamp);
drivers/gpu/drm/i915/gt/intel_context_types.h +8 -1
index a5bc876face7..e54351a170e2 100644
@@ -18,8 +18,9 @@
  #include "intel_engine_types.h"
  #include "intel_sseu.h"
 
-#define CONTEXT_REDZONE POISON_INUSE
+#include "uc/intel_guc_fwif.h"
 
+#define CONTEXT_REDZONE POISON_INUSE
  DECLARE_EWMA(runtime, 3, 8);
 
  struct i915_gem_context;
@@ -191,6 +192,12 @@ struct intel_context {
 
  	/* GuC context blocked fence */
  	struct i915_sw_fence guc_blocked;
+
+	/*
+	 * GuC priority management
+	 */
+	u8 guc_prio;
+	u32 guc_prio_count[GUC_CLIENT_PRIORITY_NUM];
  };
 
  #endif /* __INTEL_CONTEXT_TYPES__ */
drivers/gpu/drm/i915/gt/intel_engine_user.c +4 -0
index 84142127ebd8..8f8bea08e734 100644
@@ -11,6 +11,7 @@
  #include "intel_engine.h"
  #include "intel_engine_user.h"
  #include "intel_gt.h"
+#include "uc/intel_guc_submission.h"
 
  struct intel_engine_cs *
  intel_engine_lookup_user(struct drm_i915_private *i915, u8 class, u8 instance)
@@ -115,6 +116,9 @@ static void set_scheduler_caps(struct drm_i915_private *i915)
  			disabled |= (I915_SCHEDULER_CAP_ENABLED |
  				     I915_SCHEDULER_CAP_PRIORITY);
 
+		if (intel_uc_uses_guc_submission(&i915->gt.uc))
+			enabled |= I915_SCHEDULER_CAP_STATIC_PRIORITY_MAP;
+
  		for (i = 0; i < ARRAY_SIZE(map); i++) {
  			if (engine->flags & BIT(map[i].engine))
  				enabled |= BIT(map[i].sched);
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +210 -2
index 3ff42d6e934f..b760cbf6ca0e 100644
@@ -81,6 +81,7 @@ guc_create_virtual(struct intel_engine_cs **siblings, unsigned int count);
   */
  #define SCHED_STATE_NO_LOCK_ENABLED			BIT(0)
  #define SCHED_STATE_NO_LOCK_PENDING_ENABLE		BIT(1)
+#define SCHED_STATE_NO_LOCK_REGISTERED			BIT(2)
  static inline bool context_enabled(struct intel_context *ce)
  {
  	return (atomic_read(&ce->guc_sched_state_no_lock) &
@@ -116,6 +117,24 @@ static inline void clr_context_pending_enable(struct intel_context *ce)
  		   &ce->guc_sched_state_no_lock);
  }
 
+static inline bool context_registered(struct intel_context *ce)
+{
+	return (atomic_read(&ce->guc_sched_state_no_lock) &
+		SCHED_STATE_NO_LOCK_REGISTERED);
+}
+
+static inline void set_context_registered(struct intel_context *ce)
+{
+	atomic_or(SCHED_STATE_NO_LOCK_REGISTERED,
+		  &ce->guc_sched_state_no_lock);
+}
+
+static inline void clr_context_registered(struct intel_context *ce)
+{
+	atomic_and((u32)~SCHED_STATE_NO_LOCK_REGISTERED,
+		   &ce->guc_sched_state_no_lock);
+}
+
  /*
   * Below is a set of functions which control the GuC scheduling state which
   * require a lock, aside from the special case where the functions are called
@@ -1092,6 +1111,7 @@ static int steal_guc_id(struct intel_guc *guc)
 
  		list_del_init(&ce->guc_id_link);
  		guc_id = ce->guc_id;
+		clr_context_registered(ce);
  		set_context_guc_id_invalid(ce);
  		return guc_id;
  	} else {
@@ -1201,10 +1221,15 @@ static int register_context(struct intel_context *ce, bool loop)
  	struct intel_guc *guc = ce_to_guc(ce);
  	u32 offset = intel_guc_ggtt_offset(guc, guc->lrc_desc_pool) +
  		ce->guc_id * sizeof(struct guc_lrc_desc);
+	int ret;
 
  	trace_intel_context_register(ce);
 
-	return __guc_action_register_context(guc, ce->guc_id, offset, loop);
+	ret = __guc_action_register_context(guc, ce->guc_id, offset, loop);
+	if (likely(!ret))
+		set_context_registered(ce);
+
+	return ret;
  }
 
  static int __guc_action_deregister_context(struct intel_guc *guc,
@@ -1260,6 +1285,8 @@ static void guc_context_policy_init(struct intel_engine_cs *engine,
  	desc->preemption_timeout = engine->props.preempt_timeout_ms * 1000;
  }
 
+static inline u8 map_i915_prio_to_guc_prio(int prio);
+
  static int guc_lrc_desc_pin(struct intel_context *ce, bool loop)
  {
  	struct intel_engine_cs *engine = ce->engine;
@@ -1267,6 +1294,8 @@ static int guc_lrc_desc_pin(struct intel_context *ce, bool loop)
  	struct intel_guc *guc = &engine->gt->uc.guc;
  	u32 desc_idx = ce->guc_id;
  	struct guc_lrc_desc *desc;
+	const struct i915_gem_context *ctx;
+	int prio = I915_CONTEXT_DEFAULT_PRIORITY;
  	bool context_registered;
  	intel_wakeref_t wakeref;
  	int ret = 0;
@@ -1282,6 +1311,12 @@ static int guc_lrc_desc_pin(struct intel_context *ce, bool loop)
 
  	context_registered = lrc_desc_registered(guc, desc_idx);
 
+	rcu_read_lock();
+	ctx = rcu_dereference(ce->gem_context);
+	if (ctx)
+		prio = ctx->sched.priority;
+	rcu_read_unlock();
+
  	reset_lrc_desc(guc, desc_idx);
  	set_lrc_desc_registered(guc, desc_idx, ce);
 
@@ -1290,7 +1325,8 @@ static int guc_lrc_desc_pin(struct intel_context *ce, bool loop)
  	desc->engine_submit_mask = adjust_engine_mask(engine->class,
  						      engine->mask);
  	desc->hw_context_desc = ce->lrc.lrca;
-	desc->priority = GUC_CLIENT_PRIORITY_KMD_NORMAL;
+	ce->guc_prio = map_i915_prio_to_guc_prio(prio);
+	desc->priority = ce->guc_prio;
  	desc->context_flags = CONTEXT_REGISTRATION_FLAG_KMD;
  	guc_context_policy_init(engine, desc);
  	init_sched_state(ce);
@@ -1693,11 +1729,17 @@ static inline void guc_lrc_desc_unpin(struct intel_context *ce)
  	GEM_BUG_ON(ce != __get_context(guc, ce->guc_id));
  	GEM_BUG_ON(context_enabled(ce));
 
+	clr_context_registered(ce);
  	deregister_context(ce, ce->guc_id, true);
  }
 
  static void __guc_context_destroy(struct intel_context *ce)
  {
+	GEM_BUG_ON(ce->guc_prio_count[GUC_CLIENT_PRIORITY_KMD_HIGH] ||
+		   ce->guc_prio_count[GUC_CLIENT_PRIORITY_HIGH] ||
+		   ce->guc_prio_count[GUC_CLIENT_PRIORITY_KMD_NORMAL] ||
+		   ce->guc_prio_count[GUC_CLIENT_PRIORITY_NORMAL]);
+
  	lrc_fini(ce);
  	intel_context_fini(ce);
 
@@ -1791,15 +1833,124 @@ static int guc_context_alloc(struct intel_context *ce)
  	return lrc_alloc(ce, ce->engine);
  }
 
+static void guc_context_set_prio(struct intel_guc *guc,
+				 struct intel_context *ce,
+				 u8 prio)
+{
+	u32 action[] = {
+		INTEL_GUC_ACTION_SET_CONTEXT_PRIORITY,
+		ce->guc_id,
+		prio,
+	};
+
+	GEM_BUG_ON(prio < GUC_CLIENT_PRIORITY_KMD_HIGH ||
+		   prio > GUC_CLIENT_PRIORITY_NORMAL);
+
+	if (ce->guc_prio == prio || submission_disabled(guc) ||
+	    !context_registered(ce))
+		return;
+
+	guc_submission_send_busy_loop(guc, action, ARRAY_SIZE(action), 0, true);
+
+	ce->guc_prio = prio;
+	trace_intel_context_set_prio(ce);
+}
+
+static inline u8 map_i915_prio_to_guc_prio(int prio)
+{
+	if (prio == I915_PRIORITY_NORMAL)
+		return GUC_CLIENT_PRIORITY_KMD_NORMAL;
+	else if (prio < I915_PRIORITY_NORMAL)
+		return GUC_CLIENT_PRIORITY_NORMAL;
+	else if (prio < I915_PRIORITY_DISPLAY)
+		return GUC_CLIENT_PRIORITY_HIGH;
+	else
+		return GUC_CLIENT_PRIORITY_KMD_HIGH;
+}
+
+static inline void add_context_inflight_prio(struct intel_context *ce,
+					     u8 guc_prio)
+{
+	lockdep_assert_held(&ce->guc_active.lock);
+	GEM_BUG_ON(guc_prio >= ARRAY_SIZE(ce->guc_prio_count));
+
+	++ce->guc_prio_count[guc_prio];
+
+	/* Overflow protection */
+	GEM_WARN_ON(!ce->guc_prio_count[guc_prio]);
+}
+
+static inline void sub_context_inflight_prio(struct intel_context *ce,
+					     u8 guc_prio)
+{
+	lockdep_assert_held(&ce->guc_active.lock);
+	GEM_BUG_ON(guc_prio >= ARRAY_SIZE(ce->guc_prio_count));
+
+	/* Underflow protection */
+	GEM_WARN_ON(!ce->guc_prio_count[guc_prio]);
+
+	--ce->guc_prio_count[guc_prio];
+}
+
+static inline void update_context_prio(struct intel_context *ce)
+{
+	struct intel_guc *guc = &ce->engine->gt->uc.guc;
+	int i;
+
+	BUILD_BUG_ON(GUC_CLIENT_PRIORITY_KMD_HIGH != 0);
+	BUILD_BUG_ON(GUC_CLIENT_PRIORITY_KMD_HIGH > GUC_CLIENT_PRIORITY_NORMAL);
+
+	lockdep_assert_held(&ce->guc_active.lock);
+
+	for (i = 0; i < ARRAY_SIZE(ce->guc_prio_count); ++i) {
+		if (ce->guc_prio_count[i]) {
+			guc_context_set_prio(guc, ce, i);
+			break;
+		}
+	}
+}
+
+static inline bool new_guc_prio_higher(u8 old_guc_prio, u8 new_guc_prio)
+{
+	/* Lower value is higher priority */
+	return new_guc_prio < old_guc_prio;
+}
+
  static void add_to_context(struct i915_request *rq)
  {
  	struct intel_context *ce = rq->context;
+	u8 new_guc_prio = map_i915_prio_to_guc_prio(rq_prio(rq));
+
+	GEM_BUG_ON(rq->guc_prio == GUC_PRIO_FINI);
 
  	spin_lock(&ce->guc_active.lock);
  	list_move_tail(&rq->sched.link, &ce->guc_active.requests);
+
+	if (rq->guc_prio == GUC_PRIO_INIT) {
+		rq->guc_prio = new_guc_prio;
+		add_context_inflight_prio(ce, rq->guc_prio);
+	} else if (new_guc_prio_higher(rq->guc_prio, new_guc_prio)) {
+		sub_context_inflight_prio(ce, rq->guc_prio);
+		rq->guc_prio = new_guc_prio;
+		add_context_inflight_prio(ce, rq->guc_prio);
+	}
+	update_context_prio(ce);
+
  	spin_unlock(&ce->guc_active.lock);
  }
 
+static void guc_prio_fini(struct i915_request *rq, struct intel_context *ce)
+{
+	lockdep_assert_held(&ce->guc_active.lock);
+
+	if (rq->guc_prio != GUC_PRIO_INIT &&
+	    rq->guc_prio != GUC_PRIO_FINI) {
+		sub_context_inflight_prio(ce, rq->guc_prio);
+		update_context_prio(ce);
+	}
+	rq->guc_prio = GUC_PRIO_FINI;
+}
+
  static void remove_from_context(struct i915_request *rq)
  {
  	struct intel_context *ce = rq->context;
@@ -1812,6 +1963,8 @@ static void remove_from_context(struct i915_request *rq)
  	/* Prevent further __await_execution() registering a cb, then flush */
  	set_bit(I915_FENCE_FLAG_ACTIVE, &rq->fence.flags);
 
+	guc_prio_fini(rq, ce);
+
  	spin_unlock_irq(&ce->guc_active.lock);
 
  	atomic_dec(&ce->guc_id_ref);
@@ -2093,6 +2246,39 @@ static void guc_init_breadcrumbs(struct intel_engine_cs *engine)
  	}
  }
 
+static void guc_bump_inflight_request_prio(struct i915_request *rq,
+					   int prio)
+{
+	struct intel_context *ce = rq->context;
+	u8 new_guc_prio = map_i915_prio_to_guc_prio(prio);
+
+	/* Short circuit function */
+	if (prio < I915_PRIORITY_NORMAL ||
+	    rq->guc_prio == GUC_PRIO_FINI ||
+	    (rq->guc_prio != GUC_PRIO_INIT &&
+	     !new_guc_prio_higher(rq->guc_prio, new_guc_prio)))
+		return;
+
+	spin_lock(&ce->guc_active.lock);
+	if (rq->guc_prio != GUC_PRIO_FINI) {
+		if (rq->guc_prio != GUC_PRIO_INIT)
+			sub_context_inflight_prio(ce, rq->guc_prio);
+		rq->guc_prio = new_guc_prio;
+		add_context_inflight_prio(ce, rq->guc_prio);
+		update_context_prio(ce);
+	}
+	spin_unlock(&ce->guc_active.lock);
+}
+
+static void guc_retire_inflight_request_prio(struct i915_request *rq)
+{
+	struct intel_context *ce = rq->context;
+
+	spin_lock(&ce->guc_active.lock);
+	guc_prio_fini(rq, ce);
+	spin_unlock(&ce->guc_active.lock);
+}
+
  static void sanitize_hwsp(struct intel_engine_cs *engine)
  {
  	struct intel_timeline *tl;
@@ -2317,6 +2503,10 @@ int intel_guc_submission_setup(struct intel_engine_cs *engine)
  		guc->sched_engine->disabled = guc_sched_engine_disabled;
  		guc->sched_engine->private_data = guc;
  		guc->sched_engine->destroy = guc_sched_engine_destroy;
+		guc->sched_engine->bump_inflight_request_prio =
+			guc_bump_inflight_request_prio;
+		guc->sched_engine->retire_inflight_request_prio =
+			guc_retire_inflight_request_prio;
  		tasklet_setup(&guc->sched_engine->tasklet,
  			      guc_submission_tasklet);
  	}
@@ -2694,6 +2884,22 @@ void intel_guc_submission_print_info(struct intel_guc *guc,
  	drm_printf(p, "\n");
  }
 
+static inline void guc_log_context_priority(struct drm_printer *p,
+					    struct intel_context *ce)
+{
+	int i;
+
+	drm_printf(p, "\t\tPriority: %d\n",
+		   ce->guc_prio);
+	drm_printf(p, "\t\tNumber Requests (lower index == higher priority)\n");
+	for (i = GUC_CLIENT_PRIORITY_KMD_HIGH;
+	     i < GUC_CLIENT_PRIORITY_NUM; ++i) {
+		drm_printf(p, "\t\tNumber requests in priority band[%d]: %d\n",
+			   i, ce->guc_prio_count[i]);
+	}
+	drm_printf(p, "\n");
+}
+
  void intel_guc_submission_print_context_info(struct intel_guc *guc,
  					     struct drm_printer *p)
  {
@@ -2716,6 +2922,8 @@ void intel_guc_submission_print_context_info(struct intel_guc *guc,
  		drm_printf(p, "\t\tSchedule State: 0x%x, 0x%x\n\n",
  			   ce->guc_state.sched_state,
  			   atomic_read(&ce->guc_sched_state_no_lock));
+
+		guc_log_context_priority(p, ce);
  	}
  }
 
drivers/gpu/drm/i915/i915_request.c +5 -0
index 541a20371502..1f1d4a6a0eff 100644
@@ -114,6 +114,9 @@ static void i915_fence_release(struct dma_fence *fence)
  {
  	struct i915_request *rq = to_request(fence);
 
+	GEM_BUG_ON(rq->guc_prio != GUC_PRIO_INIT &&
+		   rq->guc_prio != GUC_PRIO_FINI);
+
  	/*
  	 * The request is put onto a RCU freelist (i.e. the address
  	 * is immediately reused), mark the fences as being freed now.
@@ -924,6 +927,8 @@ __i915_request_create(struct intel_context *ce, gfp_t gfp)
 
  	rq->rcustate = get_state_synchronize_rcu(); /* acts as smp_mb() */
 
+	rq->guc_prio = GUC_PRIO_INIT;
+
  	/* We bump the ref for the fence chain */
  	i915_sw_fence_reinit(&i915_request_get(rq)->submit);
  	i915_sw_fence_reinit(&i915_request_get(rq)->semaphore);
drivers/gpu/drm/i915/i915_request.h +9 -0
index ac0e3326c067..e6a0e0ebc9aa 100644
@@ -293,6 +293,15 @@ struct i915_request {
  	 */
  	struct list_head guc_fence_link;
 
+	/**
+	 * Priority level while the request is inflight. Differs from i915
+	 * scheduler priority. See comment above
+	 * I915_SCHEDULER_CAP_STATIC_PRIORITY_MAP for details.
+	 */
+#define	GUC_PRIO_INIT	0xff
+#define	GUC_PRIO_FINI	0xfe
+	u8 guc_prio;
+
  	I915_SELFTEST_DECLARE(struct {
  		struct list_head link;
  		unsigned long delay;
drivers/gpu/drm/i915/i915_scheduler.c +7 -0
index 28dd887eb1be..17843c204356 100644
@@ -241,6 +241,9 @@ static void __i915_schedule(struct i915_sched_node *node,
  	/* Fifo and depth-first replacement ensure our deps execute before us */
  	sched_engine = lock_sched_engine(node, sched_engine, &cache);
  	list_for_each_entry_safe_reverse(dep, p, &dfs, dfs_link) {
+		struct i915_request *from = container_of(dep->signaler,
+							 struct i915_request,
+							 sched);
  		INIT_LIST_HEAD(&dep->dfs_link);
 
  		node = dep->signaler;
@@ -254,6 +257,10 @@ static void __i915_schedule(struct i915_sched_node *node,
  		GEM_BUG_ON(node_to_request(node)->engine->sched_engine !=
  			   sched_engine);
 
+		/* Must be called before changing the nodes priority */
+		if (sched_engine->bump_inflight_request_prio)
+			sched_engine->bump_inflight_request_prio(from, prio);
+
  		WRITE_ONCE(node->attr.priority, prio);
 
  		/*
drivers/gpu/drm/i915/i915_scheduler_types.h +12 -0
index eaef233e9080..b0a1b58c7893 100644
@@ -179,6 +179,18 @@ struct i915_sched_engine {
  	void	(*kick_backend)(const struct i915_request *rq,
  				int prio);
 
+	/**
+	 * @bump_inflight_request_prio: update priority of an inflight request
+	 */
+	void	(*bump_inflight_request_prio)(struct i915_request *rq,
+					      int prio);
+
+	/**
+	 * @retire_inflight_request_prio: indicate request is retired to
+	 * priority tracking
+	 */
+	void	(*retire_inflight_request_prio)(struct i915_request *rq);
+
  	/**
  	 * @schedule: adjust priority of request
  	 *
drivers/gpu/drm/i915/i915_trace.h +15 -2
index 9613a7c19661..806ad688274b 100644
@@ -904,6 +904,7 @@ DECLARE_EVENT_CLASS(intel_context,
  			     __field(int, pin_count)
  			     __field(u32, sched_state)
  			     __field(u32, guc_sched_state_no_lock)
+			     __field(u8, guc_prio)
  			     ),
 
  		    TP_fast_assign(
@@ -912,12 +913,19 @@ DECLARE_EVENT_CLASS(intel_context,
  			   __entry->sched_state = ce->guc_state.sched_state;
  			   __entry->guc_sched_state_no_lock =
  			   atomic_read(&ce->guc_sched_state_no_lock);
+			   __entry->guc_prio = ce->guc_prio;
  			   ),
 
-		    TP_printk("guc_id=%d, pin_count=%d sched_state=0x%x,0x%x",
+		    TP_printk("guc_id=%d, pin_count=%d sched_state=0x%x,0x%x, guc_prio=%u",
  			      __entry->guc_id, __entry->pin_count,
  			      __entry->sched_state,
-			      __entry->guc_sched_state_no_lock)
+			      __entry->guc_sched_state_no_lock,
+			      __entry->guc_prio)
+);
+
+DEFINE_EVENT(intel_context, intel_context_set_prio,
+	     TP_PROTO(struct intel_context *ce),
+	     TP_ARGS(ce)
  );
 
  DEFINE_EVENT(intel_context, intel_context_reset,
@@ -1017,6 +1025,11 @@ trace_i915_request_out(struct i915_request *rq)
  {
  }
 
+static inline void
+trace_intel_context_set_prio(struct intel_context *ce)
+{
+}
+
  static inline void
  trace_intel_context_reset(struct intel_context *ce)
  {
include/uapi/drm/i915_drm.h +9 -0
index 975087553ea0..7f13d241417f 100644
@@ -572,6 +572,15 @@ typedef struct drm_i915_irq_wait {
  #define   I915_SCHEDULER_CAP_PREEMPTION	(1ul << 2)
  #define   I915_SCHEDULER_CAP_SEMAPHORES	(1ul << 3)
  #define   I915_SCHEDULER_CAP_ENGINE_BUSY_STATS	(1ul << 4)
+/*
+ * Indicates the 2k user priority levels are statically mapped into 3 buckets as
+ * follows:
+ *
+ * -1k to -1	Low priority
+ * 0		Normal priority
+ * 1 to 1k	Highest priority
+ */
+#define   I915_SCHEDULER_CAP_STATIC_PRIORITY_MAP	(1ul << 5)
 
  #define I915_PARAM_HUC_STATUS		 42
 
#46 lore raw

Re: [Intel-gfx] [PATCH 32/33] drm/i915/guc: Implement GuC priority management

Quoted 16 lines · Tvrtko Ursulin

A blast from the past..

Quoted 11 lines · Matthew Brost

Implement a simple static mapping algorithm of the i915 priority levels (int, -1k to 1k exposed to user) to the 4 GuC levels. Mapping is as follows:

i915 level < 0          -> GuC low level     (3)
i915 level == 0         -> GuC normal level  (2)
i915 level < INT_MAX    -> GuC high level    (1)
i915 level == INT_MAX   -> GuC highest level (0)

We believe this mapping should cover the UMD use cases (3 distinct user levels + 1 kernel level).

Quoted 7 lines

I've noticed Vulkan has VK_EXT_global_priority and AFAICT Mesa implementation maps those priorities to i915 uapi:

    VK_QUEUE_GLOBAL_PRIORITY_LOW_KHR = -512
    VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_KHR = 0
    VK_QUEUE_GLOBAL_PRIORITY_HIGH_KHR = +512
    VK_QUEUE_GLOBAL_PRIORITY_REALTIME_KHR = +1023

Wasn't aware of the REALTIME option. Does Mesa have that as well? Pretty sure it only had low/medium/high last I time looked but that was quite a while ago.

Quoted 8 lines

GuC as per this patch remaps to:

    VK_QUEUE_GLOBAL_PRIORITY_LOW_KHR = GUC_CLIENT_PRIORITY_NORMAL VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_KHR = GUC_CLIENT_PRIORITY_KMD_NORMAL VK_QUEUE_GLOBAL_PRIORITY_HIGH_KHR = GUC_CLIENT_PRIORITY_HIGH VK_QUEUE_GLOBAL_PRIORITY_REALTIME_KHR = GUC_CLIENT_PRIORITY_HIGH

Last two being the same, so we lose one level. I don't think it is a problem according to VK spec, which is very loose, so considered fine for us and just unfortunate?

My recollection is that both Vulkan and Mesa describe the priority as merely a hint. The implementation is free to obey or ignore as it desires (or as it is capable). So while it would be good to support what we can, we don't actually fail any compatibility rules if we don't. And I think the idea was to reserve the highest priority for KMD only tasks such as the heartbeat.

Quoted 2 lines

Also, given drm/sched has three priorities - what is the plan to connect GuC's four into those three? I ask because I noticed the

I guess the plan there is a straight 1:1 for low/medium/high. Matthew would be the person with more idea on the drm/scheduler, though.

Quoted 3 lines

fixed three levels does not really fit with some other drivers like msm for instance. There are up to four hardware priorities there and currently an odd mapping scheme is implemented. So I am getting a feeling drm/sched should rather be extended to allow more flexibility for drivers.

And finally a side question on this particular patch - shouldn't GuC map I915_PRIORITY_HEARTBEAT to GUC_CLIENT_PRIORITY_KMD_HIGH (highest)? I'd say yes - we certainly want heartbeats to preempt maximum user priority.

Hmm. Not sure what the point of the HEARTBEAT define is. The heartbeat pulse itself starts at minimum priority and then bumps upwards on each time period until it hits the max. So eventually, it will run at higher than maximum user priority. The HEARTBEAT prio itself seems to be the mid-point. So we don't want that to be super-high. It would even maybe make more sense for it to match NORMAL.

John.

Quoted 575 lines

Regards,

Tvrtko

Quoted 570 lines

In addition to static mapping, a simple counter system is attached to each context tracking the number of requests inflight on the context at each level. This is needed as the GuC levels are per context while in the i915 levels are per request.

v2:
  (Daniele)
   - Add BUILD_BUG_ON to enforce ordering of priority levels
   - Add missing lockdep to guc_prio_fini
   - Check for return before setting context registered flag
   - Map DISPLAY priority or higher to highest guc prio
   - Update comment for guc_prio

---
  drivers/gpu/drm/i915/gt/intel_breadcrumbs.c   |   3 + drivers/gpu/drm/i915/gt/intel_context_types.h |   9 +- drivers/gpu/drm/i915/gt/intel_engine_user.c   |   4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 212 +++++++++++++++++- drivers/gpu/drm/i915/i915_request.c           |   5 + drivers/gpu/drm/i915/i915_request.h           |   9 + drivers/gpu/drm/i915/i915_scheduler.c         |   7 + drivers/gpu/drm/i915/i915_scheduler_types.h   |  12 + drivers/gpu/drm/i915/i915_trace.h             |  17 +- include/uapi/drm/i915_drm.h                   |   9 +

  10 files changed, 282 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/gt/intel_breadcrumbs.c +2 -0
index 2007dc6f6b99..209cf265bf74 100644
@@ -245,6 +245,9 @@ static void signal_irq_work(struct irq_work *work)
               llist_entry(signal, typeof(*rq), signal_node);
           struct list_head cb_list;
   +        if (rq->engine->sched_engine->retire_inflight_request_prio)
+ rq->engine->sched_engine->retire_inflight_request_prio(rq);
+
           spin_lock(&rq->lock);
           list_replace(&rq->fence.cb_list, &cb_list);
           __dma_fence_signal__timestamp(&rq->fence, timestamp);
drivers/gpu/drm/i915/gt/intel_context_types.h +0 -0
index a5bc876face7..e54351a170e2 100644
@@ -18,8 +18,9 @@
   #include "intel_engine_types.h"
   #include "intel_sseu.h"

  -#define CONTEXT_REDZONE POISON_INUSE
+#include "uc/intel_guc_fwif.h"
  +#define CONTEXT_REDZONE POISON_INUSE
  DECLARE_EWMA(runtime, 3, 8);
    struct i915_gem_context;

drivers/gpu/drm/i915/gt/intel_context_types.h +6 -0
@@ -191,6 +192,12 @@ struct intel_context {
         /* GuC context blocked fence */
       struct i915_sw_fence guc_blocked;
+
+    /*
+     * GuC priority management
+     */
+    u8 guc_prio;
+    u32 guc_prio_count[GUC_CLIENT_PRIORITY_NUM];
   };
     #endif /* __INTEL_CONTEXT_TYPES__ */
drivers/gpu/drm/i915/gt/intel_engine_user.c +1 -0
index 84142127ebd8..8f8bea08e734 100644
@@ -11,6 +11,7 @@
   #include "intel_engine.h"
   #include "intel_engine_user.h"
   #include "intel_gt.h"
+#include "uc/intel_guc_submission.h"

    struct intel_engine_cs *
  intel_engine_lookup_user(struct drm_i915_private *i915, u8 class, u8 instance)

drivers/gpu/drm/i915/gt/intel_engine_user.c +0 -0
@@ -115,6 +116,9 @@ static void set_scheduler_caps(struct 
 drm_i915_private *i915)

              disabled |= (I915_SCHEDULER_CAP_ENABLED | I915_SCHEDULER_CAP_PRIORITY); +        if (intel_uc_uses_guc_submission(&i915->gt.uc)) +            enabled |= I915_SCHEDULER_CAP_STATIC_PRIORITY_MAP; +
          for (i = 0; i < ARRAY_SIZE(map); i++) {
              if (engine->flags & BIT(map[i].engine)) enabled |= BIT(map[i].sched);

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +1 -0
index 3ff42d6e934f..b760cbf6ca0e 100644
@@ -81,6 +81,7 @@ guc_create_virtual(struct intel_engine_cs 
 **siblings, unsigned int count);
    */
   #define SCHED_STATE_NO_LOCK_ENABLED            BIT(0)
   #define SCHED_STATE_NO_LOCK_PENDING_ENABLE        BIT(1)
+#define SCHED_STATE_NO_LOCK_REGISTERED            BIT(2)
   static inline bool context_enabled(struct intel_context *ce)
   {

      return (atomic_read(&ce->guc_sched_state_no_lock) &

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +17 -0
@@ -116,6 +117,24 @@ static inline void 
 clr_context_pending_enable(struct intel_context *ce)
              &ce->guc_sched_state_no_lock);
   }
   +static inline bool context_registered(struct intel_context *ce)
+{
+    return (atomic_read(&ce->guc_sched_state_no_lock) &
+        SCHED_STATE_NO_LOCK_REGISTERED);
+}
+
+static inline void set_context_registered(struct intel_context *ce)
+{
+    atomic_or(SCHED_STATE_NO_LOCK_REGISTERED,
+          &ce->guc_sched_state_no_lock);
+}
+
+static inline void clr_context_registered(struct intel_context *ce)
+{
+    atomic_and((u32)~SCHED_STATE_NO_LOCK_REGISTERED,
+           &ce->guc_sched_state_no_lock);
+}
+
   /*
    * Below is a set of functions which control the GuC scheduling state which

   * require a lock, aside from the special case where the functions are called

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +1 -0
@@ -1092,6 +1111,7 @@ static int steal_guc_id(struct intel_guc *guc)
             list_del_init(&ce->guc_id_link);
           guc_id = ce->guc_id;
+        clr_context_registered(ce);
           set_context_guc_id_invalid(ce);
           return guc_id;
       } else {
@@ -1201,10 +1221,15 @@ static int register_context(struct 
 intel_context *ce, bool loop)
       struct intel_guc *guc = ce_to_guc(ce);

      u32 offset = intel_guc_ggtt_offset(guc, guc->lrc_desc_pool) + ce->guc_id * sizeof(struct guc_lrc_desc);
+    int ret;
        trace_intel_context_register(ce);
  -    return __guc_action_register_context(guc, ce->guc_id, offset, loop); +    ret = __guc_action_register_context(guc, ce->guc_id, offset, loop); +    if (likely(!ret))
+        set_context_registered(ce);
+
+    return ret;
  }
    static int __guc_action_deregister_context(struct intel_guc *guc,

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +1 -0
@@ -1260,6 +1285,8 @@ static void guc_context_policy_init(struct 
 intel_engine_cs *engine,
       desc->preemption_timeout = engine->props.preempt_timeout_ms * 1000;
   }
   +static inline u8 map_i915_prio_to_guc_prio(int prio);
+
   static int guc_lrc_desc_pin(struct intel_context *ce, bool loop)
   {

      struct intel_engine_cs *engine = ce->engine;

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2 -0
@@ -1267,6 +1294,8 @@ static int guc_lrc_desc_pin(struct 
 intel_context *ce, bool loop)
       struct intel_guc *guc = &engine->gt->uc.guc;
       u32 desc_idx = ce->guc_id;
       struct guc_lrc_desc *desc;
+    const struct i915_gem_context *ctx;
+    int prio = I915_CONTEXT_DEFAULT_PRIORITY;
       bool context_registered;
       intel_wakeref_t wakeref;

      int ret = 0;

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5 -0
@@ -1282,6 +1311,12 @@ static int guc_lrc_desc_pin(struct 
 intel_context *ce, bool loop)
         context_registered = lrc_desc_registered(guc, desc_idx);
   +    rcu_read_lock();
+    ctx = rcu_dereference(ce->gem_context);
+    if (ctx)
+        prio = ctx->sched.priority;
+    rcu_read_unlock();
+
       reset_lrc_desc(guc, desc_idx);
       set_lrc_desc_registered(guc, desc_idx, ce);
   @@ -1290,7 +1325,8 @@ static int guc_lrc_desc_pin(struct intel_context *ce, bool loop)

      desc->engine_submit_mask = adjust_engine_mask(engine->class, engine->mask); desc->hw_context_desc = ce->lrc.lrca;
-    desc->priority = GUC_CLIENT_PRIORITY_KMD_NORMAL;
+    ce->guc_prio = map_i915_prio_to_guc_prio(prio);
+    desc->priority = ce->guc_prio;
      desc->context_flags = CONTEXT_REGISTRATION_FLAG_KMD; guc_context_policy_init(engine, desc); init_sched_state(ce);

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5 -0
@@ -1693,11 +1729,17 @@ static inline void guc_lrc_desc_unpin(struct 
 intel_context *ce)
       GEM_BUG_ON(ce != __get_context(guc, ce->guc_id));
       GEM_BUG_ON(context_enabled(ce));
   +    clr_context_registered(ce);
       deregister_context(ce, ce->guc_id, true);
   }
     static void __guc_context_destroy(struct intel_context *ce)
   {
+ GEM_BUG_ON(ce->guc_prio_count[GUC_CLIENT_PRIORITY_KMD_HIGH] ||
+           ce->guc_prio_count[GUC_CLIENT_PRIORITY_HIGH] ||
+ ce->guc_prio_count[GUC_CLIENT_PRIORITY_KMD_NORMAL] ||
+           ce->guc_prio_count[GUC_CLIENT_PRIORITY_NORMAL]);
+
       lrc_fini(ce);
       intel_context_fini(ce);
   @@ -1791,15 +1833,124 @@ static int guc_context_alloc(struct intel_context *ce)

      return lrc_alloc(ce, ce->engine);
  }
  +static void guc_context_set_prio(struct intel_guc *guc, +                 struct intel_context *ce,
+                 u8 prio)

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +15 -0
+{
+    u32 action[] = {
+        INTEL_GUC_ACTION_SET_CONTEXT_PRIORITY,
+        ce->guc_id,
+        prio,
+    };
+
+    GEM_BUG_ON(prio < GUC_CLIENT_PRIORITY_KMD_HIGH ||
+           prio > GUC_CLIENT_PRIORITY_NORMAL);
+
+    if (ce->guc_prio == prio || submission_disabled(guc) ||
+        !context_registered(ce))
+        return;
+
+    guc_submission_send_busy_loop(guc, action, ARRAY_SIZE(action), 

0, true);

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +48 -0
+
+    ce->guc_prio = prio;
+    trace_intel_context_set_prio(ce);
+}
+
+static inline u8 map_i915_prio_to_guc_prio(int prio)
+{
+    if (prio == I915_PRIORITY_NORMAL)
+        return GUC_CLIENT_PRIORITY_KMD_NORMAL;
+    else if (prio < I915_PRIORITY_NORMAL)
+        return GUC_CLIENT_PRIORITY_NORMAL;
+    else if (prio < I915_PRIORITY_DISPLAY)
+        return GUC_CLIENT_PRIORITY_HIGH;
+    else
+        return GUC_CLIENT_PRIORITY_KMD_HIGH;
+}
+
+static inline void add_context_inflight_prio(struct intel_context *ce,
+                         u8 guc_prio)
+{
+    lockdep_assert_held(&ce->guc_active.lock);
+    GEM_BUG_ON(guc_prio >= ARRAY_SIZE(ce->guc_prio_count));
+
+    ++ce->guc_prio_count[guc_prio];
+
+    /* Overflow protection */
+    GEM_WARN_ON(!ce->guc_prio_count[guc_prio]);
+}
+
+static inline void sub_context_inflight_prio(struct intel_context *ce,
+                         u8 guc_prio)
+{
+    lockdep_assert_held(&ce->guc_active.lock);
+    GEM_BUG_ON(guc_prio >= ARRAY_SIZE(ce->guc_prio_count));
+
+    /* Underflow protection */
+    GEM_WARN_ON(!ce->guc_prio_count[guc_prio]);
+
+    --ce->guc_prio_count[guc_prio];
+}
+
+static inline void update_context_prio(struct intel_context *ce)
+{
+    struct intel_guc *guc = &ce->engine->gt->uc.guc;
+    int i;
+
+    BUILD_BUG_ON(GUC_CLIENT_PRIORITY_KMD_HIGH != 0);
+    BUILD_BUG_ON(GUC_CLIENT_PRIORITY_KMD_HIGH > 

GUC_CLIENT_PRIORITY_NORMAL);

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +12 -0
+
+    lockdep_assert_held(&ce->guc_active.lock);
+
+    for (i = 0; i < ARRAY_SIZE(ce->guc_prio_count); ++i) {
+        if (ce->guc_prio_count[i]) {
+            guc_context_set_prio(guc, ce, i);
+            break;
+        }
+    }
+}
+
+static inline bool new_guc_prio_higher(u8 old_guc_prio, u8 

new_guc_prio)

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5 -0
+{
+    /* Lower value is higher priority */
+    return new_guc_prio < old_guc_prio;
+}
+

  static void add_to_context(struct i915_request *rq) {
      struct intel_context *ce = rq->context;
+    u8 new_guc_prio = map_i915_prio_to_guc_prio(rq_prio(rq)); +
+    GEM_BUG_ON(rq->guc_prio == GUC_PRIO_FINI); spin_lock(&ce->guc_active.lock); list_move_tail(&rq->sched.link, &ce->guc_active.requests);

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +11 -0
+
+    if (rq->guc_prio == GUC_PRIO_INIT) {
+        rq->guc_prio = new_guc_prio;
+        add_context_inflight_prio(ce, rq->guc_prio);
+    } else if (new_guc_prio_higher(rq->guc_prio, new_guc_prio)) {
+        sub_context_inflight_prio(ce, rq->guc_prio);
+        rq->guc_prio = new_guc_prio;
+        add_context_inflight_prio(ce, rq->guc_prio);
+    }
+    update_context_prio(ce);
+

      spin_unlock(&ce->guc_active.lock);
  }
  +static void guc_prio_fini(struct i915_request *rq, struct intel_context *ce)

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +11 -0
+{
+    lockdep_assert_held(&ce->guc_active.lock);
+
+    if (rq->guc_prio != GUC_PRIO_INIT &&
+        rq->guc_prio != GUC_PRIO_FINI) {
+        sub_context_inflight_prio(ce, rq->guc_prio);
+        update_context_prio(ce);
+    }
+    rq->guc_prio = GUC_PRIO_FINI;
+}
+

  static void remove_from_context(struct i915_request *rq) {
      struct intel_context *ce = rq->context;

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +33 -0
@@ -1812,6 +1963,8 @@ static void remove_from_context(struct 
 i915_request *rq)
       /* Prevent further __await_execution() registering a cb, then flush */
       set_bit(I915_FENCE_FLAG_ACTIVE, &rq->fence.flags);
   +    guc_prio_fini(rq, ce);
+
       spin_unlock_irq(&ce->guc_active.lock);
         atomic_dec(&ce->guc_id_ref);
@@ -2093,6 +2246,39 @@ static void guc_init_breadcrumbs(struct 
 intel_engine_cs *engine)
       }
   }
   +static void guc_bump_inflight_request_prio(struct i915_request *rq,
+                       int prio)
+{
+    struct intel_context *ce = rq->context;
+    u8 new_guc_prio = map_i915_prio_to_guc_prio(prio);
+
+    /* Short circuit function */
+    if (prio < I915_PRIORITY_NORMAL ||
+        rq->guc_prio == GUC_PRIO_FINI ||
+        (rq->guc_prio != GUC_PRIO_INIT &&
+         !new_guc_prio_higher(rq->guc_prio, new_guc_prio)))
+        return;
+
+    spin_lock(&ce->guc_active.lock);
+    if (rq->guc_prio != GUC_PRIO_FINI) {
+        if (rq->guc_prio != GUC_PRIO_INIT)
+            sub_context_inflight_prio(ce, rq->guc_prio);
+        rq->guc_prio = new_guc_prio;
+        add_context_inflight_prio(ce, rq->guc_prio);
+        update_context_prio(ce);
+    }
+    spin_unlock(&ce->guc_active.lock);
+}
+
+static void guc_retire_inflight_request_prio(struct i915_request *rq)
+{
+    struct intel_context *ce = rq->context;
+
+    spin_lock(&ce->guc_active.lock);
+    guc_prio_fini(rq, ce);
+    spin_unlock(&ce->guc_active.lock);
+}
+
   static void sanitize_hwsp(struct intel_engine_cs *engine)
   {

      struct intel_timeline *tl;

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +4 -0
@@ -2317,6 +2503,10 @@ int intel_guc_submission_setup(struct 
 intel_engine_cs *engine)
           guc->sched_engine->disabled = guc_sched_engine_disabled;
           guc->sched_engine->private_data = guc;
           guc->sched_engine->destroy = guc_sched_engine_destroy;
+        guc->sched_engine->bump_inflight_request_prio =
+            guc_bump_inflight_request_prio;
+        guc->sched_engine->retire_inflight_request_prio =
+            guc_retire_inflight_request_prio;
           tasklet_setup(&guc->sched_engine->tasklet,
                     guc_submission_tasklet);

      }

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +15 -0
@@ -2694,6 +2884,22 @@ void intel_guc_submission_print_info(struct 
 intel_guc *guc,
       drm_printf(p, "\n");
   }
   +static inline void guc_log_context_priority(struct drm_printer *p,
+                        struct intel_context *ce)
+{
+    int i;
+
+    drm_printf(p, "\t\tPriority: %d\n",
+           ce->guc_prio);
+    drm_printf(p, "\t\tNumber Requests (lower index == higher 
 priority)\n");
+    for (i = GUC_CLIENT_PRIORITY_KMD_HIGH;
+         i < GUC_CLIENT_PRIORITY_NUM; ++i) {
+        drm_printf(p, "\t\tNumber requests in priority band[%d]: %d\n",
+               i, ce->guc_prio_count[i]);
+    }
+    drm_printf(p, "\n");
+}
+
   void intel_guc_submission_print_context_info(struct intel_guc *guc,

                           struct drm_printer *p)
  {

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2 -0
@@ -2716,6 +2922,8 @@ void 
 intel_guc_submission_print_context_info(struct intel_guc *guc,
           drm_printf(p, "\t\tSchedule State: 0x%x, 0x%x\n\n",
                  ce->guc_state.sched_state,
 atomic_read(&ce->guc_sched_state_no_lock));
+
+        guc_log_context_priority(p, ce);
       }
   }

  diff --git a/drivers/gpu/drm/i915/i915_request.c b/drivers/gpu/drm/i915/i915_request.c index 541a20371502..1f1d4a6a0eff 100644

drivers/gpu/drm/i915/i915_request.c +0 -0
@@ -114,6 +114,9 @@ static void i915_fence_release(struct dma_fence 
 *fence)
   {
       struct i915_request *rq = to_request(fence);

  +    GEM_BUG_ON(rq->guc_prio != GUC_PRIO_INIT &&
+           rq->guc_prio != GUC_PRIO_FINI);
+
      /*
       * The request is put onto a RCU freelist (i.e. the address
       * is immediately reused), mark the fences as being freed now.

drivers/gpu/drm/i915/i915_request.c +0 -0
@@ -924,6 +927,8 @@ __i915_request_create(struct intel_context *ce, 
 gfp_t gfp)

        rq->rcustate = get_state_synchronize_rcu(); /* acts as smp_mb() */ +    rq->guc_prio = GUC_PRIO_INIT;
+
      /* We bump the ref for the fence chain */ i915_sw_fence_reinit(&i915_request_get(rq)->submit); i915_sw_fence_reinit(&i915_request_get(rq)->semaphore);

drivers/gpu/drm/i915/i915_request.h +0 -0
index ac0e3326c067..e6a0e0ebc9aa 100644
@@ -293,6 +293,15 @@ struct i915_request {
        */
       struct list_head guc_fence_link;

  +    /**
+     * Priority level while the request is inflight. Differs from i915 +     * scheduler priority. See comment above
+     * I915_SCHEDULER_CAP_STATIC_PRIORITY_MAP for details. +     */

drivers/gpu/drm/i915/i915_request.h +4 -0
+#define    GUC_PRIO_INIT    0xff
+#define    GUC_PRIO_FINI    0xfe
+    u8 guc_prio;
+

      I915_SELFTEST_DECLARE(struct {
          struct list_head link;
          unsigned long delay;

drivers/gpu/drm/i915/i915_scheduler.c +3 -0
index 28dd887eb1be..17843c204356 100644
@@ -241,6 +241,9 @@ static void __i915_schedule(struct 
 i915_sched_node *node,
       /* Fifo and depth-first replacement ensure our deps execute before us */
       sched_engine = lock_sched_engine(node, sched_engine, &cache);
       list_for_each_entry_safe_reverse(dep, p, &dfs, dfs_link) {
+        struct i915_request *from = container_of(dep->signaler,
+                             struct i915_request,
+                             sched);
           INIT_LIST_HEAD(&dep->dfs_link);
             node = dep->signaler;
@@ -254,6 +257,10 @@ static void __i915_schedule(struct 
 i915_sched_node *node,

GEM_BUG_ON(node_to_request(node)->engine->sched_engine != sched_engine);
  +        /* Must be called before changing the nodes priority */ +        if (sched_engine->bump_inflight_request_prio) +            sched_engine->bump_inflight_request_prio(from, prio); +
          WRITE_ONCE(node->attr.priority, prio);
            /*

drivers/gpu/drm/i915/i915_scheduler_types.h +0 -0
index eaef233e9080..b0a1b58c7893 100644
@@ -179,6 +179,18 @@ struct i915_sched_engine {
       void    (*kick_backend)(const struct i915_request *rq,
                   int prio);

  +    /**
+     * @bump_inflight_request_prio: update priority of an inflight request
+     */
+    void    (*bump_inflight_request_prio)(struct i915_request *rq, +                          int prio);

drivers/gpu/drm/i915/i915_scheduler_types.h +7 -0
+
+    /**
+     * @retire_inflight_request_prio: indicate request is retired to
+     * priority tracking
+     */
+    void    (*retire_inflight_request_prio)(struct i915_request *rq);
+

      /**
       * @schedule: adjust priority of request
       *

drivers/gpu/drm/i915/i915_trace.h +1 -0
index 9613a7c19661..806ad688274b 100644
@@ -904,6 +904,7 @@ DECLARE_EVENT_CLASS(intel_context,
                    __field(int, pin_count)
                    __field(u32, sched_state)
                    __field(u32, guc_sched_state_no_lock)
+                 __field(u8, guc_prio)
                    ),

                TP_fast_assign(

drivers/gpu/drm/i915/i915_trace.h +0 -0
@@ -912,12 +913,19 @@ DECLARE_EVENT_CLASS(intel_context,
                  __entry->sched_state = ce->guc_state.sched_state;

                 __entry->guc_sched_state_no_lock = atomic_read(&ce->guc_sched_state_no_lock);
+               __entry->guc_prio = ce->guc_prio;
                 ),
  -            TP_printk("guc_id=%d, pin_count=%d sched_state=0x%x,0x%x", +            TP_printk("guc_id=%d, pin_count=%d sched_state=0x%x,0x%x, guc_prio=%u",
                    __entry->guc_id, __entry->pin_count, __entry->sched_state,
-                  __entry->guc_sched_state_no_lock)
+                  __entry->guc_sched_state_no_lock,
+                  __entry->guc_prio)

drivers/gpu/drm/i915/i915_trace.h +5 -0
+);
+
+DEFINE_EVENT(intel_context, intel_context_set_prio,
+         TP_PROTO(struct intel_context *ce),
+         TP_ARGS(ce)

  );
    DEFINE_EVENT(intel_context, intel_context_reset,

drivers/gpu/drm/i915/i915_trace.h +0 -0
@@ -1017,6 +1025,11 @@ trace_i915_request_out(struct i915_request *rq)
   {
   }

  +static inline void

drivers/gpu/drm/i915/i915_trace.h +4 -0
+trace_intel_context_set_prio(struct intel_context *ce)
+{
+}
+

  static inline void trace_intel_context_reset(struct intel_context *ce) {

include/uapi/drm/i915_drm.h +2 -0
index 975087553ea0..7f13d241417f 100644
@@ -572,6 +572,15 @@ typedef struct drm_i915_irq_wait {
   #define   I915_SCHEDULER_CAP_PREEMPTION    (1ul << 2)
   #define   I915_SCHEDULER_CAP_SEMAPHORES    (1ul << 3)
   #define   I915_SCHEDULER_CAP_ENGINE_BUSY_STATS    (1ul << 4)
+/*
+ * Indicates the 2k user priority levels are statically mapped into 

3 buckets as
+ * follows:
+ *
+ * -1k to -1    Low priority
+ * 0        Normal priority
+ * 1 to 1k    Highest priority
+ */
+#define   I915_SCHEDULER_CAP_STATIC_PRIORITY_MAP    (1ul << 5) #define I915_PARAM_HUC_STATUS         42

#47 lore raw

PATCH 33/33 drm/i915/guc: Unblock GuC submission on Gen11+

In reply to Matthew Brost

From: Daniele Ceraolo Spurio <[email protected]>

Unblock GuC submission on Gen11+ platforms.

v2:
(Martin Peres / John H)
- Delete debug message when GuC is disabled by default on certain platforms

---
 drivers/gpu/drm/i915/gt/uc/intel_guc.h            |  1 +
 drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c |  8 ++++++++
 drivers/gpu/drm/i915/gt/uc/intel_guc_submission.h |  3 +--
 drivers/gpu/drm/i915/gt/uc/intel_uc.c             | 13 ++++++++-----
 4 files changed, 18 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +1 -0
index 8ab70a2223b0..a9547069ee7e 100644
@@ -55,6 +55,7 @@ struct intel_guc {
 	struct ida guc_ids;
 	struct list_head guc_id_list;
 
+	bool submission_supported;
 	bool submission_selected;
 
 	struct i915_vma *ads_vma;
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +8 -0
index b760cbf6ca0e..89ff0e4b4bc7 100644
@@ -2543,6 +2543,13 @@ void intel_guc_submission_disable(struct intel_guc *guc)
 	/* Note: By the time we're here, GuC may have already been reset */
 }
 
+static bool __guc_submission_supported(struct intel_guc *guc)
+{
+	/* GuC submission is unavailable for pre-Gen11 */
+	return intel_guc_is_supported(guc) &&
+	       GRAPHICS_VER(guc_to_gt(guc)->i915) >= 11;
+}
+
 static bool __guc_submission_selected(struct intel_guc *guc)
 {
 	struct drm_i915_private *i915 = guc_to_gt(guc)->i915;
@@ -2555,6 +2562,7 @@ static bool __guc_submission_selected(struct intel_guc *guc)
 
 void intel_guc_submission_init_early(struct intel_guc *guc)
 {
+	guc->submission_supported = __guc_submission_supported(guc);
 	guc->submission_selected = __guc_submission_selected(guc);
 }
 
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.h +1 -2
index 03bc1c83a4d2..c7ef44fa0c36 100644
@@ -38,8 +38,7 @@ int intel_guc_wait_for_pending_msg(struct intel_guc *guc,
 
 static inline bool intel_guc_submission_is_supported(struct intel_guc *guc)
 {
-	/* XXX: GuC submission is unavailable for now */
-	return false;
+	return guc->submission_supported;
 }
 
 static inline bool intel_guc_submission_is_wanted(struct intel_guc *guc)
drivers/gpu/drm/i915/gt/uc/intel_uc.c +8 -5
index 7a69c3c027e9..da57d18d9f6b 100644
@@ -34,8 +34,14 @@ static void uc_expand_default_options(struct intel_uc *uc)
 		return;
 	}
 
-	/* Default: enable HuC authentication only */
-	i915->params.enable_guc = ENABLE_GUC_LOAD_HUC;
+	/* Intermediate platforms are HuC authentication only */
+	if (IS_DG1(i915) || IS_ALDERLAKE_S(i915)) {
+		i915->params.enable_guc = ENABLE_GUC_LOAD_HUC;
+		return;
+	}
+
+	/* Default: enable HuC authentication and GuC submission */
+	i915->params.enable_guc = ENABLE_GUC_LOAD_HUC | ENABLE_GUC_SUBMISSION;
 }
 
 /* Reset GuC providing us with fresh state for both GuC and HuC.
@@ -313,9 +319,6 @@ static int __uc_init(struct intel_uc *uc)
 	if (i915_inject_probe_failure(uc_to_gt(uc)->i915))
 		return -ENOMEM;
 
-	/* XXX: GuC submission is unavailable for now */
-	GEM_BUG_ON(intel_uc_uses_guc_submission(uc));
-
 	ret = intel_guc_init(guc);
 	if (ret)
 		return ret;
Signature · 1 line
2.28.0
#48 lore raw

[Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for Remaining patches for basic GuC submission (rev2)

In reply to Matthew Brost
== Series Details ==

== Series Details ==

Series: Remaining patches for basic GuC submission (rev2)
URL : https://patchwork.freedesktop.org/series/92912/
State : warning

== Summary ==

$ dim checkpatch origin/drm-tip
ac863c9f348a drm/i915/guc: GuC virtual engines
9b36b2e16d7c drm/i915/guc: Make hangcheck work with GuC virtual engines
ed1445d8ce6f drm/i915: Hold reference to intel_context over life of i915_request
abfd1c8cfaa0 drm/i915/guc: Disable bonding extension with GuC submission
ac8ef76f077e drm/i915/guc: Direct all breadcrumbs for a class to single breadcrumbs
0d5374470d54 drm/i915: Add i915_sched_engine destroy vfunc
3f313ad9f442 drm/i915: Move active request tracking to a vfunc
8c910728fa04 drm/i915/guc: Reset implementation for new GuC interface
a1ca24637d57 drm/i915: Reset GPU immediately if submission is disabled
1a63021400c4 drm/i915/guc: Add disable interrupts to guc sanitize
fa315ef03efe drm/i915/guc: Suspend/resume implementation for new interface
08b660a9380b drm/i915/guc: Handle context reset notification
b1236debf959 drm/i915/guc: Handle engine reset failure notification
a60a262a833a drm/i915/guc: Enable the timer expired interrupt for GuC
097d8dffbea2 drm/i915/guc: Provide mmio list to be saved/restored on engine reset
b8a7d8414a62 drm/i915/guc: Don't complain about reset races
b3eee1de5c25 drm/i915/guc: Enable GuC engine reset
a424d1e77c48 drm/i915/guc: Capture error state on context reset
ab288a02fdde drm/i915/guc: Fix for error capture after full GPU reset with GuC
ab399a7b42aa drm/i915/guc: Hook GuC scheduling policies up
429ef8022df4 drm/i915/guc: Connect reset modparam updates to GuC policy flags
-:53: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'i915' - possible side-effects?
#53: FILE: drivers/gpu/drm/i915/i915_debugfs_params.c:17:
+#define GET_I915(i915, name, ptr)	\
+	do {	\
+		struct i915_params *params;	\
+		params = container_of(((void *)(ptr)), typeof(*params), name);	\
+		(i915) = container_of(params, typeof(*(i915)), params);	\
+	} while (0)

total: 0 errors, 0 warnings, 1 checks, 69 lines checked
4931fc2c2985 drm/i915/guc: Include scheduling policies in the debugfs state dump a399f5609dd5 drm/i915/guc: Add golden context to GuC ADS
fb573301cd48 drm/i915/guc: Implement banned contexts for GuC submission 5ee97bf1a9b0 drm/i915/guc: Support request cancellation
091a73620c37 drm/i915/selftest: Better error reporting from hangcheck selftest bead9216b818 drm/i915/selftest: Fix workarounds selftest for GuC submission
-:282: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #282:
new file mode 100644

total: 0 errors, 1 warnings, 0 checks, 339 lines checked 94b67f9319f7 drm/i915/selftest: Fix MOCS selftest for GuC submission d7c6339f4730 drm/i915/selftest: Increase some timeouts in live_requests e481342871b4 drm/i915/selftest: Fix hangcheck self test for GuC submission -:538: WARNING:LONG_LINE: line length of 105 exceeds 100 columns #538: FILE: drivers/gpu/drm/i915/gt/selftest_workarounds.c:814:
+ SELFTEST_SCHEDULER_MODIFY_FAST_RESET);

total: 0 errors, 1 warnings, 0 checks, 538 lines checked 6375845fa9bb drm/i915/selftest: Bump selftest timeouts for hangcheck 89bb4b174ae8 drm/i915/guc: Implement GuC priority management 58dceac32800 drm/i915/guc: Unblock GuC submission on Gen11+

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

#49 lore raw

[Intel-gfx] ✓ Fi.CI.BAT: success for Remaining patches for basic GuC submission (rev2)

In reply to Matthew Brost
== Series Details ==

== Series Details ==

Series: Remaining patches for basic GuC submission (rev2)
URL : https://patchwork.freedesktop.org/series/92912/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_10399 -> Patchwork_20708
====================================================

Summary
-------

**SUCCESS**

No regressions found.

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

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

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

### IGT changes ###

#### Issues hit ####

* igt@prime_vgem@basic-userptr:
- fi-pnv-d510: NOTRUN -> [SKIP][1] ([fdo#109271]) +48 similar issues
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/fi-pnv-d510/igt@[email protected]

#### Possible fixes ####

* igt@gem_exec_parallel@engines@userptr:
- fi-pnv-d510: [INCOMPLETE][2] ([i915#299]) -> [PASS][3]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/fi-pnv-d510/igt@gem_exec_parallel@[email protected]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/fi-pnv-d510/igt@gem_exec_parallel@[email protected]

* igt@kms_flip@basic-flip-vs-dpms@a-dsi1:
- {fi-tgl-dsi}: [DMESG-WARN][4] ([i915#1982]) -> [PASS][5]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/fi-tgl-dsi/igt@kms_flip@[email protected]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/fi-tgl-dsi/igt@kms_flip@[email protected]

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

[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[i915#1982]: https://gitlab.freedesktop.org/drm/intel/issues/1982
[i915#299]: https://gitlab.freedesktop.org/drm/intel/issues/299

Participating hosts (39 -> 35)
------------------------------

Missing (4): fi-ilk-m540 fi-bsw-cyan fi-bdw-samus fi-hsw-4200u

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

* Linux: CI_DRM_10399 -> Patchwork_20708

CI-20190529: 20190529
CI_DRM_10399: 669037414c99bf454019d7e2497fe29995e31e61 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_6151: c3170c2d3744521b8351a4b9c579792bc9a5f835 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_20708: 58dceac32800dc66ca7ed0ffd6e134d62fd78bc5 @ git://anongit.freedesktop.org/gfx-ci/linux

== Linux commits ==

58dceac32800 drm/i915/guc: Unblock GuC submission on Gen11+ 89bb4b174ae8 drm/i915/guc: Implement GuC priority management 6375845fa9bb drm/i915/selftest: Bump selftest timeouts for hangcheck e481342871b4 drm/i915/selftest: Fix hangcheck self test for GuC submission d7c6339f4730 drm/i915/selftest: Increase some timeouts in live_requests 94b67f9319f7 drm/i915/selftest: Fix MOCS selftest for GuC submission bead9216b818 drm/i915/selftest: Fix workarounds selftest for GuC submission 091a73620c37 drm/i915/selftest: Better error reporting from hangcheck selftest 5ee97bf1a9b0 drm/i915/guc: Support request cancellation
fb573301cd48 drm/i915/guc: Implement banned contexts for GuC submission a399f5609dd5 drm/i915/guc: Add golden context to GuC ADS
4931fc2c2985 drm/i915/guc: Include scheduling policies in the debugfs state dump 429ef8022df4 drm/i915/guc: Connect reset modparam updates to GuC policy flags ab399a7b42aa drm/i915/guc: Hook GuC scheduling policies up ab288a02fdde drm/i915/guc: Fix for error capture after full GPU reset with GuC a424d1e77c48 drm/i915/guc: Capture error state on context reset b3eee1de5c25 drm/i915/guc: Enable GuC engine reset
b8a7d8414a62 drm/i915/guc: Don't complain about reset races 097d8dffbea2 drm/i915/guc: Provide mmio list to be saved/restored on engine reset a60a262a833a drm/i915/guc: Enable the timer expired interrupt for GuC b1236debf959 drm/i915/guc: Handle engine reset failure notification 08b660a9380b drm/i915/guc: Handle context reset notification fa315ef03efe drm/i915/guc: Suspend/resume implementation for new interface 1a63021400c4 drm/i915/guc: Add disable interrupts to guc sanitize a1ca24637d57 drm/i915: Reset GPU immediately if submission is disabled 8c910728fa04 drm/i915/guc: Reset implementation for new GuC interface 3f313ad9f442 drm/i915: Move active request tracking to a vfunc 0d5374470d54 drm/i915: Add i915_sched_engine destroy vfunc ac8ef76f077e drm/i915/guc: Direct all breadcrumbs for a class to single breadcrumbs abfd1c8cfaa0 drm/i915/guc: Disable bonding extension with GuC submission ed1445d8ce6f drm/i915: Hold reference to intel_context over life of i915_request 9b36b2e16d7c drm/i915/guc: Make hangcheck work with GuC virtual engines ac863c9f348a drm/i915/guc: GuC virtual engines

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/index.html

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

#50 lore raw

[Intel-gfx] ✓ Fi.CI.IGT: success for Remaining patches for basic GuC submission (rev2)

In reply to Matthew Brost
== Series Details ==

== Series Details ==

Series: Remaining patches for basic GuC submission (rev2)
URL : https://patchwork.freedesktop.org/series/92912/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_10399_full -> Patchwork_20708_full
====================================================

Summary
-------

**SUCCESS**

No regressions found.

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

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

### IGT changes ###

#### Suppressed ####

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

* igt@i915_pm_rpm@dpms-non-lpsp:
- {shard-rkl}: NOTRUN -> [SKIP][1] +1 similar issue
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-rkl-2/igt@[email protected]

* igt@i915_selftest@live@execlists:
- {shard-rkl}: NOTRUN -> [DMESG-FAIL][2]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-rkl-5/igt@i915_selftest@[email protected]

* igt@kms_vblank@pipe-b-ts-continuation-dpms-suspend:
- {shard-rkl}: NOTRUN -> [DMESG-WARN][3]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-rkl-6/igt@[email protected]

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

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

### IGT changes ###

#### Issues hit ####

* igt@gem_ctx_persistence@legacy-engines-queued:
- shard-snb: NOTRUN -> [SKIP][4] ([fdo#109271] / [i915#1099]) +3 similar issues
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-snb2/igt@[email protected]

* igt@gem_exec_fair@basic-deadline:
- shard-glk: [PASS][5] -> [FAIL][6] ([i915#2846])
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-glk1/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-glk8/igt@[email protected]

* igt@gem_exec_fair@basic-pace-share@rcs0:
- shard-tglb: [PASS][7] -> [FAIL][8] ([i915#2842])
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-tglb3/igt@gem_exec_fair@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-tglb1/igt@gem_exec_fair@[email protected]

* igt@gem_exec_fair@basic-pace@rcs0:
- shard-glk: [PASS][9] -> [FAIL][10] ([i915#2842])
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-glk6/igt@gem_exec_fair@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-glk1/igt@gem_exec_fair@[email protected]

* igt@gem_exec_fair@basic-pace@vecs0:
- shard-kbl: [PASS][11] -> [FAIL][12] ([i915#2842])
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-kbl2/igt@gem_exec_fair@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-kbl7/igt@gem_exec_fair@[email protected]

* igt@gem_exec_flush@basic-batch-kernel-default-cmd:
- shard-snb: NOTRUN -> [SKIP][13] ([fdo#109271]) +354 similar issues
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-snb7/igt@[email protected]

* igt@gem_huc_copy@huc-copy:
- shard-tglb: [PASS][14] -> [SKIP][15] ([i915#2190])
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-tglb1/igt@[email protected]
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-tglb6/igt@[email protected]
- shard-kbl: NOTRUN -> [SKIP][16] ([fdo#109271] / [i915#2190])
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-kbl6/igt@[email protected]

* igt@gem_mmap_gtt@cpuset-medium-copy:
- shard-iclb: [PASS][17] -> [FAIL][18] ([i915#307])
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-iclb2/igt@[email protected]
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb4/igt@[email protected]

* igt@gem_pwrite@basic-exhaustion:
- shard-apl: NOTRUN -> [WARN][19] ([i915#2658])
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-apl3/igt@[email protected]

* igt@gem_render_copy@y-tiled-to-vebox-y-tiled:
- shard-iclb: NOTRUN -> [SKIP][20] ([i915#768])
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb5/igt@[email protected]

* igt@gem_userptr_blits@readonly-unsync:
- shard-iclb: NOTRUN -> [SKIP][21] ([i915#3297])
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb5/igt@[email protected]

* igt@gen7_exec_parse@oacontrol-tracking:
- shard-iclb: NOTRUN -> [SKIP][22] ([fdo#109289])
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb5/igt@[email protected]

* igt@i915_pm_dc@dc5-psr:
- shard-skl: [PASS][23] -> [INCOMPLETE][24] ([i915#198]) +1 similar issue
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-skl10/igt@[email protected]
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-skl8/igt@[email protected]

* igt@i915_pm_lpsp@kms-lpsp@kms-lpsp-dp:
- shard-apl: NOTRUN -> [SKIP][25] ([fdo#109271] / [i915#1937])
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-apl2/igt@i915_pm_lpsp@[email protected]

* igt@i915_pm_rpm@gem-idle:
- shard-iclb: NOTRUN -> [SKIP][26] ([i915#579]) +2 similar issues
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb5/igt@[email protected]

* igt@i915_selftest@live@execlists:
- shard-skl: NOTRUN -> [INCOMPLETE][27] ([i915#198] / [i915#2782])
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-skl1/igt@i915_selftest@[email protected]

* igt@i915_suspend@forcewake:
- shard-apl: NOTRUN -> [DMESG-WARN][28] ([i915#180])
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-apl3/igt@[email protected]

* igt@i915_suspend@sysfs-reader:
- shard-apl: [PASS][29] -> [DMESG-WARN][30] ([i915#180]) +1 similar issue
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-apl8/igt@[email protected]
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-apl3/igt@[email protected]

* igt@kms_big_fb@y-tiled-max-hw-stride-64bpp-rotate-180-hflip:
- shard-skl: NOTRUN -> [SKIP][31] ([fdo#109271] / [i915#3777])
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-skl7/igt@[email protected]

* igt@kms_big_fb@yf-tiled-8bpp-rotate-90:
- shard-iclb: NOTRUN -> [SKIP][32] ([fdo#110723])
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb5/igt@[email protected]

* igt@kms_ccs@pipe-b-random-ccs-data-y_tiled_gen12_mc_ccs:
- shard-iclb: NOTRUN -> [SKIP][33] ([fdo#109278]) +8 similar issues
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb5/igt@kms_ccs@pipe-b-random-ccs-data-y_tiled_gen12_mc_ccs.html

* igt@kms_ccs@pipe-d-crc-primary-basic-y_tiled_ccs:
- shard-kbl: NOTRUN -> [SKIP][34] ([fdo#109271]) +92 similar issues
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-kbl6/igt@kms_ccs@pipe-d-crc-primary-basic-y_tiled_ccs.html

* igt@kms_chamelium@vga-hpd-for-each-pipe:
- shard-kbl: NOTRUN -> [SKIP][35] ([fdo#109271] / [fdo#111827]) +8 similar issues
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-kbl2/igt@[email protected]

* igt@kms_chamelium@vga-hpd-with-enabled-mode:
- shard-iclb: NOTRUN -> [SKIP][36] ([fdo#109284] / [fdo#111827]) +4 similar issues
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb5/igt@[email protected]

* igt@kms_color@pipe-d-ctm-0-5:
- shard-iclb: NOTRUN -> [SKIP][37] ([fdo#109278] / [i915#1149]) +1 similar issue
[37]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb5/igt@[email protected]

* igt@kms_color_chamelium@pipe-a-ctm-0-5:
- shard-apl: NOTRUN -> [SKIP][38] ([fdo#109271] / [fdo#111827]) +13 similar issues
[38]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-apl3/igt@[email protected]

* igt@kms_color_chamelium@pipe-a-ctm-blue-to-red:
- shard-snb: NOTRUN -> [SKIP][39] ([fdo#109271] / [fdo#111827]) +19 similar issues
[39]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-snb2/igt@[email protected]

* igt@kms_color_chamelium@pipe-d-ctm-green-to-red:
- shard-skl: NOTRUN -> [SKIP][40] ([fdo#109271] / [fdo#111827]) +4 similar issues
[40]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-skl7/igt@[email protected]

* igt@kms_content_protection@atomic-dpms:
- shard-apl: NOTRUN -> [TIMEOUT][41] ([i915#1319])
[41]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-apl3/igt@[email protected]

* igt@kms_content_protection@dp-mst-lic-type-0:
- shard-iclb: NOTRUN -> [SKIP][42] ([i915#3116])
[42]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb5/igt@[email protected]

* igt@kms_content_protection@uevent:
- shard-apl: NOTRUN -> [FAIL][43] ([i915#2105])
[43]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-apl7/igt@[email protected]

* igt@kms_cursor_crc@pipe-a-cursor-512x170-offscreen:
- shard-iclb: NOTRUN -> [SKIP][44] ([fdo#109278] / [fdo#109279])
[44]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb5/igt@[email protected]

* igt@kms_cursor_legacy@cursorb-vs-flipb-atomic-transitions-varying-size:
- shard-iclb: NOTRUN -> [SKIP][45] ([fdo#109274] / [fdo#109278]) +1 similar issue
[45]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb5/igt@kms_cursor_legacy@cursorb-vs-flipb-atomic-transitions-varying-size.html

* igt@kms_flip@2x-flip-vs-dpms:
- shard-iclb: NOTRUN -> [SKIP][46] ([fdo#109274]) +2 similar issues
[46]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb5/igt@[email protected]

* igt@kms_flip@flip-vs-suspend@c-dp1:
- shard-kbl: [PASS][47] -> [DMESG-WARN][48] ([i915#180]) +5 similar issues
[47]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-kbl6/igt@kms_flip@[email protected]
[48]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-kbl7/igt@kms_flip@[email protected]

* igt@kms_flip@plain-flip-fb-recreate-interruptible@b-edp1:
- shard-skl: [PASS][49] -> [FAIL][50] ([i915#2122])
[49]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-skl6/igt@kms_flip@[email protected]
[50]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-skl5/igt@kms_flip@[email protected]

* igt@kms_flip_scaled_crc@flip-32bpp-ytile-to-32bpp-ytilegen12rcccs:
- shard-kbl: NOTRUN -> [SKIP][51] ([fdo#109271] / [i915#2672])
[51]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-kbl2/igt@kms_flip_scaled_crc@flip-32bpp-ytile-to-32bpp-ytilegen12rcccs.html

* igt@kms_flip_scaled_crc@flip-32bpp-ytileccs-to-64bpp-ytile:
- shard-skl: NOTRUN -> [SKIP][52] ([fdo#109271]) +52 similar issues
[52]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-skl7/igt@[email protected]

* igt@kms_frontbuffer_tracking@psr-1p-primscrn-spr-indfb-fullscreen:
- shard-skl: [PASS][53] -> [FAIL][54] ([i915#1888])
[53]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-skl6/igt@kms_frontbuffer_tracking@psr-1p-primscrn-spr-indfb-fullscreen.html
[54]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-skl5/igt@kms_frontbuffer_tracking@psr-1p-primscrn-spr-indfb-fullscreen.html

* igt@kms_frontbuffer_tracking@psr-2p-primscrn-pri-indfb-draw-render:
- shard-iclb: NOTRUN -> [SKIP][55] ([fdo#109280]) +8 similar issues
[55]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb5/igt@kms_frontbuffer_tracking@psr-2p-primscrn-pri-indfb-draw-render.html

* igt@kms_hdr@static-swap:
- shard-iclb: NOTRUN -> [SKIP][56] ([i915#1187])
[56]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb5/igt@[email protected]

* igt@kms_pipe_crc_basic@suspend-read-crc-pipe-a:
- shard-kbl: NOTRUN -> [DMESG-WARN][57] ([i915#180])
[57]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-kbl4/igt@[email protected]

* igt@kms_pipe_crc_basic@suspend-read-crc-pipe-d:
- shard-apl: NOTRUN -> [SKIP][58] ([fdo#109271] / [i915#533]) +1 similar issue
[58]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-apl2/igt@[email protected]

* igt@kms_plane_alpha_blend@pipe-a-alpha-basic:
- shard-apl: NOTRUN -> [FAIL][59] ([fdo#108145] / [i915#265]) +2 similar issues
[59]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-apl2/igt@[email protected]

* igt@kms_plane_alpha_blend@pipe-b-alpha-opaque-fb:
- shard-kbl: NOTRUN -> [FAIL][60] ([fdo#108145] / [i915#265])
[60]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-kbl4/igt@[email protected]

* igt@kms_plane_lowres@pipe-b-tiling-x:
- shard-iclb: NOTRUN -> [SKIP][61] ([i915#3536]) +1 similar issue
[61]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb5/igt@[email protected]

* igt@kms_psr2_sf@overlay-plane-update-sf-dmg-area-4:
- shard-apl: NOTRUN -> [SKIP][62] ([fdo#109271] / [i915#658]) +2 similar issues
[62]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-apl2/igt@[email protected]

* igt@kms_psr2_sf@plane-move-sf-dmg-area-3:
- shard-iclb: NOTRUN -> [SKIP][63] ([i915#658]) +2 similar issues
[63]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb5/igt@[email protected]
- shard-kbl: NOTRUN -> [SKIP][64] ([fdo#109271] / [i915#658]) +2 similar issues
[64]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-kbl4/igt@[email protected]

* igt@kms_psr@psr2_cursor_blt:
- shard-iclb: NOTRUN -> [SKIP][65] ([fdo#109441])
[65]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb5/igt@kms_psr@psr2_cursor_blt.html

* igt@kms_psr@psr2_primary_render:
- shard-iclb: [PASS][66] -> [SKIP][67] ([fdo#109441])
[66]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-iclb2/igt@kms_psr@psr2_primary_render.html
[67]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb4/igt@kms_psr@psr2_primary_render.html

* igt@kms_vblank@pipe-a-ts-continuation-suspend:
- shard-apl: [PASS][68] -> [DMESG-WARN][69] ([i915#180] / [i915#295])
[68]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-apl6/igt@[email protected]
[69]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-apl2/igt@[email protected]

* igt@kms_vblank@pipe-d-ts-continuation-idle:
- shard-apl: NOTRUN -> [SKIP][70] ([fdo#109271]) +120 similar issues
[70]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-apl2/igt@[email protected]

* igt@kms_writeback@writeback-fb-id:
- shard-apl: NOTRUN -> [SKIP][71] ([fdo#109271] / [i915#2437]) +1 similar issue
[71]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-apl2/igt@[email protected]

* igt@kms_writeback@writeback-pixel-formats:
- shard-kbl: NOTRUN -> [SKIP][72] ([fdo#109271] / [i915#2437])
[72]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-kbl6/igt@[email protected]

* igt@nouveau_crc@pipe-b-ctx-flip-detection:
- shard-iclb: NOTRUN -> [SKIP][73] ([i915#2530])
[73]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb5/igt@[email protected]

* igt@nouveau_crc@pipe-d-ctx-flip-skip-current-frame:
- shard-iclb: NOTRUN -> [SKIP][74] ([fdo#109278] / [i915#2530])
[74]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb5/igt@[email protected]

* igt@perf@short-reads:
- shard-skl: NOTRUN -> [FAIL][75] ([i915#51])
[75]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-skl2/igt@[email protected]

* igt@prime_nv_test@i915_nv_sharing:
- shard-iclb: NOTRUN -> [SKIP][76] ([fdo#109291]) +1 similar issue
[76]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb5/igt@prime_nv_test@i915_nv_sharing.html

* igt@sysfs_clients@fair-1:
- shard-kbl: NOTRUN -> [SKIP][77] ([fdo#109271] / [i915#2994])
[77]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-kbl6/igt@[email protected]

* igt@sysfs_clients@sema-10:
- shard-apl: NOTRUN -> [SKIP][78] ([fdo#109271] / [i915#2994]) +1 similar issue
[78]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-apl2/igt@[email protected]

* igt@sysfs_clients@sema-50:
- shard-tglb: NOTRUN -> [SKIP][79] ([i915#2994])
[79]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-tglb3/igt@[email protected]

* igt@sysfs_clients@split-25:
- shard-skl: NOTRUN -> [SKIP][80] ([fdo#109271] / [i915#2994]) +1 similar issue
[80]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-skl2/igt@[email protected]

#### Possible fixes ####

* igt@gem_exec_fair@basic-none-rrul@rcs0:
- shard-glk: [FAIL][81] ([i915#2842]) -> [PASS][82]
[81]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-glk7/igt@gem_exec_fair@[email protected]
[82]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-glk5/igt@gem_exec_fair@[email protected]

* igt@gem_exec_fair@basic-none-share@rcs0:
- shard-apl: [SKIP][83] ([fdo#109271]) -> [PASS][84]
[83]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-apl2/igt@gem_exec_fair@[email protected]
[84]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-apl6/igt@gem_exec_fair@[email protected]

* igt@gem_exec_fair@basic-pace@rcs0:
- shard-kbl: [FAIL][85] ([i915#2842]) -> [PASS][86] +2 similar issues
[85]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-kbl2/igt@gem_exec_fair@[email protected]
[86]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-kbl7/igt@gem_exec_fair@[email protected]

* igt@gem_exec_schedule@u-independent@vecs0:
- shard-tglb: [FAIL][87] ([i915#3795]) -> [PASS][88]
[87]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-tglb2/igt@gem_exec_schedule@[email protected]
[88]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-tglb7/igt@gem_exec_schedule@[email protected]

* igt@gen9_exec_parse@allowed-single:
- shard-skl: [DMESG-WARN][89] ([i915#1436] / [i915#716]) -> [PASS][90]
[89]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-skl3/igt@[email protected]
[90]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-skl7/igt@[email protected]

* igt@i915_selftest@live@hangcheck:
- shard-skl: [INCOMPLETE][91] ([i915#2782]) -> [PASS][92]
[91]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-skl4/igt@i915_selftest@[email protected]
[92]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-skl1/igt@i915_selftest@[email protected]

* igt@kms_big_fb@linear-64bpp-rotate-180:
- shard-iclb: [DMESG-WARN][93] ([i915#3621]) -> [PASS][94]
[93]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-iclb1/igt@[email protected]
[94]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb5/igt@[email protected]

* igt@kms_big_fb@x-tiled-32bpp-rotate-180:
- shard-glk: [DMESG-WARN][95] ([i915#118] / [i915#95]) -> [PASS][96] +1 similar issue
[95]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-glk8/igt@[email protected]
[96]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-glk1/igt@[email protected]

* igt@kms_cursor_crc@pipe-c-cursor-64x64-random:
- shard-skl: [FAIL][97] ([i915#3444]) -> [PASS][98]
[97]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-skl5/igt@[email protected]
[98]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-skl9/igt@[email protected]

* igt@kms_cursor_legacy@flip-vs-cursor-atomic-transitions:
- shard-skl: [FAIL][99] ([i915#2346]) -> [PASS][100]
[99]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-skl9/igt@[email protected]
[100]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-skl4/igt@[email protected]

* igt@kms_flip@flip-vs-suspend-interruptible@a-dp1:
- shard-kbl: [DMESG-WARN][101] ([i915#180]) -> [PASS][102] +4 similar issues
[101]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-kbl7/igt@kms_flip@[email protected]
[102]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-kbl6/igt@kms_flip@[email protected]

* igt@kms_flip@flip-vs-suspend@a-edp1:
- shard-skl: [INCOMPLETE][103] ([i915#146] / [i915#198] / [i915#2910]) -> [PASS][104]
[103]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-skl10/igt@kms_flip@[email protected]
[104]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-skl2/igt@kms_flip@[email protected]

* igt@kms_flip@plain-flip-fb-recreate-interruptible@c-edp1:
- shard-skl: [FAIL][105] ([i915#2122]) -> [PASS][106] +1 similar issue
[105]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-skl6/igt@kms_flip@[email protected]
[106]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-skl5/igt@kms_flip@[email protected]

* igt@kms_hdr@bpc-switch-suspend:
- shard-skl: [FAIL][107] ([i915#1188]) -> [PASS][108]
[107]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-skl7/igt@[email protected]
[108]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-skl4/igt@[email protected]

* igt@kms_pipe_crc_basic@read-crc-pipe-b-frame-sequence:
- shard-skl: [DMESG-WARN][109] ([i915#1982]) -> [PASS][110]
[109]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-skl1/igt@[email protected]
[110]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-skl4/igt@[email protected]

* igt@kms_pipe_crc_basic@suspend-read-crc-pipe-b:
- shard-apl: [DMESG-WARN][111] ([i915#180]) -> [PASS][112]
[111]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-apl1/igt@[email protected]
[112]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-apl7/igt@[email protected]

* igt@kms_plane_alpha_blend@pipe-a-coverage-7efc:
- shard-skl: [FAIL][113] ([fdo#108145] / [i915#265]) -> [PASS][114]
[113]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-skl7/igt@[email protected]
[114]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-skl1/igt@[email protected]

* igt@kms_psr2_su@page_flip:
- shard-iclb: [SKIP][115] ([fdo#109642] / [fdo#111068] / [i915#658]) -> [PASS][116]
[115]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-iclb5/igt@kms_psr2_su@page_flip.html
[116]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb2/igt@kms_psr2_su@page_flip.html

* igt@kms_vblank@pipe-b-ts-continuation-suspend:
- shard-iclb: [INCOMPLETE][117] ([fdo#111764] / [i915#1185] / [i915#2828]) -> [PASS][118]
[117]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-iclb3/igt@[email protected]
[118]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb5/igt@[email protected]

* igt@perf@polling-parameterized:
- shard-skl: [FAIL][119] ([i915#1542]) -> [PASS][120]
[119]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-skl7/igt@[email protected]
[120]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-skl1/igt@[email protected]

* igt@perf@polling-small-buf:
- shard-skl: [FAIL][121] ([i915#1722]) -> [PASS][122]
[121]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-skl3/igt@[email protected]
[122]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-skl10/igt@[email protected]

#### Warnings ####

* igt@gem_exec_fair@basic-throttle@rcs0:
- shard-iclb: [FAIL][123] ([i915#2849]) -> [FAIL][124] ([i915#2842])
[123]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-iclb5/igt@gem_exec_fair@[email protected]
[124]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb8/igt@gem_exec_fair@[email protected]

* igt@i915_pm_rc6_residency@rc6-fence:
- shard-iclb: [WARN][125] ([i915#2684]) -> [WARN][126] ([i915#1804] / [i915#2684])
[125]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-iclb2/igt@[email protected]
[126]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb4/igt@[email protected]

* igt@kms_psr2_sf@overlay-plane-update-sf-dmg-area-1:
- shard-iclb: [SKIP][127] ([i915#2920]) -> [SKIP][128] ([i915#658]) +1 similar issue
[127]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-iclb2/igt@[email protected]
[128]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb4/igt@[email protected]

* igt@runner@aborted:
- shard-iclb: ([FAIL][129], [FAIL][130], [FAIL][131]) ([i915#1814] / [i915#3002]) -> ([FAIL][132], [FAIL][133]) ([i915#3002])
[129]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-iclb7/igt@[email protected]
[130]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-iclb5/igt@[email protected]
[131]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-iclb1/igt@[email protected]
[132]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb8/igt@[email protected]
[133]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-iclb8/igt@[email protected]
- shard-apl: ([FAIL][134], [FAIL][135], [FAIL][136]) ([fdo#109271] / [i915#1814] / [i915#3002] / [i915#3363]) -> ([FAIL][137], [FAIL][138], [FAIL][139], [FAIL][140], [FAIL][141], [FAIL][142]) ([i915#180] / [i915#1814] / [i915#3002] / [i915#3363])
[134]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-apl2/igt@[email protected]
[135]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-apl1/igt@[email protected]
[136]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-apl2/igt@[email protected]
[137]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-apl3/igt@[email protected]
[138]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-apl6/igt@[email protected]
[139]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-apl2/igt@[email protected]
[140]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-apl3/igt@[email protected]
[141]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-apl6/igt@[email protected]
[142]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-apl2/igt@[email protected]
- shard-skl: ([FAIL][143], [FAIL][144], [FAIL][145]) ([i915#1436] / [i915#3002] / [i915#3363]) -> ([FAIL][146], [FAIL][147]) ([i915#3002] / [i915#3363])
[143]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-skl3/igt@[email protected]
[144]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-skl1/igt@[email protected]
[145]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10399/shard-skl3/igt@[email protected]
[146]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-skl7/igt@[email protected]
[147]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/shard-skl7/igt@[email protected]

{name}: This element is suppressed. This means it is ignored when computing

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20708/index.html

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