Skip to contentSkip to conversation

drm/amdgpu/userq: rename suspend/resume callbacks

PATCH In review Alex Deucher 3 participants 15 messages Apr 10, 2025 – Apr 11, 2025

Subsystems (2)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/9 drm/amdgpu/userq: rename suspend/resume callbacks

Rename to map and umap to better align with what is happening at the firmware level and remove the extra level of indirection in the MES userq code.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 10 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h |  8 ++--
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c    | 46 ++++++-------------
 3 files changed, 23 insertions(+), 41 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +5 -5
index ecd49cf15b2a9..2be1e54b78997 100644
@@ -432,11 +432,11 @@ amdgpu_userqueue_resume_all(struct amdgpu_userq_mgr *uq_mgr)
 	/* Resume all the queues for this process */
 	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);
+		ret = userq_funcs->map(uq_mgr, queue);
 	}
 
 	if (ret)
-		DRM_ERROR("Failed to resume all the queue\n");
+		DRM_ERROR("Failed to map all the queues\n");
 	return ret;
 }
 
@@ -587,14 +587,14 @@ amdgpu_userqueue_suspend_all(struct amdgpu_userq_mgr *uq_mgr)
 	int queue_id;
 	int ret = 0;
 
-	/* Try to suspend all the queues in this process ctx */
+	/* Try to unmap all the queues in this process ctx */
 	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);
+		ret += userq_funcs->unmap(uq_mgr, queue);
 	}
 
 	if (ret)
-		DRM_ERROR("Couldn't suspend all the queues\n");
+		DRM_ERROR("Couldn't unmap all the queues\n");
 	return ret;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h +4 -4
index ec1a4ca6f6321..a0cf6978f2ba8 100644
@@ -64,10 +64,10 @@ struct amdgpu_userq_funcs {
 			  struct amdgpu_usermode_queue *queue);
 	void (*mqd_destroy)(struct amdgpu_userq_mgr *uq_mgr,
 			    struct amdgpu_usermode_queue *uq);
-	int (*suspend)(struct amdgpu_userq_mgr *uq_mgr,
-		       struct amdgpu_usermode_queue *queue);
-	int (*resume)(struct amdgpu_userq_mgr *uq_mgr,
-		      struct amdgpu_usermode_queue *queue);
+	int (*unmap)(struct amdgpu_userq_mgr *uq_mgr,
+		     struct amdgpu_usermode_queue *queue);
+	int (*map)(struct amdgpu_userq_mgr *uq_mgr,
+		   struct amdgpu_usermode_queue *queue);
 };
 
 /* Usermode queues for gfx */
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +14 -32

89 lines not on this page · raw message

Signature · 1 line
2.49.0
author maintainer
#1 lore raw

PATCH 2/9 drm/amdgpu/userq: rework front end call sequence

Split out the queue map from the mqd create call and split out the queue unmap from the mqd destroy call. This splits the queue setup and teardown with the actual enablement in the firmware.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 17 +++++++++++++++--
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c    | 10 ----------
 2 files changed, 15 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +15 -2
index 2be1e54b78997..c3873041ec942 100644
@@ -263,7 +263,10 @@ amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)
 {
 	struct amdgpu_fpriv *fpriv = filp->driver_priv;
 	struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;
+	struct amdgpu_device *adev = uq_mgr->adev;
+	const struct amdgpu_userq_funcs *uq_funcs;
 	struct amdgpu_usermode_queue *queue;
+	int r;
 
 	cancel_delayed_work(&uq_mgr->resume_work);
 	mutex_lock(&uq_mgr->userq_mutex);
@@ -274,12 +277,13 @@ amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)
 		mutex_unlock(&uq_mgr->userq_mutex);
 		return -EINVAL;
 	}
-
+	uq_funcs = adev->userq_funcs[queue->queue_type];
+	r = uq_funcs->unmap(uq_mgr, queue);
 	amdgpu_bo_unpin(queue->db_obj.obj);
 	amdgpu_bo_unref(&queue->db_obj.obj);
 	amdgpu_userqueue_cleanup(uq_mgr, queue, queue_id);
 	mutex_unlock(&uq_mgr->userq_mutex);
-	return 0;
+	return r;
 }
 
 static int
@@ -364,6 +368,15 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 		r = -ENOMEM;
 		goto unlock;
 	}
+
+	r = uq_funcs->map(uq_mgr, queue);
+	if (r) {
+		DRM_ERROR("Failed to map Queue\n");
+		uq_funcs->mqd_destroy(uq_mgr, queue);
+		kfree(queue);
+		goto unlock;
+	}
+
 	args->out.queue_id = qid;
 
 unlock:
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0 -10
index 94fee99bd2a08..abd32415d7343 100644
@@ -321,13 +321,6 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
 		goto free_ctx;
 	}
 
-	/* Map userqueue into FW using MES */
-	r = mes_userq_map(uq_mgr, queue);
-	if (r) {
-		DRM_ERROR("Failed to init MQD\n");
-		goto free_ctx;
-	}
-
 	return 0;
 
 free_ctx:
@@ -351,9 +344,6 @@ mes_userq_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr,
 {
 	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);
Signature · 1 line
2.49.0
Reviewed-by Sunil Khatri on v1 2/9
#2 lore raw

Re: [PATCH 2/9] drm/amdgpu/userq: rework front end call sequence

Quoted 86 lines · Alex Deucher

Split out the queue map from the mqd create call and split out the queue unmap from the mqd destroy call. This splits the queue setup and teardown with the actual enablement in the firmware.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 17 +++++++++++++++--
  drivers/gpu/drm/amd/amdgpu/mes_userqueue.c    | 10 ----------
  2 files changed, 15 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +15 -2
index 2be1e54b78997..c3873041ec942 100644
@@ -263,7 +263,10 @@ amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)
  {
  	struct amdgpu_fpriv *fpriv = filp->driver_priv;
  	struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;
+	struct amdgpu_device *adev = uq_mgr->adev;
+	const struct amdgpu_userq_funcs *uq_funcs;
  	struct amdgpu_usermode_queue *queue;
+	int r;
 
  	cancel_delayed_work(&uq_mgr->resume_work);
  	mutex_lock(&uq_mgr->userq_mutex);
@@ -274,12 +277,13 @@ amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)
  		mutex_unlock(&uq_mgr->userq_mutex);
  		return -EINVAL;
  	}
-
+	uq_funcs = adev->userq_funcs[queue->queue_type];
+	r = uq_funcs->unmap(uq_mgr, queue);
  	amdgpu_bo_unpin(queue->db_obj.obj);
  	amdgpu_bo_unref(&queue->db_obj.obj);
  	amdgpu_userqueue_cleanup(uq_mgr, queue, queue_id);
  	mutex_unlock(&uq_mgr->userq_mutex);
-	return 0;
+	return r;
  }
 
  static int
@@ -364,6 +368,15 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
  		r = -ENOMEM;
  		goto unlock;
  	}
+
+	r = uq_funcs->map(uq_mgr, queue);
+	if (r) {
+		DRM_ERROR("Failed to map Queue\n");
+		uq_funcs->mqd_destroy(uq_mgr, queue);
+		kfree(queue);
+		goto unlock;
+	}
+
  	args->out.queue_id = qid;
 
  unlock:
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0 -10
index 94fee99bd2a08..abd32415d7343 100644
@@ -321,13 +321,6 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
  		goto free_ctx;
  	}
 
-	/* Map userqueue into FW using MES */
-	r = mes_userq_map(uq_mgr, queue);
-	if (r) {
-		DRM_ERROR("Failed to init MQD\n");
-		goto free_ctx;
-	}
-
  	return 0;
 
  free_ctx:
@@ -351,9 +344,6 @@ mes_userq_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr,
  {
  	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);
author maintainer
#3 lore raw

PATCH 3/9 drm/amdgpu/userq: move some code around

In reply to Alex Deucher

Move some userq fence handling code into amdgpu_userq_fence.c. This matches the other code in that file.

---
 .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c   | 26 +++++++++++++++++++
 .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.h   |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 26 -------------------
 3 files changed, 27 insertions(+), 26 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +26 -0
index a4953d668972a..ee73d7846c2ca 100644
@@ -120,6 +120,32 @@ int amdgpu_userq_fence_driver_alloc(struct amdgpu_device *adev,
 	return r;
 }
 
+static void amdgpu_userq_walk_and_drop_fence_drv(struct xarray *xa)
+{
+	struct amdgpu_userq_fence_driver *fence_drv;
+	unsigned long index;
+
+	if (xa_empty(xa))
+		return;
+
+	xa_lock(xa);
+	xa_for_each(xa, index, fence_drv) {
+		__xa_erase(xa, index);
+		amdgpu_userq_fence_driver_put(fence_drv);
+	}
+
+	xa_unlock(xa);
+}
+
+void
+amdgpu_userq_fence_driver_free(struct amdgpu_usermode_queue *userq)
+{
+	amdgpu_userq_walk_and_drop_fence_drv(&userq->fence_drv_xa);
+	xa_destroy(&userq->fence_drv_xa);
+	/* Drop the fence_drv reference held by user queue */
+	amdgpu_userq_fence_driver_put(userq->fence_drv);
+}
+
 void amdgpu_userq_fence_driver_process(struct amdgpu_userq_fence_driver *fence_drv)
 {
 	struct amdgpu_userq_fence *userq_fence, *tmp;
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.h +1 -0
index f0a91cc028808..7bbae238cca0b 100644
@@ -66,6 +66,7 @@ void amdgpu_userq_fence_driver_get(struct amdgpu_userq_fence_driver *fence_drv);
 void amdgpu_userq_fence_driver_put(struct amdgpu_userq_fence_driver *fence_drv);
 int amdgpu_userq_fence_driver_alloc(struct amdgpu_device *adev,
 				    struct amdgpu_usermode_queue *userq);
+void amdgpu_userq_fence_driver_free(struct amdgpu_usermode_queue *userq);
 void amdgpu_userq_fence_driver_process(struct amdgpu_userq_fence_driver *fence_drv);
 void amdgpu_userq_fence_driver_destroy(struct kref *ref);
 int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +0 -26
index c3873041ec942..79f4df4255c50 100644
@@ -28,32 +28,6 @@
 #include "amdgpu_userqueue.h"
 #include "amdgpu_userq_fence.h"
 
-static void amdgpu_userq_walk_and_drop_fence_drv(struct xarray *xa)
-{
-	struct amdgpu_userq_fence_driver *fence_drv;
-	unsigned long index;
-
-	if (xa_empty(xa))
-		return;
-
-	xa_lock(xa);
-	xa_for_each(xa, index, fence_drv) {
-		__xa_erase(xa, index);
-		amdgpu_userq_fence_driver_put(fence_drv);
-	}
-
-	xa_unlock(xa);
-}
-
-static void
-amdgpu_userq_fence_driver_free(struct amdgpu_usermode_queue *userq)
-{
-	amdgpu_userq_walk_and_drop_fence_drv(&userq->fence_drv_xa);
-	xa_destroy(&userq->fence_drv_xa);
-	/* Drop the fence_drv reference held by user queue */
-	amdgpu_userq_fence_driver_put(userq->fence_drv);
-}
-
 static void
 amdgpu_userqueue_cleanup(struct amdgpu_userq_mgr *uq_mgr,
 			 struct amdgpu_usermode_queue *queue,
Signature · 1 line
2.49.0
Reviewed-by Sunil Khatri on v1 3/9
#4 lore raw

Re: [PATCH 3/9] drm/amdgpu/userq: move some code around

Quoted 96 lines · Alex Deucher

Move some userq fence handling code into amdgpu_userq_fence.c. This matches the other code in that file.

---
  .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c   | 26 +++++++++++++++++++
  .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.h   |  1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 26 -------------------
  3 files changed, 27 insertions(+), 26 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +26 -0
index a4953d668972a..ee73d7846c2ca 100644
@@ -120,6 +120,32 @@ int amdgpu_userq_fence_driver_alloc(struct amdgpu_device *adev,
  	return r;
  }
 
+static void amdgpu_userq_walk_and_drop_fence_drv(struct xarray *xa)
+{
+	struct amdgpu_userq_fence_driver *fence_drv;
+	unsigned long index;
+
+	if (xa_empty(xa))
+		return;
+
+	xa_lock(xa);
+	xa_for_each(xa, index, fence_drv) {
+		__xa_erase(xa, index);
+		amdgpu_userq_fence_driver_put(fence_drv);
+	}
+
+	xa_unlock(xa);
+}
+
+void
+amdgpu_userq_fence_driver_free(struct amdgpu_usermode_queue *userq)
+{
+	amdgpu_userq_walk_and_drop_fence_drv(&userq->fence_drv_xa);
+	xa_destroy(&userq->fence_drv_xa);
+	/* Drop the fence_drv reference held by user queue */
+	amdgpu_userq_fence_driver_put(userq->fence_drv);
+}
+
  void amdgpu_userq_fence_driver_process(struct amdgpu_userq_fence_driver *fence_drv)
  {
  	struct amdgpu_userq_fence *userq_fence, *tmp;
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.h +1 -0
index f0a91cc028808..7bbae238cca0b 100644
@@ -66,6 +66,7 @@ void amdgpu_userq_fence_driver_get(struct amdgpu_userq_fence_driver *fence_drv);
  void amdgpu_userq_fence_driver_put(struct amdgpu_userq_fence_driver *fence_drv);
  int amdgpu_userq_fence_driver_alloc(struct amdgpu_device *adev,
  				    struct amdgpu_usermode_queue *userq);
+void amdgpu_userq_fence_driver_free(struct amdgpu_usermode_queue *userq);
  void amdgpu_userq_fence_driver_process(struct amdgpu_userq_fence_driver *fence_drv);
  void amdgpu_userq_fence_driver_destroy(struct kref *ref);
  int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +0 -26
index c3873041ec942..79f4df4255c50 100644
@@ -28,32 +28,6 @@
  #include "amdgpu_userqueue.h"
  #include "amdgpu_userq_fence.h"
 
-static void amdgpu_userq_walk_and_drop_fence_drv(struct xarray *xa)
-{
-	struct amdgpu_userq_fence_driver *fence_drv;
-	unsigned long index;
-
-	if (xa_empty(xa))
-		return;
-
-	xa_lock(xa);
-	xa_for_each(xa, index, fence_drv) {
-		__xa_erase(xa, index);
-		amdgpu_userq_fence_driver_put(fence_drv);
-	}
-
-	xa_unlock(xa);
-}
-
-static void
-amdgpu_userq_fence_driver_free(struct amdgpu_usermode_queue *userq)
-{
-	amdgpu_userq_walk_and_drop_fence_drv(&userq->fence_drv_xa);
-	xa_destroy(&userq->fence_drv_xa);
-	/* Drop the fence_drv reference held by user queue */
-	amdgpu_userq_fence_driver_put(userq->fence_drv);
-}
-
  static void
  amdgpu_userqueue_cleanup(struct amdgpu_userq_mgr *uq_mgr,
  			 struct amdgpu_usermode_queue *queue,
author maintainer
#5 lore raw

PATCH 4/9 drm/amdgpu/userq: properly clean up userq fence driver on failure

In reply to Alex Deucher

If userq creation fails, we need to properly unwind and free the user queue fence driver.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +3 -0
index 79f4df4255c50..6157258092cef 100644
@@ -330,6 +330,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 	r = uq_funcs->mqd_create(uq_mgr, &args->in, queue);
 	if (r) {
 		DRM_ERROR("Failed to create Queue\n");
+		amdgpu_userq_fence_driver_free(queue);
 		kfree(queue);
 		goto unlock;
 	}
@@ -337,6 +338,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 	qid = idr_alloc(&uq_mgr->userq_idr, queue, 1, AMDGPU_MAX_USERQ_COUNT, GFP_KERNEL);
 	if (qid < 0) {
 		DRM_ERROR("Failed to allocate a queue id\n");
+		amdgpu_userq_fence_driver_free(queue);
 		uq_funcs->mqd_destroy(uq_mgr, queue);
 		kfree(queue);
 		r = -ENOMEM;
@@ -346,6 +348,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 	r = uq_funcs->map(uq_mgr, queue);
 	if (r) {
 		DRM_ERROR("Failed to map Queue\n");
+		amdgpu_userq_fence_driver_free(queue);
 		uq_funcs->mqd_destroy(uq_mgr, queue);
 		kfree(queue);
 		goto unlock;
Signature · 1 line
2.49.0
#6 lore raw

Re: [PATCH 4/9] drm/amdgpu/userq: properly clean up userq fence driver on failure

Quoted 29 lines · Alex Deucher

If userq creation fails, we need to properly unwind and free the user queue fence driver.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +2 -0
index 79f4df4255c50..6157258092cef 100644
@@ -330,6 +330,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
  	r = uq_funcs->mqd_create(uq_mgr, &args->in, queue);
  	if (r) {
  		DRM_ERROR("Failed to create Queue\n");
+		amdgpu_userq_fence_driver_free(queue);
  		kfree(queue);
  		goto unlock;
  	}
@@ -337,6 +338,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
  	qid = idr_alloc(&uq_mgr->userq_idr, queue, 1, AMDGPU_MAX_USERQ_COUNT, GFP_KERNEL);
  	if (qid < 0) {
  		DRM_ERROR("Failed to allocate a queue id\n");
+		amdgpu_userq_fence_driver_free(queue);
  		uq_funcs->mqd_destroy(uq_mgr, queue);
  		kfree(queue);
  		r = -ENOMEM;

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args) · line 352

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +1 -0
@@ -346,6 +348,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
  	r = uq_funcs->map(uq_mgr, queue);
  	if (r) {
  		DRM_ERROR("Failed to map Queue\n");
+		amdgpu_userq_fence_driver_free(queue);
  		uq_funcs->mqd_destroy(uq_mgr, queue);

We should have an idr_remove too added here.

regards
Sunil Khatri

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +0 -0
  		kfree(queue);
  		goto unlock;
author maintainer
#7 lore raw

PATCH 5/9 drm/amdgpu/userq: add suspend and resume helpers

In reply to Alex Deucher

Add helpers to unmap and map user queues on suspend and resume.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 39 +++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h |  3 ++
 2 files changed, 42 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +39 -0
index 6157258092cef..48e2df6bdf63f 100644
@@ -680,3 +680,42 @@ void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr)
 	mutex_unlock(&userq_mgr->userq_mutex);
 	mutex_destroy(&userq_mgr->userq_mutex);
 }
+
+int amdgpu_userq_suspend(struct amdgpu_device *adev)
+{
+	const struct amdgpu_userq_funcs *userq_funcs;
+	struct amdgpu_usermode_queue *queue;
+	struct amdgpu_userq_mgr *uqm, *tmp;
+	int queue_id;
+	int ret = 0;
+
+	mutex_lock(&adev->userq_mutex);
+	list_for_each_entry_safe(uqm, tmp, &adev->userq_mgr_list, list) {
+		cancel_delayed_work_sync(&uqm->resume_work);
+		idr_for_each_entry(&uqm->userq_idr, queue, queue_id) {
+			userq_funcs = adev->userq_funcs[queue->queue_type];
+			ret |= userq_funcs->unmap(uqm, queue);
+		}
+	}
+	mutex_unlock(&adev->userq_mutex);
+	return ret;
+}
+
+int amdgpu_userq_resume(struct amdgpu_device *adev)
+{
+	const struct amdgpu_userq_funcs *userq_funcs;
+	struct amdgpu_usermode_queue *queue;
+	struct amdgpu_userq_mgr *uqm, *tmp;
+	int queue_id;
+	int ret = 0;
+
+	mutex_lock(&adev->userq_mutex);
+	list_for_each_entry_safe(uqm, tmp, &adev->userq_mgr_list, list) {
+		idr_for_each_entry(&uqm->userq_idr, queue, queue_id) {
+			userq_funcs = adev->userq_funcs[queue->queue_type];
+			ret |= userq_funcs->map(uqm, queue);
+		}
+	}
+	mutex_unlock(&adev->userq_mutex);
+	return ret;
+}
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h +3 -0
index a0cf6978f2ba8..381b9c6f0573d 100644
@@ -111,4 +111,7 @@ uint64_t amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,
 					     struct amdgpu_db_info *db_info,
 					     struct drm_file *filp);
 
+int amdgpu_userq_suspend(struct amdgpu_device *adev);
+int amdgpu_userq_resume(struct amdgpu_device *adev);
+
 #endif
Signature · 1 line
2.49.0
author maintainer
#8 lore raw

PATCH 6/9 drm/amdgpu/userq: handle system suspend and resume

In reply to Alex Deucher

Unmap user queues on suspend and map them on resume.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +13 -1
index 6fb234832ff3e..4e1c97a919cec 100644
@@ -3489,6 +3489,9 @@ static int amdgpu_device_ip_fini_early(struct amdgpu_device *adev)
 	amdgpu_device_set_cg_state(adev, AMD_CG_STATE_UNGATE);
 
 	amdgpu_amdkfd_suspend(adev, false);
+#ifdef CONFIG_DRM_AMDGPU_NAVI3X_USERQ
+	amdgpu_userq_suspend(adev);
+#endif
 
 	/* Workaround for ASICs need to disable SMC first */
 	amdgpu_device_smu_fini_early(adev);
@@ -5057,8 +5060,12 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients)
 
 	amdgpu_device_ip_suspend_phase1(adev);
 
-	if (!adev->in_s0ix)
+	if (!adev->in_s0ix) {
 		amdgpu_amdkfd_suspend(adev, adev->in_runpm);
+#ifdef CONFIG_DRM_AMDGPU_NAVI3X_USERQ
+		amdgpu_userq_suspend(adev);
+#endif
+	}
 
 	r = amdgpu_device_evict_resources(adev);
 	if (r)
@@ -5125,6 +5132,11 @@ int amdgpu_device_resume(struct drm_device *dev, bool notify_clients)
 		r = amdgpu_amdkfd_resume(adev, adev->in_runpm);
 		if (r)
 			goto exit;
+#ifdef CONFIG_DRM_AMDGPU_NAVI3X_USERQ
+		r = amdgpu_userq_resume(adev);
+		if (r)
+			goto exit;
+#endif
 	}
 
 	r = amdgpu_device_ip_late_init(adev);
Signature · 1 line
2.49.0
author maintainer
#9 lore raw

PATCH 7/9 drm/amdgpu: don't swallow errors in amdgpu_userqueue_resume_all()

In reply to Alex Deucher

since we loop through the queues |= the errors.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +1 -1
index 48e2df6bdf63f..09c2b01955c58 100644
@@ -422,7 +422,7 @@ amdgpu_userqueue_resume_all(struct amdgpu_userq_mgr *uq_mgr)
 	/* Resume all the queues for this process */
 	idr_for_each_entry(&uq_mgr->userq_idr, queue, queue_id) {
 		userq_funcs = adev->userq_funcs[queue->queue_type];
-		ret = userq_funcs->map(uq_mgr, queue);
+		ret |= userq_funcs->map(uq_mgr, queue);
 	}
 
 	if (ret)
Signature · 1 line
2.49.0
author maintainer
#10 lore raw

PATCH 8/9 drm/amdgpu/userq: add helpers to start/stop scheduling

In reply to Alex Deucher

This will be used to stop/start user queue scheduling for example when switching between kernel and user queues when enforce isolation is enabled.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h           |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 66 +++++++++++++++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h |  3 +
 3 files changed, 63 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index bb5df7831308f..b818ad63dc84f 100644
@@ -1242,6 +1242,7 @@ struct amdgpu_device {
 
 	struct list_head		userq_mgr_list;
 	struct mutex                    userq_mutex;
+	bool                            userq_halt;
 };
 
 static inline uint32_t amdgpu_ip_version(const struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +59 -7

82 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h +3 -0
index 381b9c6f0573d..fd0542f60433b 100644
@@ -114,4 +114,7 @@ uint64_t amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,
 int amdgpu_userq_suspend(struct amdgpu_device *adev);
 int amdgpu_userq_resume(struct amdgpu_device *adev);
 
+int amdgpu_userq_stop_sched(struct amdgpu_device *adev, u32 idx);
+int amdgpu_userq_start_sched(struct amdgpu_device *adev, u32 idx);
+
 #endif
Signature · 1 line
2.49.0
author maintainer
#11 lore raw

PATCH 9/9 drm/amdgpu/userq: integrate with enforce isolation

In reply to Alex Deucher

Enforce isolation serializes access to the GFX IP. User queues are isolated in the MES scheduler, but we still need to serialize between kernel queues and user queues. For enforce isolation, group KGD user queues with KFD user queues.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c    | 34 ++++++++++++----------
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h    |  6 ++--
 3 files changed, 22 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
index 4e1c97a919cec..3c6679fce7c20 100644
@@ -4344,7 +4344,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 		amdgpu_sync_create(&adev->isolation[i].active);
 		amdgpu_sync_create(&adev->isolation[i].prev);
 	}
-	mutex_init(&adev->gfx.kfd_sch_mutex);
+	mutex_init(&adev->gfx.userq_sch_mutex);
 	mutex_init(&adev->gfx.workload_profile_mutex);
 	mutex_init(&adev->vcn.workload_profile_mutex);
 	mutex_init(&adev->userq_mutex);
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +18 -16
index a42ac1060fa92..e08323f601535 100644
@@ -1928,39 +1928,41 @@ void amdgpu_gfx_cleaner_shader_init(struct amdgpu_device *adev,
 static void amdgpu_gfx_kfd_sch_ctrl(struct amdgpu_device *adev, u32 idx,
 				    bool enable)
 {
-	mutex_lock(&adev->gfx.kfd_sch_mutex);
+	mutex_lock(&adev->gfx.userq_sch_mutex);
 
 	if (enable) {
 		/* If the count is already 0, it means there's an imbalance bug somewhere.
 		 * Note that the bug may be in a different caller than the one which triggers the
 		 * WARN_ON_ONCE.
 		 */
-		if (WARN_ON_ONCE(adev->gfx.kfd_sch_req_count[idx] == 0)) {
+		if (WARN_ON_ONCE(adev->gfx.userq_sch_req_count[idx] == 0)) {
 			dev_err(adev->dev, "Attempted to enable KFD scheduler when reference count is already zero\n");
 			goto unlock;
 		}
 
-		adev->gfx.kfd_sch_req_count[idx]--;
+		adev->gfx.userq_sch_req_count[idx]--;
 
-		if (adev->gfx.kfd_sch_req_count[idx] == 0 &&
-		    adev->gfx.kfd_sch_inactive[idx]) {
+		if (adev->gfx.userq_sch_req_count[idx] == 0 &&
+		    adev->gfx.userq_sch_inactive[idx]) {
 			schedule_delayed_work(&adev->gfx.enforce_isolation[idx].work,
 					      msecs_to_jiffies(adev->gfx.enforce_isolation_time[idx]));
 		}
 	} else {
-		if (adev->gfx.kfd_sch_req_count[idx] == 0) {
+		if (adev->gfx.userq_sch_req_count[idx] == 0) {
 			cancel_delayed_work_sync(&adev->gfx.enforce_isolation[idx].work);
-			if (!adev->gfx.kfd_sch_inactive[idx]) {
-				amdgpu_amdkfd_stop_sched(adev, idx);
-				adev->gfx.kfd_sch_inactive[idx] = true;
+			if (!adev->gfx.userq_sch_inactive[idx]) {
+				amdgpu_userq_stop_sched(adev, idx);
+				if (adev->kfd.init_complete)
+					amdgpu_amdkfd_stop_sched(adev, idx);
+				adev->gfx.userq_sch_inactive[idx] = true;
 			}
 		}
 
-		adev->gfx.kfd_sch_req_count[idx]++;
+		adev->gfx.userq_sch_req_count[idx]++;
 	}
 
 unlock:
-	mutex_unlock(&adev->gfx.kfd_sch_mutex);
+	mutex_unlock(&adev->gfx.userq_sch_mutex);
 }
 
 /**
@@ -2005,12 +2007,12 @@ void amdgpu_gfx_enforce_isolation_handler(struct work_struct *work)
 				      msecs_to_jiffies(1));
 	} else {
 		/* Tell KFD to resume the runqueue */
-		if (adev->kfd.init_complete) {
-			WARN_ON_ONCE(!adev->gfx.kfd_sch_inactive[idx]);
-			WARN_ON_ONCE(adev->gfx.kfd_sch_req_count[idx]);
+		WARN_ON_ONCE(!adev->gfx.userq_sch_inactive[idx]);
+		WARN_ON_ONCE(adev->gfx.userq_sch_req_count[idx]);
+		amdgpu_userq_start_sched(adev, idx);
+		if (adev->kfd.init_complete)
 			amdgpu_amdkfd_start_sched(adev, idx);
-			adev->gfx.kfd_sch_inactive[idx] = false;
-		}
+		adev->gfx.userq_sch_inactive[idx] = false;
 	}
 	mutex_unlock(&adev->enforce_isolation_mutex);
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +3 -3
index caaddab31023f..70b64bb1847c9 100644
@@ -475,9 +475,9 @@ struct amdgpu_gfx {
 	bool				enable_cleaner_shader;
 	struct amdgpu_isolation_work	enforce_isolation[MAX_XCP];
 	/* Mutex for synchronizing KFD scheduler operations */
-	struct mutex                    kfd_sch_mutex;
-	u64				kfd_sch_req_count[MAX_XCP];
-	bool				kfd_sch_inactive[MAX_XCP];
+	struct mutex                    userq_sch_mutex;
+	u64				userq_sch_req_count[MAX_XCP];
+	bool				userq_sch_inactive[MAX_XCP];
 	unsigned long			enforce_isolation_jiffies[MAX_XCP];
 	unsigned long			enforce_isolation_time[MAX_XCP];
 
Signature · 1 line
2.49.0
Acked-by Sunil Khatri on v1 9/9
#12 lore raw

Re: [PATCH 9/9] drm/amdgpu/userq: integrate with enforce isolation

Are we replacing the kfx user queue with KGD userqueue names here? Also this looks like KFD user queue and KGD userqueue are both treated at par ?

Looks good in general if the above understanding is correct. Some one with better understanding of isolation should review.

Quoted 118 lines · Alex Deucher

Enforce isolation serializes access to the GFX IP. User queues are isolated in the MES scheduler, but we still need to serialize between kernel queues and user queues. For enforce isolation, group KGD user queues with KFD user queues.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c    | 34 ++++++++++++----------
  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h    |  6 ++--
  3 files changed, 22 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
index 4e1c97a919cec..3c6679fce7c20 100644
@@ -4344,7 +4344,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
  		amdgpu_sync_create(&adev->isolation[i].active);
  		amdgpu_sync_create(&adev->isolation[i].prev);
  	}
-	mutex_init(&adev->gfx.kfd_sch_mutex);
+	mutex_init(&adev->gfx.userq_sch_mutex);
  	mutex_init(&adev->gfx.workload_profile_mutex);
  	mutex_init(&adev->vcn.workload_profile_mutex);
  	mutex_init(&adev->userq_mutex);
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +18 -16
index a42ac1060fa92..e08323f601535 100644
@@ -1928,39 +1928,41 @@ void amdgpu_gfx_cleaner_shader_init(struct amdgpu_device *adev,
  static void amdgpu_gfx_kfd_sch_ctrl(struct amdgpu_device *adev, u32 idx,
  				    bool enable)
  {
-	mutex_lock(&adev->gfx.kfd_sch_mutex);
+	mutex_lock(&adev->gfx.userq_sch_mutex);
 
  	if (enable) {
  		/* If the count is already 0, it means there's an imbalance bug somewhere.
  		 * Note that the bug may be in a different caller than the one which triggers the
  		 * WARN_ON_ONCE.
  		 */
-		if (WARN_ON_ONCE(adev->gfx.kfd_sch_req_count[idx] == 0)) {
+		if (WARN_ON_ONCE(adev->gfx.userq_sch_req_count[idx] == 0)) {
  			dev_err(adev->dev, "Attempted to enable KFD scheduler when reference count is already zero\n");
  			goto unlock;
  		}
 
-		adev->gfx.kfd_sch_req_count[idx]--;
+		adev->gfx.userq_sch_req_count[idx]--;
 
-		if (adev->gfx.kfd_sch_req_count[idx] == 0 &&
-		    adev->gfx.kfd_sch_inactive[idx]) {
+		if (adev->gfx.userq_sch_req_count[idx] == 0 &&
+		    adev->gfx.userq_sch_inactive[idx]) {
  			schedule_delayed_work(&adev->gfx.enforce_isolation[idx].work,
  					      msecs_to_jiffies(adev->gfx.enforce_isolation_time[idx]));
  		}
  	} else {
-		if (adev->gfx.kfd_sch_req_count[idx] == 0) {
+		if (adev->gfx.userq_sch_req_count[idx] == 0) {
  			cancel_delayed_work_sync(&adev->gfx.enforce_isolation[idx].work);
-			if (!adev->gfx.kfd_sch_inactive[idx]) {
-				amdgpu_amdkfd_stop_sched(adev, idx);
-				adev->gfx.kfd_sch_inactive[idx] = true;
+			if (!adev->gfx.userq_sch_inactive[idx]) {
+				amdgpu_userq_stop_sched(adev, idx);
+				if (adev->kfd.init_complete)
+					amdgpu_amdkfd_stop_sched(adev, idx);
+				adev->gfx.userq_sch_inactive[idx] = true;
  			}
  		}
 
-		adev->gfx.kfd_sch_req_count[idx]++;
+		adev->gfx.userq_sch_req_count[idx]++;
  	}
 
  unlock:
-	mutex_unlock(&adev->gfx.kfd_sch_mutex);
+	mutex_unlock(&adev->gfx.userq_sch_mutex);
  }
 
  /**
@@ -2005,12 +2007,12 @@ void amdgpu_gfx_enforce_isolation_handler(struct work_struct *work)
  				      msecs_to_jiffies(1));
  	} else {
  		/* Tell KFD to resume the runqueue */
-		if (adev->kfd.init_complete) {
-			WARN_ON_ONCE(!adev->gfx.kfd_sch_inactive[idx]);
-			WARN_ON_ONCE(adev->gfx.kfd_sch_req_count[idx]);
+		WARN_ON_ONCE(!adev->gfx.userq_sch_inactive[idx]);
+		WARN_ON_ONCE(adev->gfx.userq_sch_req_count[idx]);
+		amdgpu_userq_start_sched(adev, idx);
+		if (adev->kfd.init_complete)
  			amdgpu_amdkfd_start_sched(adev, idx);
-			adev->gfx.kfd_sch_inactive[idx] = false;
-		}
+		adev->gfx.userq_sch_inactive[idx] = false;
  	}
  	mutex_unlock(&adev->enforce_isolation_mutex);
  }
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +3 -3
index caaddab31023f..70b64bb1847c9 100644
@@ -475,9 +475,9 @@ struct amdgpu_gfx {
  	bool				enable_cleaner_shader;
  	struct amdgpu_isolation_work	enforce_isolation[MAX_XCP];
  	/* Mutex for synchronizing KFD scheduler operations */
-	struct mutex                    kfd_sch_mutex;
-	u64				kfd_sch_req_count[MAX_XCP];
-	bool				kfd_sch_inactive[MAX_XCP];
+	struct mutex                    userq_sch_mutex;
+	u64				userq_sch_req_count[MAX_XCP];
+	bool				userq_sch_inactive[MAX_XCP];
  	unsigned long			enforce_isolation_jiffies[MAX_XCP];
  	unsigned long			enforce_isolation_time[MAX_XCP];
 
#13 lore raw

Re: [PATCH 9/9] drm/amdgpu/userq: integrate with enforce isolation

Quoted 4 lines · Sunil

Are we replacing the kfx user queue with KGD userqueue names here? Also this looks like KFD user queue and KGD userqueue are both treated at par ?

Yeah, I could split this into two patches, one to rename the variables because they are no longer KFD specific and then the change to add the new function calls for userqs.

Alex

Quoted 124 lines

Looks good in general if the above understanding is correct. Some one with better understanding of isolation should review.

Quoted 118 lines · Alex Deucher

Enforce isolation serializes access to the GFX IP. User queues are isolated in the MES scheduler, but we still need to serialize between kernel queues and user queues. For enforce isolation, group KGD user queues with KFD user queues.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c    | 34 ++++++++++++----------
  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h    |  6 ++--
  3 files changed, 22 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
index 4e1c97a919cec..3c6679fce7c20 100644
@@ -4344,7 +4344,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
              amdgpu_sync_create(&adev->isolation[i].active);
              amdgpu_sync_create(&adev->isolation[i].prev);
      }
-     mutex_init(&adev->gfx.kfd_sch_mutex);
+     mutex_init(&adev->gfx.userq_sch_mutex);
      mutex_init(&adev->gfx.workload_profile_mutex);
      mutex_init(&adev->vcn.workload_profile_mutex);
      mutex_init(&adev->userq_mutex);
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +18 -16
index a42ac1060fa92..e08323f601535 100644
@@ -1928,39 +1928,41 @@ void amdgpu_gfx_cleaner_shader_init(struct amdgpu_device *adev,
  static void amdgpu_gfx_kfd_sch_ctrl(struct amdgpu_device *adev, u32 idx,
                                  bool enable)
  {
-     mutex_lock(&adev->gfx.kfd_sch_mutex);
+     mutex_lock(&adev->gfx.userq_sch_mutex);
 
      if (enable) {
              /* If the count is already 0, it means there's an imbalance bug somewhere.
               * Note that the bug may be in a different caller than the one which triggers the
               * WARN_ON_ONCE.
               */
-             if (WARN_ON_ONCE(adev->gfx.kfd_sch_req_count[idx] == 0)) {
+             if (WARN_ON_ONCE(adev->gfx.userq_sch_req_count[idx] == 0)) {
                      dev_err(adev->dev, "Attempted to enable KFD scheduler when reference count is already zero\n");
                      goto unlock;
              }
 
-             adev->gfx.kfd_sch_req_count[idx]--;
+             adev->gfx.userq_sch_req_count[idx]--;
 
-             if (adev->gfx.kfd_sch_req_count[idx] == 0 &&
-                 adev->gfx.kfd_sch_inactive[idx]) {
+             if (adev->gfx.userq_sch_req_count[idx] == 0 &&
+                 adev->gfx.userq_sch_inactive[idx]) {
                      schedule_delayed_work(&adev->gfx.enforce_isolation[idx].work,
                                            msecs_to_jiffies(adev->gfx.enforce_isolation_time[idx]));
              }
      } else {
-             if (adev->gfx.kfd_sch_req_count[idx] == 0) {
+             if (adev->gfx.userq_sch_req_count[idx] == 0) {
                      cancel_delayed_work_sync(&adev->gfx.enforce_isolation[idx].work);
-                     if (!adev->gfx.kfd_sch_inactive[idx]) {
-                             amdgpu_amdkfd_stop_sched(adev, idx);
-                             adev->gfx.kfd_sch_inactive[idx] = true;
+                     if (!adev->gfx.userq_sch_inactive[idx]) {
+                             amdgpu_userq_stop_sched(adev, idx);
+                             if (adev->kfd.init_complete)
+                                     amdgpu_amdkfd_stop_sched(adev, idx);
+                             adev->gfx.userq_sch_inactive[idx] = true;
                      }
              }
 
-             adev->gfx.kfd_sch_req_count[idx]++;
+             adev->gfx.userq_sch_req_count[idx]++;
      }
 
  unlock:
-     mutex_unlock(&adev->gfx.kfd_sch_mutex);
+     mutex_unlock(&adev->gfx.userq_sch_mutex);
  }
 
  /**
@@ -2005,12 +2007,12 @@ void amdgpu_gfx_enforce_isolation_handler(struct work_struct *work)
                                    msecs_to_jiffies(1));
      } else {
              /* Tell KFD to resume the runqueue */
-             if (adev->kfd.init_complete) {
-                     WARN_ON_ONCE(!adev->gfx.kfd_sch_inactive[idx]);
-                     WARN_ON_ONCE(adev->gfx.kfd_sch_req_count[idx]);
+             WARN_ON_ONCE(!adev->gfx.userq_sch_inactive[idx]);
+             WARN_ON_ONCE(adev->gfx.userq_sch_req_count[idx]);
+             amdgpu_userq_start_sched(adev, idx);
+             if (adev->kfd.init_complete)
                      amdgpu_amdkfd_start_sched(adev, idx);
-                     adev->gfx.kfd_sch_inactive[idx] = false;
-             }
+             adev->gfx.userq_sch_inactive[idx] = false;
      }
      mutex_unlock(&adev->enforce_isolation_mutex);
  }
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +3 -3
index caaddab31023f..70b64bb1847c9 100644
@@ -475,9 +475,9 @@ struct amdgpu_gfx {
      bool                            enable_cleaner_shader;
      struct amdgpu_isolation_work    enforce_isolation[MAX_XCP];
      /* Mutex for synchronizing KFD scheduler operations */
-     struct mutex                    kfd_sch_mutex;
-     u64                             kfd_sch_req_count[MAX_XCP];
-     bool                            kfd_sch_inactive[MAX_XCP];
+     struct mutex                    userq_sch_mutex;
+     u64                             userq_sch_req_count[MAX_XCP];
+     bool                            userq_sch_inactive[MAX_XCP];
      unsigned long                   enforce_isolation_jiffies[MAX_XCP];
      unsigned long                   enforce_isolation_time[MAX_XCP];
 
Reviewed-by Sunil Khatri on v1 1/9
#14 lore raw
In reply to Alex Deucher
Quoted 164 lines · Alex Deucher

Rename to map and umap to better align with what is happening at the firmware level and remove the extra level of indirection in the MES userq code.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 10 ++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h |  8 ++--
  drivers/gpu/drm/amd/amdgpu/mes_userqueue.c    | 46 ++++++-------------
  3 files changed, 23 insertions(+), 41 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +5 -5
index ecd49cf15b2a9..2be1e54b78997 100644
@@ -432,11 +432,11 @@ amdgpu_userqueue_resume_all(struct amdgpu_userq_mgr *uq_mgr)
  	/* Resume all the queues for this process */
  	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);
+		ret = userq_funcs->map(uq_mgr, queue);
  	}
 
  	if (ret)
-		DRM_ERROR("Failed to resume all the queue\n");
+		DRM_ERROR("Failed to map all the queues\n");
  	return ret;
  }
 
@@ -587,14 +587,14 @@ amdgpu_userqueue_suspend_all(struct amdgpu_userq_mgr *uq_mgr)
  	int queue_id;
  	int ret = 0;
 
-	/* Try to suspend all the queues in this process ctx */
+	/* Try to unmap all the queues in this process ctx */
  	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);
+		ret += userq_funcs->unmap(uq_mgr, queue);
  	}
 
  	if (ret)
-		DRM_ERROR("Couldn't suspend all the queues\n");
+		DRM_ERROR("Couldn't unmap all the queues\n");
  	return ret;
  }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h +4 -4
index ec1a4ca6f6321..a0cf6978f2ba8 100644
@@ -64,10 +64,10 @@ struct amdgpu_userq_funcs {
  			  struct amdgpu_usermode_queue *queue);
  	void (*mqd_destroy)(struct amdgpu_userq_mgr *uq_mgr,
  			    struct amdgpu_usermode_queue *uq);
-	int (*suspend)(struct amdgpu_userq_mgr *uq_mgr,
-		       struct amdgpu_usermode_queue *queue);
-	int (*resume)(struct amdgpu_userq_mgr *uq_mgr,
-		      struct amdgpu_usermode_queue *queue);
+	int (*unmap)(struct amdgpu_userq_mgr *uq_mgr,
+		     struct amdgpu_usermode_queue *queue);
+	int (*map)(struct amdgpu_userq_mgr *uq_mgr,
+		   struct amdgpu_usermode_queue *queue);
  };
 
  /* Usermode queues for gfx */
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +14 -32
index b9705cbec74d2..94fee99bd2a08 100644
@@ -99,14 +99,17 @@ mes_userq_create_wptr_mapping(struct amdgpu_userq_mgr *uq_mgr,
  }
 
  static int mes_userq_map(struct amdgpu_userq_mgr *uq_mgr,
-			 struct amdgpu_usermode_queue *queue,
-			 struct amdgpu_mqd_prop *userq_props)
+			 struct amdgpu_usermode_queue *queue)
  {
  	struct amdgpu_device *adev = uq_mgr->adev;
  	struct amdgpu_userq_obj *ctx = &queue->fw_obj;
+	struct amdgpu_mqd_prop *userq_props = queue->userq_prop;
  	struct mes_add_queue_input queue_input;
  	int r;
 
+	if (queue->queue_active)
+		return 0;
+
  	memset(&queue_input, 0x0, sizeof(struct mes_add_queue_input));
 
  	queue_input.process_va_start = 0;
@@ -144,14 +147,17 @@ static int mes_userq_map(struct amdgpu_userq_mgr *uq_mgr,
  	return 0;
  }
 
-static void mes_userq_unmap(struct amdgpu_userq_mgr *uq_mgr,
-			    struct amdgpu_usermode_queue *queue)
+static int mes_userq_unmap(struct amdgpu_userq_mgr *uq_mgr,
+			   struct amdgpu_usermode_queue *queue)
  {
  	struct amdgpu_device *adev = uq_mgr->adev;
  	struct mes_remove_queue_input queue_input;
  	struct amdgpu_userq_obj *ctx = &queue->fw_obj;
  	int r;
 
+	if (!queue->queue_active)
+		return 0;
+
  	memset(&queue_input, 0x0, sizeof(struct mes_remove_queue_input));
  	queue_input.doorbell_offset = queue->doorbell_index;
  	queue_input.gang_context_addr = ctx->gpu_addr + AMDGPU_USERQ_PROC_CTX_SZ;
@@ -162,6 +168,7 @@ static void mes_userq_unmap(struct amdgpu_userq_mgr *uq_mgr,
  	if (r)
  		DRM_ERROR("Failed to unmap queue in HW, err (%d)\n", r);
  	queue->queue_active = false;
+	return r;
  }
 
  static int mes_userq_create_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
@@ -315,7 +322,7 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
  	}
 
  	/* Map userqueue into FW using MES */
-	r = mes_userq_map(uq_mgr, queue, userq_props);
+	r = mes_userq_map(uq_mgr, queue);
  	if (r) {
  		DRM_ERROR("Failed to init MQD\n");
  		goto free_ctx;
@@ -355,34 +362,9 @@ mes_userq_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr,
  	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
  }
 
-static int mes_userq_suspend(struct amdgpu_userq_mgr *uq_mgr,
-				   struct amdgpu_usermode_queue *queue)
-{
-	if (queue->queue_active)
-		mes_userq_unmap(uq_mgr, queue);
-
-	return 0;
-}
-
-static int mes_userq_resume(struct amdgpu_userq_mgr *uq_mgr,
-				  struct amdgpu_usermode_queue *queue)
-{
-	int ret;
-
-	if (queue->queue_active)
-		return 0;
-
-	ret = mes_userq_map(uq_mgr, queue, queue->userq_prop);
-	if (ret) {
-		DRM_ERROR("Failed to resume queue\n");
-		return ret;
-	}
-	return 0;
-}
-
  const struct amdgpu_userq_funcs userq_mes_funcs = {
  	.mqd_create = mes_userq_mqd_create,
  	.mqd_destroy = mes_userq_mqd_destroy,
-	.suspend = mes_userq_suspend,
-	.resume = mes_userq_resume,
+	.unmap = mes_userq_unmap,
+	.map = mes_userq_map,
  };