Skip to contentSkip to conversation

drm/amdgpu/userq: move runpm handling into core userq code

PATCH In review Alex Deucher 3 participants 3 messages Apr 13, 2025 – Apr 14, 2025

Subsystems (2)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/1 drm/amdgpu/userq: move runpm handling into core userq code

Pull it out of the MES code and into the generic code. It's not MES specific and needs to be applied to all user queues regardless of the backend.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 13 +++++++++++++
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c    | 15 ---------------
 2 files changed, 13 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +13 -0
index 98e1ed794c346..08a94822eb17c 100644
@@ -24,6 +24,8 @@
 
 #include <drm/drm_auth.h>
 #include <drm/drm_exec.h>
+#include <linux/pm_runtime.h>
+
 #include "amdgpu.h"
 #include "amdgpu_vm.h"
 #include "amdgpu_userqueue.h"
@@ -258,6 +260,10 @@ amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)
 	amdgpu_bo_unref(&queue->db_obj.obj);
 	amdgpu_userqueue_cleanup(uq_mgr, queue, queue_id);
 	mutex_unlock(&uq_mgr->userq_mutex);
+
+	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
+	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
+
 	return r;
 }
 
@@ -311,6 +317,13 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 		return -EINVAL;
 	}
 
+	r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
+	if (r < 0) {
+		dev_err(adev->dev, "pm_runtime_get_sync() failed for userqueue mqd create\n");
+		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
+		return r;
+	}
+
 	/*
 	 * There could be a situation that we are creating a new queue while
 	 * the other queues under this UQ_mgr are suspended. So if there is any
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0 -15
index e175f05bba6a9..b3157df8ae107 100644
@@ -25,7 +25,6 @@
 #include "amdgpu_gfx.h"
 #include "mes_userqueue.h"
 #include "amdgpu_userq_fence.h"
-#include <linux/pm_runtime.h>
 
 #define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE
 #define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
@@ -313,12 +312,6 @@ 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 < 0) {
-		dev_err(adev->dev, "pm_runtime_get_sync() failed for userqueue mqd create\n");
-		goto deference_pm;
-	}
-
 	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");
@@ -346,9 +339,6 @@ 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);
-deference_pm:
-	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
 free_props:
 	kfree(userq_props);
@@ -360,14 +350,9 @@ static void
 mes_userq_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr,
 		      struct amdgpu_usermode_queue *queue)
 {
-	struct amdgpu_device *adev = uq_mgr->adev;
-
 	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);
 }
 
 const struct amdgpu_userq_funcs userq_mes_funcs = {
Signature · 1 line
2.49.0
#1 lore raw
Quoted 61 lines · Alex Deucher

Pull it out of the MES code and into the generic code. It's not MES specific and needs to be applied to all user queues regardless of the backend.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 13 +++++++++++++
  drivers/gpu/drm/amd/amdgpu/mes_userqueue.c    | 15 ---------------
  2 files changed, 13 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +13 -0
index 98e1ed794c346..08a94822eb17c 100644
@@ -24,6 +24,8 @@
 
  #include <drm/drm_auth.h>
  #include <drm/drm_exec.h>
+#include <linux/pm_runtime.h>
+
  #include "amdgpu.h"
  #include "amdgpu_vm.h"
  #include "amdgpu_userqueue.h"
@@ -258,6 +260,10 @@ amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)
  	amdgpu_bo_unref(&queue->db_obj.obj);
  	amdgpu_userqueue_cleanup(uq_mgr, queue, queue_id);
  	mutex_unlock(&uq_mgr->userq_mutex);
+
+	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
+	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
+
  	return r;
  }
 
@@ -311,6 +317,13 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
  		return -EINVAL;
  	}
 
+	r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
+	if (r < 0) {
+		dev_err(adev->dev, "pm_runtime_get_sync() failed for userqueue mqd create\n");
+		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
+		return r;
+	}
+
  	/*
  	 * There could be a situation that we are creating a new queue while
  	 * the other queues under this UQ_mgr are suspended. So if there is any
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0 -1
index e175f05bba6a9..b3157df8ae107 100644
@@ -25,7 +25,6 @@
  #include "amdgpu_gfx.h"
  #include "mes_userqueue.h"
  #include "amdgpu_userq_fence.h"
-#include <linux/pm_runtime.h>
 
  #define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE
  #define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, · line 318

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0 -3
@@ -313,12 +312,6 @@ 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 < 0) {
-		dev_err(adev->dev, "pm_runtime_get_sync() failed for userqueue mqd create\n");

We should update the comment "pm_runtime_get_sync() failed for userqueue create". With that change its reviewed. Reviewed-by: Sunil Khatri <[email protected]> Regards Sunil Khatri

Quoted 31 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0 -11
-		goto deference_pm;
-	}
-
  	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");
@@ -346,9 +339,6 @@ 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);
-deference_pm:
-	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
  free_props:
  	kfree(userq_props);
@@ -360,14 +350,9 @@ static void
  mes_userq_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr,
  		      struct amdgpu_usermode_queue *queue)
  {
-	struct amdgpu_device *adev = uq_mgr->adev;
-
  	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);
  }
 
  const struct amdgpu_userq_funcs userq_mes_funcs = {
Reviewed-by on v1 1/1
#2 lore raw
In reply to Alex Deucher

[AMD Official Use Only - AMD Internal Distribution Only]

Looks good to me .

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Sunday, April 13, 2025 2:24 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: [PATCH] drm/amdgpu/userq: move runpm handling into core userq code

Pull it out of the MES code and into the generic code.
It's not MES specific and needs to be applied to all user queues regardless of the backend.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 13 +++++++++++++
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c    | 15 ---------------
 2 files changed, 13 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +13 -0
index 98e1ed794c346..08a94822eb17c 100644
@@ -24,6 +24,8 @@
 
 #include <drm/drm_auth.h>
 #include <drm/drm_exec.h>
+#include <linux/pm_runtime.h>
+
 #include "amdgpu.h"
 #include "amdgpu_vm.h"
 #include "amdgpu_userqueue.h"
@@ -258,6 +260,10 @@ amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)
        amdgpu_bo_unref(&queue->db_obj.obj);
        amdgpu_userqueue_cleanup(uq_mgr, queue, queue_id);
        mutex_unlock(&uq_mgr->userq_mutex);
+
+       pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
+       pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
+
        return r;
 }
 
@@ -311,6 +317,13 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
                return -EINVAL;
        }
 
+       r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
+       if (r < 0) {
+               dev_err(adev->dev, "pm_runtime_get_sync() failed for userqueue mqd create\n");
+               pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
+               return r;
+       }
+
        /*
         * There could be a situation that we are creating a new queue while
         * the other queues under this UQ_mgr are suspended. So if there is any diff --git a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c

index e175f05bba6a9..b3157df8ae107 100644

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0 -1
@@ -25,7 +25,6 @@
 #include "amdgpu_gfx.h"
 #include "mes_userqueue.h"
 #include "amdgpu_userq_fence.h"
-#include <linux/pm_runtime.h>
 
 #define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE  #define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE @@ -313,12 +312,6 @@ 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 < 0) {
- dev_err(adev->dev, "pm_runtime_get_sync() failed for userqueue mqd create\n");
- goto deference_pm;
- }
-

        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"); @@ -346,9 +339,6 @@ 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);
-deference_pm:
- pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);

free_props:

        kfree(userq_props);
@@ -360,14 +350,9 @@ static void
 mes_userq_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr,
                      struct amdgpu_usermode_queue *queue)  {
-       struct amdgpu_device *adev = uq_mgr->adev;
-
        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);
}

const struct amdgpu_userq_funcs userq_mes_funcs = {
--
2.49.0