]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
'drm/xe/hw_engine_group: Register hw engine group's exec queues
authorFrancois Dugast <francois.dugast@intel.com>
Fri, 9 Aug 2024 15:51:28 +0000 (17:51 +0200)
committerMatthew Brost <matthew.brost@intel.com>
Sun, 18 Aug 2024 01:31:51 +0000 (18:31 -0700)
Add helpers to safely add and delete the exec queues attached to a hw
engine group, and make use them at the time of creation and destruction of
the exec queues. Keeping track of them is required to control the
execution mode of the hw engine group.

v2: Improve error handling and robustness, suspend exec queues created in
    fault mode if group in dma-fence mode, init queue link (Matt Brost)

v3: Delete queue from hw engine group when it is destroyed by the user,
    also clean up at the time of closing the file in case the user did
    not destroy the queue

v4: Use correct list when checking if empty, do not add the queue if VM
    is in xe_vm_in_preempt_fence_mode (Matt Brost)

v5: Remove unrelated newline, add checks and asserts for group, unwind on
    suspend failure (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-4-francois.dugast@intel.com
drivers/gpu/drm/xe/xe_device.c
drivers/gpu/drm/xe/xe_exec_queue.c
drivers/gpu/drm/xe/xe_exec_queue_types.h
drivers/gpu/drm/xe/xe_hw_engine_group.c
drivers/gpu/drm/xe/xe_hw_engine_group.h

index 2063283871503ed9fc71e6f30ed7f039179ddf40..b6db7e082d887a7b88983c68a7f2cec83feafd7d 100644 (file)
@@ -37,6 +37,7 @@
 #include "xe_gt_printk.h"
 #include "xe_gt_sriov_vf.h"
 #include "xe_guc.h"
+#include "xe_hw_engine_group.h"
 #include "xe_hwmon.h"
 #include "xe_irq.h"
 #include "xe_memirq.h"
@@ -165,6 +166,8 @@ static void xe_file_close(struct drm_device *dev, struct drm_file *file)
         * vm->lock taken during xe_exec_queue_kill().
         */
        xa_for_each(&xef->exec_queue.xa, idx, q) {
+               if (q->vm && q->hwe->hw_engine_group)
+                       xe_hw_engine_group_del_exec_queue(q->hwe->hw_engine_group, q);
                xe_exec_queue_kill(q);
                xe_exec_queue_put(q);
        }
index 7f0b33098182be81b047ee9d4359b0d2bff465b5..ebc80add10aca4b4ebad00431ba5b15a4acd0cc0 100644 (file)
@@ -14,6 +14,7 @@
 #include "xe_device.h"
 #include "xe_gt.h"
 #include "xe_hw_engine_class_sysfs.h"
+#include "xe_hw_engine_group.h"
 #include "xe_hw_fence.h"
 #include "xe_lrc.h"
 #include "xe_macros.h"
@@ -73,6 +74,7 @@ static struct xe_exec_queue *__xe_exec_queue_alloc(struct xe_device *xe,
        q->ops = gt->exec_queue_ops;
        INIT_LIST_HEAD(&q->lr.link);
        INIT_LIST_HEAD(&q->multi_gt_link);
+       INIT_LIST_HEAD(&q->hw_engine_group_link);
 
        q->sched_props.timeslice_us = hwe->eclass->sched_props.timeslice_us;
        q->sched_props.preempt_timeout_us =
@@ -624,6 +626,12 @@ int xe_exec_queue_create_ioctl(struct drm_device *dev, void *data,
                        if (XE_IOCTL_DBG(xe, err))
                                goto put_exec_queue;
                }
+
+               if (q->vm && q->hwe->hw_engine_group) {
+                       err = xe_hw_engine_group_add_exec_queue(q->hwe->hw_engine_group, q);
+                       if (err)
+                               goto put_exec_queue;
+               }
        }
 
        mutex_lock(&xef->exec_queue.lock);
@@ -815,6 +823,9 @@ int xe_exec_queue_destroy_ioctl(struct drm_device *dev, void *data,
        if (XE_IOCTL_DBG(xe, !q))
                return -ENOENT;
 
+       if (q->vm && q->hwe->hw_engine_group)
+               xe_hw_engine_group_del_exec_queue(q->hwe->hw_engine_group, q);
+
        xe_exec_queue_kill(q);
 
        trace_xe_exec_queue_close(q);
index 1408b02eea53546355684eec6d9b9491ccf01dae..315f874426bdfbc9d260d947d5b06a95a9a5a057 100644 (file)
@@ -142,6 +142,8 @@ struct xe_exec_queue {
         * Protected by @vm's resv. Unused if @vm == NULL.
         */
        u64 tlb_flush_seqno;
+       /** @hw_engine_group_link: link into exec queues in the same hw engine group */
+       struct list_head hw_engine_group_link;
        /** @lrc: logical ring context for this exec queue */
        struct xe_lrc *lrc[];
 };
index 1d109c08c7a6b8c110efac2c3cc957aed8856261..b362af7ffab52419b01215ab25e0b35461da1ef0 100644 (file)
@@ -5,9 +5,12 @@
 
 #include <drm/drm_managed.h>
 
+#include "xe_assert.h"
 #include "xe_device.h"
+#include "xe_exec_queue.h"
 #include "xe_gt.h"
 #include "xe_hw_engine_group.h"
+#include "xe_vm.h"
 
 static void
 hw_engine_group_free(struct drm_device *drm, void *arg)
@@ -100,3 +103,66 @@ err_group_rcs_ccs:
 
        return err;
 }
+
+/**
+ * xe_hw_engine_group_add_exec_queue() - Add an exec queue to a hw engine group
+ * @group: The hw engine group
+ * @q: The exec_queue
+ *
+ * Return: 0 on success,
+ *         -EINTR if the lock could not be acquired
+ */
+int xe_hw_engine_group_add_exec_queue(struct xe_hw_engine_group *group, struct xe_exec_queue *q)
+{
+       int err;
+       struct xe_device *xe = gt_to_xe(q->gt);
+
+       xe_assert(xe, group);
+       xe_assert(xe, !(q->flags & EXEC_QUEUE_FLAG_VM));
+       xe_assert(xe, q->vm);
+
+       if (xe_vm_in_preempt_fence_mode(q->vm))
+               return 0;
+
+       err = down_write_killable(&group->mode_sem);
+       if (err)
+               return err;
+
+       if (xe_vm_in_fault_mode(q->vm) && group->cur_mode == EXEC_MODE_DMA_FENCE) {
+               q->ops->suspend(q);
+               err = q->ops->suspend_wait(q);
+               if (err)
+                       goto err_suspend;
+
+               queue_work(group->resume_wq, &group->resume_work);
+       }
+
+       list_add(&q->hw_engine_group_link, &group->exec_queue_list);
+       up_write(&group->mode_sem);
+
+       return 0;
+
+err_suspend:
+       up_write(&group->mode_sem);
+       return err;
+}
+
+/**
+ * xe_hw_engine_group_del_exec_queue() - Delete an exec queue from a hw engine group
+ * @group: The hw engine group
+ * @q: The exec_queue
+ */
+void xe_hw_engine_group_del_exec_queue(struct xe_hw_engine_group *group, struct xe_exec_queue *q)
+{
+       struct xe_device *xe = gt_to_xe(q->gt);
+
+       xe_assert(xe, group);
+       xe_assert(xe, q->vm);
+
+       down_write(&group->mode_sem);
+
+       if (!list_empty(&q->hw_engine_group_link))
+               list_del(&q->hw_engine_group_link);
+
+       up_write(&group->mode_sem);
+}
index c2648f87f7ef9455a3c568f87b2cfd57c40c7dd7..857a83787504147c05a3848ad5fb00562676faab 100644 (file)
@@ -9,8 +9,12 @@
 #include "xe_hw_engine_group_types.h"
 
 struct drm_device;
+struct xe_exec_queue;
 struct xe_gt;
 
 int xe_hw_engine_setup_groups(struct xe_gt *gt);
 
+int xe_hw_engine_group_add_exec_queue(struct xe_hw_engine_group *group, struct xe_exec_queue *q);
+void xe_hw_engine_group_del_exec_queue(struct xe_hw_engine_group *group, struct xe_exec_queue *q);
+
 #endif