]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/xe: Use usleep_range for accurate long-running workload timeslicing
authorMatthew Brost <matthew.brost@intel.com>
Fri, 12 Dec 2025 18:28:42 +0000 (10:28 -0800)
committerThomas Hellström <thomas.hellstrom@linux.intel.com>
Thu, 18 Dec 2025 17:25:42 +0000 (18:25 +0100)
msleep is not very accurate in terms of how long it actually sleeps,
whereas usleep_range is precise. Replace the timeslice sleep for
long-running workloads with the more accurate usleep_range to avoid
jitter if the sleep period is less than 20ms.

Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
Cc: stable@vger.kernel.org
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Link: https://patch.msgid.link/20251212182847.1683222-3-matthew.brost@intel.com
(cherry picked from commit ca415c4d4c17ad676a2c8981e1fcc432221dce79)
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
drivers/gpu/drm/xe/xe_guc_submit.c

index 311cd047911a4494dfb310572310825f31e7ff81..f6ba2b0f074d23062bf22d4e0b856a13047640e8 100644 (file)
@@ -717,6 +717,24 @@ static bool vf_recovery(struct xe_guc *guc)
        return xe_gt_recovery_pending(guc_to_gt(guc));
 }
 
+static inline void relaxed_ms_sleep(unsigned int delay_ms)
+{
+       unsigned long min_us, max_us;
+
+       if (!delay_ms)
+               return;
+
+       if (delay_ms > 20) {
+               msleep(delay_ms);
+               return;
+       }
+
+       min_us = mul_u32_u32(delay_ms, 1000);
+       max_us = min_us + 500;
+
+       usleep_range(min_us, max_us);
+}
+
 static int wq_wait_for_space(struct xe_exec_queue *q, u32 wqi_size)
 {
        struct xe_guc *guc = exec_queue_to_guc(q);
@@ -1587,7 +1605,7 @@ static void __guc_exec_queue_process_msg_suspend(struct xe_sched_msg *msg)
                                since_resume_ms;
 
                        if (wait_ms > 0 && q->guc->resume_time)
-                               msleep(wait_ms);
+                               relaxed_ms_sleep(wait_ms);
 
                        set_exec_queue_suspended(q);
                        disable_scheduling(q, false);