drm/xe/hw_engine_group: Add helper to suspend faulting LR jobs
authorFrancois Dugast <francois.dugast@intel.com>
Fri, 9 Aug 2024 15:51:29 +0000 (17:51 +0200)
committerMatthew Brost <matthew.brost@intel.com>
Sun, 18 Aug 2024 01:31:52 +0000 (18:31 -0700)
This is a required feature for dma fence jobs to preempt faulting long
running jobs in order to ensure mutual exclusion on a given hw engine
group.

v2: Pipeline calls to suspend(q) and suspend_wait(q) to improve
    efficiency, switch to lockdep_assert_held_write (Matt Brost)

v3: Return error on suspend_wait failure to propagate on the call stack
    up to IOCTL (Matt Brost)

Signed-off-by: Francois Dugast <francois.dugast@intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240809155156.1955925-5-francois.dugast@intel.com
drivers/gpu/drm/xe/xe_hw_engine_group.c

index b362af7ffab52419b01215ab25e0b35461da1ef0..8659332012ddf0b0fec20799620ba20111876f3b 100644 (file)
@@ -166,3 +166,39 @@ void xe_hw_engine_group_del_exec_queue(struct xe_hw_engine_group *group, struct
 
        up_write(&group->mode_sem);
 }
+
+/**
+ * xe_hw_engine_group_suspend_faulting_lr_jobs() - Suspend the faulting LR jobs of this group
+ * @group: The hw engine group
+ *
+ * Return: 0 on success, negative error code on error.
+ */
+static int xe_hw_engine_group_suspend_faulting_lr_jobs(struct xe_hw_engine_group *group)
+{
+       int err;
+       struct xe_exec_queue *q;
+
+       lockdep_assert_held_write(&group->mode_sem);
+
+       list_for_each_entry(q, &group->exec_queue_list, hw_engine_group_link) {
+               if (!xe_vm_in_fault_mode(q->vm))
+                       continue;
+
+               q->ops->suspend(q);
+       }
+
+       list_for_each_entry(q, &group->exec_queue_list, hw_engine_group_link) {
+               if (!xe_vm_in_fault_mode(q->vm))
+                       continue;
+
+               err = q->ops->suspend_wait(q);
+               if (err)
+                       goto err_suspend;
+       }
+
+       return 0;
+
+err_suspend:
+       up_write(&group->mode_sem);
+       return err;
+}