Skip to contentSkip to conversation

GuC based preemption

RFC In review Michał Winiarski 4 participants 19 messages Feb 23, 2017 – Mar 6, 2017

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

Now that we're able to unsubmit requests, let's try to actually preempt.

The series is partially based on "Preemption support for GPU scheduler":
https://lists.freedesktop.org/archives/intel-gfx/2015-December/082817.html

It requires "drm/i915/scheduler: Support user-defined priorities"

It's still not very mature, I'm observing GPU hangs with basic sanity checks (create low_prio ctx, do work, create high_prio ctx, do work, expect that high_prio finished before low_prio, repeat) due to incorrect handling of the preemptive requests sent to GuC.

What I'd like to discuss is the overall approach and userspace interactions. When considering preemption I've stayed with the "absolute" threshold approach (we're only considering requests with priority higher than some threshold), though I'm not sure whether it's the right way of doing things (since userspace applications won't be able to increase their priority without CAP_SYS_ADMIN). Perhaps it would be better to track the highest priority of the inflight requests on each engine and consider preemption relative to that?

There's also the question of whether we want to have an "opt-in" interface for userspace to explicitly state "I'm ready to handle preemption".
We know that we can safely preempt on the batch buffer boundary, unfortunately when we try to preempt in the middle of user batches, there are cases where the default settings are "unsafe" (e.g. require different batch buffer programming from the userspace), which is why there seems to be a preference towards an opt-in ABI (either by execbuf flag or context param).
The preemption granularity is being controlled through whitelisted GEN8_CS_CHICKEN1 register, maybe we could get away with programming a "safe" default values instead?

Awaiting for feedback!

-Michał

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

#1 lore raw

RFC 1/11 drm/i915/scheduler: Remember request priority throughout its lifetime

Since request can be cancelled, we need to avoid overriding its priority during submission to be able to resubmit it.

---
 drivers/gpu/drm/i915/i915_guc_submission.c | 1 -
 drivers/gpu/drm/i915/intel_lrc.c           | 1 -
 2 files changed, 2 deletions(-)
drivers/gpu/drm/i915/i915_guc_submission.c +0 -1
index 89ee0f4..2c76377 100644
@@ -589,7 +589,6 @@ static bool i915_guc_dequeue(struct intel_engine_cs *engine)
 		rb = rb_next(rb);
 		rb_erase(&cursor->priotree.node, &engine->execlist_queue);
 		RB_CLEAR_NODE(&cursor->priotree.node);
-		cursor->priotree.priority = INT_MAX;
 
 		i915_guc_submit(cursor);
 		last = cursor;
drivers/gpu/drm/i915/intel_lrc.c +0 -1
index 6e76d11..d4cfaa1 100644
@@ -476,7 +476,6 @@ static void execlists_dequeue(struct intel_engine_cs *engine)
 		rb = rb_next(rb);
 		rb_erase(&cursor->priotree.node, &engine->execlist_queue);
 		RB_CLEAR_NODE(&cursor->priotree.node);
-		cursor->priotree.priority = INT_MAX;
 
 		__i915_gem_request_submit(cursor);
 		trace_i915_gem_request_in(cursor, port - engine->execlist_port);
Signature · 6 lines
2.9.3

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

Re: [RFC 01/11] drm/i915/scheduler: Remember request priority throughout its lifetime

Quoted 2 lines · Michał Winiarski

Since request can be cancelled, we need to avoid overriding its priority during submission to be able to resubmit it.

And this breaks rescheduling.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw

RFC 2/11 drm/i915/preempt: Add module parameter for preemption

In reply to Michał Winiarski

We're going to support preemption on platforms where GuC submission is enabled.

---
 drivers/gpu/drm/i915/i915_drv.c            |  6 ++++++
 drivers/gpu/drm/i915/i915_drv.h            |  3 +++
 drivers/gpu/drm/i915/i915_gem.c            | 22 ++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_guc_submission.c |  8 ++++++++
 drivers/gpu/drm/i915/i915_params.c         |  5 +++++
 drivers/gpu/drm/i915/i915_params.h         |  1 +
 drivers/gpu/drm/i915/intel_ringbuffer.h    |  3 +++
 7 files changed, 48 insertions(+)
drivers/gpu/drm/i915/i915_drv.c +6 -0
index b76e8f7..e2c0bec 100644
@@ -994,6 +994,12 @@ static void intel_sanitize_options(struct drm_i915_private *dev_priv)
 
 	i915.semaphores = intel_sanitize_semaphores(dev_priv, i915.semaphores);
 	DRM_DEBUG_DRIVER("use GPU semaphores? %s\n", yesno(i915.semaphores));
+
+	i915.enable_preemption =
+		intel_sanitize_enable_preemption(dev_priv,
+						 i915.enable_preemption);
+	DRM_DEBUG_DRIVER("preemption enabled? %s\n",
+			 yesno(i915.enable_preemption));
 }
 
 /**
drivers/gpu/drm/i915/i915_drv.h +3 -0
index eed9ead..f26c42c5 100644
@@ -2963,6 +2963,9 @@ int intel_sanitize_enable_ppgtt(struct drm_i915_private *dev_priv,
 
 bool intel_sanitize_semaphores(struct drm_i915_private *dev_priv, int value);
 
+bool intel_sanitize_enable_preemption(struct drm_i915_private *dev_priv,
+				      int enable_preemption);
+
 /* i915_drv.c */
 void __printf(3, 4)
 __i915_printk(struct drm_i915_private *dev_priv, const char *level,
drivers/gpu/drm/i915/i915_gem.c +22 -0
index a816700..9213425 100644
@@ -4482,6 +4482,28 @@ bool intel_sanitize_semaphores(struct drm_i915_private *dev_priv, int value)
 	return true;
 }
 
+/**
+ * intel_sanitize_enable_preemption() - sanitize i915.enable_preemption
+ * @dev_priv: i915 device private
+ * @enable_preemption: value of i915.enable_preemption module parameter.
+ *
+ * We're currently only supporting preemption when GuC submission is being
+ * used.
+ *
+ * Return: true if preemption is supported and has to be enabled.
+ */
+bool intel_sanitize_enable_preemption(struct drm_i915_private *dev_priv,
+				      int enable_preemption)
+{
+	if (!i915.enable_guc_submission)
+		return false;
+
+	if (enable_preemption >= 0)
+		return enable_preemption;
+
+	return false;
+}
+
 int i915_gem_init(struct drm_i915_private *dev_priv)
 {
 	int ret;
drivers/gpu/drm/i915/i915_guc_submission.c +8 -0
index 2c76377..feccd65 100644
@@ -489,6 +489,11 @@ static int guc_ring_doorbell(struct i915_guc_client *client)
 	return ret;
 }
 
+static int i915_guc_preempt_noop(struct intel_engine_cs *engine)
+{
+	return 0;
+}
+
 /**
  * __i915_guc_submit() - Submit commands through GuC
  * @rq:		request associated with the commands
@@ -1043,6 +1048,9 @@ int i915_guc_submission_enable(struct drm_i915_private *dev_priv)
 		 */
 		engine->irq_tasklet.func = i915_guc_irq_handler;
 
+		if (i915.enable_preemption)
+			engine->preempt = i915_guc_preempt_noop;
+
 		/* Replay the current set of previously submitted requests */
 		spin_lock_irqsave(&engine->timeline->lock, flags);
 		list_for_each_entry(rq, &engine->timeline->requests, link) {
drivers/gpu/drm/i915/i915_params.c +5 -0
index 2e9645e..c5b6929 100644
@@ -63,6 +63,7 @@ struct i915_params i915 __read_mostly = {
 	.inject_load_failure = 0,
 	.enable_dpcd_backlight = false,
 	.enable_gvt = false,
+	.enable_preemption = 0,
 };
 
 module_param_named(modeset, i915.modeset, int, 0400);
@@ -243,3 +244,7 @@ MODULE_PARM_DESC(enable_dpcd_backlight,
 module_param_named(enable_gvt, i915.enable_gvt, bool, 0400);
 MODULE_PARM_DESC(enable_gvt,
 	"Enable support for Intel GVT-g graphics virtualization host support(default:false)");
+
+module_param_named_unsafe(enable_preemption, i915.enable_preemption, int, 0400);
+MODULE_PARM_DESC(enable_preemption,
+	"Enable preemption (0=disabled [default], 1=enabled)");
drivers/gpu/drm/i915/i915_params.h +1 -0
index 55d47ee..e0f2f7e 100644
@@ -49,6 +49,7 @@
 	func(int, use_mmio_flip); \
 	func(int, mmio_debug); \
 	func(int, edp_vswing); \
+	func(int, enable_preemption); \
 	func(unsigned int, inject_load_failure); \
 	/* leave bools at the end to not create holes */ \
 	func(bool, alpha_support); \
drivers/gpu/drm/i915/intel_ringbuffer.h +3 -0
index 0f29e07..9c7f36e 100644
@@ -312,6 +312,9 @@ struct intel_engine_cs {
 	void		(*schedule)(struct drm_i915_gem_request *request,
 				    int priority);
 
+	/* Called to attempt preemption of currently executing workload */
+	int		(*preempt)(struct intel_engine_cs *engine);
+
 	/* Some chipsets are not quite as coherent as advertised and need
 	 * an expensive kick to force a true read of the up-to-date seqno.
 	 * However, the up-to-date seqno is not always required and the last
Signature · 6 lines
2.9.3

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

RFC 3/11 drm/i915/preempt: Add information needed to track engine preempt state

In reply to Michał Winiarski

We're using engine->preempt_requested to mark that preemption has started, and new hws entry allowing HW to mark that preemption has finished and the engine is idle, allowing us to do the postprocessing.

---
 drivers/gpu/drm/i915/intel_ringbuffer.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/gpu/drm/i915/intel_ringbuffer.h +10 -0
index 9c7f36e..637a83c 100644
@@ -392,6 +392,8 @@ struct intel_engine_cs {
 	struct rb_node *execlist_first;
 	unsigned int fw_domains;
 
+	bool preempt_requested;
+
 	/* Contexts are pinned whilst they are active on the GPU. The last
 	 * context executed remains active whilst the GPU is idle - the
 	 * switch away and write to the context object only occurs on the
@@ -486,9 +488,17 @@ intel_write_status_page(struct intel_engine_cs *engine,
  */
 #define I915_GEM_HWS_INDEX		0x30
 #define I915_GEM_HWS_INDEX_ADDR (I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT)
+#define I915_GEM_HWS_PREEMPT_INDEX	0x32
+#define I915_GEM_HWS_PREEMPT_ADDR (I915_GEM_HWS_PREEMPT_INDEX << MI_STORE_DWORD_INDEX_SHIFT)
 #define I915_GEM_HWS_SCRATCH_INDEX	0x40
 #define I915_GEM_HWS_SCRATCH_ADDR (I915_GEM_HWS_SCRATCH_INDEX << MI_STORE_DWORD_INDEX_SHIFT)
 
+static inline bool
+intel_engine_is_preempt_finished(struct intel_engine_cs *engine)
+{
+	return intel_read_status_page(engine, I915_GEM_HWS_PREEMPT_INDEX);
+}
+
 struct intel_ring *
 intel_engine_create_ring(struct intel_engine_cs *engine, int size);
 int intel_ring_pin(struct intel_ring *ring, unsigned int offset_bias);
Signature · 6 lines
2.9.3

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

RFC 4/11 drm/i915/preempt: Implement null preemption method

In reply to Michał Winiarski

We're only requesting preemption for requests that have high enough priority (above threshold). Currently we're also ignoring requests that have dependencies on different engines.

---
 drivers/gpu/drm/i915/i915_guc_submission.c |  3 ++
 drivers/gpu/drm/i915/intel_lrc.c           | 81 +++++++++++++++++++++++++++++-
 2 files changed, 83 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_guc_submission.c +3 -0
index feccd65..6d9431d 100644
@@ -491,6 +491,9 @@ static int guc_ring_doorbell(struct i915_guc_client *client)
 
 static int i915_guc_preempt_noop(struct intel_engine_cs *engine)
 {
+	engine->preempt_requested = false;
+	intel_write_status_page(engine, I915_GEM_HWS_PREEMPT_INDEX, 0);
+
 	return 0;
 }
 
drivers/gpu/drm/i915/intel_lrc.c +80 -1

115 lines not on this page · raw message

Signature · 6 lines
2.9.3

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

Re: [RFC 04/11] drm/i915/preempt: Implement null preemption method

Quoted 20 lines · Michał Winiarski
drivers/gpu/drm/i915/intel_lrc.c +20 -0
+static void __execlists_try_preempt(struct intel_engine_cs *engine,
+				  int prio)
+{
+	struct drm_i915_gem_request *rq;
+	int highest_prio = INT_MIN;
+	int ret;
+
+	spin_lock_irq(&engine->timeline->lock);
+
+	/* Engine is idle */
+	if (execlists_elsp_idle(engine))
+		goto out_unlock;
+
+	if (engine->preempt_requested)
+		goto out_unlock;
+
+	list_for_each_entry_reverse(rq, &engine->timeline->requests, link) {
+		if (!i915_gem_request_completed(rq)) {
+			highest_prio = (rq->priotree.priority > highest_prio) ?
+				 rq->priotree.priority : highest_prio;

drivers/gpu/drm/i915/intel_lrc.c pt_lock_engine(struct i915_priotree *pt, struct intel_engine_cs *locked) · line 708

Quoted 10 lines
drivers/gpu/drm/i915/intel_lrc.c +10 -0
+		} else
+			break;
+	}
+
+	/* Bail out if our priority is lower than any of the inflight requests
+	 * (also if there are none requests) */
+	if (highest_prio == INT_MIN || prio <= highest_prio)
+		goto out_unlock;
+
+	engine->preempt_requested = true;

Here you are meant to unwind the already submitted requests and put them back onto their rq->timelines.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#7 lore raw

RFC 5/11 drm/i915/preempt: Handle preemption event in guc tasklet

In reply to Michał Winiarski

We need to avoid sending new work if the preemption is in progress. Once it finished, we need to identify and unsubmit the preempted workload, submit new workload (potentially the one responsible for preemption) and resubmit the preempted workload.

---
 drivers/gpu/drm/i915/i915_gem_request.h    |  2 +
 drivers/gpu/drm/i915/i915_guc_submission.c | 64 ++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+)
drivers/gpu/drm/i915/i915_gem_request.h +2 -0
index 5f73d8c..a78408dd 100644
@@ -170,6 +170,8 @@ struct drm_i915_gem_request {
 	/** Time at which this request was emitted, in jiffies. */
 	unsigned long emitted_jiffies;
 
+	struct list_head resubmit_link;
+
 	/** engine->request_list entry for this request */
 	struct list_head link;
 
drivers/gpu/drm/i915/i915_guc_submission.c +64 -0

93 lines not on this page · raw message

Signature · 6 lines
2.9.3

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

Re: [RFC 05/11] drm/i915/preempt: Handle preemption event in guc tasklet

drivers/gpu/drm/i915/i915_guc_submission.c static bool i915_guc_dequeue(struct intel_engine_cs *engine) · line 632

Quoted 13 lines · Michał Winiarski
drivers/gpu/drm/i915/i915_guc_submission.c +13 -0
+static void unsubmit_inflight_requests(struct intel_engine_cs *engine,
+					 struct list_head *resubmit)
+{
+	struct drm_i915_gem_request *rq, *prev;
+
+	assert_spin_locked(&engine->timeline->lock);
+
+	list_for_each_entry_safe_reverse(rq, prev,
+					 &engine->timeline->requests, link) {
+		if (!i915_gem_request_completed(rq)) {
+			i915_gem_request_get(rq);
+			__i915_gem_request_unsubmit(rq);
+			list_add(&rq->resubmit_link, resubmit);

I was thinking it would be going back to the execlist queue, where it would be priority sorted against later requests.

Pro/cons?
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#9 lore raw

Re: [RFC 05/11] drm/i915/preempt: Handle preemption event in guc tasklet

Quoted 17 lines · Chris Wilson

drivers/gpu/drm/i915/i915_guc_submission.c static bool i915_guc_dequeue(struct intel_engine_cs *engine) · line 632

Quoted 13 lines · Michał Winiarski
drivers/gpu/drm/i915/i915_guc_submission.c +13 -0
+static void unsubmit_inflight_requests(struct intel_engine_cs *engine,
+					 struct list_head *resubmit)
+{
+	struct drm_i915_gem_request *rq, *prev;
+
+	assert_spin_locked(&engine->timeline->lock);
+
+	list_for_each_entry_safe_reverse(rq, prev,
+					 &engine->timeline->requests, link) {
+		if (!i915_gem_request_completed(rq)) {
+			i915_gem_request_get(rq);
+			__i915_gem_request_unsubmit(rq);
+			list_add(&rq->resubmit_link, resubmit);

I was thinking it would be going back to the execlist queue, where it would be priority sorted against later requests.

Hmm. The execlists rbtree is setup to keep fifo ordering. We would end up reversing the inflight requests if we are not careful. :| -Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#10 lore raw

RFC 6/11 drm/i915/guc: Remove extra arguments from guc_client_alloc

In reply to Michał Winiarski

We're always using all engines and kernel context for guc clients, let's remove those arguments from guc_client_alloc.

---
 drivers/gpu/drm/i915/i915_guc_submission.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/i915_guc_submission.c +4 -12
index 6c64ce1..3080735 100644
@@ -838,21 +838,15 @@ static void guc_init_doorbell_hw(struct intel_guc *guc)
 /**
  * guc_client_alloc() - Allocate an i915_guc_client
  * @dev_priv:	driver private data structure
- * @engines:	The set of engines to enable for this client
  * @priority:	four levels priority _CRITICAL, _HIGH, _NORMAL and _LOW
  * 		The kernel client to replace ExecList submission is created with
  * 		NORMAL priority. Priority of a client for scheduler can be HIGH,
  * 		while a preemption context can use CRITICAL.
- * @ctx:	the context that owns the client (we use the default render
- * 		context)
- *
  * Return:	An i915_guc_client object if success, else NULL.
  */
 static struct i915_guc_client *
 guc_client_alloc(struct drm_i915_private *dev_priv,
-		 uint32_t engines,
-		 uint32_t priority,
-		 struct i915_gem_context *ctx)
+		 uint32_t priority)
 {
 	struct i915_guc_client *client;
 	struct intel_guc *guc = &dev_priv->guc;
@@ -864,9 +858,9 @@ guc_client_alloc(struct drm_i915_private *dev_priv,
 	if (!client)
 		return NULL;
 
-	client->owner = ctx;
+	client->owner = dev_priv->kernel_context;
 	client->guc = guc;
-	client->engines = engines;
+	client->engines = INTEL_INFO(dev_priv)->ring_mask;
 	client->priority = priority;
 	client->doorbell_id = GUC_INVALID_DOORBELL_ID;
 
@@ -1062,9 +1056,7 @@ int i915_guc_submission_init(struct drm_i915_private *dev_priv)
 	guc_addon_create(guc);
 
 	guc->execbuf_client = guc_client_alloc(dev_priv,
-					       INTEL_INFO(dev_priv)->ring_mask,
-					       GUC_CTX_PRIORITY_KMD_NORMAL,
-					       dev_priv->kernel_context);
+					       GUC_CTX_PRIORITY_KMD_NORMAL);
 	if (!guc->execbuf_client) {
 		DRM_ERROR("Failed to create GuC client for execbuf!\n");
 		goto err;
Signature · 6 lines
2.9.3

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

Re: [RFC 06/11] drm/i915/guc: Remove extra arguments from guc_client_alloc

Quoted 2 lines · Michał Winiarski

We're always using all engines and kernel context for guc clients, let's remove those arguments from guc_client_alloc.

I am quite new to the GuC but, by the look of it, passing the ctx was groundwork for direct submission (which means calling guc_client_alloc with contexts different than kernel_context). Why not leave it there, since someone was careful to lay the groundwork? I don't see an obvious use for the engines, though (clients that only have access to some of the engines?).

Quoted 45 lines
---
  drivers/gpu/drm/i915/i915_guc_submission.c | 16 ++++------------
  1 file changed, 4 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/i915_guc_submission.c +3 -9
index 6c64ce1..3080735 100644
@@ -838,21 +838,15 @@ static void guc_init_doorbell_hw(struct intel_guc *guc)
  /**
   * guc_client_alloc() - Allocate an i915_guc_client
   * @dev_priv:	driver private data structure
- * @engines:	The set of engines to enable for this client
   * @priority:	four levels priority _CRITICAL, _HIGH, _NORMAL and _LOW
   * 		The kernel client to replace ExecList submission is created with
   * 		NORMAL priority. Priority of a client for scheduler can be HIGH,
   * 		while a preemption context can use CRITICAL.
- * @ctx:	the context that owns the client (we use the default render
- * 		context)
- *
   * Return:	An i915_guc_client object if success, else NULL.
   */
  static struct i915_guc_client *
  guc_client_alloc(struct drm_i915_private *dev_priv,
-		 uint32_t engines,
-		 uint32_t priority,
-		 struct i915_gem_context *ctx)
+		 uint32_t priority)
  {
  	struct i915_guc_client *client;
  	struct intel_guc *guc = &dev_priv->guc;
@@ -864,9 +858,9 @@ guc_client_alloc(struct drm_i915_private *dev_priv,
  	if (!client)
  		return NULL;
 
-	client->owner = ctx;
+	client->owner = dev_priv->kernel_context;
  	client->guc = guc;
-	client->engines = engines;
+	client->engines = INTEL_INFO(dev_priv)->ring_mask;
  	client->priority = priority;
  	client->doorbell_id = GUC_INVALID_DOORBELL_ID;
 

drivers/gpu/drm/i915/i915_guc_submission.c int i915_guc_submission_init(struct drm_i915_private *dev_priv) · line 1062

Quoted 10 lines
drivers/gpu/drm/i915/i915_guc_submission.c +1 -3
@@ -1062,9 +1056,7 @@ int i915_guc_submission_init(struct drm_i915_private *dev_priv)
  	guc_addon_create(guc);
 
  	guc->execbuf_client = guc_client_alloc(dev_priv,
-					       INTEL_INFO(dev_priv)->ring_mask,
-					       GUC_CTX_PRIORITY_KMD_NORMAL,
-					       dev_priv->kernel_context);
+					       GUC_CTX_PRIORITY_KMD_NORMAL);
  	if (!guc->execbuf_client) {
  		DRM_ERROR("Failed to create GuC client for execbuf!\n");
  		goto err;

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

#12 lore raw

Re: [RFC 06/11] drm/i915/guc: Remove extra arguments from guc_client_alloc

Quoted 12 lines · Oscar Mateo
Quoted 2 lines · Michał Winiarski

We're always using all engines and kernel context for guc clients, let's remove those arguments from guc_client_alloc.

I am quite new to the GuC but, by the look of it, passing the ctx was groundwork for direct submission (which means calling guc_client_alloc with contexts different than kernel_context). Why not leave it there, since someone was careful to lay the groundwork? I don't see an obvious use for the engines, though (clients that only have access to some of the engines?).

If I recall correctly the idea behind having the engine flag was for possibly having dedicated clients for single engines and/or engines groups if 1 work-queue + doorbell pair turned out to not be enough for our needs. There might also be some little performance benefit in that scenario because we can update different work-queues in parallel, but we're still capped by how fast GuC can process them. Not sure if it still makes sense though.

Daniele

Quoted 55 lines
Quoted 55 lines
---
  drivers/gpu/drm/i915/i915_guc_submission.c | 16 ++++------------
  1 file changed, 4 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/i915_guc_submission.c +0 -1
index 6c64ce1..3080735 100644
@@ -838,21 +838,15 @@ static void guc_init_doorbell_hw(struct
 intel_guc *guc)
  /**
   * guc_client_alloc() - Allocate an i915_guc_client
   * @dev_priv:    driver private data structure
- * @engines:    The set of engines to enable for this client
   * @priority:    four levels priority _CRITICAL, _HIGH, _NORMAL and

_LOW
* The kernel client to replace ExecList submission is
created with
* NORMAL priority. Priority of a client for scheduler can
be HIGH,
* while a preemption context can use CRITICAL.
- * @ctx: the context that owns the client (we use the default render
- * context)
- *
* Return: An i915_guc_client object if success, else NULL.
*/
static struct i915_guc_client * guc_client_alloc(struct drm_i915_private *dev_priv,

drivers/gpu/drm/i915/i915_guc_submission.c +3 -4
-         uint32_t engines,
-         uint32_t priority,
-         struct i915_gem_context *ctx)
+         uint32_t priority)
  {
      struct i915_guc_client *client;
      struct intel_guc *guc = &dev_priv->guc;
@@ -864,9 +858,9 @@ guc_client_alloc(struct drm_i915_private *dev_priv,
      if (!client)
          return NULL;
  -    client->owner = ctx;
+    client->owner = dev_priv->kernel_context;
      client->guc = guc;
-    client->engines = engines;
+    client->engines = INTEL_INFO(dev_priv)->ring_mask;
      client->priority = priority;
      client->doorbell_id = GUC_INVALID_DOORBELL_ID;
  @@ -1062,9 +1056,7 @@ int i915_guc_submission_init(struct

drm_i915_private *dev_priv)

      guc_addon_create(guc);
        guc->execbuf_client = guc_client_alloc(dev_priv,
drivers/gpu/drm/i915/i915_guc_submission.c +1 -3
-                           INTEL_INFO(dev_priv)->ring_mask,
-                           GUC_CTX_PRIORITY_KMD_NORMAL,
-                           dev_priv->kernel_context);
+                           GUC_CTX_PRIORITY_KMD_NORMAL);
Quoted 8 lines
Quoted 3 lines
      if (!guc->execbuf_client) {
          DRM_ERROR("Failed to create GuC client for execbuf!\n");
          goto err;

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

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

#13 lore raw

RFC 7/11 drm/i915/guc: Add a second client, to be used for preemption

In reply to Michał Winiarski

From: Dave Gordon <[email protected]>

This second client is created with priority KMD_HIGH, and marked as preemptive.

v2: Rebase, cleanup, use an array for the second client.

---
 drivers/gpu/drm/i915/i915_debugfs.c        |  8 +--
 drivers/gpu/drm/i915/i915_guc_submission.c | 86 ++++++++++++++++++++----------
 drivers/gpu/drm/i915/intel_uc.h            |  9 +++-
 3 files changed, 71 insertions(+), 32 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +5 -3
index 1a28b52..10490bf 100644
@@ -2514,7 +2514,7 @@ static int i915_guc_info(struct seq_file *m, void *data)
 	enum intel_engine_id id;
 	u64 total;
 
-	if (!guc->execbuf_client) {
+	if (!guc->client[NORMAL]) {
 		seq_printf(m, "GuC submission %s\n",
 			   HAS_GUC_SCHED(dev_priv) ?
 			   "disabled" :
@@ -2542,8 +2542,10 @@ static int i915_guc_info(struct seq_file *m, void *data)
 	}
 	seq_printf(m, "\t%s: %llu\n", "Total", total);
 
-	seq_printf(m, "\nGuC execbuf client @ %p:\n", guc->execbuf_client);
-	i915_guc_client_info(m, dev_priv, guc->execbuf_client);
+	seq_printf(m, "\nGuC execbuf client @ %p:\n", guc->client[NORMAL]);
+	i915_guc_client_info(m, dev_priv, guc->client[NORMAL]);
+	seq_printf(m, "\nGuC preempt client @ %p:\n", guc->client[PREEMPT]);
+	i915_guc_client_info(m, dev_priv, guc->client[PREEMPT]);
 
 	i915_guc_log_info(m, dev_priv);
 
drivers/gpu/drm/i915/i915_guc_submission.c +58 -28

180 lines not on this page · raw message

drivers/gpu/drm/i915/intel_uc.h +8 -1
index d74f4d3..9dcd8fa 100644
@@ -146,6 +146,13 @@ struct intel_guc_log {
 	u32 flush_count[GUC_MAX_LOG_BUFFER];
 };
 
+#define I915_GUC_NUM_CLIENTS 2
+
+enum i915_guc_client_id {
+        NORMAL = 0,
+        PREEMPT
+};
+
 struct intel_guc {
 	struct intel_uc_fw fw;
 	struct intel_guc_log log;
@@ -157,7 +164,7 @@ struct intel_guc {
 	struct i915_vma *ctx_pool_vma;
 	struct ida ctx_ids;
 
-	struct i915_guc_client *execbuf_client;
+	struct i915_guc_client *client[I915_GUC_NUM_CLIENTS];
 
 	DECLARE_BITMAP(doorbell_bitmap, GUC_MAX_DOORBELLS);
 	uint32_t db_cacheline;		/* Cyclic counter mod pagesize	*/
Signature · 6 lines
2.9.3

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

RFC 8/11 drm/i915/guc: Add preemption action to GuC firmware interface

In reply to Michał Winiarski
---
 drivers/gpu/drm/i915/intel_guc_fwif.h | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/i915/intel_guc_fwif.h +7 -0
index 25691f0..5b79ce0 100644
@@ -497,6 +497,7 @@ union guc_log_control {
 /* This Action will be programmed in C180 - SOFT_SCRATCH_O_REG */
 enum intel_guc_action {
 	INTEL_GUC_ACTION_DEFAULT = 0x0,
+	INTEL_GUC_ACTION_REQUEST_PREEMPTION = 0x2,
 	INTEL_GUC_ACTION_SAMPLE_FORCEWAKE = 0x6,
 	INTEL_GUC_ACTION_ALLOCATE_DOORBELL = 0x10,
 	INTEL_GUC_ACTION_DEALLOCATE_DOORBELL = 0x20,
@@ -510,6 +511,12 @@ enum intel_guc_action {
 	INTEL_GUC_ACTION_LIMIT
 };
 
+enum intel_guc_preempt_options {
+	INTEL_GUC_PREEMPT_OPTION_IMMEDIATE = 0x1,
+	INTEL_GUC_PREEMPT_OPTION_DROP_WORK_Q = 0x4,
+	INTEL_GUC_PREEMPT_OPTION_DROP_SUBMIT_Q = 0x8,
+};
+
 /*
  * The GuC sends its response to a command by overwriting the
  * command in SS0. The response is distinguishable from a command
Signature · 6 lines
2.9.3

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

RFC 9/11 HACK drm/i915/preempt: Actually send the preemption request

In reply to Michał Winiarski

Now that we're able to post-process the preemption event, let's actually send it to GuC. To identify that preemption has finished, we're using a dummy request sent through kernel_context.

---
 drivers/gpu/drm/i915/i915_guc_submission.c | 90 ++++++++++++++++++++++++++++--
 1 file changed, 86 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/i915_guc_submission.c +86 -4
index 2a658b9..7ccc5b4 100644
@@ -491,14 +491,96 @@ static int guc_ring_doorbell(struct i915_guc_client *client)
 	return ret;
 }
 
-static int i915_guc_preempt_noop(struct intel_engine_cs *engine)
+static int add_preemption_workitem(struct intel_engine_cs *engine)
 {
-	engine->preempt_requested = false;
-	intel_write_status_page(engine, I915_GEM_HWS_PREEMPT_INDEX, 0);
+	struct drm_i915_private *dev_priv = engine->i915;
+	struct intel_guc *guc = &engine->i915->guc;
+	struct i915_gem_context *ctx = engine->i915->kernel_context;
+	struct i915_guc_client *client = guc->client[PREEMPT];
+	struct drm_i915_gem_request rq;
+	u32 *cs;
+
+	rq.i915 = engine->i915;
+	rq.engine = engine;
+	rq.ctx = ctx;
+	rq.global_seqno = 0;
+	rq.file_priv = NULL;
+	rq.batch = NULL;
+	rq.reserved_space = 32;
+	rq.ring = ctx->engine[engine->id].ring;
+
+	if (engine->id == RCS) {
+		cs = intel_ring_begin(&rq, 8);
+		if (IS_ERR(cs))
+			return PTR_ERR(cs);
+
+		*cs++ = GFX_OP_PIPE_CONTROL(6);
+		*cs++ = PIPE_CONTROL_GLOBAL_GTT_IVB |
+			PIPE_CONTROL_CS_STALL |
+			PIPE_CONTROL_QW_WRITE;
+		*cs++ = engine->status_page.ggtt_offset +
+			I915_GEM_HWS_PREEMPT_ADDR;
+		*cs++ = 0;
+		*cs++ = 1;
+		*cs++ = 0;
+		*cs++ = MI_USER_INTERRUPT;
+		*cs++ = MI_NOOP;
+		intel_ring_advance(&rq, cs);
+	} else {
+		cs = intel_ring_begin(&rq, 6);
+		if (IS_ERR(cs))
+			return PTR_ERR(cs);
+
+		*cs++ = (MI_FLUSH_DW + 1) | MI_FLUSH_DW_OP_STOREDW;
+		*cs++ = (engine->status_page.ggtt_offset + I915_GEM_HWS_PREEMPT_ADDR) |
+		        MI_FLUSH_DW_USE_GTT;
+		*cs++ = 0;
+		*cs++ = 1;
+		*cs++ = MI_USER_INTERRUPT;
+		*cs++ = MI_NOOP;
+		intel_ring_advance(&rq, cs);
+	}
+	rq.tail = intel_ring_offset(&rq, cs);
+
+	spin_lock_irq(&client->wq_lock);
+	client->wq_rsvd += sizeof(struct guc_wq_item);
+	guc_wq_item_append(client, &rq);
+	if (i915_vma_is_map_and_fenceable(rq.ring->vma))
+		POSTING_READ_FW(GUC_STATUS);
+	spin_unlock_irq(&client->wq_lock);
 
 	return 0;
 }
 
+static int i915_guc_preempt(struct intel_engine_cs *engine)
+{
+	struct intel_guc *guc = &engine->i915->guc;
+	struct i915_guc_client *client = guc->client[PREEMPT];
+	struct guc_process_desc *desc;
+	u32 data[7];
+	int ret;
+
+	ret = add_preemption_workitem(engine);
+	if (ret)
+		return ret;
+
+	desc = client->vaddr + client->proc_desc_offset;
+	desc->tail = client->wq_tail;
+
+	data[0] = INTEL_GUC_ACTION_REQUEST_PREEMPTION;
+	data[1] = client->ctx_index;
+	data[2] = INTEL_GUC_PREEMPT_OPTION_IMMEDIATE |
+		  INTEL_GUC_PREEMPT_OPTION_DROP_WORK_Q |
+		  INTEL_GUC_PREEMPT_OPTION_DROP_SUBMIT_Q;
+	data[3] = engine->guc_id;
+	data[4] = guc->client[NORMAL]->priority;
+	data[5] = guc->client[NORMAL]->ctx_index;
+	data[6] = engine->status_page.ggtt_offset +
+		  (LRC_GUCSHR_PN * PAGE_SIZE);
+
+	return intel_guc_send(guc, data, ARRAY_SIZE(data));
+}
+
 /**
  * __i915_guc_submit() - Submit commands through GuC
  * @rq:		request associated with the commands
@@ -1143,7 +1225,7 @@ int i915_guc_submission_enable(struct drm_i915_private *dev_priv)
 		engine->irq_tasklet.func = i915_guc_irq_handler;
 
 		if (i915.enable_preemption)
-			engine->preempt = i915_guc_preempt_noop;
+			engine->preempt = i915_guc_preempt;
 
 		/* Replay the current set of previously submitted requests */
 		spin_lock_irqsave(&engine->timeline->lock, flags);
Signature · 6 lines
2.9.3

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

RFC 10/11 drm/i915/preempt: Emit MI_ARB_CHECK before the start of user batch

In reply to Michał Winiarski

We should probably do this conditionally, based on whether preemption is actually enabled.

---
 drivers/gpu/drm/i915/intel_lrc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_lrc.c +4 -1
index 869b96e..972f9bd 100644
@@ -1418,10 +1418,13 @@ static int gen8_emit_bb_start(struct drm_i915_gem_request *req,
 		req->ctx->ppgtt->pd_dirty_rings &= ~intel_engine_flag(req->engine);
 	}
 
-	cs = intel_ring_begin(req, 4);
+	cs = intel_ring_begin(req, 6);
 	if (IS_ERR(cs))
 		return PTR_ERR(cs);
 
+	*cs++ = MI_ARB_CHECK;
+	*cs++ = MI_NOOP;
+
 	/* FIXME(BDW): Address space and security selectors. */
 	*cs++ = MI_BATCH_BUFFER_START_GEN8 | (ppgtt << 8) | (dispatch_flags &
 		I915_DISPATCH_RS ? MI_BATCH_RESOURCE_STREAMER : 0);
Signature · 6 lines
2.9.3

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

Re: [RFC 10/11] drm/i915/preempt: Emit MI_ARB_CHECK before the start of user batch

Quoted 17 lines · Michał Winiarski

We should probably do this conditionally, based on whether preemption is actually enabled.

---
 drivers/gpu/drm/i915/intel_lrc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_lrc.c +0 -1
index 869b96e..972f9bd 100644
@@ -1418,10 +1418,13 @@ static int gen8_emit_bb_start(struct drm_i915_gem_request *req,
 		req->ctx->ppgtt->pd_dirty_rings &= ~intel_engine_flag(req->engine);
 	}
 
-	cs = intel_ring_begin(req, 4);

drivers/gpu/drm/i915/intel_lrc.c static int gen8_emit_bb_start(struct drm_i915_gem_request *req, · line 1430

Quoted 10 lines
drivers/gpu/drm/i915/intel_lrc.c +4 -0
+	cs = intel_ring_begin(req, 6);
 	if (IS_ERR(cs))
 		return PTR_ERR(cs);
 
+	*cs++ = MI_ARB_CHECK;
+	*cs++ = MI_NOOP;
+
 	/* FIXME(BDW): Address space and security selectors. */
 	*cs++ = MI_BATCH_BUFFER_START_GEN8 | (ppgtt << 8) | (dispatch_flags &
 		I915_DISPATCH_RS ? MI_BATCH_RESOURCE_STREAMER : 0);

Shouldn't we only enable arbitration across the batch, i.e. add the disable here? The flush and breadcrumb are not worth interrupting and saves us some work if they are not.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#18 lore raw

RFC 11/11 drm/i915/preempt: Show engine preempt state in engine_info debugfs

In reply to Michał Winiarski
---
 drivers/gpu/drm/i915/i915_debugfs.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/i915/i915_debugfs.c +4 -0
index 10490bf..b71420c 100644
@@ -3268,6 +3268,10 @@ static int i915_engine_info(struct seq_file *m, void *unused)
 			   engine->hangcheck.seqno,
 			   jiffies_to_msecs(jiffies - engine->hangcheck.action_timestamp));
 
+		seq_printf(m, "\tpreempt [requested %d, finished %d]\n",
+			   engine->preempt_requested,
+			   intel_engine_is_preempt_finished(engine));
+
 		rcu_read_lock();
 
 		seq_printf(m, "\tRequests:\n");
Signature · 6 lines
2.9.3

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