Skip to contentSkip to conversation

AMDGPU Usermode queues

PATCH Superseded Shashank Sharma 8 participants 56 messages Mar 29, 2023 – Apr 11, 2023 1 message not in the archive

Subsystems (3)

v3 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v3 cover AMDGPU Usermode queues

This patch series introduces AMDGPU usermode queues for gfx workloads. Usermode queues is a method of GPU workload submission into the graphics hardware without any interaction with kernel/DRM schedulers. In this method, a userspace graphics application can create its own workqueue and submit it directly in the GPU HW.

The general idea of how this is supposed to work:
- The application creates the following GPU objetcs:
- A queue object to hold the workload packets.
- A read pointer object.
- A write pointer object.
- A doorbell page.
- The application picks a 32-bit offset in the doorbell page for this queue.
- The application uses the usermode_queue_create IOCTL introduced in this patch, by passing the the GPU addresses of these objects (read ptr, write ptr, queue base address and 32-bit doorbell offset from the doorbell page)
- The kernel creates the queue and maps it in the HW.
- The application can start submitting the data in the queue as soon as the kernel IOCTL returns.
- After filling the workload data in the queue, the app must write the number of dwords added in the queue into the doorbell offset, and the GPU will start fetching the data.

libDRM changes for this series and a sample DRM test program can be found in the MESA merge request here:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/287

This patch series depends on the doorbell-manager changes, which are being reviewed here:
https://patchwork.freedesktop.org/series/115802/

Alex Deucher (1):
drm/amdgpu: UAPI for user queue management

Arvind Yadav (2):
drm/amdgpu: add new parameters in v11_struct
drm/amdgpu: map wptr BO into GART

Shashank Sharma (6):
drm/amdgpu: add usermode queue base code drm/amdgpu: add new IOCTL for usermode queue drm/amdgpu: create GFX-gen11 MQD for userqueue drm/amdgpu: create context space for usermode queue drm/amdgpu: map usermode queue into MES drm/amdgpu: generate doorbell index for userqueue

 drivers/gpu/drm/amd/amdgpu/Makefile           |   3 +
 drivers/gpu/drm/amd/amdgpu/amdgpu.h           |  10 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |   2 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |   6 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 298 ++++++++++++++++++
 .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 230 ++++++++++++++
 .../gpu/drm/amd/include/amdgpu_userqueue.h    |  66 ++++
 drivers/gpu/drm/amd/include/v11_structs.h     |  16 +-
 include/uapi/drm/amdgpu_drm.h                 |  55 ++++
 9 files changed, 677 insertions(+), 9 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c
 create mode 100644 drivers/gpu/drm/amd/include/amdgpu_userqueue.h
Signature · 1 line
2.40.0
#1 lore raw

PATCH v3 1/9 drm/amdgpu: UAPI for user queue management

From: Alex Deucher <[email protected]>

This patch intorduces new UAPI/IOCTL for usermode graphics queue. The userspace app will fill this structure and request the graphics driver to add a graphics work queue for it. The output of this UAPI is a queue id.

This UAPI maps the queue into GPU, so the graphics app can start submitting work to the queue as soon as the call returns.

V2: Addressed review comments from Alex and Christian
- Make the doorbell offset's comment clearer
- Change the output parameter name to queue_id
V3: Integration with doorbell manager

---
 include/uapi/drm/amdgpu_drm.h | 55 +++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
include/uapi/drm/amdgpu_drm.h +55 -0
index cc5d551abda5..e4943099b9d2 100644
@@ -54,6 +54,7 @@ extern "C" {
 #define DRM_AMDGPU_VM			0x13
 #define DRM_AMDGPU_FENCE_TO_HANDLE	0x14
 #define DRM_AMDGPU_SCHED		0x15
+#define DRM_AMDGPU_USERQ		0x16
 
 #define DRM_IOCTL_AMDGPU_GEM_CREATE	DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
 #define DRM_IOCTL_AMDGPU_GEM_MMAP	DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -71,6 +72,7 @@ extern "C" {
 #define DRM_IOCTL_AMDGPU_VM		DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_VM, union drm_amdgpu_vm)
 #define DRM_IOCTL_AMDGPU_FENCE_TO_HANDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FENCE_TO_HANDLE, union drm_amdgpu_fence_to_handle)
 #define DRM_IOCTL_AMDGPU_SCHED		DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_SCHED, union drm_amdgpu_sched)
+#define DRM_IOCTL_AMDGPU_USERQ		DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ, union drm_amdgpu_userq)
 
 /**
  * DOC: memory domains
@@ -307,6 +309,59 @@ union drm_amdgpu_ctx {
 	union drm_amdgpu_ctx_out out;
 };
 
+/* user queue IOCTL */
+#define AMDGPU_USERQ_OP_CREATE	1
+#define AMDGPU_USERQ_OP_FREE	2
+
+#define AMDGPU_USERQ_MQD_FLAGS_SECURE	(1 << 0)
+#define AMDGPU_USERQ_MQD_FLAGS_AQL	(1 << 1)
+
+struct drm_amdgpu_userq_mqd {
+	/** Flags: AMDGPU_USERQ_MQD_FLAGS_* */
+	__u32	flags;
+	/** IP type: AMDGPU_HW_IP_* */
+	__u32	ip_type;
+	/** GEM object handle */
+	__u32   doorbell_handle;
+	/** Doorbell's offset in the doorbell bo */
+	__u32   doorbell_offset;
+	/** GPU virtual address of the queue */
+	__u64   queue_va;
+	/** Size of the queue in bytes */
+	__u64   queue_size;
+	/** GPU virtual address of the rptr */
+	__u64   rptr_va;
+	/** GPU virtual address of the wptr */
+	__u64   wptr_va;
+	/** GPU virtual address of the shadow context space */
+	__u64	shadow_va;
+};
+
+struct drm_amdgpu_userq_in {
+	/** AMDGPU_USERQ_OP_* */
+	__u32	op;
+	/** Flags */
+	__u32	flags;
+	/** Queue handle to associate the queue free call with,
+	 * unused for queue create calls */
+	__u32	queue_id;
+	__u32	pad;
+	/** Queue descriptor */
+	struct drm_amdgpu_userq_mqd mqd;
+};
+
+struct drm_amdgpu_userq_out {
+	/** Queue handle */
+	__u32	queue_id;
+	/** Flags */
+	__u32	flags;
+};
+
+union drm_amdgpu_userq {
+	struct drm_amdgpu_userq_in in;
+	struct drm_amdgpu_userq_out out;
+};
+
 /* vm ioctl */
 #define AMDGPU_VM_OP_RESERVE_VMID	1
 #define AMDGPU_VM_OP_UNRESERVE_VMID	2
Signature · 1 line
2.40.0
maintainer Reviewed-by on v3 1/9
#2 lore raw

Re: [PATCH v3 1/9] drm/amdgpu: UAPI for user queue management

Am 29.03.23 um 18:04 schrieb Shashank Sharma:

Quoted 15 lines

From: Alex Deucher <[email protected]>

This patch intorduces new UAPI/IOCTL for usermode graphics queue. The userspace app will fill this structure and request the graphics driver to add a graphics work queue for it. The output of this UAPI is a queue id.

This UAPI maps the queue into GPU, so the graphics app can start submitting work to the queue as soon as the call returns.

V2: Addressed review comments from Alex and Christian
- Make the doorbell offset's comment clearer
- Change the output parameter name to queue_id
V3: Integration with doorbell manager

Quoted 4 lines
Quoted 84 lines
---
  include/uapi/drm/amdgpu_drm.h | 55 +++++++++++++++++++++++++++++++++++
  1 file changed, 55 insertions(+)
include/uapi/drm/amdgpu_drm.h +55 -0
index cc5d551abda5..e4943099b9d2 100644
@@ -54,6 +54,7 @@ extern "C" {
  #define DRM_AMDGPU_VM			0x13
  #define DRM_AMDGPU_FENCE_TO_HANDLE	0x14
  #define DRM_AMDGPU_SCHED		0x15
+#define DRM_AMDGPU_USERQ		0x16
 
  #define DRM_IOCTL_AMDGPU_GEM_CREATE	DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
  #define DRM_IOCTL_AMDGPU_GEM_MMAP	DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -71,6 +72,7 @@ extern "C" {
  #define DRM_IOCTL_AMDGPU_VM		DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_VM, union drm_amdgpu_vm)
  #define DRM_IOCTL_AMDGPU_FENCE_TO_HANDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FENCE_TO_HANDLE, union drm_amdgpu_fence_to_handle)
  #define DRM_IOCTL_AMDGPU_SCHED		DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_SCHED, union drm_amdgpu_sched)
+#define DRM_IOCTL_AMDGPU_USERQ		DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ, union drm_amdgpu_userq)
 
  /**
   * DOC: memory domains
@@ -307,6 +309,59 @@ union drm_amdgpu_ctx {
  	union drm_amdgpu_ctx_out out;
  };
 
+/* user queue IOCTL */
+#define AMDGPU_USERQ_OP_CREATE	1
+#define AMDGPU_USERQ_OP_FREE	2
+
+#define AMDGPU_USERQ_MQD_FLAGS_SECURE	(1 << 0)
+#define AMDGPU_USERQ_MQD_FLAGS_AQL	(1 << 1)
+
+struct drm_amdgpu_userq_mqd {
+	/** Flags: AMDGPU_USERQ_MQD_FLAGS_* */
+	__u32	flags;
+	/** IP type: AMDGPU_HW_IP_* */
+	__u32	ip_type;
+	/** GEM object handle */
+	__u32   doorbell_handle;
+	/** Doorbell's offset in the doorbell bo */
+	__u32   doorbell_offset;
+	/** GPU virtual address of the queue */
+	__u64   queue_va;
+	/** Size of the queue in bytes */
+	__u64   queue_size;
+	/** GPU virtual address of the rptr */
+	__u64   rptr_va;
+	/** GPU virtual address of the wptr */
+	__u64   wptr_va;
+	/** GPU virtual address of the shadow context space */
+	__u64	shadow_va;
+};
+
+struct drm_amdgpu_userq_in {
+	/** AMDGPU_USERQ_OP_* */
+	__u32	op;
+	/** Flags */
+	__u32	flags;
+	/** Queue handle to associate the queue free call with,
+	 * unused for queue create calls */
+	__u32	queue_id;
+	__u32	pad;
+	/** Queue descriptor */
+	struct drm_amdgpu_userq_mqd mqd;
+};
+
+struct drm_amdgpu_userq_out {
+	/** Queue handle */
+	__u32	queue_id;
+	/** Flags */
+	__u32	flags;
+};
+
+union drm_amdgpu_userq {
+	struct drm_amdgpu_userq_in in;
+	struct drm_amdgpu_userq_out out;
+};
+
  /* vm ioctl */
  #define AMDGPU_VM_OP_RESERVE_VMID	1
  #define AMDGPU_VM_OP_UNRESERVE_VMID	2
#3 lore raw

Re: [PATCH v3 1/9] drm/amdgpu: UAPI for user queue management

In reply to Shashank Sharma
Quoted 65 lines · Shashank Sharma

From: Alex Deucher <[email protected]>

This patch intorduces new UAPI/IOCTL for usermode graphics queue. The userspace app will fill this structure and request the graphics driver to add a graphics work queue for it. The output of this UAPI is a queue id.

This UAPI maps the queue into GPU, so the graphics app can start submitting work to the queue as soon as the call returns.

V2: Addressed review comments from Alex and Christian
- Make the doorbell offset's comment clearer
- Change the output parameter name to queue_id
V3: Integration with doorbell manager

---
 include/uapi/drm/amdgpu_drm.h | 55 +++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
include/uapi/drm/amdgpu_drm.h +19 -0
index cc5d551abda5..e4943099b9d2 100644
@@ -54,6 +54,7 @@ extern "C" {
 #define DRM_AMDGPU_VM                  0x13
 #define DRM_AMDGPU_FENCE_TO_HANDLE     0x14
 #define DRM_AMDGPU_SCHED               0x15
+#define DRM_AMDGPU_USERQ               0x16
 
 #define DRM_IOCTL_AMDGPU_GEM_CREATE    DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
 #define DRM_IOCTL_AMDGPU_GEM_MMAP      DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -71,6 +72,7 @@ extern "C" {
 #define DRM_IOCTL_AMDGPU_VM            DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_VM, union drm_amdgpu_vm)
 #define DRM_IOCTL_AMDGPU_FENCE_TO_HANDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FENCE_TO_HANDLE, union drm_amdgpu_fence_to_handle)
 #define DRM_IOCTL_AMDGPU_SCHED         DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_SCHED, union drm_amdgpu_sched)
+#define DRM_IOCTL_AMDGPU_USERQ         DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ, union drm_amdgpu_userq)
 
 /**
  * DOC: memory domains
@@ -307,6 +309,59 @@ union drm_amdgpu_ctx {
        union drm_amdgpu_ctx_out out;
 };
 
+/* user queue IOCTL */
+#define AMDGPU_USERQ_OP_CREATE 1
+#define AMDGPU_USERQ_OP_FREE   2
+
+#define AMDGPU_USERQ_MQD_FLAGS_SECURE  (1 << 0)
+#define AMDGPU_USERQ_MQD_FLAGS_AQL     (1 << 1)
+
+struct drm_amdgpu_userq_mqd {
+       /** Flags: AMDGPU_USERQ_MQD_FLAGS_* */
+       __u32   flags;
+       /** IP type: AMDGPU_HW_IP_* */
+       __u32   ip_type;
+       /** GEM object handle */
+       __u32   doorbell_handle;
+       /** Doorbell's offset in the doorbell bo */
+       __u32   doorbell_offset;
+       /** GPU virtual address of the queue */

include/uapi/drm/amdgpu_drm.h union drm_amdgpu_ctx { · line 338

Quoted 10 lines
include/uapi/drm/amdgpu_drm.h +10 -0
+       __u64   queue_va;
+       /** Size of the queue in bytes */
+       __u64   queue_size;
+       /** GPU virtual address of the rptr */
+       __u64   rptr_va;
+       /** GPU virtual address of the wptr */
+       __u64   wptr_va;
+       /** GPU virtual address of the shadow context space */
+       __u64   shadow_va;
+};

We may want to make the MQD engine specific. E.g., shadow is gfx specific. We also probably need the csa and gds buffers for gfx as well. Other engines may have their own additional buffer requirements.

Alex

Quoted 32 lines
include/uapi/drm/amdgpu_drm.h +26 -1
+
+struct drm_amdgpu_userq_in {
+       /** AMDGPU_USERQ_OP_* */
+       __u32   op;
+       /** Flags */
+       __u32   flags;
+       /** Queue handle to associate the queue free call with,
+        * unused for queue create calls */
+       __u32   queue_id;
+       __u32   pad;
+       /** Queue descriptor */
+       struct drm_amdgpu_userq_mqd mqd;
+};
+
+struct drm_amdgpu_userq_out {
+       /** Queue handle */
+       __u32   queue_id;
+       /** Flags */
+       __u32   flags;
+};
+
+union drm_amdgpu_userq {
+       struct drm_amdgpu_userq_in in;
+       struct drm_amdgpu_userq_out out;
+};
+
 /* vm ioctl */
 #define AMDGPU_VM_OP_RESERVE_VMID      1
 #define AMDGPU_VM_OP_UNRESERVE_VMID    2
--

2.40.0

#4 lore raw

Re: [PATCH v3 1/9] drm/amdgpu: UAPI for user queue management

Hey Alex,

Quoted 81 lines · Alex Deucher
Quoted 64 lines · Shashank Sharma

From: Alex Deucher <[email protected]>

This patch intorduces new UAPI/IOCTL for usermode graphics queue. The userspace app will fill this structure and request the graphics driver to add a graphics work queue for it. The output of this UAPI is a queue id.

This UAPI maps the queue into GPU, so the graphics app can start submitting work to the queue as soon as the call returns.

V2: Addressed review comments from Alex and Christian
- Make the doorbell offset's comment clearer
- Change the output parameter name to queue_id
V3: Integration with doorbell manager

---
  include/uapi/drm/amdgpu_drm.h | 55 +++++++++++++++++++++++++++++++++++
  1 file changed, 55 insertions(+)
include/uapi/drm/amdgpu_drm.h +19 -0
index cc5d551abda5..e4943099b9d2 100644
@@ -54,6 +54,7 @@ extern "C" {
  #define DRM_AMDGPU_VM                  0x13
  #define DRM_AMDGPU_FENCE_TO_HANDLE     0x14
  #define DRM_AMDGPU_SCHED               0x15
+#define DRM_AMDGPU_USERQ               0x16
 
  #define DRM_IOCTL_AMDGPU_GEM_CREATE    DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
  #define DRM_IOCTL_AMDGPU_GEM_MMAP      DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -71,6 +72,7 @@ extern "C" {
  #define DRM_IOCTL_AMDGPU_VM            DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_VM, union drm_amdgpu_vm)
  #define DRM_IOCTL_AMDGPU_FENCE_TO_HANDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FENCE_TO_HANDLE, union drm_amdgpu_fence_to_handle)
  #define DRM_IOCTL_AMDGPU_SCHED         DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_SCHED, union drm_amdgpu_sched)
+#define DRM_IOCTL_AMDGPU_USERQ         DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ, union drm_amdgpu_userq)
 
  /**
   * DOC: memory domains
@@ -307,6 +309,59 @@ union drm_amdgpu_ctx {
         union drm_amdgpu_ctx_out out;
  };
 
+/* user queue IOCTL */
+#define AMDGPU_USERQ_OP_CREATE 1
+#define AMDGPU_USERQ_OP_FREE   2
+
+#define AMDGPU_USERQ_MQD_FLAGS_SECURE  (1 << 0)
+#define AMDGPU_USERQ_MQD_FLAGS_AQL     (1 << 1)
+
+struct drm_amdgpu_userq_mqd {
+       /** Flags: AMDGPU_USERQ_MQD_FLAGS_* */
+       __u32   flags;
+       /** IP type: AMDGPU_HW_IP_* */
+       __u32   ip_type;
+       /** GEM object handle */
+       __u32   doorbell_handle;
+       /** Doorbell's offset in the doorbell bo */
+       __u32   doorbell_offset;
+       /** GPU virtual address of the queue */

include/uapi/drm/amdgpu_drm.h union drm_amdgpu_ctx { · line 338

Quoted 10 lines
include/uapi/drm/amdgpu_drm.h +10 -0
+       __u64   queue_va;
+       /** Size of the queue in bytes */
+       __u64   queue_size;
+       /** GPU virtual address of the rptr */
+       __u64   rptr_va;
+       /** GPU virtual address of the wptr */
+       __u64   wptr_va;
+       /** GPU virtual address of the shadow context space */
+       __u64   shadow_va;
+};

We may want to make the MQD engine specific. E.g., shadow is gfx specific. We also probably need the csa and gds buffers for gfx as well. Other engines may have their own additional buffer requirements.

Quoted 1 line

Alex

Sure, we can call it drm_amdgpu_userq_mqd_gfx to clarify that this MQD is specific to GFX engine.

- Shashank

Quoted 34 lines
Quoted 34 lines
include/uapi/drm/amdgpu_drm.h +26 -1
+
+struct drm_amdgpu_userq_in {
+       /** AMDGPU_USERQ_OP_* */
+       __u32   op;
+       /** Flags */
+       __u32   flags;
+       /** Queue handle to associate the queue free call with,
+        * unused for queue create calls */
+       __u32   queue_id;
+       __u32   pad;
+       /** Queue descriptor */
+       struct drm_amdgpu_userq_mqd mqd;
+};
+
+struct drm_amdgpu_userq_out {
+       /** Queue handle */
+       __u32   queue_id;
+       /** Flags */
+       __u32   flags;
+};
+
+union drm_amdgpu_userq {
+       struct drm_amdgpu_userq_in in;
+       struct drm_amdgpu_userq_out out;
+};
+
  /* vm ioctl */
  #define AMDGPU_VM_OP_RESERVE_VMID      1
  #define AMDGPU_VM_OP_UNRESERVE_VMID    2
--

2.40.0

#5 lore raw

Re: [PATCH v3 1/9] drm/amdgpu: UAPI for user queue management

Quoted 85 lines · Shashank Sharma

Hey Alex,

Quoted 81 lines · Alex Deucher
Quoted 64 lines · Shashank Sharma

From: Alex Deucher <[email protected]>

This patch intorduces new UAPI/IOCTL for usermode graphics queue. The userspace app will fill this structure and request the graphics driver to add a graphics work queue for it. The output of this UAPI is a queue id.

This UAPI maps the queue into GPU, so the graphics app can start submitting work to the queue as soon as the call returns.

V2: Addressed review comments from Alex and Christian
- Make the doorbell offset's comment clearer
- Change the output parameter name to queue_id
V3: Integration with doorbell manager

---
  include/uapi/drm/amdgpu_drm.h | 55 +++++++++++++++++++++++++++++++++++
  1 file changed, 55 insertions(+)
include/uapi/drm/amdgpu_drm.h +19 -0
index cc5d551abda5..e4943099b9d2 100644
@@ -54,6 +54,7 @@ extern "C" {
  #define DRM_AMDGPU_VM                  0x13
  #define DRM_AMDGPU_FENCE_TO_HANDLE     0x14
  #define DRM_AMDGPU_SCHED               0x15
+#define DRM_AMDGPU_USERQ               0x16
 
  #define DRM_IOCTL_AMDGPU_GEM_CREATE    DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
  #define DRM_IOCTL_AMDGPU_GEM_MMAP      DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -71,6 +72,7 @@ extern "C" {
  #define DRM_IOCTL_AMDGPU_VM            DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_VM, union drm_amdgpu_vm)
  #define DRM_IOCTL_AMDGPU_FENCE_TO_HANDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FENCE_TO_HANDLE, union drm_amdgpu_fence_to_handle)
  #define DRM_IOCTL_AMDGPU_SCHED         DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_SCHED, union drm_amdgpu_sched)
+#define DRM_IOCTL_AMDGPU_USERQ         DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ, union drm_amdgpu_userq)
 
  /**
   * DOC: memory domains
@@ -307,6 +309,59 @@ union drm_amdgpu_ctx {
         union drm_amdgpu_ctx_out out;
  };
 
+/* user queue IOCTL */
+#define AMDGPU_USERQ_OP_CREATE 1
+#define AMDGPU_USERQ_OP_FREE   2
+
+#define AMDGPU_USERQ_MQD_FLAGS_SECURE  (1 << 0)
+#define AMDGPU_USERQ_MQD_FLAGS_AQL     (1 << 1)
+
+struct drm_amdgpu_userq_mqd {
+       /** Flags: AMDGPU_USERQ_MQD_FLAGS_* */
+       __u32   flags;
+       /** IP type: AMDGPU_HW_IP_* */
+       __u32   ip_type;
+       /** GEM object handle */
+       __u32   doorbell_handle;
+       /** Doorbell's offset in the doorbell bo */
+       __u32   doorbell_offset;
+       /** GPU virtual address of the queue */

include/uapi/drm/amdgpu_drm.h union drm_amdgpu_ctx { · line 338

Quoted 10 lines
include/uapi/drm/amdgpu_drm.h +10 -0
+       __u64   queue_va;
+       /** Size of the queue in bytes */
+       __u64   queue_size;
+       /** GPU virtual address of the rptr */
+       __u64   rptr_va;
+       /** GPU virtual address of the wptr */
+       __u64   wptr_va;
+       /** GPU virtual address of the shadow context space */
+       __u64   shadow_va;
+};

We may want to make the MQD engine specific. E.g., shadow is gfx specific. We also probably need the csa and gds buffers for gfx as well. Other engines may have their own additional buffer requirements.

Quoted 4 lines
Quoted 1 line

Alex

Sure, we can call it drm_amdgpu_userq_mqd_gfx to clarify that this MQD is specific to GFX engine.

We can make it a union and then add additional entries for SDMA, compute, and VCN. We should also move the IP type into struct drm_amdgpu_userq_in so we know how to interpret the union. Or make it a u64 and handle it similarly to the chunks interface in drm_amdgpu_cs_chunk.

Alex

Quoted 37 lines

- Shashank

Quoted 34 lines
Quoted 34 lines
include/uapi/drm/amdgpu_drm.h +26 -1
+
+struct drm_amdgpu_userq_in {
+       /** AMDGPU_USERQ_OP_* */
+       __u32   op;
+       /** Flags */
+       __u32   flags;
+       /** Queue handle to associate the queue free call with,
+        * unused for queue create calls */
+       __u32   queue_id;
+       __u32   pad;
+       /** Queue descriptor */
+       struct drm_amdgpu_userq_mqd mqd;
+};
+
+struct drm_amdgpu_userq_out {
+       /** Queue handle */
+       __u32   queue_id;
+       /** Flags */
+       __u32   flags;
+};
+
+union drm_amdgpu_userq {
+       struct drm_amdgpu_userq_in in;
+       struct drm_amdgpu_userq_out out;
+};
+
  /* vm ioctl */
  #define AMDGPU_VM_OP_RESERVE_VMID      1
  #define AMDGPU_VM_OP_UNRESERVE_VMID    2
--

2.40.0

#6 lore raw

Re: [PATCH v3 1/9] drm/amdgpu: UAPI for user queue management

Quoted 85 lines · Alex Deucher
Quoted 84 lines · Shashank Sharma

Hey Alex,

Quoted 81 lines · Alex Deucher
Quoted 64 lines · Shashank Sharma

From: Alex Deucher <[email protected]>

This patch intorduces new UAPI/IOCTL for usermode graphics queue. The userspace app will fill this structure and request the graphics driver to add a graphics work queue for it. The output of this UAPI is a queue id.

This UAPI maps the queue into GPU, so the graphics app can start submitting work to the queue as soon as the call returns.

V2: Addressed review comments from Alex and Christian
- Make the doorbell offset's comment clearer
- Change the output parameter name to queue_id
V3: Integration with doorbell manager

---
   include/uapi/drm/amdgpu_drm.h | 55 +++++++++++++++++++++++++++++++++++
   1 file changed, 55 insertions(+)
include/uapi/drm/amdgpu_drm.h +19 -0
index cc5d551abda5..e4943099b9d2 100644
@@ -54,6 +54,7 @@ extern "C" {
   #define DRM_AMDGPU_VM                  0x13
   #define DRM_AMDGPU_FENCE_TO_HANDLE     0x14
   #define DRM_AMDGPU_SCHED               0x15
+#define DRM_AMDGPU_USERQ               0x16
 
   #define DRM_IOCTL_AMDGPU_GEM_CREATE    DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
   #define DRM_IOCTL_AMDGPU_GEM_MMAP      DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -71,6 +72,7 @@ extern "C" {
   #define DRM_IOCTL_AMDGPU_VM            DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_VM, union drm_amdgpu_vm)
   #define DRM_IOCTL_AMDGPU_FENCE_TO_HANDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FENCE_TO_HANDLE, union drm_amdgpu_fence_to_handle)
   #define DRM_IOCTL_AMDGPU_SCHED         DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_SCHED, union drm_amdgpu_sched)
+#define DRM_IOCTL_AMDGPU_USERQ         DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ, union drm_amdgpu_userq)
 
   /**
    * DOC: memory domains
@@ -307,6 +309,59 @@ union drm_amdgpu_ctx {
          union drm_amdgpu_ctx_out out;
   };
 
+/* user queue IOCTL */
+#define AMDGPU_USERQ_OP_CREATE 1
+#define AMDGPU_USERQ_OP_FREE   2
+
+#define AMDGPU_USERQ_MQD_FLAGS_SECURE  (1 << 0)
+#define AMDGPU_USERQ_MQD_FLAGS_AQL     (1 << 1)
+
+struct drm_amdgpu_userq_mqd {
+       /** Flags: AMDGPU_USERQ_MQD_FLAGS_* */
+       __u32   flags;
+       /** IP type: AMDGPU_HW_IP_* */
+       __u32   ip_type;
+       /** GEM object handle */
+       __u32   doorbell_handle;
+       /** Doorbell's offset in the doorbell bo */
+       __u32   doorbell_offset;
+       /** GPU virtual address of the queue */

include/uapi/drm/amdgpu_drm.h union drm_amdgpu_ctx { · line 338

Quoted 10 lines
include/uapi/drm/amdgpu_drm.h +10 -0
+       __u64   queue_va;
+       /** Size of the queue in bytes */
+       __u64   queue_size;
+       /** GPU virtual address of the rptr */
+       __u64   rptr_va;
+       /** GPU virtual address of the wptr */
+       __u64   wptr_va;
+       /** GPU virtual address of the shadow context space */
+       __u64   shadow_va;
+};

We may want to make the MQD engine specific. E.g., shadow is gfx specific. We also probably need the csa and gds buffers for gfx as well. Other engines may have their own additional buffer requirements.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Alex

Sure, we can call it drm_amdgpu_userq_mqd_gfx to clarify that this MQD is specific to GFX engine.

We can make it a union and then add additional entries for SDMA, compute, and VCN. We should also move the IP type into struct drm_amdgpu_userq_in so we know how to interpret the union.

I was exactly thinking to do this :), it would be a small change.

Please have a look at rest of the series as well considering this done.

- Shashank

Quoted 40 lines

Or make it
a u64 and handle it similarly to the chunks interface in drm_amdgpu_cs_chunk.
Alex

Quoted 35 lines

- Shashank

Quoted 33 lines
Quoted 33 lines
include/uapi/drm/amdgpu_drm.h +26 -1
+
+struct drm_amdgpu_userq_in {
+       /** AMDGPU_USERQ_OP_* */
+       __u32   op;
+       /** Flags */
+       __u32   flags;
+       /** Queue handle to associate the queue free call with,
+        * unused for queue create calls */
+       __u32   queue_id;
+       __u32   pad;
+       /** Queue descriptor */
+       struct drm_amdgpu_userq_mqd mqd;
+};
+
+struct drm_amdgpu_userq_out {
+       /** Queue handle */
+       __u32   queue_id;
+       /** Flags */
+       __u32   flags;
+};
+
+union drm_amdgpu_userq {
+       struct drm_amdgpu_userq_in in;
+       struct drm_amdgpu_userq_out out;
+};
+
   /* vm ioctl */
   #define AMDGPU_VM_OP_RESERVE_VMID      1
   #define AMDGPU_VM_OP_UNRESERVE_VMID    2
--

2.40.0

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw

Re: [PATCH v3 1/9] drm/amdgpu: UAPI for user queue management

Hello Pierre-Eric,

Thanks for your review, my comments inline.

Quoted 50 lines · Pierre-Eric Pelloux-Prayer

Hi Shashank,

Quoted 47 lines · Shashank Sharma

From: Alex Deucher <[email protected]>

This patch intorduces new UAPI/IOCTL for usermode graphics queue. The userspace app will fill this structure and request the graphics driver to add a graphics work queue for it. The output of this UAPI is a queue id.

This UAPI maps the queue into GPU, so the graphics app can start submitting work to the queue as soon as the call returns.

V2: Addressed review comments from Alex and Christian
     - Make the doorbell offset's comment clearer
     - Change the output parameter name to queue_id
V3: Integration with doorbell manager

---
  include/uapi/drm/amdgpu_drm.h | 55 +++++++++++++++++++++++++++++++++++

  1 file changed, 55 insertions(+)
include/uapi/drm/amdgpu_drm.h +3 -0
index cc5d551abda5..e4943099b9d2 100644
@@ -54,6 +54,7 @@ extern "C" {
   #define DRM_AMDGPU_VM            0x13
   #define DRM_AMDGPU_FENCE_TO_HANDLE    0x14
   #define DRM_AMDGPU_SCHED        0x15
+#define DRM_AMDGPU_USERQ        0x16
     #define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
   #define DRM_IOCTL_AMDGPU_GEM_MMAP    DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -71,6 +72,7 @@ extern "C" {
   #define DRM_IOCTL_AMDGPU_VM        DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_VM, union drm_amdgpu_vm)
   #define DRM_IOCTL_AMDGPU_FENCE_TO_HANDLE DRM_IOWR(DRM_COMMAND_BASE 
+ DRM_AMDGPU_FENCE_TO_HANDLE, union drm_amdgpu_fence_to_handle)
   #define DRM_IOCTL_AMDGPU_SCHED        DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_SCHED, union drm_amdgpu_sched)
+#define DRM_IOCTL_AMDGPU_USERQ        DRM_IOW(DRM_COMMAND_BASE + 
 DRM_AMDGPU_USERQ, union drm_amdgpu_userq)
     /**

   * DOC: memory domains

include/uapi/drm/amdgpu_drm.h +0 -0
@@ -307,6 +309,59 @@ union drm_amdgpu_ctx {
       union drm_amdgpu_ctx_out out;
   };

  +/* user queue IOCTL */

Quoted 8 lines

include/uapi/drm/amdgpu_drm.h union drm_amdgpu_ctx { · line 317

Quoted 5 lines
include/uapi/drm/amdgpu_drm.h +5 -0
+#define AMDGPU_USERQ_OP_CREATE    1
+#define AMDGPU_USERQ_OP_FREE    2
+
+#define AMDGPU_USERQ_MQD_FLAGS_SECURE    (1 << 0)
+#define AMDGPU_USERQ_MQD_FLAGS_AQL    (1 << 1)

What is the purpose of these flags?
Could you add some documentation?

Noted,

Quoted 21 lines
Quoted 21 lines
include/uapi/drm/amdgpu_drm.h +20 -0
+
+struct drm_amdgpu_userq_mqd {
+    /** Flags: AMDGPU_USERQ_MQD_FLAGS_* */
+    __u32    flags;
+    /** IP type: AMDGPU_HW_IP_* */
+    __u32    ip_type;
+    /** GEM object handle */
+    __u32   doorbell_handle;
+    /** Doorbell's offset in the doorbell bo */
+    __u32   doorbell_offset;
+    /** GPU virtual address of the queue */
+    __u64   queue_va;
+    /** Size of the queue in bytes */
+    __u64   queue_size;
+    /** GPU virtual address of the rptr */
+    __u64   rptr_va;
+    /** GPU virtual address of the wptr */
+    __u64   wptr_va;
+    /** GPU virtual address of the shadow context space */
+    __u64    shadow_va;
Quoted 8 lines
Quoted 1 line

+};

The comments inside drm_amdgpu_userq_mqd could be improved. Here are some questions I have looking at the API:
* what is a doorbell in this context?
* what's the purpose of the doorbell offset?
* how UMD should size each buffer? I assume doorbell, rptr, wptr have min size requirements?

We are planning to add all these in a detailed doc in form of cover-letter/text comment in the follow-up libDRM UAPI version, as discussed internally.

Quoted 4 lines

I'm also wondering why the doorbell needs a handle+offset but other buffers are passed in as virtual addresses?

As you know, doorbell offset here will be an relative offset in this doorbell page, but the MQD needs the absolute offset on the doorbell PCI BAR.

So kernel needs both the object as well as relative offset to calculate absolute offset.

something like: absolute offset = base offset of this doorbell page + relative offset of this doorbell.

Quoted 8 lines

include/uapi/drm/amdgpu_drm.h union drm_amdgpu_ctx { · line 344

Quoted 6 lines
include/uapi/drm/amdgpu_drm.h +6 -0
+
+struct drm_amdgpu_userq_in {
+    /** AMDGPU_USERQ_OP_* */
+    __u32    op;
+    /** Flags */
+    __u32    flags;

What are these flags?

We have kept these flags to indicate special conditions like secure display, encryption etc. We will start utilizing these once we have the

base code (this series) merged up.

Quoted 12 lines
Quoted 8 lines

+    /** Queue handle to associate the queue free call with, +     * unused for queue create calls */
+    __u32    queue_id;
+    __u32    pad;
+    /** Queue descriptor */
+    struct drm_amdgpu_userq_mqd mqd;
+};

I'm not familiar with ioctl design but would a union work to identify the parameters of each operation?

Quoted 9 lines

union {
   struct {
      struct drm_amdgpu_userq_mqd mqd;
   } create;
   struct {
      __u32 queue_id;
      __u32 pad;
   } free;
};

I think it might work. I can check this out.

Quoted 10 lines

include/uapi/drm/amdgpu_drm.h union drm_amdgpu_ctx { · line 357

Quoted 7 lines
include/uapi/drm/amdgpu_drm.h +6 -0
+
+struct drm_amdgpu_userq_out {
+    /** Queue handle */
+    __u32    queue_id;
+    /** Flags */
+    __u32    flags;

What are these flags?

These are not utilized yet. We have kept these flags to indicate special out conditions like over subscription/failure due to no more queue slot etc.

Noted to be covered in the doc as well.

- Shashank

Quoted 13 lines

Thanks,
Pierre-Eric

Quoted 10 lines
include/uapi/drm/amdgpu_drm.h +7 -0
+};
+
+union drm_amdgpu_userq {
+    struct drm_amdgpu_userq_in in;
+    struct drm_amdgpu_userq_out out;
+};
+

  /* vm ioctl */
  #define AMDGPU_VM_OP_RESERVE_VMID    1
  #define AMDGPU_VM_OP_UNRESERVE_VMID    2

#9 lore raw

Re: [PATCH v3 1/9] drm/amdgpu: UAPI for user queue management

Am 30.03.23 um 10:15 schrieb Shashank Sharma:

Quoted 10 lines

Hello Pierre-Eric,
[SNIP]

Quoted 3 lines

I'm also wondering why the doorbell needs a handle+offset but other buffers are passed in as virtual addresses?

As you know, doorbell offset here will be an relative offset in this doorbell page, but the MQD needs the absolute offset on the doorbell PCI BAR.

So kernel needs both the object as well as relative offset to calculate absolute offset.

something like: absolute offset = base offset of this doorbell page + relative offset of this doorbell.

Another much more obvious reason is that the doorbell doesn't have a virtual address.

At least for GFX the doorbell is used to signal to the hw that new commands are available. So as long as we don't want a shader to kick of other work we don't need to map the doorbell into the GPUVM address space.

Christian.

#10 lore raw

Re: [PATCH v3 1/9] drm/amdgpu: UAPI for user queue management

Quoted 17 lines · Christian König

Am 30.03.23 um 10:15 schrieb Shashank Sharma:

Quoted 9 lines

Hello Pierre-Eric,
[SNIP]

Quoted 3 lines

I'm also wondering why the doorbell needs a handle+offset but other buffers are passed in as virtual addresses?

As you know, doorbell offset here will be an relative offset in this doorbell page, but the MQD needs the absolute offset on the doorbell PCI BAR.

Quoted 5 lines

So kernel needs both the object as well as relative offset to calculate absolute offset.

something like: absolute offset = base offset of this doorbell page + relative offset of this doorbell.

Quoted 6 lines

Another much more obvious reason is that the doorbell doesn't have a virtual address.

At least for GFX the doorbell is used to signal to the hw that new commands are available. So as long as we don't want a shader to kick of other work we don't need to map the doorbell into the GPUVM address space.

This certainly could be done if the app wanted to, but to set up the queue in the firmware API we need the index within the doorbell BAR.

Alex

#11 lore raw

PATCH v3 2/9 drm/amdgpu: add usermode queue base code

In reply to Shashank Sharma

From: Shashank Sharma <[email protected]>

This patch adds skeleton code for amdgpu usermode queue. It contains:
- A new files with init functions of usermode queues.
- A queue context manager in driver private data.

V1: Worked on design review comments from RFC patch series:
(https://patchwork.freedesktop.org/series/112214/)
- Alex: Keep a list of queues, instead of single queue per process.
- Christian: Use the queue manager instead of global ptrs, Don't keep the queue structure in amdgpu_ctx

V2:
- Reformatted code, split the big patch into two

V3:
- Integration with doorbell manager

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/Makefile           |  2 +
 drivers/gpu/drm/amd/amdgpu/amdgpu.h           | 10 +++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |  6 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 39 +++++++++++++++
 .../gpu/drm/amd/include/amdgpu_userqueue.h    | 49 +++++++++++++++++++
 6 files changed, 106 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
 create mode 100644 drivers/gpu/drm/amd/include/amdgpu_userqueue.h
drivers/gpu/drm/amd/amdgpu/Makefile +2 -0
index 204665f20319..2d90ba618e5d 100644
@@ -210,6 +210,8 @@ amdgpu-y += \
 # add amdkfd interfaces
 amdgpu-y += amdgpu_amdkfd.o
 
+# add usermode queue
+amdgpu-y += amdgpu_userqueue.o
 
 ifneq ($(CONFIG_HSA_AMD),)
 AMDKFD_PATH := ../amdkfd
drivers/gpu/drm/amd/amdgpu/amdgpu.h +9 -1
index 6b74df446694..c5f9af0e74ee 100644
@@ -438,6 +438,14 @@ struct amdgpu_sa_manager {
 	uint32_t		align;
 };
 
+/* Gfx usermode queues */
+struct amdgpu_userq_mgr {
+	struct idr userq_idr;
+	struct mutex userq_mutex;
+	struct amdgpu_device *adev;
+	const struct amdgpu_userq_funcs *userq_funcs[AMDGPU_HW_IP_NUM];
+};
+
 /* sub-allocation buffer */
 struct amdgpu_sa_bo {
 	struct list_head		olist;
@@ -470,7 +478,6 @@ struct amdgpu_flip_work {
 	bool				async;
 };
 
-
 /*
  * file private structure
  */
@@ -482,6 +489,7 @@ struct amdgpu_fpriv {
 	struct mutex		bo_list_lock;
 	struct idr		bo_list_handles;
 	struct amdgpu_ctx_mgr	ctx_mgr;
+	struct amdgpu_userq_mgr	userq_mgr;
 };
 
 int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv **fpriv);
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
index b4f2d61ea0d5..2d6bcfd727c8 100644
@@ -52,6 +52,7 @@
 #include "amdgpu_ras.h"
 #include "amdgpu_xgmi.h"
 #include "amdgpu_reset.h"
+#include "amdgpu_userqueue.h"
 
 /*
  * KMS wrapper.
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +6 -0
index 7aa7e52ca784..b16b8155a157 100644
@@ -43,6 +43,7 @@
 #include "amdgpu_gem.h"
 #include "amdgpu_display.h"
 #include "amdgpu_ras.h"
+#include "amdgpu_userqueue.h"
 
 void amdgpu_unregister_gpu_instance(struct amdgpu_device *adev)
 {
@@ -1187,6 +1188,10 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 
 	amdgpu_ctx_mgr_init(&fpriv->ctx_mgr, adev);
 
+	r = amdgpu_userq_mgr_init(&fpriv->userq_mgr, adev);
+	if (r)
+		DRM_WARN("Can't setup usermode queues, only legacy workload submission will work\n");
+
 	file_priv->driver_priv = fpriv;
 	goto out_suspend;
 
@@ -1254,6 +1259,7 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,
 
 	amdgpu_ctx_mgr_fini(&fpriv->ctx_mgr);
 	amdgpu_vm_fini(adev, &fpriv->vm);
+	amdgpu_userq_mgr_fini(&fpriv->userq_mgr);
 
 	if (pasid)
 		amdgpu_pasid_free_delayed(pd->tbo.base.resv, pasid);
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c new file +39 -0
new file mode 100644
index 000000000000..13e1eebc1cb6
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include "amdgpu.h"
+
+int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_device *adev)
+{
+    mutex_init(&userq_mgr->userq_mutex);
+    idr_init_base(&userq_mgr->userq_idr, 1);
+    userq_mgr->adev = adev;
+
+    return 0;
+}
+
+void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr)
+{
+    idr_destroy(&userq_mgr->userq_idr);
+    mutex_destroy(&userq_mgr->userq_mutex);
+}
drivers/gpu/drm/amd/include/amdgpu_userqueue.h new file +49 -0

49 lines not on this page · raw message

Signature · 1 line
2.40.0
#12 lore raw

Re: [PATCH v3 2/9] drm/amdgpu: add usermode queue base code

Quoted 51 lines · Shashank Sharma

From: Shashank Sharma <[email protected]>

This patch adds skeleton code for amdgpu usermode queue. It contains:
- A new files with init functions of usermode queues.
- A queue context manager in driver private data.

V1: Worked on design review comments from RFC patch series:
(https://patchwork.freedesktop.org/series/112214/)
- Alex: Keep a list of queues, instead of single queue per process.
- Christian: Use the queue manager instead of global ptrs, Don't keep the queue structure in amdgpu_ctx

V2:
- Reformatted code, split the big patch into two

V3:
- Integration with doorbell manager

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/Makefile           |  2 +
 drivers/gpu/drm/amd/amdgpu/amdgpu.h           | 10 +++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |  6 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 39 +++++++++++++++
 .../gpu/drm/amd/include/amdgpu_userqueue.h    | 49 +++++++++++++++++++
 6 files changed, 106 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
 create mode 100644 drivers/gpu/drm/amd/include/amdgpu_userqueue.h
drivers/gpu/drm/amd/amdgpu/Makefile +2 -0
index 204665f20319..2d90ba618e5d 100644
@@ -210,6 +210,8 @@ amdgpu-y += \
 # add amdkfd interfaces
 amdgpu-y += amdgpu_amdkfd.o
 
+# add usermode queue
+amdgpu-y += amdgpu_userqueue.o
 
 ifneq ($(CONFIG_HSA_AMD),)
 AMDKFD_PATH := ../amdkfd
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
index 6b74df446694..c5f9af0e74ee 100644

drivers/gpu/drm/amd/amdgpu/amdgpu.h struct amdgpu_sa_manager { · line 446

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +6 -0
@@ -438,6 +438,14 @@ struct amdgpu_sa_manager {
        uint32_t                align;
 };
 
+/* Gfx usermode queues */
+struct amdgpu_userq_mgr {
+       struct idr userq_idr;
+       struct mutex userq_mutex;
+       struct amdgpu_device *adev;
+       const struct amdgpu_userq_funcs *userq_funcs[AMDGPU_HW_IP_NUM];

These function pointers can be per device rather than per userq_mgr. Just hang them off of adev and then each IP can fill them in during their init functions.

Alex

Quoted 167 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -1
+};
+
 /* sub-allocation buffer */
 struct amdgpu_sa_bo {
        struct list_head                olist;
@@ -470,7 +478,6 @@ struct amdgpu_flip_work {
        bool                            async;
 };
 
-
 /*
  * file private structure
  */
@@ -482,6 +489,7 @@ struct amdgpu_fpriv {
        struct mutex            bo_list_lock;
        struct idr              bo_list_handles;
        struct amdgpu_ctx_mgr   ctx_mgr;
+       struct amdgpu_userq_mgr userq_mgr;
 };
 
 int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv **fpriv);
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
index b4f2d61ea0d5..2d6bcfd727c8 100644
@@ -52,6 +52,7 @@
 #include "amdgpu_ras.h"
 #include "amdgpu_xgmi.h"
 #include "amdgpu_reset.h"
+#include "amdgpu_userqueue.h"
 
 /*
  * KMS wrapper.
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +6 -0
index 7aa7e52ca784..b16b8155a157 100644
@@ -43,6 +43,7 @@
 #include "amdgpu_gem.h"
 #include "amdgpu_display.h"
 #include "amdgpu_ras.h"
+#include "amdgpu_userqueue.h"
 
 void amdgpu_unregister_gpu_instance(struct amdgpu_device *adev)
 {
@@ -1187,6 +1188,10 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 
        amdgpu_ctx_mgr_init(&fpriv->ctx_mgr, adev);
 
+       r = amdgpu_userq_mgr_init(&fpriv->userq_mgr, adev);
+       if (r)
+               DRM_WARN("Can't setup usermode queues, only legacy workload submission will work\n");
+
        file_priv->driver_priv = fpriv;
        goto out_suspend;
 
@@ -1254,6 +1259,7 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,
 
        amdgpu_ctx_mgr_fini(&fpriv->ctx_mgr);
        amdgpu_vm_fini(adev, &fpriv->vm);
+       amdgpu_userq_mgr_fini(&fpriv->userq_mgr);
 
        if (pasid)
                amdgpu_pasid_free_delayed(pd->tbo.base.resv, pasid);
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c new file +39 -0
new file mode 100644
index 000000000000..13e1eebc1cb6
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include "amdgpu.h"
+
+int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_device *adev)
+{
+    mutex_init(&userq_mgr->userq_mutex);
+    idr_init_base(&userq_mgr->userq_idr, 1);
+    userq_mgr->adev = adev;
+
+    return 0;
+}
+
+void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr)
+{
+    idr_destroy(&userq_mgr->userq_idr);
+    mutex_destroy(&userq_mgr->userq_mutex);
+}
drivers/gpu/drm/amd/include/amdgpu_userqueue.h new file +49 -1
new file mode 100644
index 000000000000..7eeb8c9e6575
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#ifndef AMDGPU_USERQUEUE_H_
+#define AMDGPU_USERQUEUE_H_
+
+#include "amdgpu.h"
+#define AMDGPU_MAX_USERQ 512
+
+struct amdgpu_usermode_queue {
+       int queue_id;
+       int queue_type;
+       uint64_t flags;
+       uint64_t doorbell_handle;
+       struct amdgpu_vm *vm;
+       struct amdgpu_userq_mgr *userq_mgr;
+       struct amdgpu_mqd_prop userq_prop;
+};
+
+struct amdgpu_userq_funcs {
+       int (*mqd_create)(struct amdgpu_userq_mgr *, struct amdgpu_usermode_queue *);
+       void (*mqd_destroy)(struct amdgpu_userq_mgr *, struct amdgpu_usermode_queue *);
+};
+
+int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_device *adev);
+
+void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr);
+
+#endif
--

2.40.0

#13 lore raw

Re: [PATCH v3 2/9] drm/amdgpu: add usermode queue base code

Quoted 55 lines · Alex Deucher
Quoted 53 lines · Shashank Sharma

From: Shashank Sharma <[email protected]>

This patch adds skeleton code for amdgpu usermode queue. It contains:
- A new files with init functions of usermode queues.
- A queue context manager in driver private data.

V1: Worked on design review comments from RFC patch series:
(https://patchwork.freedesktop.org/series/112214/)
- Alex: Keep a list of queues, instead of single queue per process.
- Christian: Use the queue manager instead of global ptrs, Don't keep the queue structure in amdgpu_ctx

V2:
- Reformatted code, split the big patch into two

V3:
- Integration with doorbell manager

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
---
  drivers/gpu/drm/amd/amdgpu/Makefile           |  2 +
  drivers/gpu/drm/amd/amdgpu/amdgpu.h           | 10 +++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |  6 +++
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 39 +++++++++++++++
  .../gpu/drm/amd/include/amdgpu_userqueue.h    | 49 +++++++++++++++++++
  6 files changed, 106 insertions(+), 1 deletion(-)

create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c create mode 100644 drivers/gpu/drm/amd/include/amdgpu_userqueue.h

drivers/gpu/drm/amd/amdgpu/Makefile +2 -0
index 204665f20319..2d90ba618e5d 100644
@@ -210,6 +210,8 @@ amdgpu-y += \
  # add amdkfd interfaces
  amdgpu-y += amdgpu_amdkfd.o
 
+# add usermode queue
+amdgpu-y += amdgpu_userqueue.o
 
  ifneq ($(CONFIG_HSA_AMD),)
  AMDKFD_PATH := ../amdkfd
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
index 6b74df446694..c5f9af0e74ee 100644
@@ -438,6 +438,14 @@ struct amdgpu_sa_manager {
         uint32_t                align;
  };
 
Quoted 9 lines

drivers/gpu/drm/amd/amdgpu/amdgpu.h struct amdgpu_sa_manager { · line 446

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +6 -0
+/* Gfx usermode queues */
+struct amdgpu_userq_mgr {
+       struct idr userq_idr;
+       struct mutex userq_mutex;
+       struct amdgpu_device *adev;
+       const struct amdgpu_userq_funcs *userq_funcs[AMDGPU_HW_IP_NUM];

These function pointers can be per device rather than per userq_mgr. Just hang them off of adev and then each IP can fill them in during their init functions.

We kept these functions in adev in V1, and then moved them to uq_mgr due to one of the previous code review comment.

Which way should I go now ?

- Shashank

Quoted 169 lines

Alex

Quoted 167 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -1
+};
+
  /* sub-allocation buffer */
  struct amdgpu_sa_bo {
         struct list_head                olist;
@@ -470,7 +478,6 @@ struct amdgpu_flip_work {
         bool                            async;
  };
 
-
  /*
   * file private structure
   */
@@ -482,6 +489,7 @@ struct amdgpu_fpriv {
         struct mutex            bo_list_lock;
         struct idr              bo_list_handles;
         struct amdgpu_ctx_mgr   ctx_mgr;
+       struct amdgpu_userq_mgr userq_mgr;
  };
 
  int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv **fpriv);
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
index b4f2d61ea0d5..2d6bcfd727c8 100644
@@ -52,6 +52,7 @@
  #include "amdgpu_ras.h"
  #include "amdgpu_xgmi.h"
  #include "amdgpu_reset.h"
+#include "amdgpu_userqueue.h"
 
  /*
   * KMS wrapper.
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +6 -0
index 7aa7e52ca784..b16b8155a157 100644
@@ -43,6 +43,7 @@
  #include "amdgpu_gem.h"
  #include "amdgpu_display.h"
  #include "amdgpu_ras.h"
+#include "amdgpu_userqueue.h"
 
  void amdgpu_unregister_gpu_instance(struct amdgpu_device *adev)
  {
@@ -1187,6 +1188,10 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 
         amdgpu_ctx_mgr_init(&fpriv->ctx_mgr, adev);
 
+       r = amdgpu_userq_mgr_init(&fpriv->userq_mgr, adev);
+       if (r)
+               DRM_WARN("Can't setup usermode queues, only legacy workload submission will work\n");
+
         file_priv->driver_priv = fpriv;
         goto out_suspend;
 
@@ -1254,6 +1259,7 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,
 
         amdgpu_ctx_mgr_fini(&fpriv->ctx_mgr);
         amdgpu_vm_fini(adev, &fpriv->vm);
+       amdgpu_userq_mgr_fini(&fpriv->userq_mgr);
 
         if (pasid)
                 amdgpu_pasid_free_delayed(pd->tbo.base.resv, pasid);
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c new file +39 -0
new file mode 100644
index 000000000000..13e1eebc1cb6
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include "amdgpu.h"
+
+int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_device *adev)
+{
+    mutex_init(&userq_mgr->userq_mutex);
+    idr_init_base(&userq_mgr->userq_idr, 1);
+    userq_mgr->adev = adev;
+
+    return 0;
+}
+
+void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr)
+{
+    idr_destroy(&userq_mgr->userq_idr);
+    mutex_destroy(&userq_mgr->userq_mutex);
+}
drivers/gpu/drm/amd/include/amdgpu_userqueue.h new file +49 -1
new file mode 100644
index 000000000000..7eeb8c9e6575
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#ifndef AMDGPU_USERQUEUE_H_
+#define AMDGPU_USERQUEUE_H_
+
+#include "amdgpu.h"
+#define AMDGPU_MAX_USERQ 512
+
+struct amdgpu_usermode_queue {
+       int queue_id;
+       int queue_type;
+       uint64_t flags;
+       uint64_t doorbell_handle;
+       struct amdgpu_vm *vm;
+       struct amdgpu_userq_mgr *userq_mgr;
+       struct amdgpu_mqd_prop userq_prop;
+};
+
+struct amdgpu_userq_funcs {
+       int (*mqd_create)(struct amdgpu_userq_mgr *, struct amdgpu_usermode_queue *);
+       void (*mqd_destroy)(struct amdgpu_userq_mgr *, struct amdgpu_usermode_queue *);
+};
+
+int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_device *adev);
+
+void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr);
+
+#endif
--

2.40.0

#14 lore raw

Re: [PATCH v3 2/9] drm/amdgpu: add usermode queue base code

In reply to Shashank Sharma
Quoted 51 lines · Shashank Sharma

From: Shashank Sharma <[email protected]>

This patch adds skeleton code for amdgpu usermode queue. It contains:
- A new files with init functions of usermode queues.
- A queue context manager in driver private data.

V1: Worked on design review comments from RFC patch series:
(https://patchwork.freedesktop.org/series/112214/)
- Alex: Keep a list of queues, instead of single queue per process.
- Christian: Use the queue manager instead of global ptrs, Don't keep the queue structure in amdgpu_ctx

V2:
- Reformatted code, split the big patch into two

V3:
- Integration with doorbell manager

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/Makefile           |  2 +
 drivers/gpu/drm/amd/amdgpu/amdgpu.h           | 10 +++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |  6 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 39 +++++++++++++++
 .../gpu/drm/amd/include/amdgpu_userqueue.h    | 49 +++++++++++++++++++
 6 files changed, 106 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
 create mode 100644 drivers/gpu/drm/amd/include/amdgpu_userqueue.h
drivers/gpu/drm/amd/amdgpu/Makefile +2 -0
index 204665f20319..2d90ba618e5d 100644
@@ -210,6 +210,8 @@ amdgpu-y += \
 # add amdkfd interfaces
 amdgpu-y += amdgpu_amdkfd.o
 
+# add usermode queue
+amdgpu-y += amdgpu_userqueue.o
 
 ifneq ($(CONFIG_HSA_AMD),)
 AMDKFD_PATH := ../amdkfd
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
index 6b74df446694..c5f9af0e74ee 100644
@@ -438,6 +438,14 @@ struct amdgpu_sa_manager {
 	uint32_t		align;

drivers/gpu/drm/amd/amdgpu/amdgpu.h struct amdgpu_sa_manager { · line 448

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +8 -0
 };
 
+/* Gfx usermode queues */
+struct amdgpu_userq_mgr {
+	struct idr userq_idr;
+	struct mutex userq_mutex;
+	struct amdgpu_device *adev;
+	const struct amdgpu_userq_funcs *userq_funcs[AMDGPU_HW_IP_NUM];
+};
+

Could you align the member names to the largest member's column, as opposed to having only a single space in between?

It makes it so much more readable.

Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -1
 /* sub-allocation buffer */
 struct amdgpu_sa_bo {
 	struct list_head		olist;
@@ -470,7 +478,6 @@ struct amdgpu_flip_work {
 	bool				async;
 };
 
-
 /*
  * file private structure
  */

drivers/gpu/drm/amd/amdgpu/amdgpu.h struct amdgpu_fpriv { · line 493

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
@@ -482,6 +489,7 @@ struct amdgpu_fpriv {
 	struct mutex		bo_list_lock;
 	struct idr		bo_list_handles;
 	struct amdgpu_ctx_mgr	ctx_mgr;
+	struct amdgpu_userq_mgr	userq_mgr;
 };

Like here, and pretty much the rest of the kernel code.

Quoted 124 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
 int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv **fpriv);
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
index b4f2d61ea0d5..2d6bcfd727c8 100644
@@ -52,6 +52,7 @@
 #include "amdgpu_ras.h"
 #include "amdgpu_xgmi.h"
 #include "amdgpu_reset.h"
+#include "amdgpu_userqueue.h"
 
 /*
  * KMS wrapper.
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +6 -0
index 7aa7e52ca784..b16b8155a157 100644
@@ -43,6 +43,7 @@
 #include "amdgpu_gem.h"
 #include "amdgpu_display.h"
 #include "amdgpu_ras.h"
+#include "amdgpu_userqueue.h"
 
 void amdgpu_unregister_gpu_instance(struct amdgpu_device *adev)
 {
@@ -1187,6 +1188,10 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 
 	amdgpu_ctx_mgr_init(&fpriv->ctx_mgr, adev);
 
+	r = amdgpu_userq_mgr_init(&fpriv->userq_mgr, adev);
+	if (r)
+		DRM_WARN("Can't setup usermode queues, only legacy workload submission will work\n");
+
 	file_priv->driver_priv = fpriv;
 	goto out_suspend;
 
@@ -1254,6 +1259,7 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,
 
 	amdgpu_ctx_mgr_fini(&fpriv->ctx_mgr);
 	amdgpu_vm_fini(adev, &fpriv->vm);
+	amdgpu_userq_mgr_fini(&fpriv->userq_mgr);
 
 	if (pasid)
 		amdgpu_pasid_free_delayed(pd->tbo.base.resv, pasid);
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c new file +39 -0
new file mode 100644
index 000000000000..13e1eebc1cb6
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include "amdgpu.h"
+
+int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_device *adev)
+{
+    mutex_init(&userq_mgr->userq_mutex);
+    idr_init_base(&userq_mgr->userq_idr, 1);
+    userq_mgr->adev = adev;
+
+    return 0;
+}
+
+void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr)
+{
+    idr_destroy(&userq_mgr->userq_idr);
+    mutex_destroy(&userq_mgr->userq_mutex);
+}
drivers/gpu/drm/amd/include/amdgpu_userqueue.h new file +28 -0
new file mode 100644
index 000000000000..7eeb8c9e6575
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#ifndef AMDGPU_USERQUEUE_H_
+#define AMDGPU_USERQUEUE_H_
+
+#include "amdgpu.h"
+#define AMDGPU_MAX_USERQ 512

drivers/gpu/drm/amd/include/amdgpu_userqueue.h line 38

Quoted 10 lines
drivers/gpu/drm/amd/include/amdgpu_userqueue.h new file +10 -0
+
+struct amdgpu_usermode_queue {
+	int queue_id;
+	int queue_type;
+	uint64_t flags;
+	uint64_t doorbell_handle;
+	struct amdgpu_vm *vm;
+	struct amdgpu_userq_mgr *userq_mgr;
+	struct amdgpu_mqd_prop userq_prop;
+};

Could you align the member names to the largest member's column, as opposed to having only a single space in between?

It makes it so much more readable.

drivers/gpu/drm/amd/include/amdgpu_userqueue.h line 43

Quoted 5 lines
drivers/gpu/drm/amd/include/amdgpu_userqueue.h new file +5 -0
+
+struct amdgpu_userq_funcs {
+	int (*mqd_create)(struct amdgpu_userq_mgr *, struct amdgpu_usermode_queue *);
+	void (*mqd_destroy)(struct amdgpu_userq_mgr *, struct amdgpu_usermode_queue *);
+};

Here too, align to the largest column.

Regards,
Luben

Quoted 6 lines
drivers/gpu/drm/amd/include/amdgpu_userqueue.h new file +6 -0
+
+int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_device *adev);
+
+void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr);
+
+#endif
#15 lore raw

PATCH v3 3/9 drm/amdgpu: add new IOCTL for usermode queue

In reply to Shashank Sharma

From: Shashank Sharma <[email protected]>

This patch adds:
- A new IOCTL function to create and destroy
- A new structure to keep all the user queue data in one place.
- A function to generate unique index for the queue.

V1: Worked on review comments from RFC patch series:
- Alex: Keep a list of queues, instead of single queue per process.
- Christian: Use the queue manager instead of global ptrs, Don't keep the queue structure in amdgpu_ctx

V2: Worked on review comments:
- Christian:
- Formatting of text
- There is no need for queuing of userqueues, with idr in place
- Alex:
- Remove use_doorbell, its unnecessary
- Reuse amdgpu_mqd_props for saving mqd fields

- Code formatting and re-arrangement

V3:
- Integration with doorbell manager

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 113 ++++++++++++++++++
 .../gpu/drm/amd/include/amdgpu_userqueue.h    |   2 +
 3 files changed, 116 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
index 2d6bcfd727c8..229976a2d0e7 100644
@@ -2749,6 +2749,7 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {
 	DRM_IOCTL_DEF_DRV(AMDGPU_GEM_VA, amdgpu_gem_va_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF_DRV(AMDGPU_GEM_OP, amdgpu_gem_op_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF_DRV(AMDGPU_GEM_USERPTR, amdgpu_gem_userptr_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
+	DRM_IOCTL_DEF_DRV(AMDGPU_USERQ, amdgpu_userq_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
 };
 
 static const struct drm_driver amdgpu_kms_driver = {
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +113 -0

119 lines not on this page · raw message

drivers/gpu/drm/amd/include/amdgpu_userqueue.h +2 -0
index 7eeb8c9e6575..7625a862b1fc 100644
@@ -42,6 +42,8 @@ struct amdgpu_userq_funcs {
 	void (*mqd_destroy)(struct amdgpu_userq_mgr *, struct amdgpu_usermode_queue *);
 };
 
+int amdgpu_userq_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
+
 int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_device *adev);
 
 void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr);
Signature · 1 line
2.40.0
#16 lore raw

Re: [PATCH v3 3/9] drm/amdgpu: add new IOCTL for usermode queue

Quoted 92 lines · Shashank Sharma

From: Shashank Sharma <[email protected]>

This patch adds:
- A new IOCTL function to create and destroy
- A new structure to keep all the user queue data in one place.
- A function to generate unique index for the queue.

V1: Worked on review comments from RFC patch series:
- Alex: Keep a list of queues, instead of single queue per process.
- Christian: Use the queue manager instead of global ptrs, Don't keep the queue structure in amdgpu_ctx

V2: Worked on review comments:
- Christian:
- Formatting of text
- There is no need for queuing of userqueues, with idr in place
- Alex:
- Remove use_doorbell, its unnecessary
- Reuse amdgpu_mqd_props for saving mqd fields

- Code formatting and re-arrangement

V3:
- Integration with doorbell manager

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 113 ++++++++++++++++++
 .../gpu/drm/amd/include/amdgpu_userqueue.h    |   2 +
 3 files changed, 116 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
index 2d6bcfd727c8..229976a2d0e7 100644
@@ -2749,6 +2749,7 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {
        DRM_IOCTL_DEF_DRV(AMDGPU_GEM_VA, amdgpu_gem_va_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
        DRM_IOCTL_DEF_DRV(AMDGPU_GEM_OP, amdgpu_gem_op_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
        DRM_IOCTL_DEF_DRV(AMDGPU_GEM_USERPTR, amdgpu_gem_userptr_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
+       DRM_IOCTL_DEF_DRV(AMDGPU_USERQ, amdgpu_userq_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
 };
 
 static const struct drm_driver amdgpu_kms_driver = {
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +37 -0
index 13e1eebc1cb6..353f57c5a772 100644
@@ -22,6 +22,119 @@
  */
 
 #include "amdgpu.h"
+#include "amdgpu_vm.h"
+#include "amdgpu_userqueue.h"
+
+static inline int
+amdgpu_userqueue_index(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
+{
+    return idr_alloc(&uq_mgr->userq_idr, queue, 1, AMDGPU_MAX_USERQ, GFP_KERNEL);
+}
+
+static inline void
+amdgpu_userqueue_free_index(struct amdgpu_userq_mgr *uq_mgr, int queue_id)
+{
+    idr_remove(&uq_mgr->userq_idr, queue_id);
+}
+
+static struct amdgpu_usermode_queue *
+amdgpu_userqueue_find(struct amdgpu_userq_mgr *uq_mgr, int qid)
+{
+    return idr_find(&uq_mgr->userq_idr, qid);
+}
+
+static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
+{
+    struct amdgpu_usermode_queue *queue;
+    struct amdgpu_fpriv *fpriv = filp->driver_priv;
+    struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;
+    struct drm_amdgpu_userq_mqd *mqd_in = &args->in.mqd;
+    int r;
+
+    /* Do we have support userqueues for this IP ? */
+    if (!uq_mgr->userq_funcs[mqd_in->ip_type]) {
+        DRM_ERROR("GFX User queues not supported for this IP: %d\n", mqd_in->ip_type);
+        return -EINVAL;
+    }
+
+    queue = kzalloc(sizeof(struct amdgpu_usermode_queue), GFP_KERNEL);
+    if (!queue) {

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c line 71

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +10 -0
+        DRM_ERROR("Failed to allocate memory for queue\n");
+        return -ENOMEM;
+    }
+
+    mutex_lock(&uq_mgr->userq_mutex);
+    queue->userq_prop.wptr_gpu_addr = mqd_in->wptr_va;
+    queue->userq_prop.rptr_gpu_addr = mqd_in->rptr_va;
+    queue->userq_prop.queue_size = mqd_in->queue_size;
+    queue->userq_prop.hqd_base_gpu_addr = mqd_in->queue_va;
+    queue->userq_prop.queue_size = mqd_in->queue_size;

This sets queue_size twice.

Quoted 85 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +66 -0
+
+    queue->doorbell_handle = mqd_in->doorbell_handle;
+    queue->queue_type = mqd_in->ip_type;
+    queue->flags = mqd_in->flags;
+    queue->vm = &fpriv->vm;
+    queue->queue_id = amdgpu_userqueue_index(uq_mgr, queue);
+    if (queue->queue_id < 0) {
+        DRM_ERROR("Failed to allocate a queue id\n");
+        r = queue->queue_id;
+        goto free_queue;
+    }
+
+    args->out.queue_id = queue->queue_id;
+    args->out.flags = 0;
+    mutex_unlock(&uq_mgr->userq_mutex);
+    return 0;
+
+free_queue:
+    mutex_unlock(&uq_mgr->userq_mutex);
+    kfree(queue);
+    return r;
+}
+
+static void 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_usermode_queue *queue;
+
+    queue = amdgpu_userqueue_find(uq_mgr, queue_id);
+    if (!queue) {
+        DRM_DEBUG_DRIVER("Invalid queue id to destroy\n");
+        return;
+    }
+
+    mutex_lock(&uq_mgr->userq_mutex);
+    amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
+    mutex_unlock(&uq_mgr->userq_mutex);
+    kfree(queue);
+}
+
+int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
+                      struct drm_file *filp)
+{
+    union drm_amdgpu_userq *args = data;
+    int r = 0;
+
+    switch (args->in.op) {
+    case AMDGPU_USERQ_OP_CREATE:
+        r = amdgpu_userqueue_create(filp, args);
+        if (r)
+            DRM_ERROR("Failed to create usermode queue\n");
+        break;
+
+    case AMDGPU_USERQ_OP_FREE:
+        amdgpu_userqueue_destroy(filp, args->in.queue_id);
+        break;
+
+    default:
+        DRM_ERROR("Invalid user queue op specified: %d\n", args->in.op);
+        return -EINVAL;
+    }
+
+    return r;
+}
+
 
 int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_device *adev)
 {
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +2 -1
index 7eeb8c9e6575..7625a862b1fc 100644
@@ -42,6 +42,8 @@ struct amdgpu_userq_funcs {
        void (*mqd_destroy)(struct amdgpu_userq_mgr *, struct amdgpu_usermode_queue *);
 };
 
+int amdgpu_userq_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
+
 int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_device *adev);
 
 void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr);
--

2.40.0

#17 lore raw

Re: [PATCH v3 3/9] drm/amdgpu: add new IOCTL for usermode queue

Quoted 95 lines · Bas Nieuwenhuizen
Quoted 94 lines · Shashank Sharma

From: Shashank Sharma <[email protected]>

This patch adds:
- A new IOCTL function to create and destroy
- A new structure to keep all the user queue data in one place.
- A function to generate unique index for the queue.

V1: Worked on review comments from RFC patch series:
- Alex: Keep a list of queues, instead of single queue per process.
- Christian: Use the queue manager instead of global ptrs, Don't keep the queue structure in amdgpu_ctx

V2: Worked on review comments:
- Christian:
- Formatting of text
- There is no need for queuing of userqueues, with idr in place
- Alex:
- Remove use_doorbell, its unnecessary
- Reuse amdgpu_mqd_props for saving mqd fields

- Code formatting and re-arrangement

V3:
- Integration with doorbell manager

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |   1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 113 ++++++++++++++++++
  .../gpu/drm/amd/include/amdgpu_userqueue.h    |   2 +
  3 files changed, 116 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
index 2d6bcfd727c8..229976a2d0e7 100644
@@ -2749,6 +2749,7 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {
         DRM_IOCTL_DEF_DRV(AMDGPU_GEM_VA, amdgpu_gem_va_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
         DRM_IOCTL_DEF_DRV(AMDGPU_GEM_OP, amdgpu_gem_op_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
         DRM_IOCTL_DEF_DRV(AMDGPU_GEM_USERPTR, amdgpu_gem_userptr_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
+       DRM_IOCTL_DEF_DRV(AMDGPU_USERQ, amdgpu_userq_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  };
 
  static const struct drm_driver amdgpu_kms_driver = {
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +40 -0
index 13e1eebc1cb6..353f57c5a772 100644
@@ -22,6 +22,119 @@
   */
 
  #include "amdgpu.h"
+#include "amdgpu_vm.h"
+#include "amdgpu_userqueue.h"
+
+static inline int
+amdgpu_userqueue_index(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
+{
+    return idr_alloc(&uq_mgr->userq_idr, queue, 1, AMDGPU_MAX_USERQ, GFP_KERNEL);
+}
+
+static inline void
+amdgpu_userqueue_free_index(struct amdgpu_userq_mgr *uq_mgr, int queue_id)
+{
+    idr_remove(&uq_mgr->userq_idr, queue_id);
+}
+
+static struct amdgpu_usermode_queue *
+amdgpu_userqueue_find(struct amdgpu_userq_mgr *uq_mgr, int qid)
+{
+    return idr_find(&uq_mgr->userq_idr, qid);
+}
+
+static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
+{
+    struct amdgpu_usermode_queue *queue;
+    struct amdgpu_fpriv *fpriv = filp->driver_priv;
+    struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;
+    struct drm_amdgpu_userq_mqd *mqd_in = &args->in.mqd;
+    int r;
+
+    /* Do we have support userqueues for this IP ? */
+    if (!uq_mgr->userq_funcs[mqd_in->ip_type]) {
+        DRM_ERROR("GFX User queues not supported for this IP: %d\n", mqd_in->ip_type);
+        return -EINVAL;
+    }
+
+    queue = kzalloc(sizeof(struct amdgpu_usermode_queue), GFP_KERNEL);
+    if (!queue) {
+        DRM_ERROR("Failed to allocate memory for queue\n");
+        return -ENOMEM;
+    }
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c line 71

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +7 -0
+
+    mutex_lock(&uq_mgr->userq_mutex);
+    queue->userq_prop.wptr_gpu_addr = mqd_in->wptr_va;
+    queue->userq_prop.rptr_gpu_addr = mqd_in->rptr_va;
+    queue->userq_prop.queue_size = mqd_in->queue_size;
+    queue->userq_prop.hqd_base_gpu_addr = mqd_in->queue_va;
+    queue->userq_prop.queue_size = mqd_in->queue_size;

This sets queue_size twice.

Noted,

- Shashank

Quoted 86 lines
Quoted 86 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +66 -0
+
+    queue->doorbell_handle = mqd_in->doorbell_handle;
+    queue->queue_type = mqd_in->ip_type;
+    queue->flags = mqd_in->flags;
+    queue->vm = &fpriv->vm;
+    queue->queue_id = amdgpu_userqueue_index(uq_mgr, queue);
+    if (queue->queue_id < 0) {
+        DRM_ERROR("Failed to allocate a queue id\n");
+        r = queue->queue_id;
+        goto free_queue;
+    }
+
+    args->out.queue_id = queue->queue_id;
+    args->out.flags = 0;
+    mutex_unlock(&uq_mgr->userq_mutex);
+    return 0;
+
+free_queue:
+    mutex_unlock(&uq_mgr->userq_mutex);
+    kfree(queue);
+    return r;
+}
+
+static void 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_usermode_queue *queue;
+
+    queue = amdgpu_userqueue_find(uq_mgr, queue_id);
+    if (!queue) {
+        DRM_DEBUG_DRIVER("Invalid queue id to destroy\n");
+        return;
+    }
+
+    mutex_lock(&uq_mgr->userq_mutex);
+    amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
+    mutex_unlock(&uq_mgr->userq_mutex);
+    kfree(queue);
+}
+
+int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
+                      struct drm_file *filp)
+{
+    union drm_amdgpu_userq *args = data;
+    int r = 0;
+
+    switch (args->in.op) {
+    case AMDGPU_USERQ_OP_CREATE:
+        r = amdgpu_userqueue_create(filp, args);
+        if (r)
+            DRM_ERROR("Failed to create usermode queue\n");
+        break;
+
+    case AMDGPU_USERQ_OP_FREE:
+        amdgpu_userqueue_destroy(filp, args->in.queue_id);
+        break;
+
+    default:
+        DRM_ERROR("Invalid user queue op specified: %d\n", args->in.op);
+        return -EINVAL;
+    }
+
+    return r;
+}
+
 
  int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_device *adev)
  {
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +2 -1
index 7eeb8c9e6575..7625a862b1fc 100644
@@ -42,6 +42,8 @@ struct amdgpu_userq_funcs {
         void (*mqd_destroy)(struct amdgpu_userq_mgr *, struct amdgpu_usermode_queue *);
  };
 
+int amdgpu_userq_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
+
  int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_device *adev);
 
  void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr);
--

2.40.0

#18 lore raw

PATCH v3 4/9 drm/amdgpu: create GFX-gen11 MQD for userqueue

In reply to Shashank Sharma

From: Shashank Sharma <[email protected]>

A Memory queue descriptor (MQD) of a userqueue defines it in the harware's context. As MQD format can vary between different graphics IPs, we need gfx GEN specific handlers to create MQDs.

This patch:
- Introduces MQD hander functions for the usermode queues.
- Adds new functions to create and destroy MQD for GFX-GEN-11-IP

V1: Worked on review comments from Alex:
- Make MQD functions GEN and IP specific

V2: Worked on review comments from Alex:
- Reuse the existing adev->mqd[ip] for MQD creation
- Formatting and arrangement of code

V3:
- Integration with doorbell manager

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/Makefile           |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 21 +++++
 .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 84 +++++++++++++++++++
 .../gpu/drm/amd/include/amdgpu_userqueue.h    |  7 ++
 4 files changed, 113 insertions(+)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c
drivers/gpu/drm/amd/amdgpu/Makefile +1 -0
index 2d90ba618e5d..2cc7897de7e6 100644
@@ -212,6 +212,7 @@ amdgpu-y += amdgpu_amdkfd.o
 
 # add usermode queue
 amdgpu-y += amdgpu_userqueue.o
+amdgpu-y += amdgpu_userqueue_gfx_v11.o
 
 ifneq ($(CONFIG_HSA_AMD),)
 AMDKFD_PATH := ../amdkfd
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +21 -0
index 353f57c5a772..052c2c1e8aed 100644
@@ -81,6 +81,12 @@ static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq
         goto free_queue;
     }
 
+    r = uq_mgr->userq_funcs[queue->queue_type]->mqd_create(uq_mgr, queue);
+    if (r) {
+        DRM_ERROR("Failed to create/map userqueue MQD\n");
+        goto free_queue;
+    }
+
     args->out.queue_id = queue->queue_id;
     args->out.flags = 0;
     mutex_unlock(&uq_mgr->userq_mutex);
@@ -105,6 +111,7 @@ static void amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)
     }
 
     mutex_lock(&uq_mgr->userq_mutex);
+    uq_mgr->userq_funcs[queue->queue_type]->mqd_destroy(uq_mgr, queue);
     amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
     mutex_unlock(&uq_mgr->userq_mutex);
     kfree(queue);
@@ -135,6 +142,19 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
     return r;
 }
 
+extern const struct amdgpu_userq_funcs userq_gfx_v11_funcs;
+
+static void
+amdgpu_userqueue_setup_ip_funcs(struct amdgpu_userq_mgr *uq_mgr)
+{
+    int maj;
+    struct amdgpu_device *adev = uq_mgr->adev;
+    uint32_t version = adev->ip_versions[GC_HWIP][0];
+
+    maj = IP_VERSION_MAJ(version);
+    if (maj == 11)
+        uq_mgr->userq_funcs[AMDGPU_HW_IP_GFX] = &userq_gfx_v11_funcs;
+}
 
 int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_device *adev)
 {
@@ -142,6 +162,7 @@ int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_devi
     idr_init_base(&userq_mgr->userq_idr, 1);
     userq_mgr->adev = adev;
 
+    amdgpu_userqueue_setup_ip_funcs(userq_mgr);
     return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c new file +84 -0

84 lines not on this page · raw message

drivers/gpu/drm/amd/include/amdgpu_userqueue.h +7 -0
index 7625a862b1fc..2911c88d0fed 100644
@@ -27,6 +27,12 @@
 #include "amdgpu.h"
 #define AMDGPU_MAX_USERQ 512
 
+struct amdgpu_userq_ctx_space {
+	struct amdgpu_bo *obj;
+	uint64_t gpu_addr;
+	void *cpu_ptr;
+};
+
 struct amdgpu_usermode_queue {
 	int queue_id;
 	int queue_type;
@@ -35,6 +41,7 @@ struct amdgpu_usermode_queue {
 	struct amdgpu_vm *vm;
 	struct amdgpu_userq_mgr *userq_mgr;
 	struct amdgpu_mqd_prop userq_prop;
+	struct amdgpu_userq_ctx_space mqd;
 };
 
 struct amdgpu_userq_funcs {
Signature · 1 line
2.40.0
#19 lore raw

Re: [PATCH v3 4/9] drm/amdgpu: create GFX-gen11 MQD for userqueue

Quoted 78 lines · Shashank Sharma

From: Shashank Sharma <[email protected]>

A Memory queue descriptor (MQD) of a userqueue defines it in the harware's context. As MQD format can vary between different graphics IPs, we need gfx GEN specific handlers to create MQDs.

This patch:
- Introduces MQD hander functions for the usermode queues.
- Adds new functions to create and destroy MQD for GFX-GEN-11-IP

V1: Worked on review comments from Alex:
- Make MQD functions GEN and IP specific

V2: Worked on review comments from Alex:
- Reuse the existing adev->mqd[ip] for MQD creation
- Formatting and arrangement of code

V3:
- Integration with doorbell manager

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/Makefile           |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 21 +++++
 .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 84 +++++++++++++++++++
 .../gpu/drm/amd/include/amdgpu_userqueue.h    |  7 ++
 4 files changed, 113 insertions(+)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c
drivers/gpu/drm/amd/amdgpu/Makefile +1 -0
index 2d90ba618e5d..2cc7897de7e6 100644
@@ -212,6 +212,7 @@ amdgpu-y += amdgpu_amdkfd.o
 
 # add usermode queue
 amdgpu-y += amdgpu_userqueue.o
+amdgpu-y += amdgpu_userqueue_gfx_v11.o
 
 ifneq ($(CONFIG_HSA_AMD),)
 AMDKFD_PATH := ../amdkfd
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +10 -0
index 353f57c5a772..052c2c1e8aed 100644
@@ -81,6 +81,12 @@ static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq
         goto free_queue;
     }
 
+    r = uq_mgr->userq_funcs[queue->queue_type]->mqd_create(uq_mgr, queue);
+    if (r) {
+        DRM_ERROR("Failed to create/map userqueue MQD\n");
+        goto free_queue;
+    }
+
     args->out.queue_id = queue->queue_id;
     args->out.flags = 0;
     mutex_unlock(&uq_mgr->userq_mutex);
@@ -105,6 +111,7 @@ static void amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)
     }
 
     mutex_lock(&uq_mgr->userq_mutex);
+    uq_mgr->userq_funcs[queue->queue_type]->mqd_destroy(uq_mgr, queue);
     amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
     mutex_unlock(&uq_mgr->userq_mutex);
     kfree(queue);
@@ -135,6 +142,19 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
     return r;
 }
 
+extern const struct amdgpu_userq_funcs userq_gfx_v11_funcs;
+
+static void

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c int amdgpu_userq_ioctl(struct drm_device *dev, void *data, · line 157

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +10 -0
+amdgpu_userqueue_setup_ip_funcs(struct amdgpu_userq_mgr *uq_mgr)
+{
+    int maj;
+    struct amdgpu_device *adev = uq_mgr->adev;
+    uint32_t version = adev->ip_versions[GC_HWIP][0];
+
+    maj = IP_VERSION_MAJ(version);
+    if (maj == 11)
+        uq_mgr->userq_funcs[AMDGPU_HW_IP_GFX] = &userq_gfx_v11_funcs;
+}

These can be per device and done in each IP's init code.

Quoted 91 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +1 -0
 int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_device *adev)
 {
@@ -142,6 +162,7 @@ int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_devi
     idr_init_base(&userq_mgr->userq_idr, 1);
     userq_mgr->adev = adev;
 
+    amdgpu_userqueue_setup_ip_funcs(userq_mgr);
     return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c new file +74 -0
new file mode 100644
index 000000000000..12e1a785b65a
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#include "amdgpu.h"
+#include "amdgpu_userqueue.h"
+
+static int
+amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_device *adev = uq_mgr->adev;
+    struct amdgpu_userq_ctx_space *mqd = &queue->mqd;
+    struct amdgpu_mqd *gfx_v11_mqd = &adev->mqds[queue->queue_type];
+    int size = gfx_v11_mqd->mqd_size;
+    int r;
+
+    r = amdgpu_bo_create_kernel(adev, size, PAGE_SIZE,
+                                AMDGPU_GEM_DOMAIN_GTT,
+                                &mqd->obj,
+                                &mqd->gpu_addr,
+                                &mqd->cpu_ptr);
+    if (r) {
+        DRM_ERROR("Failed to allocate bo for userqueue (%d)", r);
+        return r;
+    }
+
+    memset(mqd->cpu_ptr, 0, size);
+    r = amdgpu_bo_reserve(mqd->obj, false);
+    if (unlikely(r != 0)) {
+        DRM_ERROR("Failed to reserve mqd for userqueue (%d)", r);
+        goto free_mqd;
+    }
+
+    queue->userq_prop.use_doorbell = true;
+    queue->userq_prop.mqd_gpu_addr = mqd->gpu_addr;
+    r = gfx_v11_mqd->init_mqd(adev, (void *)mqd->cpu_ptr, &queue->userq_prop);
+    amdgpu_bo_unreserve(mqd->obj);
+    if (r) {
+        DRM_ERROR("Failed to init MQD for queue\n");
+        goto free_mqd;
+    }
+
+    DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
+    return 0;
+
+free_mqd:
+    amdgpu_bo_free_kernel(&mqd->obj,
+                          &mqd->gpu_addr,
+                          &mqd->cpu_ptr);
+   return r;
+}
+
+static void
+amdgpu_userq_gfx_v11_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_userq_ctx_space *mqd = &queue->mqd;

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c line 84

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c new file +10 -0
+
+    amdgpu_bo_free_kernel(&mqd->obj,
+                          &mqd->gpu_addr,
+                          &mqd->cpu_ptr);
+}
+
+const struct amdgpu_userq_funcs userq_gfx_v11_funcs = {
+    .mqd_create = amdgpu_userq_gfx_v11_mqd_create,
+    .mqd_destroy = amdgpu_userq_gfx_v11_mqd_destroy,
+};

We can just stick these in gfx_v11_0.c. No need for a new file.

Alex

Quoted 28 lines
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +7 -1
index 7625a862b1fc..2911c88d0fed 100644
@@ -27,6 +27,12 @@
 #include "amdgpu.h"
 #define AMDGPU_MAX_USERQ 512
 
+struct amdgpu_userq_ctx_space {
+       struct amdgpu_bo *obj;
+       uint64_t gpu_addr;
+       void *cpu_ptr;
+};
+
 struct amdgpu_usermode_queue {
        int queue_id;
        int queue_type;
@@ -35,6 +41,7 @@ struct amdgpu_usermode_queue {
        struct amdgpu_vm *vm;
        struct amdgpu_userq_mgr *userq_mgr;
        struct amdgpu_mqd_prop userq_prop;
+       struct amdgpu_userq_ctx_space mqd;
 };
 
 struct amdgpu_userq_funcs {
--

2.40.0

#20 lore raw

Re: [PATCH v3 4/9] drm/amdgpu: create GFX-gen11 MQD for userqueue

Quoted 76 lines · Alex Deucher
Quoted 74 lines · Shashank Sharma

From: Shashank Sharma <[email protected]>

A Memory queue descriptor (MQD) of a userqueue defines it in the harware's context. As MQD format can vary between different graphics IPs, we need gfx GEN specific handlers to create MQDs.

This patch:
- Introduces MQD hander functions for the usermode queues.
- Adds new functions to create and destroy MQD for GFX-GEN-11-IP

V1: Worked on review comments from Alex:
- Make MQD functions GEN and IP specific

V2: Worked on review comments from Alex:
- Reuse the existing adev->mqd[ip] for MQD creation
- Formatting and arrangement of code

V3:
- Integration with doorbell manager

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
---
  drivers/gpu/drm/amd/amdgpu/Makefile           |  1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 21 +++++
  .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 84 +++++++++++++++++++
  .../gpu/drm/amd/include/amdgpu_userqueue.h    |  7 ++
  4 files changed, 113 insertions(+)

create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c

drivers/gpu/drm/amd/amdgpu/Makefile +1 -0
index 2d90ba618e5d..2cc7897de7e6 100644
@@ -212,6 +212,7 @@ amdgpu-y += amdgpu_amdkfd.o
 
  # add usermode queue
  amdgpu-y += amdgpu_userqueue.o
+amdgpu-y += amdgpu_userqueue_gfx_v11.o
 
  ifneq ($(CONFIG_HSA_AMD),)
  AMDKFD_PATH := ../amdkfd
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +7 -0
index 353f57c5a772..052c2c1e8aed 100644
@@ -81,6 +81,12 @@ static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq
          goto free_queue;
      }
 
+    r = uq_mgr->userq_funcs[queue->queue_type]->mqd_create(uq_mgr, queue);
+    if (r) {
+        DRM_ERROR("Failed to create/map userqueue MQD\n");
+        goto free_queue;
+    }
+
      args->out.queue_id = queue->queue_id;
      args->out.flags = 0;
      mutex_unlock(&uq_mgr->userq_mutex);
@@ -105,6 +111,7 @@ static void amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)
      }
 
      mutex_lock(&uq_mgr->userq_mutex);
+    uq_mgr->userq_funcs[queue->queue_type]->mqd_destroy(uq_mgr, queue);
      amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
      mutex_unlock(&uq_mgr->userq_mutex);
      kfree(queue);
@@ -135,6 +142,19 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
      return r;
  }
 
Quoted 14 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c int amdgpu_userq_ioctl(struct drm_device *dev, void *data, · line 157

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +13 -0
+extern const struct amdgpu_userq_funcs userq_gfx_v11_funcs;
+
+static void
+amdgpu_userqueue_setup_ip_funcs(struct amdgpu_userq_mgr *uq_mgr)
+{
+    int maj;
+    struct amdgpu_device *adev = uq_mgr->adev;
+    uint32_t version = adev->ip_versions[GC_HWIP][0];
+
+    maj = IP_VERSION_MAJ(version);
+    if (maj == 11)
+        uq_mgr->userq_funcs[AMDGPU_HW_IP_GFX] = &userq_gfx_v11_funcs;
+}

These can be per device and done in each IP's init code.

Agree, but as we have validated usermode queues only the gfx IP (gen 11) so far, we deliberately enabled only for this IP.

Once this code gets stable, we can gradually validate and add more engines and IPs, and then

we could also move this whole initialization code in IP->sw_init() as you suggested.

Quoted 94 lines
Quoted 94 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +1 -0
  int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_device *adev)
  {
@@ -142,6 +162,7 @@ int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_devi
      idr_init_base(&userq_mgr->userq_idr, 1);
      userq_mgr->adev = adev;
 
+    amdgpu_userqueue_setup_ip_funcs(userq_mgr);
      return 0;
  }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c new file +77 -0
new file mode 100644
index 000000000000..12e1a785b65a
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#include "amdgpu.h"
+#include "amdgpu_userqueue.h"
+
+static int
+amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_device *adev = uq_mgr->adev;
+    struct amdgpu_userq_ctx_space *mqd = &queue->mqd;
+    struct amdgpu_mqd *gfx_v11_mqd = &adev->mqds[queue->queue_type];
+    int size = gfx_v11_mqd->mqd_size;
+    int r;
+
+    r = amdgpu_bo_create_kernel(adev, size, PAGE_SIZE,
+                                AMDGPU_GEM_DOMAIN_GTT,
+                                &mqd->obj,
+                                &mqd->gpu_addr,
+                                &mqd->cpu_ptr);
+    if (r) {
+        DRM_ERROR("Failed to allocate bo for userqueue (%d)", r);
+        return r;
+    }
+
+    memset(mqd->cpu_ptr, 0, size);
+    r = amdgpu_bo_reserve(mqd->obj, false);
+    if (unlikely(r != 0)) {
+        DRM_ERROR("Failed to reserve mqd for userqueue (%d)", r);
+        goto free_mqd;
+    }
+
+    queue->userq_prop.use_doorbell = true;
+    queue->userq_prop.mqd_gpu_addr = mqd->gpu_addr;
+    r = gfx_v11_mqd->init_mqd(adev, (void *)mqd->cpu_ptr, &queue->userq_prop);
+    amdgpu_bo_unreserve(mqd->obj);
+    if (r) {
+        DRM_ERROR("Failed to init MQD for queue\n");
+        goto free_mqd;
+    }
+
+    DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
+    return 0;
+
+free_mqd:
+    amdgpu_bo_free_kernel(&mqd->obj,
+                          &mqd->gpu_addr,
+                          &mqd->cpu_ptr);
+   return r;
+}
+
+static void
+amdgpu_userq_gfx_v11_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_userq_ctx_space *mqd = &queue->mqd;
+
+    amdgpu_bo_free_kernel(&mqd->obj,
+                          &mqd->gpu_addr,
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c line 84

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c new file +7 -0
+                          &mqd->cpu_ptr);
+}
+
+const struct amdgpu_userq_funcs userq_gfx_v11_funcs = {
+    .mqd_create = amdgpu_userq_gfx_v11_mqd_create,
+    .mqd_destroy = amdgpu_userq_gfx_v11_mqd_destroy,
+};

We can just stick these in gfx_v11_0.c. No need for a new file.

Noted,

- Shashank

Quoted 31 lines

Alex

Quoted 28 lines
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +7 -1
index 7625a862b1fc..2911c88d0fed 100644
@@ -27,6 +27,12 @@
  #include "amdgpu.h"
  #define AMDGPU_MAX_USERQ 512
 
+struct amdgpu_userq_ctx_space {
+       struct amdgpu_bo *obj;
+       uint64_t gpu_addr;
+       void *cpu_ptr;
+};
+
  struct amdgpu_usermode_queue {
         int queue_id;
         int queue_type;
@@ -35,6 +41,7 @@ struct amdgpu_usermode_queue {
         struct amdgpu_vm *vm;
         struct amdgpu_userq_mgr *userq_mgr;
         struct amdgpu_mqd_prop userq_prop;
+       struct amdgpu_userq_ctx_space mqd;
  };
 
  struct amdgpu_userq_funcs {
--

2.40.0

#21 lore raw

Re: [PATCH v3 4/9] drm/amdgpu: create GFX-gen11 MQD for userqueue

In reply to Shashank Sharma
Quoted 20 lines · Shashank Sharma

From: Shashank Sharma <[email protected]>

A Memory queue descriptor (MQD) of a userqueue defines it in the harware's context. As MQD format can vary between different graphics IPs, we need gfx GEN specific handlers to create MQDs.

This patch:
- Introduces MQD hander functions for the usermode queues.
- Adds new functions to create and destroy MQD for GFX-GEN-11-IP

V1: Worked on review comments from Alex:
- Make MQD functions GEN and IP specific

V2: Worked on review comments from Alex:
- Reuse the existing adev->mqd[ip] for MQD creation
- Formatting and arrangement of code

V3:
- Integration with doorbell manager

Quoted 6 lines
Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>

---

Don't break up the Cc tag list and the Sob tag list.

Check out the following resources:
https://www.kernel.org/doc/html/v4.12/process/5.Posting.html#patch-formatting-and-changelogs
https://www.kernel.org/doc/html/v4.12/process/submitting-patches.html#the-canonical-patch-format

Quoted 167 lines
 drivers/gpu/drm/amd/amdgpu/Makefile           |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 21 +++++
 .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 84 +++++++++++++++++++
 .../gpu/drm/amd/include/amdgpu_userqueue.h    |  7 ++
 4 files changed, 113 insertions(+)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c
drivers/gpu/drm/amd/amdgpu/Makefile +1 -0
index 2d90ba618e5d..2cc7897de7e6 100644
@@ -212,6 +212,7 @@ amdgpu-y += amdgpu_amdkfd.o
 
 # add usermode queue
 amdgpu-y += amdgpu_userqueue.o
+amdgpu-y += amdgpu_userqueue_gfx_v11.o
 
 ifneq ($(CONFIG_HSA_AMD),)
 AMDKFD_PATH := ../amdkfd
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +21 -0
index 353f57c5a772..052c2c1e8aed 100644
@@ -81,6 +81,12 @@ static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq
         goto free_queue;
     }
 
+    r = uq_mgr->userq_funcs[queue->queue_type]->mqd_create(uq_mgr, queue);
+    if (r) {
+        DRM_ERROR("Failed to create/map userqueue MQD\n");
+        goto free_queue;
+    }
+
     args->out.queue_id = queue->queue_id;
     args->out.flags = 0;
     mutex_unlock(&uq_mgr->userq_mutex);
@@ -105,6 +111,7 @@ static void amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)
     }
 
     mutex_lock(&uq_mgr->userq_mutex);
+    uq_mgr->userq_funcs[queue->queue_type]->mqd_destroy(uq_mgr, queue);
     amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
     mutex_unlock(&uq_mgr->userq_mutex);
     kfree(queue);
@@ -135,6 +142,19 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
     return r;
 }
 
+extern const struct amdgpu_userq_funcs userq_gfx_v11_funcs;
+
+static void
+amdgpu_userqueue_setup_ip_funcs(struct amdgpu_userq_mgr *uq_mgr)
+{
+    int maj;
+    struct amdgpu_device *adev = uq_mgr->adev;
+    uint32_t version = adev->ip_versions[GC_HWIP][0];
+
+    maj = IP_VERSION_MAJ(version);
+    if (maj == 11)
+        uq_mgr->userq_funcs[AMDGPU_HW_IP_GFX] = &userq_gfx_v11_funcs;
+}
 
 int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_device *adev)
 {
@@ -142,6 +162,7 @@ int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_devi
     idr_init_base(&userq_mgr->userq_idr, 1);
     userq_mgr->adev = adev;
 
+    amdgpu_userqueue_setup_ip_funcs(userq_mgr);
     return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c new file +84 -0
new file mode 100644
index 000000000000..12e1a785b65a
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#include "amdgpu.h"
+#include "amdgpu_userqueue.h"
+
+static int
+amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_device *adev = uq_mgr->adev;
+    struct amdgpu_userq_ctx_space *mqd = &queue->mqd;
+    struct amdgpu_mqd *gfx_v11_mqd = &adev->mqds[queue->queue_type];
+    int size = gfx_v11_mqd->mqd_size;
+    int r;
+
+    r = amdgpu_bo_create_kernel(adev, size, PAGE_SIZE,
+                                AMDGPU_GEM_DOMAIN_GTT,
+                                &mqd->obj,
+                                &mqd->gpu_addr,
+                                &mqd->cpu_ptr);
+    if (r) {
+        DRM_ERROR("Failed to allocate bo for userqueue (%d)", r);
+        return r;
+    }
+
+    memset(mqd->cpu_ptr, 0, size);
+    r = amdgpu_bo_reserve(mqd->obj, false);
+    if (unlikely(r != 0)) {
+        DRM_ERROR("Failed to reserve mqd for userqueue (%d)", r);
+        goto free_mqd;
+    }
+
+    queue->userq_prop.use_doorbell = true;
+    queue->userq_prop.mqd_gpu_addr = mqd->gpu_addr;
+    r = gfx_v11_mqd->init_mqd(adev, (void *)mqd->cpu_ptr, &queue->userq_prop);
+    amdgpu_bo_unreserve(mqd->obj);
+    if (r) {
+        DRM_ERROR("Failed to init MQD for queue\n");
+        goto free_mqd;
+    }
+
+    DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
+    return 0;
+
+free_mqd:
+    amdgpu_bo_free_kernel(&mqd->obj,
+			   &mqd->gpu_addr,
+			   &mqd->cpu_ptr);
+   return r;
+}
+
+static void
+amdgpu_userq_gfx_v11_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_userq_ctx_space *mqd = &queue->mqd;
+
+    amdgpu_bo_free_kernel(&mqd->obj,
+			   &mqd->gpu_addr,
+			   &mqd->cpu_ptr);
+}
+
+const struct amdgpu_userq_funcs userq_gfx_v11_funcs = {
+    .mqd_create = amdgpu_userq_gfx_v11_mqd_create,
+    .mqd_destroy = amdgpu_userq_gfx_v11_mqd_destroy,
+};
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +0 -0
index 7625a862b1fc..2911c88d0fed 100644

drivers/gpu/drm/amd/include/amdgpu_userqueue.h line 35

Quoted 9 lines
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +6 -0
@@ -27,6 +27,12 @@
 #include "amdgpu.h"
 #define AMDGPU_MAX_USERQ 512
 
+struct amdgpu_userq_ctx_space {
+	struct amdgpu_bo *obj;
+	uint64_t gpu_addr;
+	void *cpu_ptr;
+};
+

Code is very readable when the name colums are aligned:

struct amdgpu_userq_ctx_space {
	struct amdgpu_bo   *obj;
	uint64_t            gpu_addr;
	void               *cpu_ptr;
};

And for the rest of your patches.

Regards,
Luben

Quoted 11 lines
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +1 -0
 struct amdgpu_usermode_queue {
 	int queue_id;
 	int queue_type;
@@ -35,6 +41,7 @@ struct amdgpu_usermode_queue {
 	struct amdgpu_vm *vm;
 	struct amdgpu_userq_mgr *userq_mgr;
 	struct amdgpu_mqd_prop userq_prop;
+	struct amdgpu_userq_ctx_space mqd;
 };
 
 struct amdgpu_userq_funcs {
#22 lore raw

PATCH v3 5/9 drm/amdgpu: create context space for usermode queue

In reply to Shashank Sharma

From: Shashank Sharma <[email protected]>

The FW expects us to allocate atleast one page as context space to process gang, process, shadow, GDS and FW related work. This patch creates a joint object for the same, and calculates GPU space offsets for each of these spaces.

V1: Addressed review comments on RFC patch:
Alex: Make this function IP specific

V2: Addressed review comments from Christian
- Allocate only one object for total FW space, and calculate offsets for each of these objects.

V3: Integration with doorbell manager

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c |  1 +
 .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 60 ++++++++++++++++++-
 .../gpu/drm/amd/include/amdgpu_userqueue.h    |  7 +++
 3 files changed, 66 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +1 -0
index 052c2c1e8aed..5672efcbcffc 100644
@@ -71,6 +71,7 @@ static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq
     queue->userq_prop.queue_size = mqd_in->queue_size;
 
     queue->doorbell_handle = mqd_in->doorbell_handle;
+    queue->shadow_ctx_gpu_addr = mqd_in->shadow_va;
     queue->queue_type = mqd_in->ip_type;
     queue->flags = mqd_in->flags;
     queue->vm = &fpriv->vm;
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +58 -2

92 lines not on this page · raw message

drivers/gpu/drm/amd/include/amdgpu_userqueue.h +7 -0
index 2911c88d0fed..8b62ef77cd26 100644
@@ -38,10 +38,17 @@ struct amdgpu_usermode_queue {
 	int queue_type;
 	uint64_t flags;
 	uint64_t doorbell_handle;
+	uint64_t proc_ctx_gpu_addr;
+	uint64_t gang_ctx_gpu_addr;
+	uint64_t gds_ctx_gpu_addr;
+	uint64_t fw_ctx_gpu_addr;
+	uint64_t shadow_ctx_gpu_addr;
+
 	struct amdgpu_vm *vm;
 	struct amdgpu_userq_mgr *userq_mgr;
 	struct amdgpu_mqd_prop userq_prop;
 	struct amdgpu_userq_ctx_space mqd;
+	struct amdgpu_userq_ctx_space fw_space;
 };
 
 struct amdgpu_userq_funcs {
Signature · 1 line
2.40.0
#23 lore raw

Re: [PATCH v3 5/9] drm/amdgpu: create context space for usermode queue

Quoted 7 lines · Shashank Sharma

From: Shashank Sharma <[email protected]>

The FW expects us to allocate atleast one page as context space to process gang, process, shadow, GDS and FW related work. This patch creates a joint object for the same, and calculates GPU space offsets for each of these spaces.

The shadow bo, at least, should come from user space since userspace will want to mess with it to optimize it's register handling at least for gfx. The gds and csa could also come from userspace. That would simplify things. The UMD would just specify them in the MQD descriptor for GFX in the IOCTL. We could allocate them in the kernel, but then we'd need to make sure they were mapped into the GPUVM space for the UMD, That could get pretty big if they have a lot of queues.

Alex

Quoted 156 lines

V1: Addressed review comments on RFC patch:
Alex: Make this function IP specific

V2: Addressed review comments from Christian
- Allocate only one object for total FW space, and calculate offsets for each of these objects.

V3: Integration with doorbell manager

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c |  1 +
 .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 60 ++++++++++++++++++-
 .../gpu/drm/amd/include/amdgpu_userqueue.h    |  7 +++
 3 files changed, 66 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +1 -0
index 052c2c1e8aed..5672efcbcffc 100644
@@ -71,6 +71,7 @@ static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq
     queue->userq_prop.queue_size = mqd_in->queue_size;
 
     queue->doorbell_handle = mqd_in->doorbell_handle;
+    queue->shadow_ctx_gpu_addr = mqd_in->shadow_va;
     queue->queue_type = mqd_in->ip_type;
     queue->flags = mqd_in->flags;
     queue->vm = &fpriv->vm;
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +58 -2
index 12e1a785b65a..52de96727f98 100644
@@ -23,6 +23,51 @@
 #include "amdgpu.h"
 #include "amdgpu_userqueue.h"
 
+#define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE
+#define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
+#define AMDGPU_USERQ_FW_CTX_SZ PAGE_SIZE
+#define AMDGPU_USERQ_GDS_CTX_SZ PAGE_SIZE
+
+static int amdgpu_userq_gfx_v11_create_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
+                                                 struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_device *adev = uq_mgr->adev;
+    struct amdgpu_userq_ctx_space *ctx = &queue->fw_space;
+    int r, size;
+
+    /*
+     * The FW expects atleast one page space allocated for
+     * process ctx, gang ctx, gds ctx, fw ctx and shadow ctx each.
+     */
+    size = AMDGPU_USERQ_PROC_CTX_SZ + AMDGPU_USERQ_GANG_CTX_SZ +
+           AMDGPU_USERQ_FW_CTX_SZ + AMDGPU_USERQ_GDS_CTX_SZ;
+    r = amdgpu_bo_create_kernel(adev, size, PAGE_SIZE,
+                                AMDGPU_GEM_DOMAIN_GTT,
+                                &ctx->obj,
+                                &ctx->gpu_addr,
+                                &ctx->cpu_ptr);
+    if (r) {
+        DRM_ERROR("Failed to allocate ctx space bo for userqueue, err:%d\n", r);
+        return r;
+    }
+
+    queue->proc_ctx_gpu_addr = ctx->gpu_addr;
+    queue->gang_ctx_gpu_addr = queue->proc_ctx_gpu_addr + AMDGPU_USERQ_PROC_CTX_SZ;
+    queue->fw_ctx_gpu_addr = queue->gang_ctx_gpu_addr + AMDGPU_USERQ_GANG_CTX_SZ;
+    queue->gds_ctx_gpu_addr = queue->fw_ctx_gpu_addr + AMDGPU_USERQ_FW_CTX_SZ;
+    return 0;
+}
+
+static void amdgpu_userq_gfx_v11_destroy_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
+                                                   struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_userq_ctx_space *ctx = &queue->fw_space;
+
+    amdgpu_bo_free_kernel(&ctx->obj,
+                          &ctx->gpu_addr,
+                          &ctx->cpu_ptr);
+}
+
 static int
 amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
 {
@@ -43,10 +88,17 @@ amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_u
     }
 
     memset(mqd->cpu_ptr, 0, size);
+
+    r = amdgpu_userq_gfx_v11_create_ctx_space(uq_mgr, queue);
+    if (r) {
+        DRM_ERROR("Failed to create CTX space for userqueue (%d)\n", r);
+        goto free_mqd;
+    }
+
     r = amdgpu_bo_reserve(mqd->obj, false);
     if (unlikely(r != 0)) {
         DRM_ERROR("Failed to reserve mqd for userqueue (%d)", r);
-        goto free_mqd;
+        goto free_ctx;
     }
 
     queue->userq_prop.use_doorbell = true;
@@ -55,12 +107,15 @@ amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_u
     amdgpu_bo_unreserve(mqd->obj);
     if (r) {
         DRM_ERROR("Failed to init MQD for queue\n");
-        goto free_mqd;
+        goto free_ctx;
     }
 
     DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
     return 0;
 
+free_ctx:
+    amdgpu_userq_gfx_v11_destroy_ctx_space(uq_mgr, queue);
+
 free_mqd:
     amdgpu_bo_free_kernel(&mqd->obj,
                           &mqd->gpu_addr,
@@ -73,6 +128,7 @@ amdgpu_userq_gfx_v11_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_
 {
     struct amdgpu_userq_ctx_space *mqd = &queue->mqd;
 
+    amdgpu_userq_gfx_v11_destroy_ctx_space(uq_mgr, queue);
     amdgpu_bo_free_kernel(&mqd->obj,
                           &mqd->gpu_addr,
                           &mqd->cpu_ptr);
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +7 -1
index 2911c88d0fed..8b62ef77cd26 100644
@@ -38,10 +38,17 @@ struct amdgpu_usermode_queue {
        int queue_type;
        uint64_t flags;
        uint64_t doorbell_handle;
+       uint64_t proc_ctx_gpu_addr;
+       uint64_t gang_ctx_gpu_addr;
+       uint64_t gds_ctx_gpu_addr;
+       uint64_t fw_ctx_gpu_addr;
+       uint64_t shadow_ctx_gpu_addr;
+
        struct amdgpu_vm *vm;
        struct amdgpu_userq_mgr *userq_mgr;
        struct amdgpu_mqd_prop userq_prop;
        struct amdgpu_userq_ctx_space mqd;
+       struct amdgpu_userq_ctx_space fw_space;
 };
 
 struct amdgpu_userq_funcs {
--

2.40.0

#24 lore raw

Re: [PATCH v3 5/9] drm/amdgpu: create context space for usermode queue

Quoted 8 lines · Alex Deucher
Quoted 6 lines · Shashank Sharma

From: Shashank Sharma <[email protected]>

The FW expects us to allocate atleast one page as context space to process gang, process, shadow, GDS and FW related work. This patch creates a joint object for the same, and calculates GPU space offsets for each of these spaces.

Quoted 8 lines

The shadow bo, at least, should come from user space since userspace will want to mess with it to optimize it's register handling at least for gfx. The gds and csa could also come from userspace. That would simplify things. The UMD would just specify them in the MQD descriptor for GFX in the IOCTL. We could allocate them in the kernel, but then we'd need to make sure they were mapped into the GPUVM space for the UMD, That could get pretty big if they have a lot of queues.

The shadow space is indeed getting created in userspace for the working solution,

I just forgot update the commit message here.  Should I move the GDS bo to

userspace as well ?

- Shashank

Quoted 158 lines

Alex

Quoted 155 lines

V1: Addressed review comments on RFC patch:
Alex: Make this function IP specific

V2: Addressed review comments from Christian
- Allocate only one object for total FW space, and calculate offsets for each of these objects.

V3: Integration with doorbell manager

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c |  1 +
  .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 60 ++++++++++++++++++-
  .../gpu/drm/amd/include/amdgpu_userqueue.h    |  7 +++
  3 files changed, 66 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +1 -0
index 052c2c1e8aed..5672efcbcffc 100644
@@ -71,6 +71,7 @@ static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq
      queue->userq_prop.queue_size = mqd_in->queue_size;
 
      queue->doorbell_handle = mqd_in->doorbell_handle;
+    queue->shadow_ctx_gpu_addr = mqd_in->shadow_va;
      queue->queue_type = mqd_in->ip_type;
      queue->flags = mqd_in->flags;
      queue->vm = &fpriv->vm;
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +58 -2
index 12e1a785b65a..52de96727f98 100644
@@ -23,6 +23,51 @@
  #include "amdgpu.h"
  #include "amdgpu_userqueue.h"
 
+#define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE
+#define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
+#define AMDGPU_USERQ_FW_CTX_SZ PAGE_SIZE
+#define AMDGPU_USERQ_GDS_CTX_SZ PAGE_SIZE
+
+static int amdgpu_userq_gfx_v11_create_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
+                                                 struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_device *adev = uq_mgr->adev;
+    struct amdgpu_userq_ctx_space *ctx = &queue->fw_space;
+    int r, size;
+
+    /*
+     * The FW expects atleast one page space allocated for
+     * process ctx, gang ctx, gds ctx, fw ctx and shadow ctx each.
+     */
+    size = AMDGPU_USERQ_PROC_CTX_SZ + AMDGPU_USERQ_GANG_CTX_SZ +
+           AMDGPU_USERQ_FW_CTX_SZ + AMDGPU_USERQ_GDS_CTX_SZ;
+    r = amdgpu_bo_create_kernel(adev, size, PAGE_SIZE,
+                                AMDGPU_GEM_DOMAIN_GTT,
+                                &ctx->obj,
+                                &ctx->gpu_addr,
+                                &ctx->cpu_ptr);
+    if (r) {
+        DRM_ERROR("Failed to allocate ctx space bo for userqueue, err:%d\n", r);
+        return r;
+    }
+
+    queue->proc_ctx_gpu_addr = ctx->gpu_addr;
+    queue->gang_ctx_gpu_addr = queue->proc_ctx_gpu_addr + AMDGPU_USERQ_PROC_CTX_SZ;
+    queue->fw_ctx_gpu_addr = queue->gang_ctx_gpu_addr + AMDGPU_USERQ_GANG_CTX_SZ;
+    queue->gds_ctx_gpu_addr = queue->fw_ctx_gpu_addr + AMDGPU_USERQ_FW_CTX_SZ;
+    return 0;
+}
+
+static void amdgpu_userq_gfx_v11_destroy_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
+                                                   struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_userq_ctx_space *ctx = &queue->fw_space;
+
+    amdgpu_bo_free_kernel(&ctx->obj,
+                          &ctx->gpu_addr,
+                          &ctx->cpu_ptr);
+}
+
  static int
  amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
  {
@@ -43,10 +88,17 @@ amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_u
      }
 
      memset(mqd->cpu_ptr, 0, size);
+
+    r = amdgpu_userq_gfx_v11_create_ctx_space(uq_mgr, queue);
+    if (r) {
+        DRM_ERROR("Failed to create CTX space for userqueue (%d)\n", r);
+        goto free_mqd;
+    }
+
      r = amdgpu_bo_reserve(mqd->obj, false);
      if (unlikely(r != 0)) {
          DRM_ERROR("Failed to reserve mqd for userqueue (%d)", r);
-        goto free_mqd;
+        goto free_ctx;
      }
 
      queue->userq_prop.use_doorbell = true;
@@ -55,12 +107,15 @@ amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_u
      amdgpu_bo_unreserve(mqd->obj);
      if (r) {
          DRM_ERROR("Failed to init MQD for queue\n");
-        goto free_mqd;
+        goto free_ctx;
      }
 
      DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
      return 0;
 
+free_ctx:
+    amdgpu_userq_gfx_v11_destroy_ctx_space(uq_mgr, queue);
+
  free_mqd:
      amdgpu_bo_free_kernel(&mqd->obj,
                            &mqd->gpu_addr,
@@ -73,6 +128,7 @@ amdgpu_userq_gfx_v11_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_
  {
      struct amdgpu_userq_ctx_space *mqd = &queue->mqd;
 
+    amdgpu_userq_gfx_v11_destroy_ctx_space(uq_mgr, queue);
      amdgpu_bo_free_kernel(&mqd->obj,
                            &mqd->gpu_addr,
                            &mqd->cpu_ptr);
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +7 -1
index 2911c88d0fed..8b62ef77cd26 100644
@@ -38,10 +38,17 @@ struct amdgpu_usermode_queue {
         int queue_type;
         uint64_t flags;
         uint64_t doorbell_handle;
+       uint64_t proc_ctx_gpu_addr;
+       uint64_t gang_ctx_gpu_addr;
+       uint64_t gds_ctx_gpu_addr;
+       uint64_t fw_ctx_gpu_addr;
+       uint64_t shadow_ctx_gpu_addr;
+
         struct amdgpu_vm *vm;
         struct amdgpu_userq_mgr *userq_mgr;
         struct amdgpu_mqd_prop userq_prop;
         struct amdgpu_userq_ctx_space mqd;
+       struct amdgpu_userq_ctx_space fw_space;
  };
 
  struct amdgpu_userq_funcs {
--

2.40.0

#25 lore raw

Re: [PATCH v3 5/9] drm/amdgpu: create context space for usermode queue

In reply to Shashank Sharma
Quoted 42 lines · Shashank Sharma

From: Shashank Sharma <[email protected]>

The FW expects us to allocate atleast one page as context space to process gang, process, shadow, GDS and FW related work. This patch creates a joint object for the same, and calculates GPU space offsets for each of these spaces.

V1: Addressed review comments on RFC patch:
Alex: Make this function IP specific

V2: Addressed review comments from Christian
- Allocate only one object for total FW space, and calculate offsets for each of these objects.

V3: Integration with doorbell manager

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c |  1 +
 .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 60 ++++++++++++++++++-
 .../gpu/drm/amd/include/amdgpu_userqueue.h    |  7 +++
 3 files changed, 66 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +1 -0
index 052c2c1e8aed..5672efcbcffc 100644
@@ -71,6 +71,7 @@ static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq
     queue->userq_prop.queue_size = mqd_in->queue_size;
 
     queue->doorbell_handle = mqd_in->doorbell_handle;
+    queue->shadow_ctx_gpu_addr = mqd_in->shadow_va;
     queue->queue_type = mqd_in->ip_type;
     queue->flags = mqd_in->flags;
     queue->vm = &fpriv->vm;
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +0 -0
index 12e1a785b65a..52de96727f98 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c line 30

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +5 -0
@@ -23,6 +23,51 @@
 #include "amdgpu.h"
 #include "amdgpu_userqueue.h"
 
+#define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE
+#define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
+#define AMDGPU_USERQ_FW_CTX_SZ PAGE_SIZE
+#define AMDGPU_USERQ_GDS_CTX_SZ PAGE_SIZE
+

Leaving a single space after the macro name and its value makes it hard to read. Please align the value columns and leave at least 3 spaces--this would make it readable. For instance,

#define AMDGPU_USERQ_PROC_CTX_SZ   PAGE_SIZE
#define AMDGPU_USERQ_GANG_CTX_SZ   PAGE_SIZE
#define AMDGPU_USERQ_FW_CTX_SZ     PAGE_SIZE
#define AMDGPU_USERQ_GDS_CTX_SZ    PAGE_SIZE

Regards,
Luben

Quoted 109 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +53 -2
+static int amdgpu_userq_gfx_v11_create_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
+                                                 struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_device *adev = uq_mgr->adev;
+    struct amdgpu_userq_ctx_space *ctx = &queue->fw_space;
+    int r, size;
+
+    /*
+     * The FW expects atleast one page space allocated for
+     * process ctx, gang ctx, gds ctx, fw ctx and shadow ctx each.
+     */
+    size = AMDGPU_USERQ_PROC_CTX_SZ + AMDGPU_USERQ_GANG_CTX_SZ +
+           AMDGPU_USERQ_FW_CTX_SZ + AMDGPU_USERQ_GDS_CTX_SZ;
+    r = amdgpu_bo_create_kernel(adev, size, PAGE_SIZE,
+                                AMDGPU_GEM_DOMAIN_GTT,
+                                &ctx->obj,
+                                &ctx->gpu_addr,
+                                &ctx->cpu_ptr);
+    if (r) {
+        DRM_ERROR("Failed to allocate ctx space bo for userqueue, err:%d\n", r);
+        return r;
+    }
+
+    queue->proc_ctx_gpu_addr = ctx->gpu_addr;
+    queue->gang_ctx_gpu_addr = queue->proc_ctx_gpu_addr + AMDGPU_USERQ_PROC_CTX_SZ;
+    queue->fw_ctx_gpu_addr = queue->gang_ctx_gpu_addr + AMDGPU_USERQ_GANG_CTX_SZ;
+    queue->gds_ctx_gpu_addr = queue->fw_ctx_gpu_addr + AMDGPU_USERQ_FW_CTX_SZ;
+    return 0;
+}
+
+static void amdgpu_userq_gfx_v11_destroy_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
+                                                   struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_userq_ctx_space *ctx = &queue->fw_space;
+
+    amdgpu_bo_free_kernel(&ctx->obj,
+                          &ctx->gpu_addr,
+                          &ctx->cpu_ptr);
+}
+
 static int
 amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
 {
@@ -43,10 +88,17 @@ amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_u
     }
 
     memset(mqd->cpu_ptr, 0, size);
+
+    r = amdgpu_userq_gfx_v11_create_ctx_space(uq_mgr, queue);
+    if (r) {
+        DRM_ERROR("Failed to create CTX space for userqueue (%d)\n", r);
+        goto free_mqd;
+    }
+
     r = amdgpu_bo_reserve(mqd->obj, false);
     if (unlikely(r != 0)) {
         DRM_ERROR("Failed to reserve mqd for userqueue (%d)", r);
-        goto free_mqd;
+        goto free_ctx;
     }
 
     queue->userq_prop.use_doorbell = true;
@@ -55,12 +107,15 @@ amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_u
     amdgpu_bo_unreserve(mqd->obj);
     if (r) {
         DRM_ERROR("Failed to init MQD for queue\n");
-        goto free_mqd;
+        goto free_ctx;
     }
 
     DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
     return 0;
 
+free_ctx:
+    amdgpu_userq_gfx_v11_destroy_ctx_space(uq_mgr, queue);
+
 free_mqd:
     amdgpu_bo_free_kernel(&mqd->obj,
 			   &mqd->gpu_addr,
@@ -73,6 +128,7 @@ amdgpu_userq_gfx_v11_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_
 {
     struct amdgpu_userq_ctx_space *mqd = &queue->mqd;
 
+    amdgpu_userq_gfx_v11_destroy_ctx_space(uq_mgr, queue);
     amdgpu_bo_free_kernel(&mqd->obj,
 			   &mqd->gpu_addr,
 			   &mqd->cpu_ptr);
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +7 -0
index 2911c88d0fed..8b62ef77cd26 100644
@@ -38,10 +38,17 @@ struct amdgpu_usermode_queue {
 	int queue_type;
 	uint64_t flags;
 	uint64_t doorbell_handle;
+	uint64_t proc_ctx_gpu_addr;
+	uint64_t gang_ctx_gpu_addr;
+	uint64_t gds_ctx_gpu_addr;
+	uint64_t fw_ctx_gpu_addr;
+	uint64_t shadow_ctx_gpu_addr;
+
 	struct amdgpu_vm *vm;
 	struct amdgpu_userq_mgr *userq_mgr;
 	struct amdgpu_mqd_prop userq_prop;
 	struct amdgpu_userq_ctx_space mqd;
+	struct amdgpu_userq_ctx_space fw_space;
 };
 
 struct amdgpu_userq_funcs {
#26 lore raw

Re: [PATCH v3 5/9] drm/amdgpu: create context space for usermode queue

Quoted 56 lines · Luben Tuikov
Quoted 42 lines · Shashank Sharma

From: Shashank Sharma <[email protected]>

The FW expects us to allocate atleast one page as context space to process gang, process, shadow, GDS and FW related work. This patch creates a joint object for the same, and calculates GPU space offsets for each of these spaces.

V1: Addressed review comments on RFC patch:
Alex: Make this function IP specific

V2: Addressed review comments from Christian
- Allocate only one object for total FW space, and calculate offsets for each of these objects.

V3: Integration with doorbell manager

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c |  1 +
  .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 60 ++++++++++++++++++-
  .../gpu/drm/amd/include/amdgpu_userqueue.h    |  7 +++
  3 files changed, 66 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +1 -0
index 052c2c1e8aed..5672efcbcffc 100644
@@ -71,6 +71,7 @@ static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq
      queue->userq_prop.queue_size = mqd_in->queue_size;
 
      queue->doorbell_handle = mqd_in->doorbell_handle;
+    queue->shadow_ctx_gpu_addr = mqd_in->shadow_va;
      queue->queue_type = mqd_in->ip_type;
      queue->flags = mqd_in->flags;
      queue->vm = &fpriv->vm;
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +0 -0
index 12e1a785b65a..52de96727f98 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c line 30

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +5 -0
@@ -23,6 +23,51 @@
  #include "amdgpu.h"
  #include "amdgpu_userqueue.h"
 
+#define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE
+#define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
+#define AMDGPU_USERQ_FW_CTX_SZ PAGE_SIZE
+#define AMDGPU_USERQ_GDS_CTX_SZ PAGE_SIZE
+

Leaving a single space after the macro name and its value makes it hard to read. Please align the value columns and leave at least 3 spaces--this would make it readable. For instance,

Quoted 4 lines
#define AMDGPU_USERQ_PROC_CTX_SZ   PAGE_SIZE
#define AMDGPU_USERQ_GANG_CTX_SZ   PAGE_SIZE
#define AMDGPU_USERQ_FW_CTX_SZ     PAGE_SIZE
#define AMDGPU_USERQ_GDS_CTX_SZ    PAGE_SIZE

Noted,

Shashank

Quoted 113 lines

Regards,
Luben

Quoted 109 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +53 -2
+static int amdgpu_userq_gfx_v11_create_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
+                                                 struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_device *adev = uq_mgr->adev;
+    struct amdgpu_userq_ctx_space *ctx = &queue->fw_space;
+    int r, size;
+
+    /*
+     * The FW expects atleast one page space allocated for
+     * process ctx, gang ctx, gds ctx, fw ctx and shadow ctx each.
+     */
+    size = AMDGPU_USERQ_PROC_CTX_SZ + AMDGPU_USERQ_GANG_CTX_SZ +
+           AMDGPU_USERQ_FW_CTX_SZ + AMDGPU_USERQ_GDS_CTX_SZ;
+    r = amdgpu_bo_create_kernel(adev, size, PAGE_SIZE,
+                                AMDGPU_GEM_DOMAIN_GTT,
+                                &ctx->obj,
+                                &ctx->gpu_addr,
+                                &ctx->cpu_ptr);
+    if (r) {
+        DRM_ERROR("Failed to allocate ctx space bo for userqueue, err:%d\n", r);
+        return r;
+    }
+
+    queue->proc_ctx_gpu_addr = ctx->gpu_addr;
+    queue->gang_ctx_gpu_addr = queue->proc_ctx_gpu_addr + AMDGPU_USERQ_PROC_CTX_SZ;
+    queue->fw_ctx_gpu_addr = queue->gang_ctx_gpu_addr + AMDGPU_USERQ_GANG_CTX_SZ;
+    queue->gds_ctx_gpu_addr = queue->fw_ctx_gpu_addr + AMDGPU_USERQ_FW_CTX_SZ;
+    return 0;
+}
+
+static void amdgpu_userq_gfx_v11_destroy_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
+                                                   struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_userq_ctx_space *ctx = &queue->fw_space;
+
+    amdgpu_bo_free_kernel(&ctx->obj,
+                          &ctx->gpu_addr,
+                          &ctx->cpu_ptr);
+}
+
  static int
  amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
  {
@@ -43,10 +88,17 @@ amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_u
      }
 
      memset(mqd->cpu_ptr, 0, size);
+
+    r = amdgpu_userq_gfx_v11_create_ctx_space(uq_mgr, queue);
+    if (r) {
+        DRM_ERROR("Failed to create CTX space for userqueue (%d)\n", r);
+        goto free_mqd;
+    }
+
      r = amdgpu_bo_reserve(mqd->obj, false);
      if (unlikely(r != 0)) {
          DRM_ERROR("Failed to reserve mqd for userqueue (%d)", r);
-        goto free_mqd;
+        goto free_ctx;
      }
 
      queue->userq_prop.use_doorbell = true;
@@ -55,12 +107,15 @@ amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_u
      amdgpu_bo_unreserve(mqd->obj);
      if (r) {
          DRM_ERROR("Failed to init MQD for queue\n");
-        goto free_mqd;
+        goto free_ctx;
      }
 
      DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
      return 0;
 
+free_ctx:
+    amdgpu_userq_gfx_v11_destroy_ctx_space(uq_mgr, queue);
+
  free_mqd:
      amdgpu_bo_free_kernel(&mqd->obj,
  			   &mqd->gpu_addr,
@@ -73,6 +128,7 @@ amdgpu_userq_gfx_v11_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_
  {
      struct amdgpu_userq_ctx_space *mqd = &queue->mqd;
 
+    amdgpu_userq_gfx_v11_destroy_ctx_space(uq_mgr, queue);
      amdgpu_bo_free_kernel(&mqd->obj,
  			   &mqd->gpu_addr,
  			   &mqd->cpu_ptr);
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +7 -0
index 2911c88d0fed..8b62ef77cd26 100644
@@ -38,10 +38,17 @@ struct amdgpu_usermode_queue {
  	int queue_type;
  	uint64_t flags;
  	uint64_t doorbell_handle;
+	uint64_t proc_ctx_gpu_addr;
+	uint64_t gang_ctx_gpu_addr;
+	uint64_t gds_ctx_gpu_addr;
+	uint64_t fw_ctx_gpu_addr;
+	uint64_t shadow_ctx_gpu_addr;
+
  	struct amdgpu_vm *vm;
  	struct amdgpu_userq_mgr *userq_mgr;
  	struct amdgpu_mqd_prop userq_prop;
  	struct amdgpu_userq_ctx_space mqd;
+	struct amdgpu_userq_ctx_space fw_space;
  };
 
  struct amdgpu_userq_funcs {
#27 lore raw

PATCH v3 6/9 drm/amdgpu: add new parameters in v11_struct

In reply to Shashank Sharma

From: Arvind Yadav <[email protected]>

This patch:
- adds some new parameters defined for the gfx usermode queues use cases in the v11_mqd_struct.
- sets those parametes with the respective allocated gpu context space addresses.

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
Cc Shashank Sharma <[email protected]>
---
 .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 21 ++++++++++++++++++-
 drivers/gpu/drm/amd/include/v11_structs.h     | 16 +++++++-------
 2 files changed, 28 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +20 -1
index 52de96727f98..39e90ea32fcb 100644
@@ -22,6 +22,7 @@
  */
 #include "amdgpu.h"
 #include "amdgpu_userqueue.h"
+#include "v11_structs.h"
 
 #define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE
 #define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
@@ -68,6 +69,22 @@ static void amdgpu_userq_gfx_v11_destroy_ctx_space(struct amdgpu_userq_mgr *uq_m
                           &ctx->cpu_ptr);
 }
 
+static void
+amdgpu_userq_set_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
+                           struct amdgpu_usermode_queue *queue)
+{
+    struct v11_gfx_mqd *mqd = queue->mqd.cpu_ptr;
+
+    mqd->shadow_base_lo = queue->shadow_ctx_gpu_addr & 0xfffffffc;
+    mqd->shadow_base_hi = upper_32_bits(queue->shadow_ctx_gpu_addr);
+
+    mqd->gds_bkup_base_lo = queue->gds_ctx_gpu_addr & 0xfffffffc;
+    mqd->gds_bkup_base_hi = upper_32_bits(queue->gds_ctx_gpu_addr);
+
+    mqd->fw_work_area_base_lo = queue->fw_ctx_gpu_addr & 0xfffffffc;
+    mqd->fw_work_area_base_lo = upper_32_bits(queue->fw_ctx_gpu_addr);
+}
+
 static int
 amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
 {
@@ -104,12 +121,14 @@ amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_u
     queue->userq_prop.use_doorbell = true;
     queue->userq_prop.mqd_gpu_addr = mqd->gpu_addr;
     r = gfx_v11_mqd->init_mqd(adev, (void *)mqd->cpu_ptr, &queue->userq_prop);
-    amdgpu_bo_unreserve(mqd->obj);
     if (r) {
+        amdgpu_bo_unreserve(mqd->obj);
         DRM_ERROR("Failed to init MQD for queue\n");
         goto free_ctx;
     }
 
+    amdgpu_userq_set_ctx_space(uq_mgr, queue);
+    amdgpu_bo_unreserve(mqd->obj);
     DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
     return 0;
 
drivers/gpu/drm/amd/include/v11_structs.h +8 -8
index b8ff7456ae0b..f8008270f813 100644
@@ -25,14 +25,14 @@
 #define V11_STRUCTS_H_
 
 struct v11_gfx_mqd {
-	uint32_t reserved_0; // offset: 0  (0x0)
-	uint32_t reserved_1; // offset: 1  (0x1)
-	uint32_t reserved_2; // offset: 2  (0x2)
-	uint32_t reserved_3; // offset: 3  (0x3)
-	uint32_t reserved_4; // offset: 4  (0x4)
-	uint32_t reserved_5; // offset: 5  (0x5)
-	uint32_t reserved_6; // offset: 6  (0x6)
-	uint32_t reserved_7; // offset: 7  (0x7)
+	uint32_t shadow_base_lo; // offset: 0  (0x0)
+	uint32_t shadow_base_hi; // offset: 1  (0x1)
+	uint32_t gds_bkup_base_lo; // offset: 2  (0x2)
+	uint32_t gds_bkup_base_hi; // offset: 3  (0x3)
+	uint32_t fw_work_area_base_lo; // offset: 4  (0x4)
+	uint32_t fw_work_area_base_hi; // offset: 5  (0x5)
+	uint32_t shadow_initialized; // offset: 6  (0x6)
+	uint32_t ib_vmid; // offset: 7  (0x7)
 	uint32_t reserved_8; // offset: 8  (0x8)
 	uint32_t reserved_9; // offset: 9  (0x9)
 	uint32_t reserved_10; // offset: 10  (0xA)
Signature · 1 line
2.40.0
#28 lore raw

Re: [PATCH v3 6/9] drm/amdgpu: add new parameters in v11_struct

Quoted 86 lines · Shashank Sharma

From: Arvind Yadav <[email protected]>

This patch:
- adds some new parameters defined for the gfx usermode queues use cases in the v11_mqd_struct.
- sets those parametes with the respective allocated gpu context space addresses.

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
Cc Shashank Sharma <[email protected]>
---
 .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 21 ++++++++++++++++++-
 drivers/gpu/drm/amd/include/v11_structs.h     | 16 +++++++-------
 2 files changed, 28 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +20 -1
index 52de96727f98..39e90ea32fcb 100644
@@ -22,6 +22,7 @@
  */
 #include "amdgpu.h"
 #include "amdgpu_userqueue.h"
+#include "v11_structs.h"
 
 #define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE
 #define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
@@ -68,6 +69,22 @@ static void amdgpu_userq_gfx_v11_destroy_ctx_space(struct amdgpu_userq_mgr *uq_m
                           &ctx->cpu_ptr);
 }
 
+static void
+amdgpu_userq_set_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
+                           struct amdgpu_usermode_queue *queue)
+{
+    struct v11_gfx_mqd *mqd = queue->mqd.cpu_ptr;
+
+    mqd->shadow_base_lo = queue->shadow_ctx_gpu_addr & 0xfffffffc;
+    mqd->shadow_base_hi = upper_32_bits(queue->shadow_ctx_gpu_addr);
+
+    mqd->gds_bkup_base_lo = queue->gds_ctx_gpu_addr & 0xfffffffc;
+    mqd->gds_bkup_base_hi = upper_32_bits(queue->gds_ctx_gpu_addr);
+
+    mqd->fw_work_area_base_lo = queue->fw_ctx_gpu_addr & 0xfffffffc;
+    mqd->fw_work_area_base_lo = upper_32_bits(queue->fw_ctx_gpu_addr);
+}
+
 static int
 amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
 {
@@ -104,12 +121,14 @@ amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_u
     queue->userq_prop.use_doorbell = true;
     queue->userq_prop.mqd_gpu_addr = mqd->gpu_addr;
     r = gfx_v11_mqd->init_mqd(adev, (void *)mqd->cpu_ptr, &queue->userq_prop);
-    amdgpu_bo_unreserve(mqd->obj);
     if (r) {
+        amdgpu_bo_unreserve(mqd->obj);
         DRM_ERROR("Failed to init MQD for queue\n");
         goto free_ctx;
     }
 
+    amdgpu_userq_set_ctx_space(uq_mgr, queue);
+    amdgpu_bo_unreserve(mqd->obj);
     DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
     return 0;
 
drivers/gpu/drm/amd/include/v11_structs.h +1 -8
index b8ff7456ae0b..f8008270f813 100644
@@ -25,14 +25,14 @@
 #define V11_STRUCTS_H_
 
 struct v11_gfx_mqd {
-       uint32_t reserved_0; // offset: 0  (0x0)
-       uint32_t reserved_1; // offset: 1  (0x1)
-       uint32_t reserved_2; // offset: 2  (0x2)
-       uint32_t reserved_3; // offset: 3  (0x3)
-       uint32_t reserved_4; // offset: 4  (0x4)
-       uint32_t reserved_5; // offset: 5  (0x5)
-       uint32_t reserved_6; // offset: 6  (0x6)
-       uint32_t reserved_7; // offset: 7  (0x7)
+       uint32_t shadow_base_lo; // offset: 0  (0x0)

drivers/gpu/drm/amd/include/v11_structs.h line 38

Quoted 10 lines
drivers/gpu/drm/amd/include/v11_structs.h +7 -0
+       uint32_t shadow_base_hi; // offset: 1  (0x1)
+       uint32_t gds_bkup_base_lo; // offset: 2  (0x2)
+       uint32_t gds_bkup_base_hi; // offset: 3  (0x3)
+       uint32_t fw_work_area_base_lo; // offset: 4  (0x4)
+       uint32_t fw_work_area_base_hi; // offset: 5  (0x5)
+       uint32_t shadow_initialized; // offset: 6  (0x6)
+       uint32_t ib_vmid; // offset: 7  (0x7)
        uint32_t reserved_8; // offset: 8  (0x8)
        uint32_t reserved_9; // offset: 9  (0x9)
        uint32_t reserved_10; // offset: 10  (0xA)

We should split this hunk out as a separate patch and upstream it now.

Alex

Quoted 3 lines

--
2.40.0

#29 lore raw

Re: [PATCH v3 6/9] drm/amdgpu: add new parameters in v11_struct

Quoted 90 lines · Alex Deucher
Quoted 88 lines · Shashank Sharma

From: Arvind Yadav <[email protected]>

This patch:
- adds some new parameters defined for the gfx usermode queues use cases in the v11_mqd_struct.
- sets those parametes with the respective allocated gpu context space addresses.

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
Cc Shashank Sharma <[email protected]>
---
  .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 21 ++++++++++++++++++-
  drivers/gpu/drm/amd/include/v11_structs.h     | 16 +++++++-------
  2 files changed, 28 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +20 -1
index 52de96727f98..39e90ea32fcb 100644
@@ -22,6 +22,7 @@
   */
  #include "amdgpu.h"
  #include "amdgpu_userqueue.h"
+#include "v11_structs.h"
 
  #define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE
  #define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
@@ -68,6 +69,22 @@ static void amdgpu_userq_gfx_v11_destroy_ctx_space(struct amdgpu_userq_mgr *uq_m
                            &ctx->cpu_ptr);
  }
 
+static void
+amdgpu_userq_set_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
+                           struct amdgpu_usermode_queue *queue)
+{
+    struct v11_gfx_mqd *mqd = queue->mqd.cpu_ptr;
+
+    mqd->shadow_base_lo = queue->shadow_ctx_gpu_addr & 0xfffffffc;
+    mqd->shadow_base_hi = upper_32_bits(queue->shadow_ctx_gpu_addr);
+
+    mqd->gds_bkup_base_lo = queue->gds_ctx_gpu_addr & 0xfffffffc;
+    mqd->gds_bkup_base_hi = upper_32_bits(queue->gds_ctx_gpu_addr);
+
+    mqd->fw_work_area_base_lo = queue->fw_ctx_gpu_addr & 0xfffffffc;
+    mqd->fw_work_area_base_lo = upper_32_bits(queue->fw_ctx_gpu_addr);
+}
+
  static int
  amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
  {
@@ -104,12 +121,14 @@ amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_u
      queue->userq_prop.use_doorbell = true;
      queue->userq_prop.mqd_gpu_addr = mqd->gpu_addr;
      r = gfx_v11_mqd->init_mqd(adev, (void *)mqd->cpu_ptr, &queue->userq_prop);
-    amdgpu_bo_unreserve(mqd->obj);
      if (r) {
+        amdgpu_bo_unreserve(mqd->obj);
          DRM_ERROR("Failed to init MQD for queue\n");
          goto free_ctx;
      }
 
+    amdgpu_userq_set_ctx_space(uq_mgr, queue);
+    amdgpu_bo_unreserve(mqd->obj);
      DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
      return 0;
 
drivers/gpu/drm/amd/include/v11_structs.h +4 -8
index b8ff7456ae0b..f8008270f813 100644
@@ -25,14 +25,14 @@
  #define V11_STRUCTS_H_
 
  struct v11_gfx_mqd {
-       uint32_t reserved_0; // offset: 0  (0x0)
-       uint32_t reserved_1; // offset: 1  (0x1)
-       uint32_t reserved_2; // offset: 2  (0x2)
-       uint32_t reserved_3; // offset: 3  (0x3)
-       uint32_t reserved_4; // offset: 4  (0x4)
-       uint32_t reserved_5; // offset: 5  (0x5)
-       uint32_t reserved_6; // offset: 6  (0x6)
-       uint32_t reserved_7; // offset: 7  (0x7)
+       uint32_t shadow_base_lo; // offset: 0  (0x0)
+       uint32_t shadow_base_hi; // offset: 1  (0x1)
+       uint32_t gds_bkup_base_lo; // offset: 2  (0x2)
+       uint32_t gds_bkup_base_hi; // offset: 3  (0x3)
Quoted 8 lines

drivers/gpu/drm/amd/include/v11_structs.h line 38

Quoted 7 lines
drivers/gpu/drm/amd/include/v11_structs.h +4 -0
+       uint32_t fw_work_area_base_lo; // offset: 4  (0x4)
+       uint32_t fw_work_area_base_hi; // offset: 5  (0x5)
+       uint32_t shadow_initialized; // offset: 6  (0x6)
+       uint32_t ib_vmid; // offset: 7  (0x7)
         uint32_t reserved_8; // offset: 8  (0x8)
         uint32_t reserved_9; // offset: 9  (0x9)
         uint32_t reserved_10; // offset: 10  (0xA)

We should split this hunk out as a separate patch and upstream it now.

Sure, we will send this as a separate patch.

~arvind

Quoted 5 lines

Alex

Quoted 3 lines

--
2.40.0

#30 lore raw

Re: [PATCH v3 6/9] drm/amdgpu: add new parameters in v11_struct

In reply to Alex Deucher
Quoted 90 lines · Alex Deucher
Quoted 88 lines · Shashank Sharma

From: Arvind Yadav <[email protected]>

This patch:
- adds some new parameters defined for the gfx usermode queues use cases in the v11_mqd_struct.
- sets those parametes with the respective allocated gpu context space addresses.

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
Cc Shashank Sharma <[email protected]>
---
  .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 21 ++++++++++++++++++-
  drivers/gpu/drm/amd/include/v11_structs.h     | 16 +++++++-------
  2 files changed, 28 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +20 -1
index 52de96727f98..39e90ea32fcb 100644
@@ -22,6 +22,7 @@
   */
  #include "amdgpu.h"
  #include "amdgpu_userqueue.h"
+#include "v11_structs.h"
 
  #define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE
  #define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
@@ -68,6 +69,22 @@ static void amdgpu_userq_gfx_v11_destroy_ctx_space(struct amdgpu_userq_mgr *uq_m
                            &ctx->cpu_ptr);
  }
 
+static void
+amdgpu_userq_set_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
+                           struct amdgpu_usermode_queue *queue)
+{
+    struct v11_gfx_mqd *mqd = queue->mqd.cpu_ptr;
+
+    mqd->shadow_base_lo = queue->shadow_ctx_gpu_addr & 0xfffffffc;
+    mqd->shadow_base_hi = upper_32_bits(queue->shadow_ctx_gpu_addr);
+
+    mqd->gds_bkup_base_lo = queue->gds_ctx_gpu_addr & 0xfffffffc;
+    mqd->gds_bkup_base_hi = upper_32_bits(queue->gds_ctx_gpu_addr);
+
+    mqd->fw_work_area_base_lo = queue->fw_ctx_gpu_addr & 0xfffffffc;
+    mqd->fw_work_area_base_lo = upper_32_bits(queue->fw_ctx_gpu_addr);
+}
+
  static int
  amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
  {
@@ -104,12 +121,14 @@ amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_u
      queue->userq_prop.use_doorbell = true;
      queue->userq_prop.mqd_gpu_addr = mqd->gpu_addr;
      r = gfx_v11_mqd->init_mqd(adev, (void *)mqd->cpu_ptr, &queue->userq_prop);
-    amdgpu_bo_unreserve(mqd->obj);
      if (r) {
+        amdgpu_bo_unreserve(mqd->obj);
          DRM_ERROR("Failed to init MQD for queue\n");
          goto free_ctx;
      }
 
+    amdgpu_userq_set_ctx_space(uq_mgr, queue);
+    amdgpu_bo_unreserve(mqd->obj);
      DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
      return 0;
 
drivers/gpu/drm/amd/include/v11_structs.h +4 -8
index b8ff7456ae0b..f8008270f813 100644
@@ -25,14 +25,14 @@
  #define V11_STRUCTS_H_
 
  struct v11_gfx_mqd {
-       uint32_t reserved_0; // offset: 0  (0x0)
-       uint32_t reserved_1; // offset: 1  (0x1)
-       uint32_t reserved_2; // offset: 2  (0x2)
-       uint32_t reserved_3; // offset: 3  (0x3)
-       uint32_t reserved_4; // offset: 4  (0x4)
-       uint32_t reserved_5; // offset: 5  (0x5)
-       uint32_t reserved_6; // offset: 6  (0x6)
-       uint32_t reserved_7; // offset: 7  (0x7)
+       uint32_t shadow_base_lo; // offset: 0  (0x0)
+       uint32_t shadow_base_hi; // offset: 1  (0x1)
+       uint32_t gds_bkup_base_lo; // offset: 2  (0x2)
+       uint32_t gds_bkup_base_hi; // offset: 3  (0x3)
Quoted 8 lines

drivers/gpu/drm/amd/include/v11_structs.h line 38

Quoted 7 lines
drivers/gpu/drm/amd/include/v11_structs.h +4 -0
+       uint32_t fw_work_area_base_lo; // offset: 4  (0x4)
+       uint32_t fw_work_area_base_hi; // offset: 5  (0x5)
+       uint32_t shadow_initialized; // offset: 6  (0x6)
+       uint32_t ib_vmid; // offset: 7  (0x7)
         uint32_t reserved_8; // offset: 8  (0x8)
         uint32_t reserved_9; // offset: 9  (0x9)
         uint32_t reserved_10; // offset: 10  (0xA)

We should split this hunk out as a separate patch and upstream it now.

Got it,

- Shashank

Quoted 6 lines

Alex

Quoted 3 lines

--
2.40.0

#31 lore raw

PATCH v3 7/9 drm/amdgpu: map usermode queue into MES

In reply to Shashank Sharma

From: Shashank Sharma <[email protected]>

This patch adds new functions to map/unmap a usermode queue into the FW, using the MES ring. As soon as this mapping is done, the queue would be considered ready to accept the workload.

V1: Addressed review comments from Alex on the RFC patch series
- Map/Unmap should be IP specific.
V2:
Addressed review comments from Christian:
- Fix the wptr_mc_addr calculation (moved into another patch) Addressed review comments from Alex:
- Do not add fptrs for map/unmap

V3: Integration with doorbell manager

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
---
 .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 70 +++++++++++++++++++
 1 file changed, 70 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +70 -0
index 39e90ea32fcb..1627641a4a4e 100644
@@ -23,12 +23,73 @@
 #include "amdgpu.h"
 #include "amdgpu_userqueue.h"
 #include "v11_structs.h"
+#include "amdgpu_mes.h"
 
 #define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE
 #define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
 #define AMDGPU_USERQ_FW_CTX_SZ PAGE_SIZE
 #define AMDGPU_USERQ_GDS_CTX_SZ PAGE_SIZE
 
+static int
+amdgpu_userq_gfx_v11_map(struct amdgpu_userq_mgr *uq_mgr,
+                         struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_device *adev = uq_mgr->adev;
+    struct mes_add_queue_input queue_input;
+    int r;
+
+    memset(&queue_input, 0x0, sizeof(struct mes_add_queue_input));
+
+    queue_input.process_va_start = 0;
+    queue_input.process_va_end = (adev->vm_manager.max_pfn - 1) << AMDGPU_GPU_PAGE_SHIFT;
+    queue_input.process_quantum = 100000; /* 10ms */
+    queue_input.gang_quantum = 10000; /* 1ms */
+    queue_input.paging = false;
+
+    queue_input.gang_context_addr = queue->gang_ctx_gpu_addr;
+    queue_input.process_context_addr = queue->proc_ctx_gpu_addr;
+    queue_input.inprocess_gang_priority = AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
+    queue_input.gang_global_priority_level = AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
+
+    queue_input.process_id = queue->vm->pasid;
+    queue_input.queue_type = queue->queue_type;
+    queue_input.mqd_addr = queue->mqd.gpu_addr;
+    queue_input.wptr_addr = queue->userq_prop.wptr_gpu_addr;
+    queue_input.queue_size = queue->userq_prop.queue_size >> 2;
+    queue_input.doorbell_offset = queue->userq_prop.doorbell_index;
+    queue_input.page_table_base_addr = amdgpu_gmc_pd_addr(queue->vm->root.bo);
+
+    amdgpu_mes_lock(&adev->mes);
+    r = adev->mes.funcs->add_hw_queue(&adev->mes, &queue_input);
+    amdgpu_mes_unlock(&adev->mes);
+    if (r) {
+        DRM_ERROR("Failed to map queue in HW, err (%d)\n", r);
+        return r;
+    }
+
+    DRM_DEBUG_DRIVER("Queue %d mapped successfully\n", queue->queue_id);
+    return 0;
+}
+
+static void
+amdgpu_userq_gfx_v11_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;
+    int r;
+
+    memset(&queue_input, 0x0, sizeof(struct mes_remove_queue_input));
+    queue_input.doorbell_offset = queue->userq_prop.doorbell_index;
+    queue_input.gang_context_addr = queue->gang_ctx_gpu_addr;
+
+    amdgpu_mes_lock(&adev->mes);
+    r = adev->mes.funcs->remove_hw_queue(&adev->mes, &queue_input);
+    amdgpu_mes_unlock(&adev->mes);
+    if (r)
+        DRM_ERROR("Failed to unmap queue in HW, err (%d)\n", r);
+}
+
 static int amdgpu_userq_gfx_v11_create_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
                                                  struct amdgpu_usermode_queue *queue)
 {
@@ -129,6 +190,14 @@ amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_u
 
     amdgpu_userq_set_ctx_space(uq_mgr, queue);
     amdgpu_bo_unreserve(mqd->obj);
+
+    /* Map the queue in HW using MES ring */
+    r = amdgpu_userq_gfx_v11_map(uq_mgr, queue);
+    if (r) {
+        DRM_ERROR("Failed to map userqueue (%d)\n", r);
+        goto free_ctx;
+    }
+
     DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
     return 0;
 
@@ -147,6 +216,7 @@ amdgpu_userq_gfx_v11_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_
 {
     struct amdgpu_userq_ctx_space *mqd = &queue->mqd;
 
+    amdgpu_userq_gfx_v11_unmap(uq_mgr, queue);
     amdgpu_userq_gfx_v11_destroy_ctx_space(uq_mgr, queue);
     amdgpu_bo_free_kernel(&mqd->obj,
 			   &mqd->gpu_addr,
Signature · 1 line
2.40.0
#32 lore raw

Re: [PATCH v3 7/9] drm/amdgpu: map usermode queue into MES

Quoted 14 lines · Shashank Sharma

From: Shashank Sharma <[email protected]>

This patch adds new functions to map/unmap a usermode queue into the FW, using the MES ring. As soon as this mapping is done, the queue would be considered ready to accept the workload.

V1: Addressed review comments from Alex on the RFC patch series
- Map/Unmap should be IP specific.
V2:
Addressed review comments from Christian:
- Fix the wptr_mc_addr calculation (moved into another patch) Addressed review comments from Alex:
- Do not add fptrs for map/unmap

Quoted 6 lines

V3: Integration with doorbell manager

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>

---

Just add all your Cc right here, and let git-send-email figure it out. Between the Cc tags and the SMTP CC list, Felix is the only one missing.

Regards,
Luben

Quoted 104 lines
 .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 70 +++++++++++++++++++
 1 file changed, 70 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +70 -0
index 39e90ea32fcb..1627641a4a4e 100644
@@ -23,12 +23,73 @@
 #include "amdgpu.h"
 #include "amdgpu_userqueue.h"
 #include "v11_structs.h"
+#include "amdgpu_mes.h"
 
 #define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE
 #define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
 #define AMDGPU_USERQ_FW_CTX_SZ PAGE_SIZE
 #define AMDGPU_USERQ_GDS_CTX_SZ PAGE_SIZE
 
+static int
+amdgpu_userq_gfx_v11_map(struct amdgpu_userq_mgr *uq_mgr,
+                         struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_device *adev = uq_mgr->adev;
+    struct mes_add_queue_input queue_input;
+    int r;
+
+    memset(&queue_input, 0x0, sizeof(struct mes_add_queue_input));
+
+    queue_input.process_va_start = 0;
+    queue_input.process_va_end = (adev->vm_manager.max_pfn - 1) << AMDGPU_GPU_PAGE_SHIFT;
+    queue_input.process_quantum = 100000; /* 10ms */
+    queue_input.gang_quantum = 10000; /* 1ms */
+    queue_input.paging = false;
+
+    queue_input.gang_context_addr = queue->gang_ctx_gpu_addr;
+    queue_input.process_context_addr = queue->proc_ctx_gpu_addr;
+    queue_input.inprocess_gang_priority = AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
+    queue_input.gang_global_priority_level = AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
+
+    queue_input.process_id = queue->vm->pasid;
+    queue_input.queue_type = queue->queue_type;
+    queue_input.mqd_addr = queue->mqd.gpu_addr;
+    queue_input.wptr_addr = queue->userq_prop.wptr_gpu_addr;
+    queue_input.queue_size = queue->userq_prop.queue_size >> 2;
+    queue_input.doorbell_offset = queue->userq_prop.doorbell_index;
+    queue_input.page_table_base_addr = amdgpu_gmc_pd_addr(queue->vm->root.bo);
+
+    amdgpu_mes_lock(&adev->mes);
+    r = adev->mes.funcs->add_hw_queue(&adev->mes, &queue_input);
+    amdgpu_mes_unlock(&adev->mes);
+    if (r) {
+        DRM_ERROR("Failed to map queue in HW, err (%d)\n", r);
+        return r;
+    }
+
+    DRM_DEBUG_DRIVER("Queue %d mapped successfully\n", queue->queue_id);
+    return 0;
+}
+
+static void
+amdgpu_userq_gfx_v11_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;
+    int r;
+
+    memset(&queue_input, 0x0, sizeof(struct mes_remove_queue_input));
+    queue_input.doorbell_offset = queue->userq_prop.doorbell_index;
+    queue_input.gang_context_addr = queue->gang_ctx_gpu_addr;
+
+    amdgpu_mes_lock(&adev->mes);
+    r = adev->mes.funcs->remove_hw_queue(&adev->mes, &queue_input);
+    amdgpu_mes_unlock(&adev->mes);
+    if (r)
+        DRM_ERROR("Failed to unmap queue in HW, err (%d)\n", r);
+}
+
 static int amdgpu_userq_gfx_v11_create_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
                                                  struct amdgpu_usermode_queue *queue)
 {
@@ -129,6 +190,14 @@ amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_u
 
     amdgpu_userq_set_ctx_space(uq_mgr, queue);
     amdgpu_bo_unreserve(mqd->obj);
+
+    /* Map the queue in HW using MES ring */
+    r = amdgpu_userq_gfx_v11_map(uq_mgr, queue);
+    if (r) {
+        DRM_ERROR("Failed to map userqueue (%d)\n", r);
+        goto free_ctx;
+    }
+
     DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
     return 0;
 
@@ -147,6 +216,7 @@ amdgpu_userq_gfx_v11_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_
 {
     struct amdgpu_userq_ctx_space *mqd = &queue->mqd;
 
+    amdgpu_userq_gfx_v11_unmap(uq_mgr, queue);
     amdgpu_userq_gfx_v11_destroy_ctx_space(uq_mgr, queue);
     amdgpu_bo_free_kernel(&mqd->obj,
 			   &mqd->gpu_addr,
#33 lore raw

Re: [PATCH v3 7/9] drm/amdgpu: map usermode queue into MES

Quoted 15 lines · Luben Tuikov
Quoted 14 lines · Shashank Sharma

From: Shashank Sharma <[email protected]>

This patch adds new functions to map/unmap a usermode queue into the FW, using the MES ring. As soon as this mapping is done, the queue would be considered ready to accept the workload.

V1: Addressed review comments from Alex on the RFC patch series
- Map/Unmap should be IP specific.
V2:
Addressed review comments from Christian:
- Fix the wptr_mc_addr calculation (moved into another patch) Addressed review comments from Alex:
- Do not add fptrs for map/unmap

Quoted 8 lines
Quoted 6 lines

V3: Integration with doorbell manager

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>

---

Just add all your Cc right here, and let git-send-email figure it out. Between the Cc tags and the SMTP CC list, Felix is the only one missing.

No, that's not how it is.

You keep people cc'ed in the cover letter so that they get informed every time this patch is pushed/used on any opensource branch.

People who are added manually in cc are required for this code review session.

- Shashank

Quoted 107 lines

Regards,
Luben

Quoted 104 lines
  .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 70 +++++++++++++++++++
  1 file changed, 70 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +70 -0
index 39e90ea32fcb..1627641a4a4e 100644
@@ -23,12 +23,73 @@
  #include "amdgpu.h"
  #include "amdgpu_userqueue.h"
  #include "v11_structs.h"
+#include "amdgpu_mes.h"
 
  #define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE
  #define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
  #define AMDGPU_USERQ_FW_CTX_SZ PAGE_SIZE
  #define AMDGPU_USERQ_GDS_CTX_SZ PAGE_SIZE
 
+static int
+amdgpu_userq_gfx_v11_map(struct amdgpu_userq_mgr *uq_mgr,
+                         struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_device *adev = uq_mgr->adev;
+    struct mes_add_queue_input queue_input;
+    int r;
+
+    memset(&queue_input, 0x0, sizeof(struct mes_add_queue_input));
+
+    queue_input.process_va_start = 0;
+    queue_input.process_va_end = (adev->vm_manager.max_pfn - 1) << AMDGPU_GPU_PAGE_SHIFT;
+    queue_input.process_quantum = 100000; /* 10ms */
+    queue_input.gang_quantum = 10000; /* 1ms */
+    queue_input.paging = false;
+
+    queue_input.gang_context_addr = queue->gang_ctx_gpu_addr;
+    queue_input.process_context_addr = queue->proc_ctx_gpu_addr;
+    queue_input.inprocess_gang_priority = AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
+    queue_input.gang_global_priority_level = AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
+
+    queue_input.process_id = queue->vm->pasid;
+    queue_input.queue_type = queue->queue_type;
+    queue_input.mqd_addr = queue->mqd.gpu_addr;
+    queue_input.wptr_addr = queue->userq_prop.wptr_gpu_addr;
+    queue_input.queue_size = queue->userq_prop.queue_size >> 2;
+    queue_input.doorbell_offset = queue->userq_prop.doorbell_index;
+    queue_input.page_table_base_addr = amdgpu_gmc_pd_addr(queue->vm->root.bo);
+
+    amdgpu_mes_lock(&adev->mes);
+    r = adev->mes.funcs->add_hw_queue(&adev->mes, &queue_input);
+    amdgpu_mes_unlock(&adev->mes);
+    if (r) {
+        DRM_ERROR("Failed to map queue in HW, err (%d)\n", r);
+        return r;
+    }
+
+    DRM_DEBUG_DRIVER("Queue %d mapped successfully\n", queue->queue_id);
+    return 0;
+}
+
+static void
+amdgpu_userq_gfx_v11_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;
+    int r;
+
+    memset(&queue_input, 0x0, sizeof(struct mes_remove_queue_input));
+    queue_input.doorbell_offset = queue->userq_prop.doorbell_index;
+    queue_input.gang_context_addr = queue->gang_ctx_gpu_addr;
+
+    amdgpu_mes_lock(&adev->mes);
+    r = adev->mes.funcs->remove_hw_queue(&adev->mes, &queue_input);
+    amdgpu_mes_unlock(&adev->mes);
+    if (r)
+        DRM_ERROR("Failed to unmap queue in HW, err (%d)\n", r);
+}
+
  static int amdgpu_userq_gfx_v11_create_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
                                                   struct amdgpu_usermode_queue *queue)
  {
@@ -129,6 +190,14 @@ amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_u
 
      amdgpu_userq_set_ctx_space(uq_mgr, queue);
      amdgpu_bo_unreserve(mqd->obj);
+
+    /* Map the queue in HW using MES ring */
+    r = amdgpu_userq_gfx_v11_map(uq_mgr, queue);
+    if (r) {
+        DRM_ERROR("Failed to map userqueue (%d)\n", r);
+        goto free_ctx;
+    }
+
      DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
      return 0;
 
@@ -147,6 +216,7 @@ amdgpu_userq_gfx_v11_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_
  {
      struct amdgpu_userq_ctx_space *mqd = &queue->mqd;
 
+    amdgpu_userq_gfx_v11_unmap(uq_mgr, queue);
      amdgpu_userq_gfx_v11_destroy_ctx_space(uq_mgr, queue);
      amdgpu_bo_free_kernel(&mqd->obj,
  			   &mqd->gpu_addr,
Reviewed-by Joshua Ashton
#34 lore raw

Re: [PATCH v3 7/9] drm/amdgpu: map usermode queue into MES

Quoted 23 lines · Shashank Sharma
Quoted 21 lines · Luben Tuikov
Quoted 20 lines · Shashank Sharma

From: Shashank Sharma <[email protected]>

This patch adds new functions to map/unmap a usermode queue into the FW, using the MES ring. As soon as this mapping is done, the queue would be considered ready to accept the workload.

V1: Addressed review comments from Alex on the RFC patch series
- Map/Unmap should be IP specific.
V2:
Addressed review comments from Christian:
- Fix the wptr_mc_addr calculation (moved into another patch) Addressed review comments from Alex:
- Do not add fptrs for map/unmap

V3: Integration with doorbell manager

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>

---

Quoted 7 lines
Quoted 2 lines

Just add all your Cc right here, and let git-send-email figure it out. Between the Cc tags and the SMTP CC list, Felix is the only one missing.

No, that's not how it is.

You keep people cc'ed in the cover letter so that they get informed every time this patch is pushed/used on any opensource branch.

The cover letter is optional, and you can add Cc tags into the cover letter and then git-send-email would extract those (any and all) tags from the cover letter too.

When you pick and choose whom to add in the Cc tags, and whom to add to the SMTP CC list, it creates division.

Quoted 2 lines

People who are added manually in cc are required for this code review session.

No such rule exists. It is best to add all the Cc into the commit message, so that it is preserved in Git history.

For instance, I just randomly did "git log drivers/gpu/drm/*.[hc]" in amd-staging-drm-next, and this is the first commit which came up,

commit 097ee58f3ddf7d

Author: Harry Wentland <[email protected]>
Date:   Fri Jan 13 11:24:09 2023 -0500

drm/connector: print max_requested_bpc in state debugfs

This is useful to understand the bpc defaults and support of a driver.

As you can see the whole Cc list and the MLs are part of the Cc tags. And the rest of the commits are also good examples of how to do it. (Don't worry about the Link tag--it is automatically added by tools maintainers use, although some use Lore.)
This preserves things in Git history, and it's a good thing if we need to data mine and brainstorm later on on patches, design, and so on.

A good tool to use is "scripts/get_maintainer.pl" which works on a file, directory and even patch files.

I usually include everyone get_maintainer.pl prints, and on subsequent patch revisions, also people who have previously commented on the patchset, as they might be interested to follow up. It's a good thing to do.

Here are a couple of resources, in addition to DRM commits in the tree,
https://www.kernel.org/doc/html/v4.12/process/5.Posting.html#patch-formatting-and-changelogs
https://www.kernel.org/doc/html/v4.12/process/submitting-patches.html#the-canonical-patch-format
(The second link includes links to more resources on good patch writing.)

Hope this helps.

Regards,
Luben

Quoted 110 lines

- Shashank

Quoted 107 lines

Regards,
Luben

Quoted 104 lines
  .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 70 +++++++++++++++++++
  1 file changed, 70 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +70 -0
index 39e90ea32fcb..1627641a4a4e 100644
@@ -23,12 +23,73 @@
  #include "amdgpu.h"
  #include "amdgpu_userqueue.h"
  #include "v11_structs.h"
+#include "amdgpu_mes.h"
 
  #define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE
  #define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
  #define AMDGPU_USERQ_FW_CTX_SZ PAGE_SIZE
  #define AMDGPU_USERQ_GDS_CTX_SZ PAGE_SIZE
 
+static int
+amdgpu_userq_gfx_v11_map(struct amdgpu_userq_mgr *uq_mgr,
+                         struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_device *adev = uq_mgr->adev;
+    struct mes_add_queue_input queue_input;
+    int r;
+
+    memset(&queue_input, 0x0, sizeof(struct mes_add_queue_input));
+
+    queue_input.process_va_start = 0;
+    queue_input.process_va_end = (adev->vm_manager.max_pfn - 1) << AMDGPU_GPU_PAGE_SHIFT;
+    queue_input.process_quantum = 100000; /* 10ms */
+    queue_input.gang_quantum = 10000; /* 1ms */
+    queue_input.paging = false;
+
+    queue_input.gang_context_addr = queue->gang_ctx_gpu_addr;
+    queue_input.process_context_addr = queue->proc_ctx_gpu_addr;
+    queue_input.inprocess_gang_priority = AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
+    queue_input.gang_global_priority_level = AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
+
+    queue_input.process_id = queue->vm->pasid;
+    queue_input.queue_type = queue->queue_type;
+    queue_input.mqd_addr = queue->mqd.gpu_addr;
+    queue_input.wptr_addr = queue->userq_prop.wptr_gpu_addr;
+    queue_input.queue_size = queue->userq_prop.queue_size >> 2;
+    queue_input.doorbell_offset = queue->userq_prop.doorbell_index;
+    queue_input.page_table_base_addr = amdgpu_gmc_pd_addr(queue->vm->root.bo);
+
+    amdgpu_mes_lock(&adev->mes);
+    r = adev->mes.funcs->add_hw_queue(&adev->mes, &queue_input);
+    amdgpu_mes_unlock(&adev->mes);
+    if (r) {
+        DRM_ERROR("Failed to map queue in HW, err (%d)\n", r);
+        return r;
+    }
+
+    DRM_DEBUG_DRIVER("Queue %d mapped successfully\n", queue->queue_id);
+    return 0;
+}
+
+static void
+amdgpu_userq_gfx_v11_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;
+    int r;
+
+    memset(&queue_input, 0x0, sizeof(struct mes_remove_queue_input));
+    queue_input.doorbell_offset = queue->userq_prop.doorbell_index;
+    queue_input.gang_context_addr = queue->gang_ctx_gpu_addr;
+
+    amdgpu_mes_lock(&adev->mes);
+    r = adev->mes.funcs->remove_hw_queue(&adev->mes, &queue_input);
+    amdgpu_mes_unlock(&adev->mes);
+    if (r)
+        DRM_ERROR("Failed to unmap queue in HW, err (%d)\n", r);
+}
+
  static int amdgpu_userq_gfx_v11_create_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
                                                   struct amdgpu_usermode_queue *queue)
  {
@@ -129,6 +190,14 @@ amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_u
 
      amdgpu_userq_set_ctx_space(uq_mgr, queue);
      amdgpu_bo_unreserve(mqd->obj);
+
+    /* Map the queue in HW using MES ring */
+    r = amdgpu_userq_gfx_v11_map(uq_mgr, queue);
+    if (r) {
+        DRM_ERROR("Failed to map userqueue (%d)\n", r);
+        goto free_ctx;
+    }
+
      DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
      return 0;
 
@@ -147,6 +216,7 @@ amdgpu_userq_gfx_v11_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_
  {
      struct amdgpu_userq_ctx_space *mqd = &queue->mqd;
 
+    amdgpu_userq_gfx_v11_unmap(uq_mgr, queue);
      amdgpu_userq_gfx_v11_destroy_ctx_space(uq_mgr, queue);
      amdgpu_bo_free_kernel(&mqd->obj,
  			   &mqd->gpu_addr,
#35 lore raw

Re: [PATCH v3 7/9] drm/amdgpu: map usermode queue into MES

Quoted 27 lines · Luben Tuikov
Quoted 26 lines · Shashank Sharma
Quoted 15 lines · Luben Tuikov
Quoted 14 lines · Shashank Sharma

From: Shashank Sharma <[email protected]>

This patch adds new functions to map/unmap a usermode queue into the FW, using the MES ring. As soon as this mapping is done, the queue would be considered ready to accept the workload.

V1: Addressed review comments from Alex on the RFC patch series
- Map/Unmap should be IP specific.
V2:
Addressed review comments from Christian:
- Fix the wptr_mc_addr calculation (moved into another patch) Addressed review comments from Alex:
- Do not add fptrs for map/unmap

Quoted 8 lines
Quoted 6 lines

V3: Integration with doorbell manager

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>

---

Just add all your Cc right here, and let git-send-email figure it out. Between the Cc tags and the SMTP CC list, Felix is the only one missing.

No, that's not how it is.

Quoted 8 lines
Quoted 2 lines

You keep people cc'ed in the cover letter so that they get informed every time this patch is pushed/used on any opensource branch.

The cover letter is optional, and you can add Cc tags into the cover letter and then git-send-email would extract those (any and all) tags from the cover letter too.

When you pick and choose whom to add in the Cc tags, and whom to add to the SMTP CC list, it creates division.

Exactly my point, there is no guideline on whom to add in Cc cover-letter and whom to add manually, its all preference.

Now different people can have different preference, and a review comment on what is your preference of what to

keep on cover letter does seem like a nitpick.

Quoted 5 lines
Quoted 3 lines

People who are added manually in cc are required for this code review session.

No such rule exists. It is best to add all the Cc into the commit message, so that it is preserved in Git history.

I believe this is also not a rule, we are discussing preferences only. It is my preference that I want to keep only Alex and Christian in Cc.

Quoted 27 lines

For instance, I just randomly did "git log drivers/gpu/drm/*.[hc]" in amd-staging-drm-next, and this is the first commit which came up,

commit 097ee58f3ddf7d

Author: Harry Wentland <[email protected]>
Date:   Fri Jan 13 11:24:09 2023 -0500

drm/connector: print max_requested_bpc in state debugfs

This is useful to understand the bpc defaults and support of a driver.

Quoted 6 lines

As you can see the whole Cc list and the MLs are part of the Cc tags. And the rest of the commits are also good examples of how to do it. (Don't worry about the Link tag--it is automatically added by tools maintainers use, although some use Lore.)
This preserves things in Git history, and it's a good thing if we need to data mine and brainstorm later on on patches, design, and so on.

No, this is not random, this is actually well planned. All of these people here in Cc are either the maintainers or respective domain experts or

contributors of color management feature and keeping them in CC is about how this color management feature is being carried forward, so this is

exactly aligned with my point. Do note that this is a DRM level change (not AMDGPU level).

Also, I would like to express that in my opinion we are spending way too much time in discussing the 'preferences' around cover letter,

words, comments and variable names. No cover letter is perfect, no commit message is good enough to explain what is happening in code,

no variable name is flawless and no comment explains what is going on in code which is clear to everyone. These are very subjective to the

author and the reader. The only deciding factor is if there is a community rule/guideline on that.

I appreciate your time and suggestions but I also certainly do not want to spend this much time to discuss how should we add people in Cc.

Let's keep preferences separate from code review process.

- Shashank

Quoted 128 lines

A good tool to use is "scripts/get_maintainer.pl" which works on a file, directory and even patch files.

I usually include everyone get_maintainer.pl prints, and on subsequent patch revisions, also people who have previously commented on the patchset, as they might be interested to follow up. It's a good thing to do.

Here are a couple of resources, in addition to DRM commits in the tree,
https://www.kernel.org/doc/html/v4.12/process/5.Posting.html#patch-formatting-and-changelogs
https://www.kernel.org/doc/html/v4.12/process/submitting-patches.html#the-canonical-patch-format
(The second link includes links to more resources on good patch writing.)

Hope this helps.

Regards,
Luben

Quoted 109 lines

- Shashank

Quoted 107 lines

Regards,
Luben

Quoted 104 lines
   .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 70 +++++++++++++++++++
   1 file changed, 70 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +70 -0
index 39e90ea32fcb..1627641a4a4e 100644
@@ -23,12 +23,73 @@
   #include "amdgpu.h"
   #include "amdgpu_userqueue.h"
   #include "v11_structs.h"
+#include "amdgpu_mes.h"
 
   #define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE
   #define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
   #define AMDGPU_USERQ_FW_CTX_SZ PAGE_SIZE
   #define AMDGPU_USERQ_GDS_CTX_SZ PAGE_SIZE
 
+static int
+amdgpu_userq_gfx_v11_map(struct amdgpu_userq_mgr *uq_mgr,
+                         struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_device *adev = uq_mgr->adev;
+    struct mes_add_queue_input queue_input;
+    int r;
+
+    memset(&queue_input, 0x0, sizeof(struct mes_add_queue_input));
+
+    queue_input.process_va_start = 0;
+    queue_input.process_va_end = (adev->vm_manager.max_pfn - 1) << AMDGPU_GPU_PAGE_SHIFT;
+    queue_input.process_quantum = 100000; /* 10ms */
+    queue_input.gang_quantum = 10000; /* 1ms */
+    queue_input.paging = false;
+
+    queue_input.gang_context_addr = queue->gang_ctx_gpu_addr;
+    queue_input.process_context_addr = queue->proc_ctx_gpu_addr;
+    queue_input.inprocess_gang_priority = AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
+    queue_input.gang_global_priority_level = AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
+
+    queue_input.process_id = queue->vm->pasid;
+    queue_input.queue_type = queue->queue_type;
+    queue_input.mqd_addr = queue->mqd.gpu_addr;
+    queue_input.wptr_addr = queue->userq_prop.wptr_gpu_addr;
+    queue_input.queue_size = queue->userq_prop.queue_size >> 2;
+    queue_input.doorbell_offset = queue->userq_prop.doorbell_index;
+    queue_input.page_table_base_addr = amdgpu_gmc_pd_addr(queue->vm->root.bo);
+
+    amdgpu_mes_lock(&adev->mes);
+    r = adev->mes.funcs->add_hw_queue(&adev->mes, &queue_input);
+    amdgpu_mes_unlock(&adev->mes);
+    if (r) {
+        DRM_ERROR("Failed to map queue in HW, err (%d)\n", r);
+        return r;
+    }
+
+    DRM_DEBUG_DRIVER("Queue %d mapped successfully\n", queue->queue_id);
+    return 0;
+}
+
+static void
+amdgpu_userq_gfx_v11_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;
+    int r;
+
+    memset(&queue_input, 0x0, sizeof(struct mes_remove_queue_input));
+    queue_input.doorbell_offset = queue->userq_prop.doorbell_index;
+    queue_input.gang_context_addr = queue->gang_ctx_gpu_addr;
+
+    amdgpu_mes_lock(&adev->mes);
+    r = adev->mes.funcs->remove_hw_queue(&adev->mes, &queue_input);
+    amdgpu_mes_unlock(&adev->mes);
+    if (r)
+        DRM_ERROR("Failed to unmap queue in HW, err (%d)\n", r);
+}
+
   static int amdgpu_userq_gfx_v11_create_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
                                                    struct amdgpu_usermode_queue *queue)
   {
@@ -129,6 +190,14 @@ amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_u
 
       amdgpu_userq_set_ctx_space(uq_mgr, queue);
       amdgpu_bo_unreserve(mqd->obj);
+
+    /* Map the queue in HW using MES ring */
+    r = amdgpu_userq_gfx_v11_map(uq_mgr, queue);
+    if (r) {
+        DRM_ERROR("Failed to map userqueue (%d)\n", r);
+        goto free_ctx;
+    }
+
       DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
       return 0;
 
@@ -147,6 +216,7 @@ amdgpu_userq_gfx_v11_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_
   {
       struct amdgpu_userq_ctx_space *mqd = &queue->mqd;
 
+    amdgpu_userq_gfx_v11_unmap(uq_mgr, queue);
       amdgpu_userq_gfx_v11_destroy_ctx_space(uq_mgr, queue);
       amdgpu_bo_free_kernel(&mqd->obj,
   			   &mqd->gpu_addr,
#36 lore raw

Re: [PATCH v3 7/9] drm/amdgpu: map usermode queue into MES

Quoted 39 lines · Shashank Sharma
Quoted 27 lines · Luben Tuikov
Quoted 26 lines · Shashank Sharma
Quoted 15 lines · Luben Tuikov
Quoted 14 lines · Shashank Sharma

From: Shashank Sharma <[email protected]>

This patch adds new functions to map/unmap a usermode queue into the FW, using the MES ring. As soon as this mapping is done, the queue would be considered ready to accept the workload.

V1: Addressed review comments from Alex on the RFC patch series
- Map/Unmap should be IP specific.
V2:
Addressed review comments from Christian:
- Fix the wptr_mc_addr calculation (moved into another patch) Addressed review comments from Alex:
- Do not add fptrs for map/unmap

Quoted 8 lines
Quoted 6 lines

V3: Integration with doorbell manager

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>

---

Just add all your Cc right here, and let git-send-email figure it out. Between the Cc tags and the SMTP CC list, Felix is the only one missing.

No, that's not how it is.

Quoted 8 lines
Quoted 2 lines

You keep people cc'ed in the cover letter so that they get informed every time this patch is pushed/used on any opensource branch.

The cover letter is optional, and you can add Cc tags into the cover letter and then git-send-email would extract those (any and all) tags from the cover letter too.

When you pick and choose whom to add in the Cc tags, and whom to add to the SMTP CC list, it creates division.

Quoted 7 lines

Exactly my point, there is no guideline on whom to add in Cc cover-letter and whom to add manually, its all preference.

Now different people can have different preference, and a review comment on what is your preference of what to

keep on cover letter does seem like a nitpick.

I am describing consensus. Take a look at DRM commits to see what people do. It'd be nice if you followed that

Quoted 35 lines
Quoted 6 lines
Quoted 4 lines

People who are added manually in cc are required for this code review session.

No such rule exists. It is best to add all the Cc into the commit message, so that it is preserved in Git history.

I believe this is also not a rule, we are discussing preferences only. It is my preference that I want to keep only Alex and Christian in Cc.

Quoted 27 lines

For instance, I just randomly did "git log drivers/gpu/drm/*.[hc]" in amd-staging-drm-next, and this is the first commit which came up,

commit 097ee58f3ddf7d

Author: Harry Wentland <[email protected]>
Date:   Fri Jan 13 11:24:09 2023 -0500

drm/connector: print max_requested_bpc in state debugfs

This is useful to understand the bpc defaults and support of a driver.

Quoted 8 lines
Quoted 6 lines

As you can see the whole Cc list and the MLs are part of the Cc tags. And the rest of the commits are also good examples of how to do it. (Don't worry about the Link tag--it is automatically added by tools maintainers use, although some use Lore.)
This preserves things in Git history, and it's a good thing if we need to data mine and brainstorm later on on patches, design, and so on.

No, this is not random, this is actually well planned. All of these

I never said it is "random"--it is not, it is well planned because everyone submitting to DRM does this--it's common practice.

Quoted 7 lines

people here in Cc are either the maintainers or respective domain experts or

contributors of color management feature and keeping them in CC is about how this color management feature is being carried forward, so this is

exactly aligned with my point. Do note that this is a DRM level change (not AMDGPU level).

So, then why isn't Felix in the Cc tags? Doorbell changes touch that area too. He's actually the only one you left out, other than the MLs emails. Either add everyone to the Cc tags in the commit message, or only add your Sob line and leave everyone to a --cc= on the command line. Both are common practice and acceptable.

Quoted 2 lines

Also, I would like to express that in my opinion we are spending way too much time in discussing the 'preferences' around cover letter,

I agree. But those aren't "preferences," they are common practices, like for instance not separating the Cc tags and the Sob tags with an empty line, or shifting struct member names to the same column for readability, and so on. Use "git log -- drivers/gpu/drm".

Regards,
Luben

Quoted 146 lines

words, comments and variable names. No cover letter is perfect, no commit message is good enough to explain what is happening in code,

no variable name is flawless and no comment explains what is going on in code which is clear to everyone. These are very subjective to the

author and the reader. The only deciding factor is if there is a community rule/guideline on that.

I appreciate your time and suggestions but I also certainly do not want to spend this much time to discuss how should we add people in Cc.

Let's keep preferences separate from code review process.

- Shashank

Quoted 128 lines

A good tool to use is "scripts/get_maintainer.pl" which works on a file, directory and even patch files.

I usually include everyone get_maintainer.pl prints, and on subsequent patch revisions, also people who have previously commented on the patchset, as they might be interested to follow up. It's a good thing to do.

Here are a couple of resources, in addition to DRM commits in the tree,
https://www.kernel.org/doc/html/v4.12/process/5.Posting.html#patch-formatting-and-changelogs
https://www.kernel.org/doc/html/v4.12/process/submitting-patches.html#the-canonical-patch-format
(The second link includes links to more resources on good patch writing.)

Hope this helps.

Regards,
Luben

Quoted 109 lines

- Shashank

Quoted 107 lines

Regards,
Luben

Quoted 104 lines
   .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 70 +++++++++++++++++++
   1 file changed, 70 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +70 -0
index 39e90ea32fcb..1627641a4a4e 100644
@@ -23,12 +23,73 @@
   #include "amdgpu.h"
   #include "amdgpu_userqueue.h"
   #include "v11_structs.h"
+#include "amdgpu_mes.h"
 
   #define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE
   #define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
   #define AMDGPU_USERQ_FW_CTX_SZ PAGE_SIZE
   #define AMDGPU_USERQ_GDS_CTX_SZ PAGE_SIZE
 
+static int
+amdgpu_userq_gfx_v11_map(struct amdgpu_userq_mgr *uq_mgr,
+                         struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_device *adev = uq_mgr->adev;
+    struct mes_add_queue_input queue_input;
+    int r;
+
+    memset(&queue_input, 0x0, sizeof(struct mes_add_queue_input));
+
+    queue_input.process_va_start = 0;
+    queue_input.process_va_end = (adev->vm_manager.max_pfn - 1) << AMDGPU_GPU_PAGE_SHIFT;
+    queue_input.process_quantum = 100000; /* 10ms */
+    queue_input.gang_quantum = 10000; /* 1ms */
+    queue_input.paging = false;
+
+    queue_input.gang_context_addr = queue->gang_ctx_gpu_addr;
+    queue_input.process_context_addr = queue->proc_ctx_gpu_addr;
+    queue_input.inprocess_gang_priority = AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
+    queue_input.gang_global_priority_level = AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
+
+    queue_input.process_id = queue->vm->pasid;
+    queue_input.queue_type = queue->queue_type;
+    queue_input.mqd_addr = queue->mqd.gpu_addr;
+    queue_input.wptr_addr = queue->userq_prop.wptr_gpu_addr;
+    queue_input.queue_size = queue->userq_prop.queue_size >> 2;
+    queue_input.doorbell_offset = queue->userq_prop.doorbell_index;
+    queue_input.page_table_base_addr = amdgpu_gmc_pd_addr(queue->vm->root.bo);
+
+    amdgpu_mes_lock(&adev->mes);
+    r = adev->mes.funcs->add_hw_queue(&adev->mes, &queue_input);
+    amdgpu_mes_unlock(&adev->mes);
+    if (r) {
+        DRM_ERROR("Failed to map queue in HW, err (%d)\n", r);
+        return r;
+    }
+
+    DRM_DEBUG_DRIVER("Queue %d mapped successfully\n", queue->queue_id);
+    return 0;
+}
+
+static void
+amdgpu_userq_gfx_v11_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;
+    int r;
+
+    memset(&queue_input, 0x0, sizeof(struct mes_remove_queue_input));
+    queue_input.doorbell_offset = queue->userq_prop.doorbell_index;
+    queue_input.gang_context_addr = queue->gang_ctx_gpu_addr;
+
+    amdgpu_mes_lock(&adev->mes);
+    r = adev->mes.funcs->remove_hw_queue(&adev->mes, &queue_input);
+    amdgpu_mes_unlock(&adev->mes);
+    if (r)
+        DRM_ERROR("Failed to unmap queue in HW, err (%d)\n", r);
+}
+
   static int amdgpu_userq_gfx_v11_create_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
                                                    struct amdgpu_usermode_queue *queue)
   {
@@ -129,6 +190,14 @@ amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_u
 
       amdgpu_userq_set_ctx_space(uq_mgr, queue);
       amdgpu_bo_unreserve(mqd->obj);
+
+    /* Map the queue in HW using MES ring */
+    r = amdgpu_userq_gfx_v11_map(uq_mgr, queue);
+    if (r) {
+        DRM_ERROR("Failed to map userqueue (%d)\n", r);
+        goto free_ctx;
+    }
+
       DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
       return 0;
 
@@ -147,6 +216,7 @@ amdgpu_userq_gfx_v11_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_
   {
       struct amdgpu_userq_ctx_space *mqd = &queue->mqd;
 
+    amdgpu_userq_gfx_v11_unmap(uq_mgr, queue);
       amdgpu_userq_gfx_v11_destroy_ctx_space(uq_mgr, queue);
       amdgpu_bo_free_kernel(&mqd->obj,
   			   &mqd->gpu_addr,
#37 lore raw

Re: [PATCH v3 7/9] drm/amdgpu: map usermode queue into MES

Quoted 41 lines · Luben Tuikov
Quoted 40 lines · Shashank Sharma
Quoted 27 lines · Luben Tuikov
Quoted 26 lines · Shashank Sharma
Quoted 15 lines · Luben Tuikov
Quoted 14 lines · Shashank Sharma

From: Shashank Sharma <[email protected]>

This patch adds new functions to map/unmap a usermode queue into the FW, using the MES ring. As soon as this mapping is done, the queue would be considered ready to accept the workload.

V1: Addressed review comments from Alex on the RFC patch series
- Map/Unmap should be IP specific.
V2:
Addressed review comments from Christian:
- Fix the wptr_mc_addr calculation (moved into another patch) Addressed review comments from Alex:
- Do not add fptrs for map/unmap

Quoted 8 lines
Quoted 6 lines

V3: Integration with doorbell manager

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>

---

Just add all your Cc right here, and let git-send-email figure it out. Between the Cc tags and the SMTP CC list, Felix is the only one missing.

No, that's not how it is.

Quoted 8 lines
Quoted 2 lines

You keep people cc'ed in the cover letter so that they get informed every time this patch is pushed/used on any opensource branch.

The cover letter is optional, and you can add Cc tags into the cover letter and then git-send-email would extract those (any and all) tags from the cover letter too.

When you pick and choose whom to add in the Cc tags, and whom to add to the SMTP CC list, it creates division.

Exactly my point, there is no guideline on whom to add in Cc cover-letter and whom to add manually, its all preference.

Quoted 6 lines
Quoted 4 lines

Now different people can have different preference, and a review comment on what is your preference of what to

keep on cover letter does seem like a nitpick.

I am describing consensus. Take a look at DRM commits to see what people do. It'd be nice if you followed that

No, not every DRM patch needs to be like that. I have added some examples below.

Quoted 46 lines
Quoted 32 lines
Quoted 4 lines
Quoted 2 lines

People who are added manually in cc are required for this code review session.

No such rule exists. It is best to add all the Cc into the commit message, so that it is preserved in Git history.

I believe this is also not a rule, we are discussing preferences only. It is my preference that I want to keep only Alex and Christian in Cc.

Quoted 26 lines

For instance, I just randomly did "git log drivers/gpu/drm/*.[hc]" in amd-staging-drm-next, and this is the first commit which came up,

commit 097ee58f3ddf7d

Author: Harry Wentland <[email protected]>
Date:   Fri Jan 13 11:24:09 2023 -0500

drm/connector: print max_requested_bpc in state debugfs

This is useful to understand the bpc defaults and support of a driver.

Quoted 7 lines
Quoted 6 lines

As you can see the whole Cc list and the MLs are part of the Cc tags. And the rest of the commits are also good examples of how to do it. (Don't worry about the Link tag--it is automatically added by tools maintainers use, although some use Lore.)
This preserves things in Git history, and it's a good thing if we need to data mine and brainstorm later on on patches, design, and so on.

No, this is not random, this is actually well planned. All of these

I never said it is "random"--it is not, it is well planned because everyone submitting to DRM does this--it's common practice.

Quoted 5 lines

people here in Cc are either the maintainers or respective domain experts or

contributors of color management feature and keeping them in CC is about how this color management feature is being carried forward, so this is

Quoted 7 lines
Quoted 2 lines

exactly aligned with my point. Do note that this is a DRM level change (not AMDGPU level).

So, then why isn't Felix in the Cc tags? Doorbell changes touch that area too. He's actually the only one you left out, other than the MLs emails. Either add everyone to the Cc tags in the commit message, or only add your Sob line and leave everyone to a --cc= on the command line. Both are common practice and acceptable.

This code touches KFD code, and that's why Felix needs to be involved in the code-review process. But

once code review is done, I don't want to spam his email every time this patch is pushed into some branch,

so he is not in cover-letter CC. This is how I prefer to drive the code review of this patch, and I don't see a problem here.

Quoted 3 lines
Quoted 2 lines

Also, I would like to express that in my opinion we are spending way too much time in discussing the 'preferences' around cover letter,

I agree. But those aren't "preferences," they are common practices,

This is not a common practice, its your interpretation of it.

I also picked a few examples:

https://patchwork.freedesktop.org/patch/531143/?series=116163&rev=1

This patch has multiple communities in Cc, none in cover-letter (also R-B'ed by you).

https://patchwork.freedesktop.org/patch/505571/

https://patchwork.freedesktop.org/patch/442410/

These are some of patches which has multiple people missing in the cover-letter CC than email-CC.

https://patchwork.freedesktop.org/patch/530652/?series=116055&rev=1

This patch has multiple people in email-cc but none in cover-letter CC.

There could be tons of such examples for both, and the maintainers do not have any problem with that,

So I don't consider this as common practice in DRM community, its just a preference, and hence it consumed

a lot more time and efforts in this discussion than what it should have.

- Shashank

Quoted 151 lines

like for instance not separating the Cc tags and the Sob tags with an empty line, or shifting struct member names to the same column for readability, and so on. Use "git log -- drivers/gpu/drm".

Regards,
Luben

Quoted 144 lines

words, comments and variable names. No cover letter is perfect, no commit message is good enough to explain what is happening in code,

no variable name is flawless and no comment explains what is going on in code which is clear to everyone. These are very subjective to the

author and the reader. The only deciding factor is if there is a community rule/guideline on that.

I appreciate your time and suggestions but I also certainly do not want to spend this much time to discuss how should we add people in Cc.

Let's keep preferences separate from code review process.

- Shashank

Quoted 127 lines

A good tool to use is "scripts/get_maintainer.pl" which works on a file, directory and even patch files.

I usually include everyone get_maintainer.pl prints, and on subsequent patch revisions, also people who have previously commented on the patchset, as they might be interested to follow up. It's a good thing to do.

Here are a couple of resources, in addition to DRM commits in the tree,
https://www.kernel.org/doc/html/v4.12/process/5.Posting.html#patch-formatting-and-changelogs
https://www.kernel.org/doc/html/v4.12/process/submitting-patches.html#the-canonical-patch-format
(The second link includes links to more resources on good patch writing.)

Hope this helps.

Regards,
Luben

Quoted 109 lines

- Shashank

Quoted 107 lines

Regards,
Luben

Quoted 104 lines
    .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 70 +++++++++++++++++++
    1 file changed, 70 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +70 -0
index 39e90ea32fcb..1627641a4a4e 100644
@@ -23,12 +23,73 @@
    #include "amdgpu.h"
    #include "amdgpu_userqueue.h"
    #include "v11_structs.h"
+#include "amdgpu_mes.h"
 
    #define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE
    #define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
    #define AMDGPU_USERQ_FW_CTX_SZ PAGE_SIZE
    #define AMDGPU_USERQ_GDS_CTX_SZ PAGE_SIZE
 
+static int
+amdgpu_userq_gfx_v11_map(struct amdgpu_userq_mgr *uq_mgr,
+                         struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_device *adev = uq_mgr->adev;
+    struct mes_add_queue_input queue_input;
+    int r;
+
+    memset(&queue_input, 0x0, sizeof(struct mes_add_queue_input));
+
+    queue_input.process_va_start = 0;
+    queue_input.process_va_end = (adev->vm_manager.max_pfn - 1) << AMDGPU_GPU_PAGE_SHIFT;
+    queue_input.process_quantum = 100000; /* 10ms */
+    queue_input.gang_quantum = 10000; /* 1ms */
+    queue_input.paging = false;
+
+    queue_input.gang_context_addr = queue->gang_ctx_gpu_addr;
+    queue_input.process_context_addr = queue->proc_ctx_gpu_addr;
+    queue_input.inprocess_gang_priority = AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
+    queue_input.gang_global_priority_level = AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
+
+    queue_input.process_id = queue->vm->pasid;
+    queue_input.queue_type = queue->queue_type;
+    queue_input.mqd_addr = queue->mqd.gpu_addr;
+    queue_input.wptr_addr = queue->userq_prop.wptr_gpu_addr;
+    queue_input.queue_size = queue->userq_prop.queue_size >> 2;
+    queue_input.doorbell_offset = queue->userq_prop.doorbell_index;
+    queue_input.page_table_base_addr = amdgpu_gmc_pd_addr(queue->vm->root.bo);
+
+    amdgpu_mes_lock(&adev->mes);
+    r = adev->mes.funcs->add_hw_queue(&adev->mes, &queue_input);
+    amdgpu_mes_unlock(&adev->mes);
+    if (r) {
+        DRM_ERROR("Failed to map queue in HW, err (%d)\n", r);
+        return r;
+    }
+
+    DRM_DEBUG_DRIVER("Queue %d mapped successfully\n", queue->queue_id);
+    return 0;
+}
+
+static void
+amdgpu_userq_gfx_v11_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;
+    int r;
+
+    memset(&queue_input, 0x0, sizeof(struct mes_remove_queue_input));
+    queue_input.doorbell_offset = queue->userq_prop.doorbell_index;
+    queue_input.gang_context_addr = queue->gang_ctx_gpu_addr;
+
+    amdgpu_mes_lock(&adev->mes);
+    r = adev->mes.funcs->remove_hw_queue(&adev->mes, &queue_input);
+    amdgpu_mes_unlock(&adev->mes);
+    if (r)
+        DRM_ERROR("Failed to unmap queue in HW, err (%d)\n", r);
+}
+
    static int amdgpu_userq_gfx_v11_create_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
                                                     struct amdgpu_usermode_queue *queue)
    {
@@ -129,6 +190,14 @@ amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_u
 
        amdgpu_userq_set_ctx_space(uq_mgr, queue);
        amdgpu_bo_unreserve(mqd->obj);
+
+    /* Map the queue in HW using MES ring */
+    r = amdgpu_userq_gfx_v11_map(uq_mgr, queue);
+    if (r) {
+        DRM_ERROR("Failed to map userqueue (%d)\n", r);
+        goto free_ctx;
+    }
+
        DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
        return 0;
 
@@ -147,6 +216,7 @@ amdgpu_userq_gfx_v11_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_
    {
        struct amdgpu_userq_ctx_space *mqd = &queue->mqd;
 
+    amdgpu_userq_gfx_v11_unmap(uq_mgr, queue);
        amdgpu_userq_gfx_v11_destroy_ctx_space(uq_mgr, queue);
        amdgpu_bo_free_kernel(&mqd->obj,
    			   &mqd->gpu_addr,
#38 lore raw

Re: [PATCH v3 7/9] drm/amdgpu: map usermode queue into MES

Am 2023-04-06 um 03:45 schrieb Shashank Sharma:

Quoted 7 lines

On 05/04/2023 23:18, Luben Tuikov wrote: So, then why isn't Felix in the Cc tags? Doorbell changes touch that area too.

Quoted 4 lines

He's actually the only one you left out, other than the MLs emails. Either add everyone to the Cc tags in the commit message, or only add your Sob line and leave everyone to a --cc= on the command line. Both are common practice and acceptable.

Quoted 5 lines

This code touches KFD code, and that's why Felix needs to be involved in the code-review process. But

once code review is done, I don't want to spam his email every time this patch is pushed into some branch,

so he is not in cover-letter CC. This is how I prefer to drive the code review of this patch, and I don't see a problem here.

It's a big patch series, and I don't have time to review the whole thing in detail. A CC tag on the patches that need my attention would help.

Thanks,
  Felix

Quoted 195 lines
Quoted 5 lines
Quoted 4 lines

Also, I would like to express that in my opinion we are spending way too much time in discussing the 'preferences' around cover letter,

I agree. But those aren't "preferences," they are common practices,

This is not a common practice, its your interpretation of it.

I also picked a few examples:

https://patchwork.freedesktop.org/patch/531143/?series=116163&rev=1

This patch has multiple communities in Cc, none in cover-letter (also R-B'ed by you).

https://patchwork.freedesktop.org/patch/505571/

https://patchwork.freedesktop.org/patch/442410/

These are some of patches which has multiple people missing in the cover-letter CC than email-CC.

https://patchwork.freedesktop.org/patch/530652/?series=116055&rev=1

This patch has multiple people in email-cc but none in cover-letter CC.

There could be tons of such examples for both, and the maintainers do not have any problem with that,

So I don't consider this as common practice in DRM community, its just a preference, and hence it consumed

a lot more time and efforts in this discussion than what it should have.

- Shashank

Quoted 159 lines

like for instance not separating the Cc tags and the Sob tags with an empty line, or shifting struct member names to the same column for readability, and so on. Use "git log -- drivers/gpu/drm".

Regards,
Luben

Quoted 152 lines

words, comments and variable names. No cover letter is perfect, no commit message is good enough to explain what is happening in code,

no variable name is flawless and no comment explains what is going on in code which is clear to everyone. These are very subjective to the

author and the reader. The only deciding factor is if there is a community rule/guideline on that.

I appreciate your time and suggestions but I also certainly do not want to spend this much time to discuss how should we add people in Cc.

Let's keep preferences separate from code review process.

- Shashank

Quoted 135 lines

A good tool to use is "scripts/get_maintainer.pl" which works on a file, directory and even patch files.

I usually include everyone get_maintainer.pl prints, and on subsequent patch revisions, also people who have previously commented on the patchset, as they might be interested to follow up. It's a good thing to do.

Here are a couple of resources, in addition to DRM commits in the tree,
https://www.kernel.org/doc/html/v4.12/process/5.Posting.html#patch-formatting-and-changelogs

https://www.kernel.org/doc/html/v4.12/process/submitting-patches.html#the-canonical-patch-format

(The second link includes links to more resources on good patch writing.)

Hope this helps.

Regards,
Luben

Quoted 115 lines

- Shashank

Quoted 113 lines

Regards,
Luben

Quoted 110 lines

.../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 70
+++++++++++++++++++

    1 file changed, 70 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +1 -0
index 39e90ea32fcb..1627641a4a4e 100644
@@ -23,12 +23,73 @@
     #include "amdgpu.h"
     #include "amdgpu_userqueue.h"
     #include "v11_structs.h"
+#include "amdgpu_mes.h"
         #define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE
     #define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
     #define AMDGPU_USERQ_FW_CTX_SZ PAGE_SIZE
     #define AMDGPU_USERQ_GDS_CTX_SZ PAGE_SIZE

    +static int

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +11 -0
+amdgpu_userq_gfx_v11_map(struct amdgpu_userq_mgr *uq_mgr,
+                         struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_device *adev = uq_mgr->adev;
+    struct mes_add_queue_input queue_input;
+    int r;
+
+    memset(&queue_input, 0x0, sizeof(struct mes_add_queue_input));
+
+    queue_input.process_va_start = 0;
+    queue_input.process_va_end = (adev->vm_manager.max_pfn - 1) 

<< AMDGPU_GPU_PAGE_SHIFT;
+    queue_input.process_quantum = 100000; /* 10ms */
+    queue_input.gang_quantum = 10000; /* 1ms */
+    queue_input.paging = false;
+
+    queue_input.gang_context_addr = queue->gang_ctx_gpu_addr; +    queue_input.process_context_addr = queue->proc_ctx_gpu_addr; +    queue_input.inprocess_gang_priority = AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
+    queue_input.gang_global_priority_level = AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
+
+    queue_input.process_id = queue->vm->pasid;
+    queue_input.queue_type = queue->queue_type;
+    queue_input.mqd_addr = queue->mqd.gpu_addr;
+    queue_input.wptr_addr = queue->userq_prop.wptr_gpu_addr; +    queue_input.queue_size = queue->userq_prop.queue_size >> 2; +    queue_input.doorbell_offset = queue->userq_prop.doorbell_index;
+    queue_input.page_table_base_addr = amdgpu_gmc_pd_addr(queue->vm->root.bo);

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +10 -0
+
+    amdgpu_mes_lock(&adev->mes);
+    r = adev->mes.funcs->add_hw_queue(&adev->mes, &queue_input);
+    amdgpu_mes_unlock(&adev->mes);
+    if (r) {
+        DRM_ERROR("Failed to map queue in HW, err (%d)\n", r);
+        return r;
+    }
+
+    DRM_DEBUG_DRIVER("Queue %d mapped successfully\n", 

queue->queue_id);
+    return 0;

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +11 -0
+}
+
+static void
+amdgpu_userq_gfx_v11_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;
+    int r;
+
+    memset(&queue_input, 0x0, sizeof(struct 

mes_remove_queue_input));
+    queue_input.doorbell_offset = queue->userq_prop.doorbell_index;
+    queue_input.gang_context_addr = queue->gang_ctx_gpu_addr; +
+    amdgpu_mes_lock(&adev->mes);
+    r = adev->mes.funcs->remove_hw_queue(&adev->mes, &queue_input);
+    amdgpu_mes_unlock(&adev->mes);
+    if (r)
+        DRM_ERROR("Failed to unmap queue in HW, err (%d)\n", r);

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +2 -0
+}
+

    static int amdgpu_userq_gfx_v11_create_ctx_space(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
    {

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +0 -0
@@ -129,6 +190,14 @@ amdgpu_userq_gfx_v11_mqd_create(struct 

amdgpu_userq_mgr *uq_mgr, struct amdgpu_u amdgpu_userq_set_ctx_space(uq_mgr, queue); amdgpu_bo_unreserve(mqd->obj);

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +8 -0
+
+    /* Map the queue in HW using MES ring */
+    r = amdgpu_userq_gfx_v11_map(uq_mgr, queue);
+    if (r) {
+        DRM_ERROR("Failed to map userqueue (%d)\n", r);
+        goto free_ctx;
+    }
+

        DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
        return 0;
    @@ -147,6 +216,7 @@ amdgpu_userq_gfx_v11_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_ {
        struct amdgpu_userq_ctx_space *mqd = &queue->mqd;
    +    amdgpu_userq_gfx_v11_unmap(uq_mgr, queue); amdgpu_userq_gfx_v11_destroy_ctx_space(uq_mgr, queue); amdgpu_bo_free_kernel(&mqd->obj,
                   &mqd->gpu_addr,

#39 lore raw

Re: [PATCH v3 7/9] drm/amdgpu: map usermode queue into MES

Quoted 8 lines · Felix Kuehling

Am 2023-04-06 um 03:45 schrieb Shashank Sharma:

Quoted 7 lines

On 05/04/2023 23:18, Luben Tuikov wrote: So, then why isn't Felix in the Cc tags? Doorbell changes touch that area too.

Quoted 4 lines

He's actually the only one you left out, other than the MLs emails. Either add everyone to the Cc tags in the commit message, or only add your Sob line and leave everyone to a --cc= on the command line. Both are common practice and acceptable.

Quoted 8 lines
Quoted 5 lines

This code touches KFD code, and that's why Felix needs to be involved in the code-review process. But

once code review is done, I don't want to spam his email every time this patch is pushed into some branch,

so he is not in cover-letter CC. This is how I prefer to drive the code review of this patch, and I don't see a problem here.

It's a big patch series, and I don't have time to review the whole thing in detail. A CC tag on the patches that need my attention would help.

Hey Felix,

noted. There are only 2 patches which touch the KFD code, I will keep you in CC only for those.

- Shashank

Quoted 200 lines

Thanks,
  Felix

Quoted 196 lines
Quoted 5 lines
Quoted 4 lines

Also, I would like to express that in my opinion we are spending way too much time in discussing the 'preferences' around cover letter,

I agree. But those aren't "preferences," they are common practices,

This is not a common practice, its your interpretation of it.

I also picked a few examples:

https://patchwork.freedesktop.org/patch/531143/?series=116163&rev=1

This patch has multiple communities in Cc, none in cover-letter (also R-B'ed by you).

https://patchwork.freedesktop.org/patch/505571/

https://patchwork.freedesktop.org/patch/442410/

These are some of patches which has multiple people missing in the cover-letter CC than email-CC.

https://patchwork.freedesktop.org/patch/530652/?series=116055&rev=1

This patch has multiple people in email-cc but none in cover-letter CC.

There could be tons of such examples for both, and the maintainers do not have any problem with that,

So I don't consider this as common practice in DRM community, its just a preference, and hence it consumed

a lot more time and efforts in this discussion than what it should have.

- Shashank

Quoted 160 lines

like for instance not separating the Cc tags and the Sob tags with an empty line, or shifting struct member names to the same column for readability, and so on. Use "git log -- drivers/gpu/drm".

Regards,
Luben

Quoted 153 lines

words, comments and variable names. No cover letter is perfect, no commit message is good enough to explain what is happening in code,

no variable name is flawless and no comment explains what is going on in code which is clear to everyone. These are very subjective to the

author and the reader. The only deciding factor is if there is a community rule/guideline on that.

I appreciate your time and suggestions but I also certainly do not want to spend this much time to discuss how should we add people in Cc.

Let's keep preferences separate from code review process.

- Shashank

Quoted 136 lines

A good tool to use is "scripts/get_maintainer.pl" which works on a file, directory and even patch files.

I usually include everyone get_maintainer.pl prints, and on subsequent patch revisions, also people who have previously commented on the patchset, as they might be interested to follow up. It's a good thing to do.

Here are a couple of resources, in addition to DRM commits in the tree,
https://www.kernel.org/doc/html/v4.12/process/5.Posting.html#patch-formatting-and-changelogs

https://www.kernel.org/doc/html/v4.12/process/submitting-patches.html#the-canonical-patch-format

(The second link includes links to more resources on good patch writing.)

Hope this helps.

Regards,
Luben

Quoted 116 lines

- Shashank

Quoted 114 lines

Regards,
Luben

Quoted 111 lines

.../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 70
+++++++++++++++++++

    1 file changed, 70 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +1 -0
index 39e90ea32fcb..1627641a4a4e 100644
@@ -23,12 +23,73 @@
     #include "amdgpu.h"
     #include "amdgpu_userqueue.h"
     #include "v11_structs.h"
+#include "amdgpu_mes.h"
         #define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE
     #define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
     #define AMDGPU_USERQ_FW_CTX_SZ PAGE_SIZE
     #define AMDGPU_USERQ_GDS_CTX_SZ PAGE_SIZE

    +static int

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +8 -0
+amdgpu_userq_gfx_v11_map(struct amdgpu_userq_mgr *uq_mgr,
+                         struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_device *adev = uq_mgr->adev;
+    struct mes_add_queue_input queue_input;
+    int r;
+
+    memset(&queue_input, 0x0, sizeof(struct 

mes_add_queue_input));
+
+    queue_input.process_va_start = 0;
+    queue_input.process_va_end = (adev->vm_manager.max_pfn -
1) << AMDGPU_GPU_PAGE_SHIFT;
+    queue_input.process_quantum = 100000; /* 10ms */
+    queue_input.gang_quantum = 10000; /* 1ms */
+    queue_input.paging = false;
+
+    queue_input.gang_context_addr = queue->gang_ctx_gpu_addr; +    queue_input.process_context_addr = queue->proc_ctx_gpu_addr; +    queue_input.inprocess_gang_priority = AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
+    queue_input.gang_global_priority_level = AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
+
+    queue_input.process_id = queue->vm->pasid;
+    queue_input.queue_type = queue->queue_type;
+    queue_input.mqd_addr = queue->mqd.gpu_addr;
+    queue_input.wptr_addr = queue->userq_prop.wptr_gpu_addr; +    queue_input.queue_size = queue->userq_prop.queue_size >> 2; +    queue_input.doorbell_offset = queue->userq_prop.doorbell_index;
+    queue_input.page_table_base_addr = amdgpu_gmc_pd_addr(queue->vm->root.bo);

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +10 -0
+
+    amdgpu_mes_lock(&adev->mes);
+    r = adev->mes.funcs->add_hw_queue(&adev->mes, &queue_input);
+    amdgpu_mes_unlock(&adev->mes);
+    if (r) {
+        DRM_ERROR("Failed to map queue in HW, err (%d)\n", r);
+        return r;
+    }
+
+    DRM_DEBUG_DRIVER("Queue %d mapped successfully\n", 

queue->queue_id);
+    return 0;

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +11 -0
+}
+
+static void
+amdgpu_userq_gfx_v11_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;
+    int r;
+
+    memset(&queue_input, 0x0, sizeof(struct 

mes_remove_queue_input));
+    queue_input.doorbell_offset = queue->userq_prop.doorbell_index;
+    queue_input.gang_context_addr = queue->gang_ctx_gpu_addr; +
+    amdgpu_mes_lock(&adev->mes);
+    r = adev->mes.funcs->remove_hw_queue(&adev->mes, &queue_input);
+    amdgpu_mes_unlock(&adev->mes);
+    if (r)
+        DRM_ERROR("Failed to unmap queue in HW, err (%d)\n", r);

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +2 -0
+}
+

    static int amdgpu_userq_gfx_v11_create_ctx_space(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
    {

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +0 -0
@@ -129,6 +190,14 @@ amdgpu_userq_gfx_v11_mqd_create(struct 

amdgpu_userq_mgr *uq_mgr, struct amdgpu_u amdgpu_userq_set_ctx_space(uq_mgr, queue); amdgpu_bo_unreserve(mqd->obj);

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +8 -0
+
+    /* Map the queue in HW using MES ring */
+    r = amdgpu_userq_gfx_v11_map(uq_mgr, queue);
+    if (r) {
+        DRM_ERROR("Failed to map userqueue (%d)\n", r);
+        goto free_ctx;
+    }
+

        DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
        return 0;
    @@ -147,6 +216,7 @@ amdgpu_userq_gfx_v11_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_ {
        struct amdgpu_userq_ctx_space *mqd = &queue->mqd;
    +    amdgpu_userq_gfx_v11_unmap(uq_mgr, queue); amdgpu_userq_gfx_v11_destroy_ctx_space(uq_mgr, queue);
        amdgpu_bo_free_kernel(&mqd->obj,
                   &mqd->gpu_addr,

#40 lore raw

PATCH v3 8/9 drm/amdgpu: map wptr BO into GART

In reply to Shashank Sharma

From: Arvind Yadav <[email protected]>

To support oversubscription, MES expects WPTR BOs to be mapped to GART, before they are submitted to usermode queues.

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
Cc Shashank Sharma <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 89 +++++++++++++++++++
 .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c |  1 +
 .../gpu/drm/amd/include/amdgpu_userqueue.h    |  1 +
 3 files changed, 91 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +89 -0
index 5672efcbcffc..7409a4ae55da 100644
@@ -43,6 +43,89 @@ amdgpu_userqueue_find(struct amdgpu_userq_mgr *uq_mgr, int qid)
     return idr_find(&uq_mgr->userq_idr, qid);
 }
 
+static int
+amdgpu_userqueue_map_gtt_bo_to_gart(struct amdgpu_device *adev, struct amdgpu_bo *bo)
+{
+    int ret;
+
+    ret = amdgpu_bo_reserve(bo, true);
+    if (ret) {
+        DRM_ERROR("Failed to reserve bo. ret %d\n", ret);
+        goto err_reserve_bo_failed;
+    }
+
+    ret = amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT);
+    if (ret) {
+        DRM_ERROR("Failed to pin bo. ret %d\n", ret);
+        goto err_pin_bo_failed;
+    }
+
+    ret = amdgpu_ttm_alloc_gart(&bo->tbo);
+    if (ret) {
+        DRM_ERROR("Failed to bind bo to GART. ret %d\n", ret);
+        goto err_map_bo_gart_failed;
+    }
+
+
+    amdgpu_bo_unreserve(bo);
+    bo = amdgpu_bo_ref(bo);
+
+    return 0;
+
+err_map_bo_gart_failed:
+    amdgpu_bo_unpin(bo);
+err_pin_bo_failed:
+    amdgpu_bo_unreserve(bo);
+err_reserve_bo_failed:
+
+    return ret;
+}
+
+
+static int
+amdgpu_userqueue_create_wptr_mapping(struct amdgpu_device *adev,
+				     struct drm_file *filp,
+				     struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_bo_va_mapping *wptr_mapping;
+    struct amdgpu_vm *wptr_vm;
+    struct amdgpu_bo *wptr_bo = NULL;
+    uint64_t wptr = queue->userq_prop.wptr_gpu_addr;
+    int ret;
+
+    wptr_vm = queue->vm;
+    ret = amdgpu_bo_reserve(wptr_vm->root.bo, false);
+    if (ret)
+        goto err_wptr_map_gart;
+
+    wptr_mapping = amdgpu_vm_bo_lookup_mapping(wptr_vm, wptr >> PAGE_SHIFT);
+    amdgpu_bo_unreserve(wptr_vm->root.bo);
+    if (!wptr_mapping) {
+        DRM_ERROR("Failed to lookup wptr bo\n");
+        ret = -EINVAL;
+        goto err_wptr_map_gart;
+    }
+
+    wptr_bo = wptr_mapping->bo_va->base.bo;
+    if (wptr_bo->tbo.base.size > PAGE_SIZE) {
+        DRM_ERROR("Requested GART mapping for wptr bo larger than one page\n");
+        ret = -EINVAL;
+        goto err_wptr_map_gart;
+    }
+
+    ret = amdgpu_userqueue_map_gtt_bo_to_gart(adev, wptr_bo);
+    if (ret) {
+        DRM_ERROR("Failed to map wptr bo to GART\n");
+        goto err_wptr_map_gart;
+    }
+
+    queue->wptr_mc_addr = wptr_bo->tbo.resource->start << PAGE_SHIFT;
+    return 0;
+
+err_wptr_map_gart:
+    return ret;
+}
+
 static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 {
     struct amdgpu_usermode_queue *queue;
@@ -82,6 +165,12 @@ static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq
         goto free_queue;
     }
 
+    r = amdgpu_userqueue_create_wptr_mapping(uq_mgr->adev, filp, queue);
+    if (r) {
+        DRM_ERROR("Failed to map WPTR (0x%llx) for userqueue\n", queue->userq_prop.wptr_gpu_addr);
+        goto free_queue;
+    }
+
     r = uq_mgr->userq_funcs[queue->queue_type]->mqd_create(uq_mgr, queue);
     if (r) {
         DRM_ERROR("Failed to create/map userqueue MQD\n");
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +1 -0
index 1627641a4a4e..274e78826334 100644
@@ -58,6 +58,7 @@ amdgpu_userq_gfx_v11_map(struct amdgpu_userq_mgr *uq_mgr,
     queue_input.queue_size = queue->userq_prop.queue_size >> 2;
     queue_input.doorbell_offset = queue->userq_prop.doorbell_index;
     queue_input.page_table_base_addr = amdgpu_gmc_pd_addr(queue->vm->root.bo);
+    queue_input.wptr_mc_addr = queue->wptr_mc_addr;
 
     amdgpu_mes_lock(&adev->mes);
     r = adev->mes.funcs->add_hw_queue(&adev->mes, &queue_input);
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +1 -0
index 8b62ef77cd26..eaab7cf5fff6 100644
@@ -38,6 +38,7 @@ struct amdgpu_usermode_queue {
 	int queue_type;
 	uint64_t flags;
 	uint64_t doorbell_handle;
+	uint64_t wptr_mc_addr;
 	uint64_t proc_ctx_gpu_addr;
 	uint64_t gang_ctx_gpu_addr;
 	uint64_t gds_ctx_gpu_addr;
Signature · 1 line
2.40.0
#41 lore raw

Re: [PATCH v3 8/9] drm/amdgpu: map wptr BO into GART

Quoted 76 lines · Shashank Sharma

From: Arvind Yadav <[email protected]>

To support oversubscription, MES expects WPTR BOs to be mapped to GART, before they are submitted to usermode queues.

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
Cc Shashank Sharma <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 89 +++++++++++++++++++
 .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c |  1 +
 .../gpu/drm/amd/include/amdgpu_userqueue.h    |  1 +
 3 files changed, 91 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +52 -0
index 5672efcbcffc..7409a4ae55da 100644
@@ -43,6 +43,89 @@ amdgpu_userqueue_find(struct amdgpu_userq_mgr *uq_mgr, int qid)
     return idr_find(&uq_mgr->userq_idr, qid);
 }
 
+static int
+amdgpu_userqueue_map_gtt_bo_to_gart(struct amdgpu_device *adev, struct amdgpu_bo *bo)
+{
+    int ret;
+
+    ret = amdgpu_bo_reserve(bo, true);
+    if (ret) {
+        DRM_ERROR("Failed to reserve bo. ret %d\n", ret);
+        goto err_reserve_bo_failed;
+    }
+
+    ret = amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT);
+    if (ret) {
+        DRM_ERROR("Failed to pin bo. ret %d\n", ret);
+        goto err_pin_bo_failed;
+    }
+
+    ret = amdgpu_ttm_alloc_gart(&bo->tbo);
+    if (ret) {
+        DRM_ERROR("Failed to bind bo to GART. ret %d\n", ret);
+        goto err_map_bo_gart_failed;
+    }
+
+
+    amdgpu_bo_unreserve(bo);
+    bo = amdgpu_bo_ref(bo);
+
+    return 0;
+
+err_map_bo_gart_failed:
+    amdgpu_bo_unpin(bo);
+err_pin_bo_failed:
+    amdgpu_bo_unreserve(bo);
+err_reserve_bo_failed:
+
+    return ret;
+}
+
+
+static int
+amdgpu_userqueue_create_wptr_mapping(struct amdgpu_device *adev,
+                                    struct drm_file *filp,
+                                    struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_bo_va_mapping *wptr_mapping;
+    struct amdgpu_vm *wptr_vm;
+    struct amdgpu_bo *wptr_bo = NULL;
+    uint64_t wptr = queue->userq_prop.wptr_gpu_addr;
+    int ret;
+
+    wptr_vm = queue->vm;
+    ret = amdgpu_bo_reserve(wptr_vm->root.bo, false);

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c amdgpu_userqueue_find(struct amdgpu_userq_mgr *uq_mgr, int qid) · line 107

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +10 -0
+    if (ret)
+        goto err_wptr_map_gart;
+
+    wptr_mapping = amdgpu_vm_bo_lookup_mapping(wptr_vm, wptr >> PAGE_SHIFT);
+    amdgpu_bo_unreserve(wptr_vm->root.bo);
+    if (!wptr_mapping) {
+        DRM_ERROR("Failed to lookup wptr bo\n");
+        ret = -EINVAL;
+        goto err_wptr_map_gart;
+    }

This triggers for wptr BOs mapped to the high half of address space, may need some mangling wrt the top bits?

Quoted 64 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +27 -0
+
+    wptr_bo = wptr_mapping->bo_va->base.bo;
+    if (wptr_bo->tbo.base.size > PAGE_SIZE) {
+        DRM_ERROR("Requested GART mapping for wptr bo larger than one page\n");
+        ret = -EINVAL;
+        goto err_wptr_map_gart;
+    }
+
+    ret = amdgpu_userqueue_map_gtt_bo_to_gart(adev, wptr_bo);
+    if (ret) {
+        DRM_ERROR("Failed to map wptr bo to GART\n");
+        goto err_wptr_map_gart;
+    }
+
+    queue->wptr_mc_addr = wptr_bo->tbo.resource->start << PAGE_SHIFT;
+    return 0;
+
+err_wptr_map_gart:
+    return ret;
+}
+
 static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 {
     struct amdgpu_usermode_queue *queue;
@@ -82,6 +165,12 @@ static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq
         goto free_queue;
     }
 
+    r = amdgpu_userqueue_create_wptr_mapping(uq_mgr->adev, filp, queue);
+    if (r) {
+        DRM_ERROR("Failed to map WPTR (0x%llx) for userqueue\n", queue->userq_prop.wptr_gpu_addr);
+        goto free_queue;
+    }
+
     r = uq_mgr->userq_funcs[queue->queue_type]->mqd_create(uq_mgr, queue);
     if (r) {
         DRM_ERROR("Failed to create/map userqueue MQD\n");
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +1 -0
index 1627641a4a4e..274e78826334 100644
@@ -58,6 +58,7 @@ amdgpu_userq_gfx_v11_map(struct amdgpu_userq_mgr *uq_mgr,
     queue_input.queue_size = queue->userq_prop.queue_size >> 2;
     queue_input.doorbell_offset = queue->userq_prop.doorbell_index;
     queue_input.page_table_base_addr = amdgpu_gmc_pd_addr(queue->vm->root.bo);
+    queue_input.wptr_mc_addr = queue->wptr_mc_addr;
 
     amdgpu_mes_lock(&adev->mes);
     r = adev->mes.funcs->add_hw_queue(&adev->mes, &queue_input);
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +1 -1
index 8b62ef77cd26..eaab7cf5fff6 100644
@@ -38,6 +38,7 @@ struct amdgpu_usermode_queue {
        int queue_type;
        uint64_t flags;
        uint64_t doorbell_handle;
+       uint64_t wptr_mc_addr;
        uint64_t proc_ctx_gpu_addr;
        uint64_t gang_ctx_gpu_addr;
        uint64_t gds_ctx_gpu_addr;
--

2.40.0

maintainer
#42 lore raw

Re: [PATCH v3 8/9] drm/amdgpu: map wptr BO into GART

Am 10.04.23 um 02:00 schrieb Bas Nieuwenhuizen:

Quoted 80 lines · Shashank Sharma
Quoted 79 lines

From: Arvind Yadav <[email protected]>

To support oversubscription, MES expects WPTR BOs to be mapped to GART, before they are submitted to usermode queues.

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
Cc Shashank Sharma <[email protected]>
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 89 +++++++++++++++++++
  .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c |  1 +
  .../gpu/drm/amd/include/amdgpu_userqueue.h    |  1 +
  3 files changed, 91 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +56 -0
index 5672efcbcffc..7409a4ae55da 100644
@@ -43,6 +43,89 @@ amdgpu_userqueue_find(struct amdgpu_userq_mgr *uq_mgr, int qid)
      return idr_find(&uq_mgr->userq_idr, qid);
  }
 
+static int
+amdgpu_userqueue_map_gtt_bo_to_gart(struct amdgpu_device *adev, struct amdgpu_bo *bo)
+{
+    int ret;
+
+    ret = amdgpu_bo_reserve(bo, true);
+    if (ret) {
+        DRM_ERROR("Failed to reserve bo. ret %d\n", ret);
+        goto err_reserve_bo_failed;
+    }
+
+    ret = amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT);
+    if (ret) {
+        DRM_ERROR("Failed to pin bo. ret %d\n", ret);
+        goto err_pin_bo_failed;
+    }
+
+    ret = amdgpu_ttm_alloc_gart(&bo->tbo);
+    if (ret) {
+        DRM_ERROR("Failed to bind bo to GART. ret %d\n", ret);
+        goto err_map_bo_gart_failed;
+    }
+
+
+    amdgpu_bo_unreserve(bo);
+    bo = amdgpu_bo_ref(bo);
+
+    return 0;
+
+err_map_bo_gart_failed:
+    amdgpu_bo_unpin(bo);
+err_pin_bo_failed:
+    amdgpu_bo_unreserve(bo);
+err_reserve_bo_failed:
+
+    return ret;
+}
+
+
+static int
+amdgpu_userqueue_create_wptr_mapping(struct amdgpu_device *adev,
+                                    struct drm_file *filp,
+                                    struct amdgpu_usermode_queue *queue)
+{
+    struct amdgpu_bo_va_mapping *wptr_mapping;
+    struct amdgpu_vm *wptr_vm;
+    struct amdgpu_bo *wptr_bo = NULL;
+    uint64_t wptr = queue->userq_prop.wptr_gpu_addr;
+    int ret;
+
+    wptr_vm = queue->vm;
+    ret = amdgpu_bo_reserve(wptr_vm->root.bo, false);
+    if (ret)
+        goto err_wptr_map_gart;
+
+    wptr_mapping = amdgpu_vm_bo_lookup_mapping(wptr_vm, wptr >> PAGE_SHIFT);
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c amdgpu_userqueue_find(struct amdgpu_userq_mgr *uq_mgr, int qid) · line 107

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +6 -0
+    amdgpu_bo_unreserve(wptr_vm->root.bo);
+    if (!wptr_mapping) {
+        DRM_ERROR("Failed to lookup wptr bo\n");
+        ret = -EINVAL;
+        goto err_wptr_map_gart;
+    }

This triggers for wptr BOs mapped to the high half of address space, may need some mangling wrt the top bits?

Yeah, correct. Shashank this needs to apply the hole mask before looking up the address.

Regards,
Christian.

Quoted 65 lines
Quoted 65 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +27 -0
+
+    wptr_bo = wptr_mapping->bo_va->base.bo;
+    if (wptr_bo->tbo.base.size > PAGE_SIZE) {
+        DRM_ERROR("Requested GART mapping for wptr bo larger than one page\n");
+        ret = -EINVAL;
+        goto err_wptr_map_gart;
+    }
+
+    ret = amdgpu_userqueue_map_gtt_bo_to_gart(adev, wptr_bo);
+    if (ret) {
+        DRM_ERROR("Failed to map wptr bo to GART\n");
+        goto err_wptr_map_gart;
+    }
+
+    queue->wptr_mc_addr = wptr_bo->tbo.resource->start << PAGE_SHIFT;
+    return 0;
+
+err_wptr_map_gart:
+    return ret;
+}
+
  static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
  {
      struct amdgpu_usermode_queue *queue;
@@ -82,6 +165,12 @@ static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq
          goto free_queue;
      }
 
+    r = amdgpu_userqueue_create_wptr_mapping(uq_mgr->adev, filp, queue);
+    if (r) {
+        DRM_ERROR("Failed to map WPTR (0x%llx) for userqueue\n", queue->userq_prop.wptr_gpu_addr);
+        goto free_queue;
+    }
+
      r = uq_mgr->userq_funcs[queue->queue_type]->mqd_create(uq_mgr, queue);
      if (r) {
          DRM_ERROR("Failed to create/map userqueue MQD\n");
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +1 -0
index 1627641a4a4e..274e78826334 100644
@@ -58,6 +58,7 @@ amdgpu_userq_gfx_v11_map(struct amdgpu_userq_mgr *uq_mgr,
      queue_input.queue_size = queue->userq_prop.queue_size >> 2;
      queue_input.doorbell_offset = queue->userq_prop.doorbell_index;
      queue_input.page_table_base_addr = amdgpu_gmc_pd_addr(queue->vm->root.bo);
+    queue_input.wptr_mc_addr = queue->wptr_mc_addr;
 
      amdgpu_mes_lock(&adev->mes);
      r = adev->mes.funcs->add_hw_queue(&adev->mes, &queue_input);
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +1 -1
index 8b62ef77cd26..eaab7cf5fff6 100644
@@ -38,6 +38,7 @@ struct amdgpu_usermode_queue {
         int queue_type;
         uint64_t flags;
         uint64_t doorbell_handle;
+       uint64_t wptr_mc_addr;
         uint64_t proc_ctx_gpu_addr;
         uint64_t gang_ctx_gpu_addr;
         uint64_t gds_ctx_gpu_addr;
--

2.40.0

#43 lore raw

Re: [PATCH v3 8/9] drm/amdgpu: map wptr BO into GART

Quoted 95 lines · Christian König

Am 10.04.23 um 02:00 schrieb Bas Nieuwenhuizen:

Quoted 85 lines · Shashank Sharma
Quoted 84 lines

From: Arvind Yadav <[email protected]>

To support oversubscription, MES expects WPTR BOs to be mapped to GART, before they are submitted to usermode queues.

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
Cc Shashank Sharma <[email protected]>

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 89
+++++++++++++++++++
  .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c |  1 + .../gpu/drm/amd/include/amdgpu_userqueue.h    |  1 +

  3 files changed, 91 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +56 -0
index 5672efcbcffc..7409a4ae55da 100644
@@ -43,6 +43,89 @@ amdgpu_userqueue_find(struct amdgpu_userq_mgr 
 *uq_mgr, int qid)
       return idr_find(&uq_mgr->userq_idr, qid);
   }
 
+static int
+amdgpu_userqueue_map_gtt_bo_to_gart(struct amdgpu_device *adev, 
 struct amdgpu_bo *bo)
+{
+    int ret;
+
+    ret = amdgpu_bo_reserve(bo, true);
+    if (ret) {
+        DRM_ERROR("Failed to reserve bo. ret %d\n", ret);
+        goto err_reserve_bo_failed;
+    }
+
+    ret = amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT);
+    if (ret) {
+        DRM_ERROR("Failed to pin bo. ret %d\n", ret);
+        goto err_pin_bo_failed;
+    }
+
+    ret = amdgpu_ttm_alloc_gart(&bo->tbo);
+    if (ret) {
+        DRM_ERROR("Failed to bind bo to GART. ret %d\n", ret);
+        goto err_map_bo_gart_failed;
+    }
+
+
+    amdgpu_bo_unreserve(bo);
+    bo = amdgpu_bo_ref(bo);
+
+    return 0;
+
+err_map_bo_gart_failed:
+    amdgpu_bo_unpin(bo);
+err_pin_bo_failed:
+    amdgpu_bo_unreserve(bo);
+err_reserve_bo_failed:
+
+    return ret;
+}
+
+
+static int
+amdgpu_userqueue_create_wptr_mapping(struct amdgpu_device *adev,
+                                    struct drm_file *filp,
+                                    struct amdgpu_usermode_queue 
 *queue)
+{
+    struct amdgpu_bo_va_mapping *wptr_mapping;
+    struct amdgpu_vm *wptr_vm;
+    struct amdgpu_bo *wptr_bo = NULL;
+    uint64_t wptr = queue->userq_prop.wptr_gpu_addr;
+    int ret;
+
+    wptr_vm = queue->vm;
+    ret = amdgpu_bo_reserve(wptr_vm->root.bo, false);
+    if (ret)
+        goto err_wptr_map_gart;
+
+    wptr_mapping = amdgpu_vm_bo_lookup_mapping(wptr_vm, wptr >> 

PAGE_SHIFT);

Quoted 8 lines
Quoted 6 lines

+    amdgpu_bo_unreserve(wptr_vm->root.bo);
+    if (!wptr_mapping) {
+        DRM_ERROR("Failed to lookup wptr bo\n");
+        ret = -EINVAL;
+        goto err_wptr_map_gart;
+    }

This triggers for wptr BOs mapped to the high half of address space, may need some mangling wrt the top bits?

Quoted 1 line

Yeah, correct. Shashank this needs to apply the hole mask before looking up the address.

Noted, will update that.

- Shashank

Quoted 75 lines

Regards,
Christian.

Quoted 70 lines
Quoted 70 lines

+
+    wptr_bo = wptr_mapping->bo_va->base.bo;
+    if (wptr_bo->tbo.base.size > PAGE_SIZE) {
+        DRM_ERROR("Requested GART mapping for wptr bo larger than one page\n");
+        ret = -EINVAL;
+        goto err_wptr_map_gart;
+    }

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +14 -0
+
+    ret = amdgpu_userqueue_map_gtt_bo_to_gart(adev, wptr_bo);
+    if (ret) {
+        DRM_ERROR("Failed to map wptr bo to GART\n");
+        goto err_wptr_map_gart;
+    }
+
+    queue->wptr_mc_addr = wptr_bo->tbo.resource->start << PAGE_SHIFT;
+    return 0;
+
+err_wptr_map_gart:
+    return ret;
+}
+

  static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args) {
      struct amdgpu_usermode_queue *queue;

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +0 -0
@@ -82,6 +165,12 @@ static int amdgpu_userqueue_create(struct 

drm_file *filp, union drm_amdgpu_userq
          goto free_queue;
      }

+    r = amdgpu_userqueue_create_wptr_mapping(uq_mgr->adev, filp, queue);
+    if (r) {
+        DRM_ERROR("Failed to map WPTR (0x%llx) for userqueue\n", queue->userq_prop.wptr_gpu_addr);
+        goto free_queue;
+    }
+
      r = uq_mgr->userq_funcs[queue->queue_type]->mqd_create(uq_mgr, queue); if (r) {
          DRM_ERROR("Failed to create/map userqueue MQD\n");

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +1 -0
index 1627641a4a4e..274e78826334 100644
@@ -58,6 +58,7 @@ amdgpu_userq_gfx_v11_map(struct amdgpu_userq_mgr 
 *uq_mgr,
       queue_input.queue_size = queue->userq_prop.queue_size >> 2;
       queue_input.doorbell_offset = queue->userq_prop.doorbell_index;
       queue_input.page_table_base_addr = amdgpu_gmc_pd_addr(queue->vm->root.bo);
+    queue_input.wptr_mc_addr = queue->wptr_mc_addr;
 
       amdgpu_mes_lock(&adev->mes);

      r = adev->mes.funcs->add_hw_queue(&adev->mes, &queue_input);

drivers/gpu/drm/amd/include/amdgpu_userqueue.h +1 -0
index 8b62ef77cd26..eaab7cf5fff6 100644
@@ -38,6 +38,7 @@ struct amdgpu_usermode_queue {
          int queue_type;
          uint64_t flags;
          uint64_t doorbell_handle;
+       uint64_t wptr_mc_addr;
          uint64_t proc_ctx_gpu_addr;
          uint64_t gang_ctx_gpu_addr;
          uint64_t gds_ctx_gpu_addr;
Signature · 1 line
2.40.0
#44 lore raw

PATCH v3 9/9 drm/amdgpu: generate doorbell index for userqueue

In reply to Shashank Sharma

The userspace sends us the doorbell object and the doobell index to be used for the usermode queue, but the FW expects the absolute doorbell index on the PCI BAR in the MQD. This patch adds a function to convert this relative doorbell index to the absolute doorbell index.

This patch is dependent on the doorbell manager series being reviewed
here: https://patchwork.freedesktop.org/series/115802/

Cc Alex Deucher <[email protected]>
Cc Christian Koenig <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 35 +++++++++++++++++++
 1 file changed, 35 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +35 -0
index 7409a4ae55da..fd4a2ca3302d 100644
@@ -43,6 +43,32 @@ amdgpu_userqueue_find(struct amdgpu_userq_mgr *uq_mgr, int qid)
     return idr_find(&uq_mgr->userq_idr, qid);
 }
 
+static uint64_t
+amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,
+                                    struct amdgpu_usermode_queue *queue,
+                                    struct drm_file *filp,
+                                    uint32_t doorbell_index)
+{
+    struct drm_gem_object *gobj;
+    struct amdgpu_bo *db_bo;
+    uint64_t index;
+
+    gobj = drm_gem_object_lookup(filp, queue->doorbell_handle);
+    if (gobj == NULL) {
+        DRM_ERROR("Can't find GEM object for doorbell\n");
+        return -EINVAL;
+    }
+
+    db_bo = amdgpu_bo_ref(gem_to_amdgpu_bo(gobj));
+    drm_gem_object_put(gobj);
+
+    index = amdgpu_doorbell_index_on_bar(uq_mgr->adev, db_bo, doorbell_index);
+
+    DRM_DEBUG_DRIVER("[Usermode queues] doorbell index=%lld\n", index);
+
+    return index;
+}
+
 static int
 amdgpu_userqueue_map_gtt_bo_to_gart(struct amdgpu_device *adev, struct amdgpu_bo *bo)
 {
@@ -132,6 +158,7 @@ static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq
     struct amdgpu_fpriv *fpriv = filp->driver_priv;
     struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;
     struct drm_amdgpu_userq_mqd *mqd_in = &args->in.mqd;
+    uint64_t index;
     int r;
 
     /* Do we have support userqueues for this IP ? */
@@ -154,6 +181,14 @@ static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq
     queue->userq_prop.queue_size = mqd_in->queue_size;
 
     queue->doorbell_handle = mqd_in->doorbell_handle;
+    index = amdgpu_userqueue_get_doorbell_index(uq_mgr, queue, filp, mqd_in->doorbell_offset);
+    if (index == (uint64_t)-EINVAL) {
+        DRM_ERROR("Invalid doorbell object\n");
+        r = -EINVAL;
+        goto free_queue;
+    }
+
+    queue->userq_prop.doorbell_index = index;
     queue->shadow_ctx_gpu_addr = mqd_in->shadow_va;
     queue->queue_type = mqd_in->ip_type;
     queue->flags = mqd_in->flags;
Signature · 1 line
2.40.0
#45 lore raw
In reply to Shashank Sharma

Hi Shashank,

I tried writing a program to experiment with usermode queues and I found some weird behavior: The first run of the program works as expected, while subsequent runs don't seem to do anything (and I allocate everything in GTT, so it should be zero initialized consistently). Is this a known issue?

The linked libdrm code for the uapi still does a doorbell ioctl so it could very well be that I do the doorbell wrong (especially since the ioctl implementation was never shared AFAICT?), but it seems like the kernel submissions (i.e. write wptr in dwords to the wptr va and to the doorbell). Is it possible to update the test in libdrm?

Code: https://gitlab.freedesktop.org/bnieuwenhuizen/usermode-queue

Thanks,
Bas

Quoted 65 lines · Shashank Sharma

This patch series introduces AMDGPU usermode queues for gfx workloads. Usermode queues is a method of GPU workload submission into the graphics hardware without any interaction with kernel/DRM schedulers. In this method, a userspace graphics application can create its own workqueue and submit it directly in the GPU HW.

The general idea of how this is supposed to work:
- The application creates the following GPU objetcs:
- A queue object to hold the workload packets.
- A read pointer object.
- A write pointer object.
- A doorbell page.
- The application picks a 32-bit offset in the doorbell page for this queue.
- The application uses the usermode_queue_create IOCTL introduced in this patch, by passing the the GPU addresses of these objects (read ptr, write ptr, queue base address and 32-bit doorbell offset from the doorbell page)
- The kernel creates the queue and maps it in the HW.
- The application can start submitting the data in the queue as soon as the kernel IOCTL returns.
- After filling the workload data in the queue, the app must write the number of dwords added in the queue into the doorbell offset, and the GPU will start fetching the data.

libDRM changes for this series and a sample DRM test program can be found in the MESA merge request here:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/287

This patch series depends on the doorbell-manager changes, which are being reviewed here:
https://patchwork.freedesktop.org/series/115802/

Alex Deucher (1):
drm/amdgpu: UAPI for user queue management

Arvind Yadav (2):
drm/amdgpu: add new parameters in v11_struct
drm/amdgpu: map wptr BO into GART

Shashank Sharma (6):
drm/amdgpu: add usermode queue base code drm/amdgpu: add new IOCTL for usermode queue drm/amdgpu: create GFX-gen11 MQD for userqueue drm/amdgpu: create context space for usermode queue drm/amdgpu: map usermode queue into MES drm/amdgpu: generate doorbell index for userqueue

 drivers/gpu/drm/amd/amdgpu/Makefile           |   3 +
 drivers/gpu/drm/amd/amdgpu/amdgpu.h           |  10 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |   2 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |   6 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 298 ++++++++++++++++++
 .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 230 ++++++++++++++
 .../gpu/drm/amd/include/amdgpu_userqueue.h    |  66 ++++
 drivers/gpu/drm/amd/include/v11_structs.h     |  16 +-
 include/uapi/drm/amdgpu_drm.h                 |  55 ++++
 9 files changed, 677 insertions(+), 9 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c
 create mode 100644 drivers/gpu/drm/amd/include/amdgpu_userqueue.h

--
2.40.0

#46 lore raw

[AMD Official Use Only - General]

Hello Bas,
Thanks for trying this out.

This could be due to the doorbell as you mentioned, Usermode queue uses doorbell manager internally.
This week, we are planning to publis the latest libDRM sample code which uses a doorbell object (instead of the doorbell hack IOCTL), adapting to that should fix your problem in my opinion. We have tested this full stack (libDRM test + Usermode queue + doorbell manager) for 500+ consecutive runs, and it worked well for us.

You can use this integrated kernel stack (1+2) from my gitlab to build your kernel: https://gitlab.freedesktop.org/contactshashanksharma/userq-amdgpu/-/tree/integrated-db-and-uq-v3
Please stay tuned for updated libDRM changes with doorbell objects.

Regards
Shashank
-----Original Message-----
From: Bas Nieuwenhuizen <[email protected]>
Sent: 10 April 2023 02:37
To: Sharma, Shashank <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH v3 0/9] AMDGPU Usermode queues

Hi Shashank,

I tried writing a program to experiment with usermode queues and I found some weird behavior: The first run of the program works as expected, while subsequent runs don't seem to do anything (and I allocate everything in GTT, so it should be zero initialized consistently). Is this a known issue?

The linked libdrm code for the uapi still does a doorbell ioctl so it could very well be that I do the doorbell wrong (especially since the ioctl implementation was never shared AFAICT?), but it seems like the kernel submissions (i.e. write wptr in dwords to the wptr va and to the doorbell). Is it possible to update the test in libdrm?

Code: https://gitlab.freedesktop.org/bnieuwenhuizen/usermode-queue

Thanks,
Bas

Quoted 66 lines · Shashank Sharma

This patch series introduces AMDGPU usermode queues for gfx workloads. Usermode queues is a method of GPU workload submission into the graphics hardware without any interaction with kernel/DRM schedulers. In this method, a userspace graphics application can create its own workqueue and submit it directly in the GPU HW.

The general idea of how this is supposed to work:
- The application creates the following GPU objetcs:
- A queue object to hold the workload packets.
- A read pointer object.
- A write pointer object.
- A doorbell page.
- The application picks a 32-bit offset in the doorbell page for this queue.
- The application uses the usermode_queue_create IOCTL introduced in this patch, by passing the the GPU addresses of these objects (read ptr, write ptr, queue base address and 32-bit doorbell offset from the doorbell page)
- The kernel creates the queue and maps it in the HW.
- The application can start submitting the data in the queue as soon as the kernel IOCTL returns.
- After filling the workload data in the queue, the app must write the number of dwords added in the queue into the doorbell offset, and the GPU will start fetching the data.

libDRM changes for this series and a sample DRM test program can be found in the MESA merge request here:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/287

This patch series depends on the doorbell-manager changes, which are being reviewed here:
https://patchwork.freedesktop.org/series/115802/

Alex Deucher (1):
drm/amdgpu: UAPI for user queue management

Arvind Yadav (2):
drm/amdgpu: add new parameters in v11_struct
drm/amdgpu: map wptr BO into GART

Shashank Sharma (6):
drm/amdgpu: add usermode queue base code drm/amdgpu: add new IOCTL for usermode queue drm/amdgpu: create GFX-gen11 MQD for userqueue drm/amdgpu: create context space for usermode queue drm/amdgpu: map usermode queue into MES drm/amdgpu: generate doorbell index for userqueue

 drivers/gpu/drm/amd/amdgpu/Makefile           |   3 +
 drivers/gpu/drm/amd/amdgpu/amdgpu.h           |  10 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |   2 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |   6 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 298 
++++++++++++++++++  .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 230 ++++++++++++++
 .../gpu/drm/amd/include/amdgpu_userqueue.h    |  66 ++++
 drivers/gpu/drm/amd/include/v11_structs.h     |  16 +-
 include/uapi/drm/amdgpu_drm.h                 |  55 ++++
 9 files changed, 677 insertions(+), 9 deletions(-)  create mode 
100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
 create mode 100644 
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c
 create mode 100644 drivers/gpu/drm/amd/include/amdgpu_userqueue.h

--
2.40.0

#47 lore raw

Hi Shashank,

I think I found the issue: I wasn't destroying the user queue in my program and the kernel doesn't clean up any remaining user queues in the postclose hook. I think we need something like
https://github.com/BNieuwenhuizen/linux/commit/e90c8d1185da7353c12837973ceddf55ccc85d29
?

While running things multiple times now works, I still have problems doing multiple submissions from the same queue. Looking forward to the updated test/sample

Thanks,
Bas

Quoted 100 lines · Shashank

[AMD Official Use Only - General]

Hello Bas,
Thanks for trying this out.

This could be due to the doorbell as you mentioned, Usermode queue uses doorbell manager internally.
This week, we are planning to publis the latest libDRM sample code which uses a doorbell object (instead of the doorbell hack IOCTL), adapting to that should fix your problem in my opinion. We have tested this full stack (libDRM test + Usermode queue + doorbell manager) for 500+ consecutive runs, and it worked well for us.

You can use this integrated kernel stack (1+2) from my gitlab to build your kernel: https://gitlab.freedesktop.org/contactshashanksharma/userq-amdgpu/-/tree/integrated-db-and-uq-v3
Please stay tuned for updated libDRM changes with doorbell objects.

Regards
Shashank
-----Original Message-----
From: Bas Nieuwenhuizen <[email protected]>
Sent: 10 April 2023 02:37
To: Sharma, Shashank <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH v3 0/9] AMDGPU Usermode queues

Hi Shashank,

I tried writing a program to experiment with usermode queues and I found some weird behavior: The first run of the program works as expected, while subsequent runs don't seem to do anything (and I allocate everything in GTT, so it should be zero initialized consistently). Is this a known issue?

The linked libdrm code for the uapi still does a doorbell ioctl so it could very well be that I do the doorbell wrong (especially since the ioctl implementation was never shared AFAICT?), but it seems like the kernel submissions (i.e. write wptr in dwords to the wptr va and to the doorbell). Is it possible to update the test in libdrm?

Code: https://gitlab.freedesktop.org/bnieuwenhuizen/usermode-queue

Thanks,
Bas

Quoted 66 lines · Shashank Sharma

This patch series introduces AMDGPU usermode queues for gfx workloads. Usermode queues is a method of GPU workload submission into the graphics hardware without any interaction with kernel/DRM schedulers. In this method, a userspace graphics application can create its own workqueue and submit it directly in the GPU HW.

The general idea of how this is supposed to work:
- The application creates the following GPU objetcs:
- A queue object to hold the workload packets.
- A read pointer object.
- A write pointer object.
- A doorbell page.
- The application picks a 32-bit offset in the doorbell page for this queue.
- The application uses the usermode_queue_create IOCTL introduced in this patch, by passing the the GPU addresses of these objects (read ptr, write ptr, queue base address and 32-bit doorbell offset from the doorbell page)
- The kernel creates the queue and maps it in the HW.
- The application can start submitting the data in the queue as soon as the kernel IOCTL returns.
- After filling the workload data in the queue, the app must write the number of dwords added in the queue into the doorbell offset, and the GPU will start fetching the data.

libDRM changes for this series and a sample DRM test program can be found in the MESA merge request here:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/287

This patch series depends on the doorbell-manager changes, which are being reviewed here:
https://patchwork.freedesktop.org/series/115802/

Alex Deucher (1):
drm/amdgpu: UAPI for user queue management

Arvind Yadav (2):
drm/amdgpu: add new parameters in v11_struct
drm/amdgpu: map wptr BO into GART

Shashank Sharma (6):
drm/amdgpu: add usermode queue base code drm/amdgpu: add new IOCTL for usermode queue drm/amdgpu: create GFX-gen11 MQD for userqueue drm/amdgpu: create context space for usermode queue drm/amdgpu: map usermode queue into MES drm/amdgpu: generate doorbell index for userqueue

 drivers/gpu/drm/amd/amdgpu/Makefile           |   3 +
 drivers/gpu/drm/amd/amdgpu/amdgpu.h           |  10 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |   2 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |   6 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 298
++++++++++++++++++  .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 230 ++++++++++++++
 .../gpu/drm/amd/include/amdgpu_userqueue.h    |  66 ++++
 drivers/gpu/drm/amd/include/v11_structs.h     |  16 +-
 include/uapi/drm/amdgpu_drm.h                 |  55 ++++
 9 files changed, 677 insertions(+), 9 deletions(-)  create mode
100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
 create mode 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c
 create mode 100644 drivers/gpu/drm/amd/include/amdgpu_userqueue.h

--
2.40.0

#48 lore raw

[AMD Official Use Only - General]

Hello Bas,

This is not the correct interpretation of the code, the USERQ_IOCTL has both the OPs (create and destroy), but th euser has to exclusively call it.

Please see the sample test program in the existing libDRM series (userq_test.c, it specifically calls amdgpu_free_userq, which does the destroy_OP

for the IOCTL.

- Shashank

-----Original Message-----
From: Bas Nieuwenhuizen <[email protected]>
Sent: 10 April 2023 11:26
To: Sharma, Shashank <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Koenig, Christian <[email protected]>; Yadav, Arvind <[email protected]>
Subject: Re: [PATCH v3 0/9] AMDGPU Usermode queues

Hi Shashank,

I think I found the issue: I wasn't destroying the user queue in my program and the kernel doesn't clean up any remaining user queues in the postclose hook. I think we need something like
https://github.com/BNieuwenhuizen/linux/commit/e90c8d1185da7353c12837973ceddf55ccc85d29
?

While running things multiple times now works, I still have problems doing multiple submissions from the same queue. Looking forward to the updated test/sample

Thanks,
Bas

Quoted 106 lines · Shashank

[AMD Official Use Only - General]

Hello Bas,
Thanks for trying this out.

This could be due to the doorbell as you mentioned, Usermode queue uses doorbell manager internally.
This week, we are planning to publis the latest libDRM sample code which uses a doorbell object (instead of the doorbell hack IOCTL), adapting to that should fix your problem in my opinion. We have tested this full stack (libDRM test + Usermode queue + doorbell manager) for 500+ consecutive runs, and it worked well for us.

You can use this integrated kernel stack (1+2) from my gitlab to build your kernel:
https://gitlab.freedesktop.org/contactshashanksharma/userq-amdgpu/-/tr
ee/integrated-db-and-uq-v3 Please stay tuned for updated libDRM changes with doorbell objects.

Regards
Shashank
-----Original Message-----
From: Bas Nieuwenhuizen <[email protected]>
Sent: 10 April 2023 02:37
To: Sharma, Shashank <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH v3 0/9] AMDGPU Usermode queues

Hi Shashank,

I tried writing a program to experiment with usermode queues and I found some weird behavior: The first run of the program works as expected, while subsequent runs don't seem to do anything (and I allocate everything in GTT, so it should be zero initialized consistently). Is this a known issue?

The linked libdrm code for the uapi still does a doorbell ioctl so it could very well be that I do the doorbell wrong (especially since the ioctl implementation was never shared AFAICT?), but it seems like the kernel submissions (i.e. write wptr in dwords to the wptr va and to the doorbell). Is it possible to update the test in libdrm?

Code: https://gitlab.freedesktop.org/bnieuwenhuizen/usermode-queue

Thanks,
Bas

Quoted 67 lines · Shashank Sharma

This patch series introduces AMDGPU usermode queues for gfx workloads. Usermode queues is a method of GPU workload submission into the graphics hardware without any interaction with kernel/DRM schedulers. In this method, a userspace graphics application can create its own workqueue and submit it directly in the GPU HW.

The general idea of how this is supposed to work:
- The application creates the following GPU objetcs:
- A queue object to hold the workload packets.
- A read pointer object.
- A write pointer object.
- A doorbell page.
- The application picks a 32-bit offset in the doorbell page for this queue.
- The application uses the usermode_queue_create IOCTL introduced in this patch, by passing the the GPU addresses of these objects (read ptr, write ptr, queue base address and 32-bit doorbell offset from the doorbell page)
- The kernel creates the queue and maps it in the HW.
- The application can start submitting the data in the queue as soon as the kernel IOCTL returns.
- After filling the workload data in the queue, the app must write the number of dwords added in the queue into the doorbell offset, and the GPU will start fetching the data.

libDRM changes for this series and a sample DRM test program can be found in the MESA merge request here:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/287

This patch series depends on the doorbell-manager changes, which are being reviewed here:
https://patchwork.freedesktop.org/series/115802/

Alex Deucher (1):
drm/amdgpu: UAPI for user queue management

Arvind Yadav (2):
drm/amdgpu: add new parameters in v11_struct
drm/amdgpu: map wptr BO into GART

Shashank Sharma (6):
drm/amdgpu: add usermode queue base code drm/amdgpu: add new IOCTL for usermode queue drm/amdgpu: create GFX-gen11 MQD for userqueue drm/amdgpu: create context space for usermode queue drm/amdgpu: map usermode queue into MES drm/amdgpu: generate doorbell index for userqueue

 drivers/gpu/drm/amd/amdgpu/Makefile           |   3 +
 drivers/gpu/drm/amd/amdgpu/amdgpu.h           |  10 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |   2 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |   6 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 298
++++++++++++++++++  .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 
++++++++++++++++++ 230 ++++++++++++++
 .../gpu/drm/amd/include/amdgpu_userqueue.h    |  66 ++++
 drivers/gpu/drm/amd/include/v11_structs.h     |  16 +-
 include/uapi/drm/amdgpu_drm.h                 |  55 ++++
 9 files changed, 677 insertions(+), 9 deletions(-)  create mode
100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
 create mode 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c
 create mode 100644 drivers/gpu/drm/amd/include/amdgpu_userqueue.h

--
2.40.0

#49 lore raw
Quoted 10 lines · Shashank

[AMD Official Use Only - General]

Hello Bas,

This is not the correct interpretation of the code, the USERQ_IOCTL has both the OPs (create and destroy), but th euser has to exclusively call it.

Please see the sample test program in the existing libDRM series (userq_test.c, it specifically calls amdgpu_free_userq, which does the destroy_OP

for the IOCTL.

In the presence of crashes the kernel should always be able to clean this up no? Otherwise there is a resource leak?

Quoted 128 lines

- Shashank

-----Original Message-----
From: Bas Nieuwenhuizen <[email protected]>
Sent: 10 April 2023 11:26
To: Sharma, Shashank <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Koenig, Christian <[email protected]>; Yadav, Arvind <[email protected]>
Subject: Re: [PATCH v3 0/9] AMDGPU Usermode queues

Hi Shashank,

I think I found the issue: I wasn't destroying the user queue in my program and the kernel doesn't clean up any remaining user queues in the postclose hook. I think we need something like
https://github.com/BNieuwenhuizen/linux/commit/e90c8d1185da7353c12837973ceddf55ccc85d29
?

While running things multiple times now works, I still have problems doing multiple submissions from the same queue. Looking forward to the updated test/sample

Thanks,
Bas

Quoted 106 lines · Shashank

[AMD Official Use Only - General]

Hello Bas,
Thanks for trying this out.

This could be due to the doorbell as you mentioned, Usermode queue uses doorbell manager internally.
This week, we are planning to publis the latest libDRM sample code which uses a doorbell object (instead of the doorbell hack IOCTL), adapting to that should fix your problem in my opinion. We have tested this full stack (libDRM test + Usermode queue + doorbell manager) for 500+ consecutive runs, and it worked well for us.

You can use this integrated kernel stack (1+2) from my gitlab to build your kernel:
https://gitlab.freedesktop.org/contactshashanksharma/userq-amdgpu/-/tr
ee/integrated-db-and-uq-v3 Please stay tuned for updated libDRM changes with doorbell objects.

Regards
Shashank
-----Original Message-----
From: Bas Nieuwenhuizen <[email protected]>
Sent: 10 April 2023 02:37
To: Sharma, Shashank <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH v3 0/9] AMDGPU Usermode queues

Hi Shashank,

I tried writing a program to experiment with usermode queues and I found some weird behavior: The first run of the program works as expected, while subsequent runs don't seem to do anything (and I allocate everything in GTT, so it should be zero initialized consistently). Is this a known issue?

The linked libdrm code for the uapi still does a doorbell ioctl so it could very well be that I do the doorbell wrong (especially since the ioctl implementation was never shared AFAICT?), but it seems like the kernel submissions (i.e. write wptr in dwords to the wptr va and to the doorbell). Is it possible to update the test in libdrm?

Code: https://gitlab.freedesktop.org/bnieuwenhuizen/usermode-queue

Thanks,
Bas

Quoted 67 lines · Shashank Sharma

This patch series introduces AMDGPU usermode queues for gfx workloads. Usermode queues is a method of GPU workload submission into the graphics hardware without any interaction with kernel/DRM schedulers. In this method, a userspace graphics application can create its own workqueue and submit it directly in the GPU HW.

The general idea of how this is supposed to work:
- The application creates the following GPU objetcs:
- A queue object to hold the workload packets.
- A read pointer object.
- A write pointer object.
- A doorbell page.
- The application picks a 32-bit offset in the doorbell page for this queue.
- The application uses the usermode_queue_create IOCTL introduced in this patch, by passing the the GPU addresses of these objects (read ptr, write ptr, queue base address and 32-bit doorbell offset from the doorbell page)
- The kernel creates the queue and maps it in the HW.
- The application can start submitting the data in the queue as soon as the kernel IOCTL returns.
- After filling the workload data in the queue, the app must write the number of dwords added in the queue into the doorbell offset, and the GPU will start fetching the data.

libDRM changes for this series and a sample DRM test program can be found in the MESA merge request here:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/287

This patch series depends on the doorbell-manager changes, which are being reviewed here:
https://patchwork.freedesktop.org/series/115802/

Alex Deucher (1):
drm/amdgpu: UAPI for user queue management

Arvind Yadav (2):
drm/amdgpu: add new parameters in v11_struct
drm/amdgpu: map wptr BO into GART

Shashank Sharma (6):
drm/amdgpu: add usermode queue base code drm/amdgpu: add new IOCTL for usermode queue drm/amdgpu: create GFX-gen11 MQD for userqueue drm/amdgpu: create context space for usermode queue drm/amdgpu: map usermode queue into MES drm/amdgpu: generate doorbell index for userqueue

 drivers/gpu/drm/amd/amdgpu/Makefile           |   3 +
 drivers/gpu/drm/amd/amdgpu/amdgpu.h           |  10 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |   2 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |   6 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 298
++++++++++++++++++  .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c |
++++++++++++++++++ 230 ++++++++++++++
 .../gpu/drm/amd/include/amdgpu_userqueue.h    |  66 ++++
 drivers/gpu/drm/amd/include/v11_structs.h     |  16 +-
 include/uapi/drm/amdgpu_drm.h                 |  55 ++++
 9 files changed, 677 insertions(+), 9 deletions(-)  create mode
100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
 create mode 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c
 create mode 100644 drivers/gpu/drm/amd/include/amdgpu_userqueue.h

--
2.40.0

#50 lore raw
Quoted 6 lines · Bas Nieuwenhuizen
Quoted 4 lines · Shashank

[AMD Official Use Only - General]

Hello Bas,

Quoted 7 lines
Quoted 5 lines

This is not the correct interpretation of the code, the USERQ_IOCTL has both the OPs (create and destroy), but th euser has to exclusively call it.

Please see the sample test program in the existing libDRM series (userq_test.c, it specifically calls amdgpu_free_userq, which does the destroy_OP

for the IOCTL.

In the presence of crashes the kernel should always be able to clean this up no? Otherwise there is a resource leak?

The crash handling is the same as any of the existing GPU resource which are allocated and freed with IOCTL_OPs.

To be honest a crash handling can be very elaborated and complex one, and hence only can be done at the driver unload IMO, which doesn't help at that stage,

coz anyways driver will re-allocate the resources on next load.

- Shashank

Quoted 126 lines
Quoted 126 lines

- Shashank

-----Original Message-----
From: Bas Nieuwenhuizen <[email protected]>
Sent: 10 April 2023 11:26
To: Sharma, Shashank <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Koenig, Christian <[email protected]>; Yadav, Arvind <[email protected]>
Subject: Re: [PATCH v3 0/9] AMDGPU Usermode queues

Hi Shashank,

I think I found the issue: I wasn't destroying the user queue in my program and the kernel doesn't clean up any remaining user queues in the postclose hook. I think we need something like
https://github.com/BNieuwenhuizen/linux/commit/e90c8d1185da7353c12837973ceddf55ccc85d29
?

While running things multiple times now works, I still have problems doing multiple submissions from the same queue. Looking forward to the updated test/sample

Thanks,
Bas

Quoted 104 lines · Shashank

[AMD Official Use Only - General]

Hello Bas,
Thanks for trying this out.

This could be due to the doorbell as you mentioned, Usermode queue uses doorbell manager internally.
This week, we are planning to publis the latest libDRM sample code which uses a doorbell object (instead of the doorbell hack IOCTL), adapting to that should fix your problem in my opinion. We have tested this full stack (libDRM test + Usermode queue + doorbell manager) for 500+ consecutive runs, and it worked well for us.

You can use this integrated kernel stack (1+2) from my gitlab to build your kernel:
https://gitlab.freedesktop.org/contactshashanksharma/userq-amdgpu/-/tr
ee/integrated-db-and-uq-v3 Please stay tuned for updated libDRM changes with doorbell objects.

Regards
Shashank
-----Original Message-----
From: Bas Nieuwenhuizen <[email protected]>
Sent: 10 April 2023 02:37
To: Sharma, Shashank <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH v3 0/9] AMDGPU Usermode queues

Hi Shashank,

I tried writing a program to experiment with usermode queues and I found some weird behavior: The first run of the program works as expected, while subsequent runs don't seem to do anything (and I allocate everything in GTT, so it should be zero initialized consistently). Is this a known issue?

The linked libdrm code for the uapi still does a doorbell ioctl so it could very well be that I do the doorbell wrong (especially since the ioctl implementation was never shared AFAICT?), but it seems like the kernel submissions (i.e. write wptr in dwords to the wptr va and to the doorbell). Is it possible to update the test in libdrm?

Code: https://gitlab.freedesktop.org/bnieuwenhuizen/usermode-queue

Thanks,
Bas

Quoted 66 lines · Shashank Sharma

This patch series introduces AMDGPU usermode queues for gfx workloads. Usermode queues is a method of GPU workload submission into the graphics hardware without any interaction with kernel/DRM schedulers. In this method, a userspace graphics application can create its own workqueue and submit it directly in the GPU HW.

The general idea of how this is supposed to work:
- The application creates the following GPU objetcs:
- A queue object to hold the workload packets.
- A read pointer object.
- A write pointer object.
- A doorbell page.
- The application picks a 32-bit offset in the doorbell page for this queue.
- The application uses the usermode_queue_create IOCTL introduced in this patch, by passing the the GPU addresses of these objects (read ptr, write ptr, queue base address and 32-bit doorbell offset from the doorbell page)
- The kernel creates the queue and maps it in the HW.
- The application can start submitting the data in the queue as soon as the kernel IOCTL returns.
- After filling the workload data in the queue, the app must write the number of dwords added in the queue into the doorbell offset, and the GPU will start fetching the data.

libDRM changes for this series and a sample DRM test program can be found in the MESA merge request here:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/287

This patch series depends on the doorbell-manager changes, which are being reviewed here:
https://patchwork.freedesktop.org/series/115802/

Alex Deucher (1):
drm/amdgpu: UAPI for user queue management

Arvind Yadav (2):
drm/amdgpu: add new parameters in v11_struct
drm/amdgpu: map wptr BO into GART

Shashank Sharma (6):
drm/amdgpu: add usermode queue base code drm/amdgpu: add new IOCTL for usermode queue drm/amdgpu: create GFX-gen11 MQD for userqueue drm/amdgpu: create context space for usermode queue drm/amdgpu: map usermode queue into MES drm/amdgpu: generate doorbell index for userqueue

  drivers/gpu/drm/amd/amdgpu/Makefile           |   3 +
  drivers/gpu/drm/amd/amdgpu/amdgpu.h           |  10 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |   2 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |   6 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 298
++++++++++++++++++  .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c |
++++++++++++++++++ 230 ++++++++++++++
  .../gpu/drm/amd/include/amdgpu_userqueue.h    |  66 ++++
  drivers/gpu/drm/amd/include/v11_structs.h     |  16 +-
  include/uapi/drm/amdgpu_drm.h                 |  55 ++++
  9 files changed, 677 insertions(+), 9 deletions(-)  create mode

100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
create mode 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c
create mode 100644 drivers/gpu/drm/amd/include/amdgpu_userqueue.h

--
2.40.0

#51 lore raw
Quoted 11 lines · Shashank Sharma
Quoted 8 lines · Bas Nieuwenhuizen
Quoted 6 lines · Shashank

[AMD Official Use Only - General]

Hello Bas,

This is not the correct interpretation of the code, the USERQ_IOCTL has both the OPs (create and destroy), but th euser has to exclusively call it.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Please see the sample test program in the existing libDRM series (userq_test.c, it specifically calls amdgpu_free_userq, which does the destroy_OP

for the IOCTL.

In the presence of crashes the kernel should always be able to clean this up no? Otherwise there is a resource leak?

The crash handling is the same as any of the existing GPU resource which are allocated and freed with IOCTL_OPs.

Most of those are handled in the when the DRM fd gets closed (i.e. when the process exits):

- buffers through drm_gem_release()
- mappings in amdgpu_vm_fini
- contexts in amdgpu_ctx_mgr_fini

etc.

Why would we do things differently for userspace queues? It doesn't look complicated looking at the above patch (which does seem to work).

Quoted 135 lines

To be honest a crash handling can be very elaborated and complex one, and hence only can be done at the driver unload IMO, which doesn't help at that stage,

coz anyways driver will re-allocate the resources on next load.

- Shashank

Quoted 126 lines
Quoted 126 lines

- Shashank

-----Original Message-----
From: Bas Nieuwenhuizen <[email protected]>
Sent: 10 April 2023 11:26
To: Sharma, Shashank <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Koenig, Christian <[email protected]>; Yadav, Arvind <[email protected]>
Subject: Re: [PATCH v3 0/9] AMDGPU Usermode queues

Hi Shashank,

I think I found the issue: I wasn't destroying the user queue in my program and the kernel doesn't clean up any remaining user queues in the postclose hook. I think we need something like
https://github.com/BNieuwenhuizen/linux/commit/e90c8d1185da7353c12837973ceddf55ccc85d29
?

While running things multiple times now works, I still have problems doing multiple submissions from the same queue. Looking forward to the updated test/sample

Thanks,
Bas

Quoted 104 lines · Shashank

[AMD Official Use Only - General]

Hello Bas,
Thanks for trying this out.

This could be due to the doorbell as you mentioned, Usermode queue uses doorbell manager internally.
This week, we are planning to publis the latest libDRM sample code which uses a doorbell object (instead of the doorbell hack IOCTL), adapting to that should fix your problem in my opinion. We have tested this full stack (libDRM test + Usermode queue + doorbell manager) for 500+ consecutive runs, and it worked well for us.

You can use this integrated kernel stack (1+2) from my gitlab to build your kernel:
https://gitlab.freedesktop.org/contactshashanksharma/userq-amdgpu/-/tr
ee/integrated-db-and-uq-v3 Please stay tuned for updated libDRM changes with doorbell objects.

Regards
Shashank
-----Original Message-----
From: Bas Nieuwenhuizen <[email protected]>
Sent: 10 April 2023 02:37
To: Sharma, Shashank <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH v3 0/9] AMDGPU Usermode queues

Hi Shashank,

I tried writing a program to experiment with usermode queues and I found some weird behavior: The first run of the program works as expected, while subsequent runs don't seem to do anything (and I allocate everything in GTT, so it should be zero initialized consistently). Is this a known issue?

The linked libdrm code for the uapi still does a doorbell ioctl so it could very well be that I do the doorbell wrong (especially since the ioctl implementation was never shared AFAICT?), but it seems like the kernel submissions (i.e. write wptr in dwords to the wptr va and to the doorbell). Is it possible to update the test in libdrm?

Code: https://gitlab.freedesktop.org/bnieuwenhuizen/usermode-queue

Thanks,
Bas

Quoted 66 lines · Shashank Sharma

This patch series introduces AMDGPU usermode queues for gfx workloads. Usermode queues is a method of GPU workload submission into the graphics hardware without any interaction with kernel/DRM schedulers. In this method, a userspace graphics application can create its own workqueue and submit it directly in the GPU HW.

The general idea of how this is supposed to work:
- The application creates the following GPU objetcs:
- A queue object to hold the workload packets.
- A read pointer object.
- A write pointer object.
- A doorbell page.
- The application picks a 32-bit offset in the doorbell page for this queue.
- The application uses the usermode_queue_create IOCTL introduced in this patch, by passing the the GPU addresses of these objects (read ptr, write ptr, queue base address and 32-bit doorbell offset from the doorbell page)
- The kernel creates the queue and maps it in the HW.
- The application can start submitting the data in the queue as soon as the kernel IOCTL returns.
- After filling the workload data in the queue, the app must write the number of dwords added in the queue into the doorbell offset, and the GPU will start fetching the data.

libDRM changes for this series and a sample DRM test program can be found in the MESA merge request here:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/287

This patch series depends on the doorbell-manager changes, which are being reviewed here:
https://patchwork.freedesktop.org/series/115802/

Alex Deucher (1):
drm/amdgpu: UAPI for user queue management

Arvind Yadav (2):
drm/amdgpu: add new parameters in v11_struct
drm/amdgpu: map wptr BO into GART

Shashank Sharma (6):
drm/amdgpu: add usermode queue base code drm/amdgpu: add new IOCTL for usermode queue drm/amdgpu: create GFX-gen11 MQD for userqueue drm/amdgpu: create context space for usermode queue drm/amdgpu: map usermode queue into MES drm/amdgpu: generate doorbell index for userqueue

  drivers/gpu/drm/amd/amdgpu/Makefile           |   3 +
  drivers/gpu/drm/amd/amdgpu/amdgpu.h           |  10 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |   2 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |   6 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 298
++++++++++++++++++  .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c |
++++++++++++++++++ 230 ++++++++++++++
  .../gpu/drm/amd/include/amdgpu_userqueue.h    |  66 ++++
  drivers/gpu/drm/amd/include/v11_structs.h     |  16 +-
  include/uapi/drm/amdgpu_drm.h                 |  55 ++++
  9 files changed, 677 insertions(+), 9 deletions(-)  create mode

100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
create mode 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c
create mode 100644 drivers/gpu/drm/amd/include/amdgpu_userqueue.h

--
2.40.0

#52 lore raw
Quoted 21 lines · Bas Nieuwenhuizen
Quoted 10 lines · Shashank Sharma
Quoted 8 lines · Bas Nieuwenhuizen
Quoted 6 lines · Shashank

[AMD Official Use Only - General]

Hello Bas,

This is not the correct interpretation of the code, the USERQ_IOCTL has both the OPs (create and destroy), but th euser has to exclusively call it.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Please see the sample test program in the existing libDRM series (userq_test.c, it specifically calls amdgpu_free_userq, which does the destroy_OP

for the IOCTL.

In the presence of crashes the kernel should always be able to clean this up no? Otherwise there is a resource leak?

The crash handling is the same as any of the existing GPU resource which are allocated and freed with IOCTL_OPs.

Most of those are handled in the when the DRM fd gets closed (i.e. when the process exits):

Quoted 8 lines

- buffers through drm_gem_release()
- mappings in amdgpu_vm_fini
- contexts in amdgpu_ctx_mgr_fini

etc.

Why would we do things differently for userspace queues? It doesn't look complicated looking at the above patch (which does seem to work).

As the code is in initial stage, I have not given much thoughts about handling resource leak due to app crash, but this seems like a good suggestion.

I am taking a note and will try to accommodate this in an upcoming version of the series.

- Shashank

Quoted 133 lines
Quoted 133 lines

To be honest a crash handling can be very elaborated and complex one, and hence only can be done at the driver unload IMO, which doesn't help at that stage,

coz anyways driver will re-allocate the resources on next load.

- Shashank

Quoted 125 lines
Quoted 125 lines

- Shashank

-----Original Message-----
From: Bas Nieuwenhuizen <[email protected]>
Sent: 10 April 2023 11:26
To: Sharma, Shashank <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Koenig, Christian <[email protected]>; Yadav, Arvind <[email protected]>
Subject: Re: [PATCH v3 0/9] AMDGPU Usermode queues

Hi Shashank,

I think I found the issue: I wasn't destroying the user queue in my program and the kernel doesn't clean up any remaining user queues in the postclose hook. I think we need something like
https://github.com/BNieuwenhuizen/linux/commit/e90c8d1185da7353c12837973ceddf55ccc85d29
?

While running things multiple times now works, I still have problems doing multiple submissions from the same queue. Looking forward to the updated test/sample

Thanks,
Bas

Quoted 104 lines · Shashank

[AMD Official Use Only - General]

Hello Bas,
Thanks for trying this out.

This could be due to the doorbell as you mentioned, Usermode queue uses doorbell manager internally.
This week, we are planning to publis the latest libDRM sample code which uses a doorbell object (instead of the doorbell hack IOCTL), adapting to that should fix your problem in my opinion. We have tested this full stack (libDRM test + Usermode queue + doorbell manager) for 500+ consecutive runs, and it worked well for us.

You can use this integrated kernel stack (1+2) from my gitlab to build your kernel:
https://gitlab.freedesktop.org/contactshashanksharma/userq-amdgpu/-/tr
ee/integrated-db-and-uq-v3 Please stay tuned for updated libDRM changes with doorbell objects.

Regards
Shashank
-----Original Message-----
From: Bas Nieuwenhuizen <[email protected]>
Sent: 10 April 2023 02:37
To: Sharma, Shashank <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH v3 0/9] AMDGPU Usermode queues

Hi Shashank,

I tried writing a program to experiment with usermode queues and I found some weird behavior: The first run of the program works as expected, while subsequent runs don't seem to do anything (and I allocate everything in GTT, so it should be zero initialized consistently). Is this a known issue?

The linked libdrm code for the uapi still does a doorbell ioctl so it could very well be that I do the doorbell wrong (especially since the ioctl implementation was never shared AFAICT?), but it seems like the kernel submissions (i.e. write wptr in dwords to the wptr va and to the doorbell). Is it possible to update the test in libdrm?

Code: https://gitlab.freedesktop.org/bnieuwenhuizen/usermode-queue

Thanks,
Bas

Quoted 66 lines · Shashank Sharma

This patch series introduces AMDGPU usermode queues for gfx workloads. Usermode queues is a method of GPU workload submission into the graphics hardware without any interaction with kernel/DRM schedulers. In this method, a userspace graphics application can create its own workqueue and submit it directly in the GPU HW.

The general idea of how this is supposed to work:
- The application creates the following GPU objetcs:
- A queue object to hold the workload packets.
- A read pointer object.
- A write pointer object.
- A doorbell page.
- The application picks a 32-bit offset in the doorbell page for this queue.
- The application uses the usermode_queue_create IOCTL introduced in this patch, by passing the the GPU addresses of these objects (read ptr, write ptr, queue base address and 32-bit doorbell offset from the doorbell page)
- The kernel creates the queue and maps it in the HW.
- The application can start submitting the data in the queue as soon as the kernel IOCTL returns.
- After filling the workload data in the queue, the app must write the number of dwords added in the queue into the doorbell offset, and the GPU will start fetching the data.

libDRM changes for this series and a sample DRM test program can be found in the MESA merge request here:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/287

This patch series depends on the doorbell-manager changes, which are being reviewed here:
https://patchwork.freedesktop.org/series/115802/

Alex Deucher (1):
drm/amdgpu: UAPI for user queue management

Arvind Yadav (2):
drm/amdgpu: add new parameters in v11_struct
drm/amdgpu: map wptr BO into GART

Shashank Sharma (6):
drm/amdgpu: add usermode queue base code drm/amdgpu: add new IOCTL for usermode queue drm/amdgpu: create GFX-gen11 MQD for userqueue drm/amdgpu: create context space for usermode queue drm/amdgpu: map usermode queue into MES drm/amdgpu: generate doorbell index for userqueue

   drivers/gpu/drm/amd/amdgpu/Makefile           |   3 +
   drivers/gpu/drm/amd/amdgpu/amdgpu.h           |  10 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |   2 +
   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |   6 +
   drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 298
++++++++++++++++++  .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c |
++++++++++++++++++ 230 ++++++++++++++
   .../gpu/drm/amd/include/amdgpu_userqueue.h    |  66 ++++
   drivers/gpu/drm/amd/include/v11_structs.h     |  16 +-
   include/uapi/drm/amdgpu_drm.h                 |  55 ++++
   9 files changed, 677 insertions(+), 9 deletions(-)  create mode

100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
create mode 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c
create mode 100644 drivers/gpu/drm/amd/include/amdgpu_userqueue.h

--
2.40.0

maintainer
#53 lore raw

Am 10.04.23 um 16:26 schrieb Shashank Sharma:

Quoted 27 lines · Bas Nieuwenhuizen
Quoted 25 lines · Shashank Sharma
Quoted 10 lines · Bas Nieuwenhuizen
Quoted 8 lines
Quoted 6 lines · Shashank

[AMD Official Use Only - General]

Hello Bas,

This is not the correct interpretation of the code, the USERQ_IOCTL has both the OPs (create and destroy), but th euser has to exclusively call  it.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Please see the sample test program in the existing libDRM series (userq_test.c, it specifically calls amdgpu_free_userq, which does the destroy_OP

for the IOCTL.

In the presence of crashes the kernel should always be able to clean this up no? Otherwise there is a resource leak?

The crash handling is the same as any of the existing GPU resource which are allocated and freed with IOCTL_OPs.

Most of those are handled in the when the DRM fd gets closed (i.e. when the process exits):

- buffers through drm_gem_release()
- mappings in amdgpu_vm_fini
- contexts in amdgpu_ctx_mgr_fini

Quoted 8 lines
Quoted 4 lines

etc.

Why would we do things differently for userspace queues? It doesn't look complicated looking at the above patch (which does seem to work).

As the code is in initial stage, I have not given much thoughts about handling resource leak due to app crash, but this seems like a good suggestion.

I am taking a note and will try to accommodate this in an upcoming version of the series.

Bas is right, the application doesn't necessary needs to clean up on exit (but it's still good custody to do so).

See amdgpu_driver_postclose_kms() for how we cleanup (for example) the ctx manager by calling amdgpu_ctx_mgr_fini() or the BO lists.

Regards,
Christian.

Quoted 142 lines

- Shashank

Quoted 139 lines
Quoted 139 lines

To be honest a crash handling can be very elaborated and complex one, and hence only can be done at the driver unload IMO, which doesn't help at that stage,

coz anyways driver will re-allocate the resources on next load.

- Shashank

Quoted 131 lines
Quoted 131 lines

- Shashank

-----Original Message-----
From: Bas Nieuwenhuizen <[email protected]>
Sent: 10 April 2023 11:26
To: Sharma, Shashank <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Koenig, Christian <[email protected]>; Yadav, Arvind <[email protected]>
Subject: Re: [PATCH v3 0/9] AMDGPU Usermode queues

Hi Shashank,

I think I found the issue: I wasn't destroying the user queue in my program and the kernel doesn't clean up any remaining user queues in the postclose hook. I think we need something like
https://github.com/BNieuwenhuizen/linux/commit/e90c8d1185da7353c12837973ceddf55ccc85d29

?

While running things multiple times now works, I still have problems doing multiple submissions from the same queue. Looking forward to the updated test/sample

Thanks,
Bas

Quoted 109 lines · Shashank

[AMD Official Use Only - General]

Hello Bas,
Thanks for trying this out.

This could be due to the doorbell as you mentioned, Usermode queue uses doorbell manager internally.
This week, we are planning to publis the latest libDRM sample code which uses a doorbell object (instead of the doorbell hack IOCTL), adapting to that should fix your problem in my opinion. We have tested this full stack (libDRM test + Usermode queue + doorbell manager) for 500+ consecutive runs, and it worked well for us.

You can use this integrated kernel stack (1+2) from my gitlab to build your kernel:
https://gitlab.freedesktop.org/contactshashanksharma/userq-amdgpu/-/tr

ee/integrated-db-and-uq-v3 Please stay tuned for updated libDRM changes with doorbell objects.

Regards
Shashank
-----Original Message-----
From: Bas Nieuwenhuizen <[email protected]>
Sent: 10 April 2023 02:37
To: Sharma, Shashank <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH v3 0/9] AMDGPU Usermode queues

Hi Shashank,

I tried writing a program to experiment with usermode queues and I found some weird behavior: The first run of the program works as expected, while subsequent runs don't seem to do anything (and I allocate everything in GTT, so it should be zero initialized consistently). Is this a known issue?

The linked libdrm code for the uapi still does a doorbell ioctl so it could very well be that I do the doorbell wrong (especially since the ioctl implementation was never shared AFAICT?), but it seems like the kernel submissions (i.e. write wptr in dwords to the wptr va and to the doorbell). Is it possible to update the test in libdrm?

Code: https://gitlab.freedesktop.org/bnieuwenhuizen/usermode-queue

Thanks,
Bas

Quoted 70 lines · Shashank Sharma

This patch series introduces AMDGPU usermode queues for gfx workloads. Usermode queues is a method of GPU workload submission into the graphics hardware without any interaction with kernel/DRM schedulers. In this method, a userspace graphics application can create its own workqueue and submit it directly in the GPU HW.

The general idea of how this is supposed to work:
- The application creates the following GPU objetcs:
    - A queue object to hold the workload packets.
    - A read pointer object.
    - A write pointer object.
    - A doorbell page.
- The application picks a 32-bit offset in the doorbell page for this queue.
- The application uses the usermode_queue_create IOCTL introduced in
    this patch, by passing the the GPU addresses of these objects (read ptr, write ptr, queue base address and 32-bit doorbell offset from the doorbell page)
- The kernel creates the queue and maps it in the HW.
- The application can start submitting the data in the queue as soon as
    the kernel IOCTL returns.
- After filling the workload data in the queue, the app must write the
    number of dwords added in the queue into the doorbell offset, and the GPU will start fetching the data.

libDRM changes for this series and a sample DRM test program can be found in the MESA merge request here:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/287

This patch series depends on the doorbell-manager changes, which are being reviewed here:
https://patchwork.freedesktop.org/series/115802/

Alex Deucher (1):
    drm/amdgpu: UAPI for user queue management

Arvind Yadav (2):
    drm/amdgpu: add new parameters in v11_struct
    drm/amdgpu: map wptr BO into GART

Shashank Sharma (6):
    drm/amdgpu: add usermode queue base code drm/amdgpu: add new IOCTL for usermode queue drm/amdgpu: create GFX-gen11 MQD for userqueue drm/amdgpu: create context space for usermode queue drm/amdgpu: map usermode queue into MES drm/amdgpu: generate doorbell index for userqueue

   drivers/gpu/drm/amd/amdgpu/Makefile           |   3 + drivers/gpu/drm/amd/amdgpu/amdgpu.h           |  10 +- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |   2 + drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |   6 + drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 298 ++++++++++++++++++ .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | ++++++++++++++++++ 230 ++++++++++++++ .../gpu/drm/amd/include/amdgpu_userqueue.h    |  66 ++++ drivers/gpu/drm/amd/include/v11_structs.h     |  16 +- include/uapi/drm/amdgpu_drm.h                 |  55 ++++

   9 files changed, 677 insertions(+), 9 deletions(-) create mode

100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c create mode 100644 drivers/gpu/drm/amd/include/amdgpu_userqueue.h

Signature · 1 line
2.40.0
#54 lore raw
Quoted 33 lines · Christian König

Am 10.04.23 um 16:26 schrieb Shashank Sharma:

Quoted 32 lines · Bas Nieuwenhuizen
Quoted 29 lines · Shashank Sharma
Quoted 10 lines · Bas Nieuwenhuizen
Quoted 8 lines
Quoted 6 lines · Shashank

[AMD Official Use Only - General]

Hello Bas,

This is not the correct interpretation of the code, the USERQ_IOCTL has both the OPs (create and destroy), but th euser has to exclusively call  it.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Please see the sample test program in the existing libDRM series (userq_test.c, it specifically calls amdgpu_free_userq, which does the destroy_OP

for the IOCTL.

In the presence of crashes the kernel should always be able to clean this up no? Otherwise there is a resource leak?

The crash handling is the same as any of the existing GPU resource which are allocated and freed with IOCTL_OPs.

Most of those are handled in the when the DRM fd gets closed (i.e. when the process exits):

- buffers through drm_gem_release()
- mappings in amdgpu_vm_fini
- contexts in amdgpu_ctx_mgr_fini

etc.

Why would we do things differently for userspace queues? It doesn't look complicated looking at the above patch (which does seem to work).

Quoted 8 lines
Quoted 3 lines

As the code is in initial stage, I have not given much thoughts about handling resource leak due to app crash, but this seems like a good suggestion.

I am taking a note and will try to accommodate this in an upcoming version of the series.

Bas is right, the application doesn't necessary needs to clean up on exit (but it's still good custody to do so).

See amdgpu_driver_postclose_kms() for how we cleanup (for example) the ctx manager by calling amdgpu_ctx_mgr_fini() or the BO lists.

Thanks for the pointers Christian,

I also feel like that its good to have this cleanup for those apps which did not clean-up themselves (due to crash or coding error).

So something like,

on close_fd,

for_idr_each {

   get_queue()

   if (queue)

       free_queue

}

But we will also keep the queue_free_OP as well, so that if an app allocate multiple queues, and wants to free some in between, it can do it.

- Shashank

Quoted 146 lines

Regards,
Christian.

Quoted 142 lines

- Shashank

Quoted 139 lines
Quoted 139 lines

To be honest a crash handling can be very elaborated and complex one, and hence only can be done at the driver unload IMO, which doesn't help at that stage,

coz anyways driver will re-allocate the resources on next load.

- Shashank

Quoted 131 lines
Quoted 131 lines

- Shashank

-----Original Message-----
From: Bas Nieuwenhuizen <[email protected]>
Sent: 10 April 2023 11:26
To: Sharma, Shashank <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Koenig, Christian <[email protected]>; Yadav, Arvind <[email protected]>
Subject: Re: [PATCH v3 0/9] AMDGPU Usermode queues

Hi Shashank,

I think I found the issue: I wasn't destroying the user queue in my program and the kernel doesn't clean up any remaining user queues in the postclose hook. I think we need something like
https://github.com/BNieuwenhuizen/linux/commit/e90c8d1185da7353c12837973ceddf55ccc85d29

?

While running things multiple times now works, I still have problems doing multiple submissions from the same queue. Looking forward to the updated test/sample

Thanks,
Bas

Quoted 109 lines · Shashank

[AMD Official Use Only - General]

Hello Bas,
Thanks for trying this out.

This could be due to the doorbell as you mentioned, Usermode queue uses doorbell manager internally.
This week, we are planning to publis the latest libDRM sample code which uses a doorbell object (instead of the doorbell hack IOCTL), adapting to that should fix your problem in my opinion. We have tested this full stack (libDRM test + Usermode queue + doorbell manager) for 500+ consecutive runs, and it worked well for us.

You can use this integrated kernel stack (1+2) from my gitlab to build your kernel:
https://gitlab.freedesktop.org/contactshashanksharma/userq-amdgpu/-/tr

ee/integrated-db-and-uq-v3 Please stay tuned for updated libDRM changes with doorbell objects.

Regards
Shashank
-----Original Message-----
From: Bas Nieuwenhuizen <[email protected]>
Sent: 10 April 2023 02:37
To: Sharma, Shashank <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH v3 0/9] AMDGPU Usermode queues

Hi Shashank,

I tried writing a program to experiment with usermode queues and I found some weird behavior: The first run of the program works as expected, while subsequent runs don't seem to do anything (and I allocate everything in GTT, so it should be zero initialized consistently). Is this a known issue?

The linked libdrm code for the uapi still does a doorbell ioctl so it could very well be that I do the doorbell wrong (especially since the ioctl implementation was never shared AFAICT?), but it seems like the kernel submissions (i.e. write wptr in dwords to the wptr va and to the doorbell). Is it possible to update the test in libdrm?

Code: https://gitlab.freedesktop.org/bnieuwenhuizen/usermode-queue

Thanks,
Bas

Quoted 70 lines · Shashank Sharma

This patch series introduces AMDGPU usermode queues for gfx workloads. Usermode queues is a method of GPU workload submission into the graphics hardware without any interaction with kernel/DRM schedulers. In this method, a userspace graphics application can create its own workqueue and submit it directly in the GPU HW.

The general idea of how this is supposed to work:
- The application creates the following GPU objetcs:
    - A queue object to hold the workload packets.
    - A read pointer object.
    - A write pointer object.
    - A doorbell page.
- The application picks a 32-bit offset in the doorbell page for this queue.
- The application uses the usermode_queue_create IOCTL introduced in
    this patch, by passing the the GPU addresses of these objects (read ptr, write ptr, queue base address and 32-bit doorbell offset from the doorbell page)
- The kernel creates the queue and maps it in the HW.
- The application can start submitting the data in the queue as soon as
    the kernel IOCTL returns.
- After filling the workload data in the queue, the app must write the
    number of dwords added in the queue into the doorbell offset, and the GPU will start fetching the data.

libDRM changes for this series and a sample DRM test program can be found in the MESA merge request here:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/287

This patch series depends on the doorbell-manager changes, which are being reviewed here:
https://patchwork.freedesktop.org/series/115802/

Alex Deucher (1):
    drm/amdgpu: UAPI for user queue management

Arvind Yadav (2):
    drm/amdgpu: add new parameters in v11_struct
    drm/amdgpu: map wptr BO into GART

Shashank Sharma (6):
    drm/amdgpu: add usermode queue base code drm/amdgpu: add new IOCTL for usermode queue drm/amdgpu: create GFX-gen11 MQD for userqueue drm/amdgpu: create context space for usermode queue drm/amdgpu: map usermode queue into MES drm/amdgpu: generate doorbell index for userqueue

   drivers/gpu/drm/amd/amdgpu/Makefile           | 3 + drivers/gpu/drm/amd/amdgpu/amdgpu.h           | 10 +- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       | 6 + drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 298 ++++++++++++++++++ .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | ++++++++++++++++++ 230 ++++++++++++++ .../gpu/drm/amd/include/amdgpu_userqueue.h    | 66 ++++ drivers/gpu/drm/amd/include/v11_structs.h     | 16 +- include/uapi/drm/amdgpu_drm.h                 | 55 ++++

   9 files changed, 677 insertions(+), 9 deletions(-) create mode

100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c create mode 100644 drivers/gpu/drm/amd/include/amdgpu_userqueue.h

Signature · 1 line
2.40.0
#55 lore raw
Quoted 52 lines · Shashank Sharma
Quoted 49 lines · Christian König

Am 10.04.23 um 16:26 schrieb Shashank Sharma:

Quoted 38 lines · Bas Nieuwenhuizen
Quoted 27 lines
Quoted 16 lines · Shashank Sharma
Quoted 14 lines · Bas Nieuwenhuizen
Quoted 12 lines · Shashank

[AMD Official Use Only - General]

Hello Bas,

This is not the correct interpretation of the code, the USERQ_IOCTL has both the OPs (create and destroy), but th euser has to exclusively call it.

Please see the sample test program in the existing libDRM series (userq_test.c, it specifically calls amdgpu_free_userq, which does the destroy_OP

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

for the IOCTL.

In the presence of crashes the kernel should always be able to clean this up no? Otherwise there is a resource leak?

The crash handling is the same as any of the existing GPU resource which
are allocated and freed with IOCTL_OPs.

Most of those are handled in the when the DRM fd gets closed (i.e. when the process exits):

Quoted 8 lines

- buffers through drm_gem_release()
- mappings in amdgpu_vm_fini
- contexts in amdgpu_ctx_mgr_fini

etc.

Why would we do things differently for userspace queues? It doesn't look complicated looking at the above patch (which does seem to work).

Quoted 6 lines

As the code is in initial stage, I have not given much thoughts about handling resource leak due to app crash, but this seems like a good suggestion.

I am taking a note and will try to accommodate this in an upcoming version of the series.

Bas is right, the application doesn't necessary needs to clean up on exit (but it's still good custody to do so).

Quoted 7 lines
Quoted 3 lines

See amdgpu_driver_postclose_kms() for how we cleanup (for example) the ctx manager by calling amdgpu_ctx_mgr_fini() or the BO lists.

Thanks for the pointers Christian,

I also feel like that its good to have this cleanup for those apps which did not clean-up themselves (due to crash or coding error).

I think the patch I linked earlier does exactly this: keep the IOCTL, but on fini goes through the list and destroys the queue:
https://github.com/BNieuwenhuizen/linux/commit/e90c8d1185da7353c12837973ceddf55ccc85d29

Quoted 201 lines

So something like,

on close_fd,

for_idr_each {

    get_queue()

    if (queue)

        free_queue

}

But we will also keep the queue_free_OP as well, so that if an app allocate multiple queues, and wants to free some in between, it can do it.

- Shashank

Quoted 181 lines

Regards,
Christian.

Quoted 177 lines

- Shashank

Quoted 174 lines
Quoted 174 lines

To be honest a crash handling can be very elaborated and complex one, and hence only can be done at the driver unload IMO, which doesn't help
at that stage,

coz anyways driver will re-allocate the resources on next load.

- Shashank

Quoted 165 lines
Quoted 165 lines

- Shashank

-----Original Message-----
From: Bas Nieuwenhuizen <[email protected]>
Sent: 10 April 2023 11:26
To: Sharma, Shashank <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Koenig, Christian <[email protected]>; Yadav, Arvind <[email protected]>
Subject: Re: [PATCH v3 0/9] AMDGPU Usermode queues

Hi Shashank,

I think I found the issue: I wasn't destroying the user queue in my program and the kernel doesn't clean up any remaining user queues in the postclose hook. I think we need something like
https://github.com/BNieuwenhuizen/linux/commit/e90c8d1185da7353c12837973ceddf55ccc85d29

?

While running things multiple times now works, I still have problems doing multiple submissions from the same queue. Looking forward to the updated test/sample

Thanks,
Bas

Quoted 135 lines · Shashank

[AMD Official Use Only - General]

Hello Bas,
Thanks for trying this out.

This could be due to the doorbell as you mentioned, Usermode queue uses doorbell manager internally.
This week, we are planning to publis the latest libDRM sample code which uses a doorbell object (instead of the doorbell hack IOCTL), adapting to that should fix your problem in my opinion. We have tested this full stack (libDRM test + Usermode queue + doorbell manager) for 500+ consecutive runs, and it worked well for us.

You can use this integrated kernel stack (1+2) from my gitlab to build
your kernel:
https://gitlab.freedesktop.org/contactshashanksharma/userq-amdgpu/-/tr

ee/integrated-db-and-uq-v3 Please stay tuned for updated libDRM changes with doorbell objects.

Regards
Shashank
-----Original Message-----
From: Bas Nieuwenhuizen <[email protected]>
Sent: 10 April 2023 02:37
To: Sharma, Shashank <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>;
Koenig, Christian <[email protected]>
Subject: Re: [PATCH v3 0/9] AMDGPU Usermode queues

Hi Shashank,

I tried writing a program to experiment with usermode queues and I found some weird behavior: The first run of the program works as expected, while subsequent runs don't seem to do anything (and I allocate everything in GTT, so it should be zero initialized consistently). Is this a known issue?

The linked libdrm code for the uapi still does a doorbell ioctl so it could very well be that I do the doorbell wrong (especially since the ioctl implementation was never shared AFAICT?), but it seems like the kernel submissions (i.e. write wptr in dwords to the wptr va and to the doorbell). Is it possible to update the test in libdrm?

Code: https://gitlab.freedesktop.org/bnieuwenhuizen/usermode-queue

Thanks,
Bas

Quoted 79 lines · Shashank Sharma

This patch series introduces AMDGPU usermode queues for gfx workloads.
Usermode queues is a method of GPU workload submission into the graphics hardware without any interaction with kernel/DRM schedulers.
In this method, a userspace graphics application can create its own
workqueue and submit it directly in the GPU HW.

The general idea of how this is supposed to work:
- The application creates the following GPU objetcs:
- A queue object to hold the workload packets.
- A read pointer object.
- A write pointer object.
- A doorbell page.
- The application picks a 32-bit offset in the doorbell page for this queue.
- The application uses the usermode_queue_create IOCTL introduced in
this patch, by passing the the GPU addresses of these
objects (read
ptr, write ptr, queue base address and 32-bit doorbell
offset from
the doorbell page)
- The kernel creates the queue and maps it in the HW.
- The application can start submitting the data in the queue as soon as
the kernel IOCTL returns.
- After filling the workload data in the queue, the app must write the
number of dwords added in the queue into the doorbell
offset, and the
GPU will start fetching the data.

libDRM changes for this series and a sample DRM test program can be
found in the MESA merge request here:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/287

This patch series depends on the doorbell-manager changes, which are
being reviewed here:
https://patchwork.freedesktop.org/series/115802/

Alex Deucher (1):
drm/amdgpu: UAPI for user queue management

Arvind Yadav (2):
drm/amdgpu: add new parameters in v11_struct
drm/amdgpu: map wptr BO into GART

Shashank Sharma (6):
drm/amdgpu: add usermode queue base code drm/amdgpu: add new IOCTL for usermode queue drm/amdgpu: create GFX-gen11 MQD for userqueue drm/amdgpu: create context space for usermode queue drm/amdgpu: map usermode queue into MES drm/amdgpu: generate doorbell index for userqueue

   drivers/gpu/drm/amd/amdgpu/Makefile           | 3 +
   drivers/gpu/drm/amd/amdgpu/amdgpu.h           | 10 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       | 2 +
   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       | 6 +
   drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 298
++++++++++++++++++ .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c |
++++++++++++++++++ 230 ++++++++++++++
   .../gpu/drm/amd/include/amdgpu_userqueue.h    | 66 ++++
   drivers/gpu/drm/amd/include/v11_structs.h     | 16 +-
   include/uapi/drm/amdgpu_drm.h                 | 55 ++++
   9 files changed, 677 insertions(+), 9 deletions(-) create mode

100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
create mode 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c
create mode 100644
drivers/gpu/drm/amd/include/amdgpu_userqueue.h

--
2.40.0

#56 lore raw
Quoted 52 lines · Bas Nieuwenhuizen
Quoted 50 lines · Shashank Sharma
Quoted 48 lines · Christian König

Am 10.04.23 um 16:26 schrieb Shashank Sharma:

Quoted 33 lines · Bas Nieuwenhuizen
Quoted 32 lines
Quoted 15 lines · Shashank Sharma
Quoted 14 lines · Bas Nieuwenhuizen
Quoted 12 lines · Shashank

[AMD Official Use Only - General]

Hello Bas,

This is not the correct interpretation of the code, the USERQ_IOCTL has both the OPs (create and destroy), but th euser has to exclusively call it.

Please see the sample test program in the existing libDRM series (userq_test.c, it specifically calls amdgpu_free_userq, which does the destroy_OP

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

for the IOCTL.

In the presence of crashes the kernel should always be able to clean this up no? Otherwise there is a resource leak?

The crash handling is the same as any of the existing GPU resource which
are allocated and freed with IOCTL_OPs.

Most of those are handled in the when the DRM fd gets closed (i.e. when the process exits):

- buffers through drm_gem_release()
- mappings in amdgpu_vm_fini
- contexts in amdgpu_ctx_mgr_fini

etc.

Quoted 8 lines
Quoted 2 lines

Why would we do things differently for userspace queues? It doesn't look complicated looking at the above patch (which does seem to work).

As the code is in initial stage, I have not given much thoughts about handling resource leak due to app crash, but this seems like a good suggestion.

I am taking a note and will try to accommodate this in an upcoming version of the series.

Bas is right, the application doesn't necessary needs to clean up on exit (but it's still good custody to do so).

See amdgpu_driver_postclose_kms() for how we cleanup (for example) the ctx manager by calling amdgpu_ctx_mgr_fini() or the BO lists.

Quoted 7 lines
Quoted 4 lines

Thanks for the pointers Christian,

I also feel like that its good to have this cleanup for those apps which did not clean-up themselves (due to crash or coding error).

I think the patch I linked earlier does exactly this: keep the IOCTL, but on fini goes through the list and destroys the queue:
https://github.com/BNieuwenhuizen/linux/commit/e90c8d1185da7353c12837973ceddf55ccc85d29

Yep, just needs additional check to free only when its not already freed, like doble free check. Will try to reuse most of it.

- Shashank

Quoted 198 lines
Quoted 198 lines

So something like,

on close_fd,

for_idr_each {

     get_queue()

     if (queue)

         free_queue

}

But we will also keep the queue_free_OP as well, so that if an app allocate multiple queues, and wants to free some in between, it can do it.

- Shashank

Quoted 179 lines

Regards,
Christian.

Quoted 176 lines

- Shashank

Quoted 174 lines
Quoted 174 lines

To be honest a crash handling can be very elaborated and complex one, and hence only can be done at the driver unload IMO, which doesn't help
at that stage,

coz anyways driver will re-allocate the resources on next load.

- Shashank

Quoted 165 lines
Quoted 165 lines

- Shashank

-----Original Message-----
From: Bas Nieuwenhuizen <[email protected]>
Sent: 10 April 2023 11:26
To: Sharma, Shashank <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Koenig, Christian <[email protected]>; Yadav, Arvind <[email protected]>
Subject: Re: [PATCH v3 0/9] AMDGPU Usermode queues

Hi Shashank,

I think I found the issue: I wasn't destroying the user queue in my program and the kernel doesn't clean up any remaining user queues in the postclose hook. I think we need something like
https://github.com/BNieuwenhuizen/linux/commit/e90c8d1185da7353c12837973ceddf55ccc85d29

?

While running things multiple times now works, I still have problems doing multiple submissions from the same queue. Looking forward to the updated test/sample

Thanks,
Bas

Quoted 135 lines · Shashank

[AMD Official Use Only - General]

Hello Bas,
Thanks for trying this out.

This could be due to the doorbell as you mentioned, Usermode queue uses doorbell manager internally.
This week, we are planning to publis the latest libDRM sample code which uses a doorbell object (instead of the doorbell hack IOCTL), adapting to that should fix your problem in my opinion. We have tested this full stack (libDRM test + Usermode queue + doorbell manager) for 500+ consecutive runs, and it worked well for us.

You can use this integrated kernel stack (1+2) from my gitlab to build
your kernel:
https://gitlab.freedesktop.org/contactshashanksharma/userq-amdgpu/-/tr

ee/integrated-db-and-uq-v3 Please stay tuned for updated libDRM changes with doorbell objects.

Regards
Shashank
-----Original Message-----
From: Bas Nieuwenhuizen <[email protected]>
Sent: 10 April 2023 02:37
To: Sharma, Shashank <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>;
Koenig, Christian <[email protected]>
Subject: Re: [PATCH v3 0/9] AMDGPU Usermode queues

Hi Shashank,

I tried writing a program to experiment with usermode queues and I found some weird behavior: The first run of the program works as expected, while subsequent runs don't seem to do anything (and I allocate everything in GTT, so it should be zero initialized consistently). Is this a known issue?

The linked libdrm code for the uapi still does a doorbell ioctl so it could very well be that I do the doorbell wrong (especially since the ioctl implementation was never shared AFAICT?), but it seems like the kernel submissions (i.e. write wptr in dwords to the wptr va and to the doorbell). Is it possible to update the test in libdrm?

Code: https://gitlab.freedesktop.org/bnieuwenhuizen/usermode-queue

Thanks,
Bas

Quoted 79 lines · Shashank Sharma

This patch series introduces AMDGPU usermode queues for gfx workloads.
Usermode queues is a method of GPU workload submission into the graphics hardware without any interaction with kernel/DRM schedulers.
In this method, a userspace graphics application can create its own
workqueue and submit it directly in the GPU HW.

The general idea of how this is supposed to work:
- The application creates the following GPU objetcs:
- A queue object to hold the workload packets.
- A read pointer object.
- A write pointer object.
- A doorbell page.
- The application picks a 32-bit offset in the doorbell page for this queue.
- The application uses the usermode_queue_create IOCTL introduced in
this patch, by passing the the GPU addresses of these
objects (read
ptr, write ptr, queue base address and 32-bit doorbell
offset from
the doorbell page)
- The kernel creates the queue and maps it in the HW.
- The application can start submitting the data in the queue as soon as
the kernel IOCTL returns.
- After filling the workload data in the queue, the app must write the
number of dwords added in the queue into the doorbell
offset, and the
GPU will start fetching the data.

libDRM changes for this series and a sample DRM test program can be
found in the MESA merge request here:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/287

This patch series depends on the doorbell-manager changes, which are
being reviewed here:
https://patchwork.freedesktop.org/series/115802/

Alex Deucher (1):
drm/amdgpu: UAPI for user queue management

Arvind Yadav (2):
drm/amdgpu: add new parameters in v11_struct
drm/amdgpu: map wptr BO into GART

Shashank Sharma (6):
drm/amdgpu: add usermode queue base code drm/amdgpu: add new IOCTL for usermode queue drm/amdgpu: create GFX-gen11 MQD for userqueue drm/amdgpu: create context space for usermode queue drm/amdgpu: map usermode queue into MES drm/amdgpu: generate doorbell index for userqueue

drivers/gpu/drm/amd/amdgpu/Makefile | 3 +
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 10 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 +
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 298
++++++++++++++++++ .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | ++++++++++++++++++ 230 ++++++++++++++

    .../gpu/drm/amd/include/amdgpu_userqueue.h    | 66 ++++
    drivers/gpu/drm/amd/include/v11_structs.h     | 16 +-
    include/uapi/drm/amdgpu_drm.h                 | 55 ++++
    9 files changed, 677 insertions(+), 9 deletions(-) create mode
100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
    create mode 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c
    create mode 100644

drivers/gpu/drm/amd/include/amdgpu_userqueue.h

--
2.40.0