Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Tomasz Lis <tomasz.lis@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: "Michał Winiarski" <michal.winiarski@intel.com>,
	"Piotr Piórkowski" <piotr.piorkowski@intel.com>,
	"Satyanarayana K V P" <satyanarayana.k.v.p@intel.com>,
	"Adam Miszczak" <adam.miszczak@linux.intel.com>
Subject: [PATCH v1] drm/xe: Delay preempt fence retries during VF migration recovery
Date: Tue,  1 Dec 2026 17:33:29 +0100	[thread overview]
Message-ID: <20261201163329.2766164-1-tomasz.lis@intel.com> (raw)

While VF post-migration recovery is pending, the queue suspend wait in
guc_exec_queue_wait_suspend_done() returns -EAGAIN immediately.
preempt_fence_work_func() then requeues itself on the ordered preempt
fence workqueue with no delay, so it spins for the whole recovery.

This keeps a worker busy at 100% for the duration of the recovery.
On a VM with few vCPUs, this competes with the recovery worker for
CPU and makes the recovery take several times longer than it should.

Make the preempt fence work a delayed work and requeue it with a 100 ms
delay on -EAGAIN. The first run is still queued with no delay, so the
normal preemption path is unchanged.

The 100 ms is enough to perform recovery in typical operation, that is
other than stress testing. During stress tests with many active exec
queues, the recovery can take longer - however, even then, repeating
the immediately exiting worker few times should not have measurable
influence on the migration recovery duration.

Signed-off-by: Tomasz Lis <tomasz.lis@intel.com>
Tested-by: Adam Miszczak <adam.miszczak@linux.intel.com>
---
 drivers/gpu/drm/xe/xe_preempt_fence.c       | 19 ++++++++++++++-----
 drivers/gpu/drm/xe/xe_preempt_fence_types.h |  4 ++--
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_preempt_fence.c b/drivers/gpu/drm/xe/xe_preempt_fence.c
index 343f1ba1e1cd..16d5875e7a5b 100644
--- a/drivers/gpu/drm/xe/xe_preempt_fence.c
+++ b/drivers/gpu/drm/xe/xe_preempt_fence.c
@@ -12,11 +12,14 @@
 #include "xe_guc_exec_queue_types.h"
 #include "xe_vm.h"
 
+/* Delay between retries while the suspend wait can't complete (VF recovery) */
+#define PREEMPT_FENCE_RETRY_DELAY_MS	100
+
 static void preempt_fence_work_func(struct work_struct *w)
 {
 	bool cookie = dma_fence_begin_signalling();
 	struct xe_preempt_fence *pfence =
-		container_of(w, typeof(*pfence), preempt_work);
+		container_of(to_delayed_work(w), typeof(*pfence), preempt_work);
 	struct xe_exec_queue *q = pfence->q;
 
 	if (pfence->error) {
@@ -27,8 +30,14 @@ static void preempt_fence_work_func(struct work_struct *w)
 		if (err == -EAGAIN) {
 			xe_gt_dbg(q->gt, "PREEMPT FENCE RETRY guc_id=%d",
 				  q->guc->id);
-			queue_work(q->vm->xe->preempt_fence_wq,
-				   &pfence->preempt_work);
+			/*
+			 * Don't retry back to back: we get EAGAIN immediately
+			 * while VF recovery is pending, so an immediate requeue
+			 * would spin the ordered wq and could starve the recovery.
+			 */
+			queue_delayed_work(q->vm->xe->preempt_fence_wq,
+					   &pfence->preempt_work,
+					   msecs_to_jiffies(PREEMPT_FENCE_RETRY_DELAY_MS));
 			dma_fence_end_signalling(cookie);
 			return;
 		}
@@ -81,7 +90,7 @@ static bool preempt_fence_enable_signaling(struct dma_fence *fence)
 	 */
 	if (!pfence->error)
 		WRITE_ONCE(q->lr.suspended, true);
-	queue_work(q->vm->xe->preempt_fence_wq, &pfence->preempt_work);
+	queue_delayed_work(q->vm->xe->preempt_fence_wq, &pfence->preempt_work, 0);
 	return true;
 }
 
@@ -113,7 +122,7 @@ struct xe_preempt_fence *xe_preempt_fence_alloc(void)
 		return ERR_PTR(-ENOMEM);
 
 	INIT_LIST_HEAD(&pfence->link);
-	INIT_WORK(&pfence->preempt_work, preempt_fence_work_func);
+	INIT_DELAYED_WORK(&pfence->preempt_work, preempt_fence_work_func);
 
 	return pfence;
 }
diff --git a/drivers/gpu/drm/xe/xe_preempt_fence_types.h b/drivers/gpu/drm/xe/xe_preempt_fence_types.h
index ac125c697a41..fb24dc39720a 100644
--- a/drivers/gpu/drm/xe/xe_preempt_fence_types.h
+++ b/drivers/gpu/drm/xe/xe_preempt_fence_types.h
@@ -23,8 +23,8 @@ struct xe_preempt_fence {
 	struct list_head link;
 	/** @q: exec queue for this preempt fence */
 	struct xe_exec_queue *q;
-	/** @preempt_work: work struct which issues preemption */
-	struct work_struct preempt_work;
+	/** @preempt_work: work which issues preemption, delayed on retry */
+	struct delayed_work preempt_work;
 	/** @lock: dma-fence fence lock */
 	spinlock_t lock;
 	/** @error: preempt fence is in error state */
-- 
2.43.0


             reply	other threads:[~2026-12-01 16:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 16:33 Tomasz Lis [this message]
2026-12-01 16:39 ` [PATCH v1] drm/xe: Delay preempt fence retries during VF migration recovery sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201163329.2766164-1-tomasz.lis@intel.com \
    --to=tomasz.lis@intel.com \
    --cc=adam.miszczak@linux.intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=michal.winiarski@intel.com \
    --cc=piotr.piorkowski@intel.com \
    --cc=satyanarayana.k.v.p@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox