This commit sets the perf state of a user queue
before publish it.

Signed-off-by: Zhu Lingshan <[email protected]>
Reviewed-by: Benjamin Welton <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 30 +++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
index b4a2164068e3..140f1bbbc39f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
@@ -686,6 +686,33 @@ static int amdgpu_userq_priority_permit(struct drm_file 
*filp,
        return -EACCES;
 }
 
+static int amdgpu_userq_attach(struct amdgpu_device *adev,
+                              struct amdgpu_usermode_queue *queue,
+                              u64 index)
+{
+       struct amdgpu_mqd *mqd_funcs = &adev->mqds[queue->queue_type];
+       int r = 0;
+
+       mutex_lock(&adev->pmc_profiler.lock);
+
+       if (adev->pmc_profiler.enable &&
+           queue->queue_type == AMDGPU_HW_IP_COMPUTE) {
+               queue->userq_prop->perfcount_enable = true;
+               r = mqd_funcs->init_mqd(adev, queue->mqd.cpu_ptr,
+                                       queue->userq_prop);
+       }
+
+       if (r)
+               drm_dbg_driver(adev_to_drm(adev), "Failed to init mqd for user 
queue %llu\n", index);
+       else
+               r = xa_insert_irq(&adev->userq_doorbell_xa, index, queue,
+                                 GFP_KERNEL);
+
+       mutex_unlock(&adev->pmc_profiler.lock);
+
+       return r;
+}
+
 static int
 amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 {
@@ -785,8 +812,7 @@ amdgpu_userq_create(struct drm_file *filp, union 
drm_amdgpu_userq *args)
        /* Update VM owner at userq submit-time for page-fault attribution. */
        amdgpu_vm_set_task_info(&fpriv->vm);
 
-       r = xa_insert_irq(&adev->userq_doorbell_xa, index, queue,
-                         GFP_KERNEL);
+       r = amdgpu_userq_attach(adev, queue, index);
        if (r)
                goto clean_mqd;
 
-- 
2.53.0

Reply via email to