Skip to contentSkip to conversation

drm/amdgpu/userq: handle runtime pm

PATCH In review Alex Deucher 3 participants 4 messages Feb 21, 2025 – Feb 25, 2025

Subsystems (2)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/2 drm/amdgpu/userq: handle runtime pm

Take a reference when we create a queue and drop it when we destroy the queue. We need to keep the device active while user queues are active.

---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +13 -1
index 9a6a5553bbc3f..3a71d01b54c92 100644
@@ -26,6 +26,7 @@
 #include "mes_userqueue.h"
 #include "amdgpu_userq_fence.h"
 #include "v11_structs.h"
+#include <linux/pm_runtime.h>
 
 #define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE
 #define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
@@ -287,6 +288,10 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
 
 	queue->userq_prop = userq_props;
 
+	r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
+	if (r)
+		goto free_mqd;
+
 	r = mqd_hw_default->init_mqd(adev, (void *)queue->mqd.cpu_ptr, userq_props);
 	if (r) {
 		DRM_ERROR("Failed to initialize MQD for userqueue\n");
@@ -321,6 +326,8 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
 
 free_mqd:
 	amdgpu_userqueue_destroy_object(uq_mgr, &queue->mqd);
+	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
+	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
 free_props:
 	kfree(userq_props);
@@ -330,14 +337,19 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
 
 static void
 mes_userq_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr,
-			    struct amdgpu_usermode_queue *queue)
+		      struct amdgpu_usermode_queue *queue)
 {
+	struct amdgpu_device *adev = uq_mgr->adev;
+
 	if (queue->queue_active)
 		mes_userq_unmap(uq_mgr, queue);
 
 	amdgpu_userqueue_destroy_object(uq_mgr, &queue->fw_obj);
 	kfree(queue->userq_prop);
 	amdgpu_userqueue_destroy_object(uq_mgr, &queue->mqd);
+
+	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
+	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 }
 
 static int mes_userq_suspend(struct amdgpu_userq_mgr *uq_mgr,
Signature · 1 line
2.48.1
author maintainer
#1 lore raw

PATCH 2/2 drm/amdgpu/userq: fix hardcoded uq functions

Use the IP type to look up the userq functions rather than hardcoding it.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +6 -6
index f1d4e29772a53..0664e04828c07 100644
@@ -415,11 +415,11 @@ amdgpu_userqueue_resume_all(struct amdgpu_userq_mgr *uq_mgr)
 	int queue_id;
 	int ret = 0;
 
-	userq_funcs = adev->userq_funcs[AMDGPU_HW_IP_GFX];
-
 	/* Resume all the queues for this process */
-	idr_for_each_entry(&uq_mgr->userq_idr, queue, queue_id)
+	idr_for_each_entry(&uq_mgr->userq_idr, queue, queue_id) {
+		userq_funcs = adev->userq_funcs[queue->queue_type];
 		ret = userq_funcs->resume(uq_mgr, queue);
+	}
 
 	if (ret)
 		DRM_ERROR("Failed to resume all the queue\n");
@@ -570,11 +570,11 @@ amdgpu_userqueue_suspend_all(struct amdgpu_userq_mgr *uq_mgr)
 	int queue_id;
 	int ret = 0;
 
-	userq_funcs = adev->userq_funcs[AMDGPU_HW_IP_GFX];
-
 	/* Try to suspend all the queues in this process ctx */
-	idr_for_each_entry(&uq_mgr->userq_idr, queue, queue_id)
+	idr_for_each_entry(&uq_mgr->userq_idr, queue, queue_id) {
+		userq_funcs = adev->userq_funcs[queue->queue_type];
 		ret += userq_funcs->suspend(uq_mgr, queue);
+	}
 
 	if (ret)
 		DRM_ERROR("Couldn't suspend all the queues\n");
Signature · 1 line
2.48.1
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] drm/amdgpu/userq: fix hardcoded uq functions

Hi Alex,

Change looks good to me.

Regards,

Saleem

Quoted 42 lines · Alex Deucher

Use the IP type to look up the userq functions rather than hardcoding it.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 12 ++++++------
  1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +6 -6
index f1d4e29772a53..0664e04828c07 100644
@@ -415,11 +415,11 @@ amdgpu_userqueue_resume_all(struct amdgpu_userq_mgr *uq_mgr)
  	int queue_id;
  	int ret = 0;
 
-	userq_funcs = adev->userq_funcs[AMDGPU_HW_IP_GFX];
-
  	/* Resume all the queues for this process */
-	idr_for_each_entry(&uq_mgr->userq_idr, queue, queue_id)
+	idr_for_each_entry(&uq_mgr->userq_idr, queue, queue_id) {
+		userq_funcs = adev->userq_funcs[queue->queue_type];
  		ret = userq_funcs->resume(uq_mgr, queue);
+	}
 
  	if (ret)
  		DRM_ERROR("Failed to resume all the queue\n");
@@ -570,11 +570,11 @@ amdgpu_userqueue_suspend_all(struct amdgpu_userq_mgr *uq_mgr)
  	int queue_id;
  	int ret = 0;
 
-	userq_funcs = adev->userq_funcs[AMDGPU_HW_IP_GFX];
-
  	/* Try to suspend all the queues in this process ctx */
-	idr_for_each_entry(&uq_mgr->userq_idr, queue, queue_id)
+	idr_for_each_entry(&uq_mgr->userq_idr, queue, queue_id) {
+		userq_funcs = adev->userq_funcs[queue->queue_type];
  		ret += userq_funcs->suspend(uq_mgr, queue);
+	}
 
  	if (ret)
  		DRM_ERROR("Couldn't suspend all the queues\n");
#3 lore raw
In reply to Alex Deucher

Ping?

Quoted 66 lines · Alex Deucher

Take a reference when we create a queue and drop it when we destroy the queue. We need to keep the device active while user queues are active.

---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +13 -2
index 9a6a5553bbc3f..3a71d01b54c92 100644
@@ -26,6 +26,7 @@
 #include "mes_userqueue.h"
 #include "amdgpu_userq_fence.h"
 #include "v11_structs.h"
+#include <linux/pm_runtime.h>
 
 #define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE
 #define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
@@ -287,6 +288,10 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
 
        queue->userq_prop = userq_props;
 
+       r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
+       if (r)
+               goto free_mqd;
+
        r = mqd_hw_default->init_mqd(adev, (void *)queue->mqd.cpu_ptr, userq_props);
        if (r) {
                DRM_ERROR("Failed to initialize MQD for userqueue\n");
@@ -321,6 +326,8 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
 
 free_mqd:
        amdgpu_userqueue_destroy_object(uq_mgr, &queue->mqd);
+       pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
+       pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
 free_props:
        kfree(userq_props);
@@ -330,14 +337,19 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
 
 static void
 mes_userq_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr,
-                           struct amdgpu_usermode_queue *queue)
+                     struct amdgpu_usermode_queue *queue)
 {
+       struct amdgpu_device *adev = uq_mgr->adev;
+
        if (queue->queue_active)
                mes_userq_unmap(uq_mgr, queue);
 
        amdgpu_userqueue_destroy_object(uq_mgr, &queue->fw_obj);
        kfree(queue->userq_prop);
        amdgpu_userqueue_destroy_object(uq_mgr, &queue->mqd);
+
+       pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
+       pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 }
 
 static int mes_userq_suspend(struct amdgpu_userq_mgr *uq_mgr,
--

2.48.1