Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] drm/xe: Delay preempt fence retries during VF migration recovery
@ 2026-12-01 16:33 Tomasz Lis
  2026-12-01 16:39 ` sashiko-bot
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Tomasz Lis @ 2026-12-01 16:33 UTC (permalink / raw)
  To: intel-xe
  Cc: Michał Winiarski, Piotr Piórkowski, Satyanarayana K V P,
	Adam Miszczak

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-01 18:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 16:33 [PATCH v1] drm/xe: Delay preempt fence retries during VF migration recovery Tomasz Lis
2026-12-01 16:39 ` sashiko-bot
2026-12-01 17:05 ` Matthew Brost
2026-12-01 17:30 ` ✓ CI.KUnit: success for " Patchwork
2026-12-01 18:06 ` ✓ Xe.CI.BAT: " Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox