Gangs are sets of userqs that schedule together. You specify the primary and secondary queues and the scheduler will make sure they always run at the same time.
v2: handle setting up the gang again after unmaps v3: split the UAPI part from the internal tracking v4: rework Cc: Yogesh Mohan Marimuthu <[email protected]> Signed-off-by: Alex Deucher <[email protected]> --- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 122 +++++++++++++++++++++- 1 file changed, 121 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c index 3afd17af28548..388385380d8bc 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c @@ -566,6 +566,7 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_que { struct amdgpu_device *adev = uq_mgr->adev; const struct amdgpu_userq_funcs *uq_funcs = adev->userq_funcs[queue->queue_type]; + struct amdgpu_usermode_queue *other_gang_queue; int r = 0; trace_amdgpu_userq_destroy_start(queue); @@ -585,6 +586,17 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_que debugfs_remove_recursive(queue->debugfs_queue); #endif r = amdgpu_userq_unmap_helper(queue); + /* clean up gangs */ + if (queue->gang_primary) { + other_gang_queue = queue->gang_primary; + other_gang_queue->gang_secondary = NULL; + queue->gang_primary = NULL; + } + if (queue->gang_secondary) { + other_gang_queue = queue->gang_secondary; + other_gang_queue->gang_primary = NULL; + queue->gang_secondary = NULL; + } atomic_dec(&uq_mgr->userq_count[queue->queue_type]); amdgpu_userq_fence_driver_free(queue); queue->fence_drv = NULL; @@ -838,6 +850,106 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args) return r; } +static int +amdgpu_userq_create_gang(struct drm_file *filp, union drm_amdgpu_userq *args) +{ + struct amdgpu_usermode_queue *primary_queue, *secondary_queue; + struct amdgpu_fpriv *fpriv = filp->driver_priv; + struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr; + const struct amdgpu_userq_funcs *userq_funcs; + struct amdgpu_device *adev = uq_mgr->adev; + int primary_queue_id = args->in_cg.primary_queue_id; + int secondary_queue_id = args->in_cg.secondary_queue_id; + int r; + + /* The reset changes the queue state and the MES is unusable meanwhile */ + guard(rwsem_read)(&adev->reset_domain->sem); + + mutex_lock(&uq_mgr->userq_mutex); + primary_queue = amdgpu_userq_get(uq_mgr, primary_queue_id); + secondary_queue = amdgpu_userq_get(uq_mgr, secondary_queue_id); + + if (!primary_queue) { + drm_file_err(uq_mgr->file, "Invalid gang primary queue id\n"); + r = -EINVAL; + goto out; + } + + if (!secondary_queue) { + drm_file_err(uq_mgr->file, "Invalid gang secondary queue id\n"); + r = -EINVAL; + goto out; + } + + if (primary_queue == secondary_queue) { + drm_file_err(uq_mgr->file, "Trying to gang the same queue\n"); + r = -EINVAL; + goto out; + } + + if ((primary_queue->queue_type != AMDGPU_HW_IP_GFX) && + (primary_queue->queue_type != AMDGPU_HW_IP_COMPUTE) && + (primary_queue->queue_type != AMDGPU_HW_IP_DMA)) { + drm_file_err(uq_mgr->file, "Invalid gang primary queue type\n"); + r = -EINVAL; + goto out; + } + + if (primary_queue->gang_primary || primary_queue->gang_secondary) { + drm_file_err(uq_mgr->file, "Primary queue already in a gang\n"); + r = -EINVAL; + goto out; + } + if (primary_queue->state == AMDGPU_USERQ_STATE_HUNG) { + drm_file_err(uq_mgr->file, "Primary queue is hung\n"); + r = -EINVAL; + goto out; + } + + if ((secondary_queue->queue_type != AMDGPU_HW_IP_GFX) && + (secondary_queue->queue_type != AMDGPU_HW_IP_COMPUTE) && + (secondary_queue->queue_type != AMDGPU_HW_IP_DMA)) { + drm_file_err(uq_mgr->file, "Invalid gang secondary queue type\n"); + r = -EINVAL; + goto out; + } + + if (secondary_queue->gang_primary || secondary_queue->gang_secondary) { + drm_file_err(uq_mgr->file, "Secondary queue already in a gang\n"); + r = -EINVAL; + goto out; + } + + if (secondary_queue->state == AMDGPU_USERQ_STATE_HUNG) { + drm_file_err(uq_mgr->file, "Secondary queue is hung\n"); + r = -EINVAL; + goto out; + } + + userq_funcs = adev->userq_funcs[primary_queue->queue_type]; + if ((primary_queue->state == AMDGPU_USERQ_STATE_MAPPED || + primary_queue->state == AMDGPU_USERQ_STATE_PREEMPTED) && + (secondary_queue->state == AMDGPU_USERQ_STATE_MAPPED || + secondary_queue->state == AMDGPU_USERQ_STATE_PREEMPTED)) + r = userq_funcs->set_gang(primary_queue, secondary_queue); + else + /* if the queues are currently unmapped, the gang state will get + * updated when they get mapped. + */ + r = 0; + if (!r) { + primary_queue->gang_secondary = secondary_queue; + secondary_queue->gang_primary = primary_queue; + } + +out: + mutex_unlock(&uq_mgr->userq_mutex); + amdgpu_userq_put(primary_queue); + amdgpu_userq_put(secondary_queue); + + return r; +} + static int amdgpu_userq_input_args_validate(struct drm_device *dev, union drm_amdgpu_userq *args, struct drm_file *filp) @@ -907,6 +1019,10 @@ static int amdgpu_userq_input_args_validate(struct drm_device *dev, args->in.mqd_size) return -EINVAL; break; + case AMDGPU_USERQ_OP_CREATE_GANG: + if (args->in_cg.pad) + return -EINVAL; + break; default: return -EINVAL; } @@ -958,7 +1074,11 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data, amdgpu_userq_put(queue); break; } - + case AMDGPU_USERQ_OP_CREATE_GANG: + r = amdgpu_userq_create_gang(filp, args); + if (r) + drm_file_err(filp, "Failed to create usermode queue gang\n"); + break; default: drm_dbg_driver(dev, "Invalid user queue op specified: %d\n", args->in.op); return -EINVAL; -- 2.56.1
