Allow num_binds/num_batch_buffer to be zero IOCTLs
Subsystems (2)
Matthew Brost
maintainerv2 cover Allow num_binds/num_batch_buffer to be zero IOCTLs
Easy way to flush exec queues. A semantic that VK will likely use.
Matthew Brost (5):
drm/xe: Use a flags field instead of bools for VMA create drm/xe: Use a flags field instead of bools for sync parse drm/xe: Allow num_binds == 0 in VM bind IOCTL
drm/xe: Allow num_batch_buffer == 0 in exec IOCTL drm/xe: Take in-syncs into account when num_execs or num_binds == 0
drivers/gpu/drm/xe/xe_exec.c | 28 ++++- drivers/gpu/drm/xe/xe_exec_queue.c | 5 +- drivers/gpu/drm/xe/xe_exec_queue_types.h | 5 +- drivers/gpu/drm/xe/xe_sync.c | 82 ++++++++++++++- drivers/gpu/drm/xe/xe_sync.h | 11 +- drivers/gpu/drm/xe/xe_vm.c | 125 ++++++++++++++--------- 6 files changed, 200 insertions(+), 56 deletions(-)
Signature · 1 line
2.34.1
Matthew Brost
maintainerPATCH v2 1/5 drm/xe: Use a flags field instead of bools for VMA create
Use a flags field instead of severval bools for VMA create as it is easier to read and less bug prone.
--- drivers/gpu/drm/xe/xe_vm.c | 64 ++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 30 deletions(-)
drivers/gpu/drm/xe/xe_vm.c +34 -30
@@ -860,17 +860,20 @@ struct dma_fence *xe_vm_rebind(struct xe_vm *vm, bool rebind_worker)return fence; } +#define VMA_CREATE_FLAG_READ_ONLY BIT(0) +#define VMA_CREATE_FLAG_IS_NULL BIT(1) +static struct xe_vma *xe_vma_create (struct xe_vm *vm,struct xe_bo *bo,u64 bo_offset_or_userptr,u64 start,u64 end, -bool read_only, -bool is_null, -u16 pat_index) +u16 pat_index,unsigned int flags) {struct xe_vma *vma;struct xe_tile *tile;u8 id; +bool read_only = (flags &VMA_CREATE_FLAG_READ_ONLY ); +bool is_null = (flags &VMA_CREATE_FLAG_IS_NULL );xe_assert (vm->xe, start < end);xe_assert (vm->xe, end < vm->size);
@@ -2242,7 +2245,7 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo, }static struct xe_vma *new_vma (struct xe_vm *vm,struct drm_gpuva_op_map *op, -bool read_only,bool is_null,u16 pat_index) +u16 pat_index,unsigned int flags) {struct xe_bo *bo = op->gem.obj ?gem_to_xe_bo (op->gem.obj) :NULL ;struct xe_vma *vma;
@@ -2257,8 +2260,7 @@ static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op, } vma =xe_vma_create (vm, bo, op->gem.offset, op->va.addr, op->va.addr + - op->va.range -1 , read_only, is_null, - pat_index); + op->va.range -1 , pat_index, flags);if (bo)xe_bo_unlock (bo);
@@ -2384,7 +2386,9 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_exec_queue *q,drm_gpuva_for_each_op (__op, ops) {struct xe_vma_op *op =gpuva_op_to_vma_op (__op); +struct xe_vma *vma;bool first =list_empty (ops_list); +unsigned int flags =0 ;INIT_LIST_HEAD (&op->link);list_add_tail (&op->link, ops_list);
@@ -2400,10 +2404,13 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_exec_queue *q,switch (op->base.op) {case DRM_GPUVA_OP_MAP : { -struct xe_vma *vma; + flags |= op->map.read_only ? +VMA_CREATE_FLAG_READ_ONLY :0 ; + flags |= op->map.is_null ? +VMA_CREATE_FLAG_IS_NULL :0 ; - vma =new_vma (vm, &op->base.map, op->map.read_only, - op->map.is_null, op->map.pat_index); + vma =new_vma (vm, &op->base.map, op->map.pat_index, + flags);if (IS_ERR (vma))return PTR_ERR (vma);
@@ -2419,16 +2426,15 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_exec_queue *q, op->remap.range =xe_vma_size (old);if (op->base.remap.prev) { -struct xe_vma *vma; -bool read_only = - op->base.remap.unmap->va->flags & -XE_VMA_READ_ONLY ; -bool is_null = - op->base.remap.unmap->va->flags & -DRM_GPUVA_SPARSE ; - - vma =new_vma (vm, op->base.remap.prev, read_only, - is_null, old->pat_index); + flags |= op->base.remap.unmap->va->flags & +XE_VMA_READ_ONLY ? +VMA_CREATE_FLAG_READ_ONLY :0 ; + flags |= op->base.remap.unmap->va->flags & +DRM_GPUVA_SPARSE ? +VMA_CREATE_FLAG_IS_NULL :0 ; + + vma =new_vma (vm, op->base.remap.prev, + old->pat_index, flags);if (IS_ERR (vma))return PTR_ERR (vma);
@@ -2451,17 +2457,15 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_exec_queue *q, }if (op->base.remap.next) { -struct xe_vma *vma; -bool read_only = - op->base.remap.unmap->va->flags & -XE_VMA_READ_ONLY ; - -bool is_null = - op->base.remap.unmap->va->flags & -DRM_GPUVA_SPARSE ; - - vma =new_vma (vm, op->base.remap.next, read_only, - is_null, old->pat_index); + flags |= op->base.remap.unmap->va->flags & +XE_VMA_READ_ONLY ? +VMA_CREATE_FLAG_READ_ONLY :0 ; + flags |= op->base.remap.unmap->va->flags & +DRM_GPUVA_SPARSE ? +VMA_CREATE_FLAG_IS_NULL :0 ; + + vma =new_vma (vm, op->base.remap.next, + old->pat_index, flags);if (IS_ERR (vma))return PTR_ERR (vma);
Signature · 1 line
2.34.1
Matthew Brost
maintainerPATCH v2 2/5 drm/xe: Use a flags field instead of bools for sync parse
In reply to Matthew BrostUse a flags field instead of severval bools for sync parse as it is easier to read and less bug prone.
v2: Pull in header change from subsequent patch
--- drivers/gpu/drm/xe/xe_exec.c | 5 +++-- drivers/gpu/drm/xe/xe_sync.c | 4 +++- drivers/gpu/drm/xe/xe_sync.h | 5 ++++- drivers/gpu/drm/xe/xe_vm.c | 5 +++-- 4 files changed, 13 insertions(+), 6 deletions(-)
drivers/gpu/drm/xe/xe_exec.c +3 -2
@@ -181,8 +181,9 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)for (i =0 ; i < args->num_syncs; i++) { err =xe_sync_entry_parse (xe, xef, &syncs[num_syncs++], - &syncs_user[i], true, -xe_vm_in_lr_mode (vm)); + &syncs_user[i],SYNC_PARSE_FLAG_EXEC | + (xe_vm_in_lr_mode (vm) ? +SYNC_PARSE_FLAG_LR_MODE :0 ));if (err) goto err_syncs; }
drivers/gpu/drm/xe/xe_sync.c +3 -1
@@ -98,10 +98,12 @@ static void user_fence_cb(struct dma_fence *fence, struct dma_fence_cb *cb)int xe_sync_entry_parse (struct xe_device *xe,struct xe_file *xef,struct xe_sync_entry *sync,struct drm_xe_sync __user *sync_user, -bool exec,bool in_lr_mode) +unsigned int flags) {struct drm_xe_sync sync_in;int err; +bool exec = flags &SYNC_PARSE_FLAG_EXEC ; +bool in_lr_mode = flags &SYNC_PARSE_FLAG_LR_MODE ;bool signal;if (copy_from_user (&sync_in, sync_user,sizeof (*sync_user)))
drivers/gpu/drm/xe/xe_sync.h +4 -1
@@ -12,10 +12,13 @@ struct xe_device;struct xe_file ;struct xe_sched_job ; +#define SYNC_PARSE_FLAG_EXEC BIT(0) +#define SYNC_PARSE_FLAG_LR_MODE BIT(1) +int xe_sync_entry_parse (struct xe_device *xe,struct xe_file *xef,struct xe_sync_entry *sync,struct drm_xe_sync __user *sync_user, -bool exec,bool compute_mode); +unsigned int flags);int xe_sync_entry_wait (struct xe_sync_entry *sync);int xe_sync_entry_add_deps (struct xe_sync_entry *sync,struct xe_sched_job *job);
drivers/gpu/drm/xe/xe_vm.c +3 -2
@@ -3106,8 +3106,9 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file) syncs_user =u64_to_user_ptr (args->syncs);for (num_syncs =0 ; num_syncs < args->num_syncs; num_syncs++) { err =xe_sync_entry_parse (xe, xef, &syncs[num_syncs], - &syncs_user[num_syncs], false, -xe_vm_in_lr_mode (vm)); + &syncs_user[num_syncs], +xe_vm_in_lr_mode (vm) ? +SYNC_PARSE_FLAG_LR_MODE :0 );if (err) goto free_syncs; }
Signature · 1 line
2.34.1
Matthew Brost
maintainerPATCH v2 3/5 drm/xe: Allow num_binds == 0 in VM bind IOCTL
In reply to Matthew BrostThe idea being out-syncs can signal indicating all previous operations on the bind queue are complete. An example use case of this would be support for implementing vkQueueWaitIdle easily.
v2: s/vkQueueWaitForIdle/vkQueueWaitIdle
--- drivers/gpu/drm/xe/xe_sync.h | 1 + drivers/gpu/drm/xe/xe_vm.c | 36 ++++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 14 deletions(-)
drivers/gpu/drm/xe/xe_sync.h +1 -0
@@ -14,6 +14,7 @@ struct xe_sched_job;#define SYNC_PARSE_FLAG_EXEC BIT(0)#define SYNC_PARSE_FLAG_LR_MODE BIT(1) +#define SYNC_PARSE_FLAG_DISALLOW_USER_FENCE BIT(2) int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef, struct xe_sync_entry *sync,
drivers/gpu/drm/xe/xe_vm.c +22 -14
@@ -2834,7 +2834,6 @@ static int vm_bind_ioctl_check_args(struct xe_device *xe,return -EINVAL ;if (XE_IOCTL_DBG (xe, args->extensions) || -XE_IOCTL_DBG (xe, !args->num_binds) ||XE_IOCTL_DBG (xe, args->num_binds >MAX_BINDS ))return -EINVAL ;
@@ -2987,7 +2986,7 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file) goto put_exec_queue; } -if (XE_IOCTL_DBG (xe, async != +if (XE_IOCTL_DBG (xe, args->num_binds && async != !!(q->flags &EXEC_QUEUE_FLAG_VM_ASYNC ))) { err = -EINVAL ; goto put_exec_queue;
@@ -3001,7 +3000,7 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file) }if (!args->exec_queue_id) { -if (XE_IOCTL_DBG (xe, async != +if (XE_IOCTL_DBG (xe, args->num_binds && async != !!(vm->flags &XE_VM_FLAG_ASYNC_DEFAULT ))) { err = -EINVAL ; goto put_vm;
@@ -3028,16 +3027,18 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file) } } - bos =kzalloc (sizeof (*bos) * args->num_binds,GFP_KERNEL ); -if (!bos) { - err = -ENOMEM ; - goto release_vm_lock; - } +if (args->num_binds) { + bos =kzalloc (sizeof (*bos) * args->num_binds,GFP_KERNEL ); +if (!bos) { + err = -ENOMEM ; + goto release_vm_lock; + } - ops =kzalloc (sizeof (*ops) * args->num_binds,GFP_KERNEL ); -if (!ops) { - err = -ENOMEM ; - goto release_vm_lock; + ops =kzalloc (sizeof (*ops) * args->num_binds,GFP_KERNEL ); +if (!ops) { + err = -ENOMEM ; + goto release_vm_lock; + } }for (i =0 ; i < args->num_binds; ++i) {
@@ -3107,12 +3108,19 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)for (num_syncs =0 ; num_syncs < args->num_syncs; num_syncs++) { err =xe_sync_entry_parse (xe, xef, &syncs[num_syncs], &syncs_user[num_syncs], -xe_vm_in_lr_mode (vm) ? -SYNC_PARSE_FLAG_LR_MODE :0 ); + (xe_vm_in_lr_mode (vm) ? +SYNC_PARSE_FLAG_LR_MODE :0 ) | + (!args->num_binds ? +SYNC_PARSE_FLAG_DISALLOW_USER_FENCE :0 ));if (err) goto free_syncs; } +if (!args->num_binds) { + err = -ENODATA ; + goto free_syncs; + } +for (i =0 ; i < args->num_binds; ++i) {u64 range = bind_ops[i].range;u64 addr = bind_ops[i].addr;
Signature · 1 line
2.34.1
Matthew Brost
maintainerPATCH v2 4/5 drm/xe: Allow num_batch_buffer == 0 in exec IOCTL
In reply to Matthew BrostThe idea being out-syncs can signal indicating all previous operations on the exec queue are complete. An example use case of this would be support for implementing vkQueueWaitIdle easily.
v2: Don't add last_fence for VM's that do not support dma fences
v3: Use a flags field instead of severval bools in sync parse (Thomas)
v4: v2: s/vkQueueWaitForIdle/vkQueueWaitIdle
--- drivers/gpu/drm/xe/xe_exec.c | 17 ++++++++++++++++- drivers/gpu/drm/xe/xe_exec_queue.c | 5 ++++- drivers/gpu/drm/xe/xe_exec_queue_types.h | 5 +++-- drivers/gpu/drm/xe/xe_sync.c | 4 ++++ 4 files changed, 27 insertions(+), 4 deletions(-)
drivers/gpu/drm/xe/xe_exec.c +16 -1
@@ -161,7 +161,8 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)if (XE_IOCTL_DBG (xe, q->flags &EXEC_QUEUE_FLAG_VM ))return -EINVAL ; -if (XE_IOCTL_DBG (xe, q->width != args->num_batch_buffer)) +if (XE_IOCTL_DBG (xe, args->num_batch_buffer && + q->width != args->num_batch_buffer))return -EINVAL ;if (XE_IOCTL_DBG (xe, q->flags &EXEC_QUEUE_FLAG_BANNED )) {
@@ -235,6 +236,18 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file) goto err_exec; } +if (!args->num_batch_buffer) { +if (xe_vm_in_lr_mode (vm)) { +struct dma_fence *fence = +xe_exec_queue_last_fence_get (q, vm); + +for (i =0 ; i < num_syncs; i++) +xe_sync_entry_signal (&syncs[i],NULL , fence); + } + + goto err_exec; + } +if (xe_exec_queue_is_lr (q) &&xe_exec_queue_ring_full (q)) { err = -EWOULDBLOCK ; goto err_exec;
@@ -328,6 +341,8 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)if (xe_exec_queue_is_lr (q)) q->ring_ops->emit_job (job); +if (xe_vm_in_lr_mode (vm)) +xe_exec_queue_last_fence_set (q, vm, &job->drm.s_fence->finished);xe_sched_job_push (job);xe_vm_reactivate_rebind (vm);
drivers/gpu/drm/xe/xe_exec_queue.c +4 -1
@@ -886,7 +886,10 @@ int xe_exec_queue_destroy_ioctl(struct drm_device *dev, void *data,static void xe_exec_queue_last_fence_lockdep_assert (struct xe_exec_queue *q,struct xe_vm *vm) { -lockdep_assert_held_write (&vm->lock); +if (q->flags &EXEC_QUEUE_FLAG_VM ) +lockdep_assert_held_write (&vm->lock); +else +xe_vm_assert_held (vm); }/**
drivers/gpu/drm/xe/xe_exec_queue_types.h +3 -2
@@ -56,8 +56,9 @@ struct xe_exec_queue {struct xe_hw_fence_irq *fence_irq;/** -* @last_fence: last fence on engine, protected by vm->lock in write -* mode if bind engine +* @last_fence: last fence on exec queue, protected by vm->lock in write +* mode if bind exec queue, protected by dma resv lock if non-bind exec +* queue */ struct dma_fence *last_fence;
drivers/gpu/drm/xe/xe_sync.c +4 -0
@@ -104,6 +104,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,int err;bool exec = flags &SYNC_PARSE_FLAG_EXEC ;bool in_lr_mode = flags &SYNC_PARSE_FLAG_LR_MODE ; +bool disallow_user_fence = flags &SYNC_PARSE_FLAG_DISALLOW_USER_FENCE ;bool signal;if (copy_from_user (&sync_in, sync_user,sizeof (*sync_user)))
@@ -164,6 +165,9 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,break ;case DRM_XE_SYNC_TYPE_USER_FENCE : +if (XE_IOCTL_DBG (xe, disallow_user_fence)) +return -EOPNOTSUPP ; +if (XE_IOCTL_DBG (xe, !signal))return -EOPNOTSUPP ;
Signature · 1 line
2.34.1
Matthew Brost
maintainerPATCH v2 5/5 drm/xe: Take in-syncs into account when num_execs or num_binds == 0
In reply to Matthew BrostWait on in-syncs before signaling out-syncs if num_execs or num_binds == 0 in execbuf IOCTL or VM bind IOCTL respectfully.
v2: Wait on last fence in addition to in-fences (Thomas)
--- drivers/gpu/drm/xe/xe_exec.c | 10 ++++- drivers/gpu/drm/xe/xe_sync.c | 74 ++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_sync.h | 5 +++ drivers/gpu/drm/xe/xe_vm.c | 24 ++++++++++-- 4 files changed, 107 insertions(+), 6 deletions(-)
drivers/gpu/drm/xe/xe_exec.c +8 -2
@@ -238,11 +238,17 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)if (!args->num_batch_buffer) {if (xe_vm_in_lr_mode (vm)) { -struct dma_fence *fence = -xe_exec_queue_last_fence_get (q, vm); +struct dma_fence *fence; + fence =xe_sync_in_fence_get (syncs, num_syncs, q, vm); +if (IS_ERR (fence)) { + err =PTR_ERR (fence); + goto err_exec; + }for (i =0 ; i < num_syncs; i++)xe_sync_entry_signal (&syncs[i],NULL , fence); +xe_exec_queue_last_fence_set (q, vm, fence); +dma_fence_put (fence); } goto err_exec;
drivers/gpu/drm/xe/xe_sync.c +74 -0
89 lines not on this page · raw message
drivers/gpu/drm/xe/xe_sync.h +5 -0
@@ -9,8 +9,10 @@#include "xe_sync_types.h" struct xe_device ; +struct xe_exec_queue ;struct xe_file ;struct xe_sched_job ; +struct xe_vm ;#define SYNC_PARSE_FLAG_EXEC BIT(0)#define SYNC_PARSE_FLAG_LR_MODE BIT(1)
@@ -27,5 +29,8 @@ void xe_sync_entry_signal(struct xe_sync_entry *sync,struct xe_sched_job *job, struct dma_fence *fence);void xe_sync_entry_cleanup (struct xe_sync_entry *sync); +struct dma_fence * +xe_sync_in_fence_get (struct xe_sync_entry *sync,int num_sync, +struct xe_exec_queue *q,struct xe_vm *vm);#endif
drivers/gpu/drm/xe/xe_vm.c +20 -4
@@ -3178,12 +3178,28 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file) unwind_ops:vm_bind_ioctl_ops_unwind (vm, ops, args->num_binds); free_syncs: -for (i =0 ; err == -ENODATA && i < num_syncs; i++) { -struct dma_fence *fence = -xe_exec_queue_last_fence_get (to_wait_exec_queue (vm, q), vm); +if (err == -ENODATA ) { +struct dma_fence *fence; + + fence =xe_sync_in_fence_get (syncs, num_syncs, +to_wait_exec_queue (vm, q), vm); +if (IS_ERR (fence)) { + err =PTR_ERR (fence); + goto cleanup_syncs; + } +for (i =0 ; i < num_syncs; i++) +xe_sync_entry_signal (&syncs[i],NULL , fence); +if (!async) { +long timeout =dma_fence_wait (fence, true); -xe_sync_entry_signal (&syncs[i],NULL , fence); +if (timeout <0 ) + err = -EINTR ; + } +xe_exec_queue_last_fence_set (to_wait_exec_queue (vm, q), vm, + fence); +dma_fence_put (fence); } +cleanup_syncs:while (num_syncs--)xe_sync_entry_cleanup (&syncs[num_syncs]);
Signature · 1 line
2.34.1