Skip to content

Commit 7970cb3

Browse files
ifdumbrost05
authored andcommitted
'drm/xe/hw_engine_group: Register hw engine group's exec queues
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
1 parent 3dc6da7 commit 7970cb3

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

drivers/gpu/drm/xe/xe_device.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "xe_gt_printk.h"
3838
#include "xe_gt_sriov_vf.h"
3939
#include "xe_guc.h"
40+
#include "xe_hw_engine_group.h"
4041
#include "xe_hwmon.h"
4142
#include "xe_irq.h"
4243
#include "xe_memirq.h"
@@ -165,6 +166,8 @@ static void xe_file_close(struct drm_device *dev, struct drm_file *file)
165166
* vm->lock taken during xe_exec_queue_kill().
166167
*/
167168
xa_for_each(&xef->exec_queue.xa, idx, q) {
169+
if (q->vm && q->hwe->hw_engine_group)
170+
xe_hw_engine_group_del_exec_queue(q->hwe->hw_engine_group, q);
168171
xe_exec_queue_kill(q);
169172
xe_exec_queue_put(q);
170173
}

drivers/gpu/drm/xe/xe_exec_queue.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "xe_device.h"
1515
#include "xe_gt.h"
1616
#include "xe_hw_engine_class_sysfs.h"
17+
#include "xe_hw_engine_group.h"
1718
#include "xe_hw_fence.h"
1819
#include "xe_lrc.h"
1920
#include "xe_macros.h"
@@ -73,6 +74,7 @@ static struct xe_exec_queue *__xe_exec_queue_alloc(struct xe_device *xe,
7374
q->ops = gt->exec_queue_ops;
7475
INIT_LIST_HEAD(&q->lr.link);
7576
INIT_LIST_HEAD(&q->multi_gt_link);
77+
INIT_LIST_HEAD(&q->hw_engine_group_link);
7678

7779
q->sched_props.timeslice_us = hwe->eclass->sched_props.timeslice_us;
7880
q->sched_props.preempt_timeout_us =
@@ -624,6 +626,12 @@ int xe_exec_queue_create_ioctl(struct drm_device *dev, void *data,
624626
if (XE_IOCTL_DBG(xe, err))
625627
goto put_exec_queue;
626628
}
629+
630+
if (q->vm && q->hwe->hw_engine_group) {
631+
err = xe_hw_engine_group_add_exec_queue(q->hwe->hw_engine_group, q);
632+
if (err)
633+
goto put_exec_queue;
634+
}
627635
}
628636

629637
mutex_lock(&xef->exec_queue.lock);
@@ -815,6 +823,9 @@ int xe_exec_queue_destroy_ioctl(struct drm_device *dev, void *data,
815823
if (XE_IOCTL_DBG(xe, !q))
816824
return -ENOENT;
817825

826+
if (q->vm && q->hwe->hw_engine_group)
827+
xe_hw_engine_group_del_exec_queue(q->hwe->hw_engine_group, q);
828+
818829
xe_exec_queue_kill(q);
819830

820831
trace_xe_exec_queue_close(q);

drivers/gpu/drm/xe/xe_exec_queue_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ struct xe_exec_queue {
142142
* Protected by @vm's resv. Unused if @vm == NULL.
143143
*/
144144
u64 tlb_flush_seqno;
145+
/** @hw_engine_group_link: link into exec queues in the same hw engine group */
146+
struct list_head hw_engine_group_link;
145147
/** @lrc: logical ring context for this exec queue */
146148
struct xe_lrc *lrc[];
147149
};

drivers/gpu/drm/xe/xe_hw_engine_group.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55

66
#include <drm/drm_managed.h>
77

8+
#include "xe_assert.h"
89
#include "xe_device.h"
10+
#include "xe_exec_queue.h"
911
#include "xe_gt.h"
1012
#include "xe_hw_engine_group.h"
13+
#include "xe_vm.h"
1114

1215
static void
1316
hw_engine_group_free(struct drm_device *drm, void *arg)
@@ -100,3 +103,66 @@ int xe_hw_engine_setup_groups(struct xe_gt *gt)
100103

101104
return err;
102105
}
106+
107+
/**
108+
* xe_hw_engine_group_add_exec_queue() - Add an exec queue to a hw engine group
109+
* @group: The hw engine group
110+
* @q: The exec_queue
111+
*
112+
* Return: 0 on success,
113+
* -EINTR if the lock could not be acquired
114+
*/
115+
int xe_hw_engine_group_add_exec_queue(struct xe_hw_engine_group *group, struct xe_exec_queue *q)
116+
{
117+
int err;
118+
struct xe_device *xe = gt_to_xe(q->gt);
119+
120+
xe_assert(xe, group);
121+
xe_assert(xe, !(q->flags & EXEC_QUEUE_FLAG_VM));
122+
xe_assert(xe, q->vm);
123+
124+
if (xe_vm_in_preempt_fence_mode(q->vm))
125+
return 0;
126+
127+
err = down_write_killable(&group->mode_sem);
128+
if (err)
129+
return err;
130+
131+
if (xe_vm_in_fault_mode(q->vm) && group->cur_mode == EXEC_MODE_DMA_FENCE) {
132+
q->ops->suspend(q);
133+
err = q->ops->suspend_wait(q);
134+
if (err)
135+
goto err_suspend;
136+
137+
queue_work(group->resume_wq, &group->resume_work);
138+
}
139+
140+
list_add(&q->hw_engine_group_link, &group->exec_queue_list);
141+
up_write(&group->mode_sem);
142+
143+
return 0;
144+
145+
err_suspend:
146+
up_write(&group->mode_sem);
147+
return err;
148+
}
149+
150+
/**
151+
* xe_hw_engine_group_del_exec_queue() - Delete an exec queue from a hw engine group
152+
* @group: The hw engine group
153+
* @q: The exec_queue
154+
*/
155+
void xe_hw_engine_group_del_exec_queue(struct xe_hw_engine_group *group, struct xe_exec_queue *q)
156+
{
157+
struct xe_device *xe = gt_to_xe(q->gt);
158+
159+
xe_assert(xe, group);
160+
xe_assert(xe, q->vm);
161+
162+
down_write(&group->mode_sem);
163+
164+
if (!list_empty(&q->hw_engine_group_link))
165+
list_del(&q->hw_engine_group_link);
166+
167+
up_write(&group->mode_sem);
168+
}

drivers/gpu/drm/xe/xe_hw_engine_group.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
#include "xe_hw_engine_group_types.h"
1010

1111
struct drm_device;
12+
struct xe_exec_queue;
1213
struct xe_gt;
1314

1415
int xe_hw_engine_setup_groups(struct xe_gt *gt);
1516

17+
int xe_hw_engine_group_add_exec_queue(struct xe_hw_engine_group *group, struct xe_exec_queue *q);
18+
void xe_hw_engine_group_del_exec_queue(struct xe_hw_engine_group *group, struct xe_exec_queue *q);
19+
1620
#endif

0 commit comments

Comments
 (0)