AMDGPU usermode queues
Subsystems (3)
v4 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.
- Shadow bufffer pages.
- 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 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 (1):
drm/amdgpu: set FW parameters in v11_struct
Shashank Sharma (8):
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: map wptr BO into GART drm/amdgpu: generate doorbell index for userqueue drm/amdgpu: cleanup leftover queues
drivers/gpu/drm/amd/amdgpu/Makefile | 2 + 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 | 333 ++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 195 ++++++++++ .../gpu/drm/amd/include/amdgpu_userqueue.h | 66 ++++ include/uapi/drm/amdgpu_drm.h | 95 +++++ 8 files changed, 708 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
Signature · 1 line
2.40.0
PATCH v4 1/10 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
V4:
- Updated the UAPI doc (Pierre-Eric)
- Created a Union for engine specific MQDs (Alex)
- Added Christian's R-B
--- include/uapi/drm/amdgpu_drm.h | 95 +++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+)
include/uapi/drm/amdgpu_drm.h +95 -0
@@ -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
@@ -302,6 +304,99 @@ 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) + +/* +* MQD (memory queue descriptor) is a set of parameters which allow +* the GPU to uniquely define and identify a usermode queue. +*/ +struct drm_amdgpu_userq_mqd_gfx { +/** +* @flags: flags to indicate special function for queue like secure +* buffer (TMZ). Unused for now. +*/ +__u32 flags; +/** +* @doorbell_handle: the handle of doorbell GEM object +* associated to this client. +*/ +__u32 doorbell_handle; +/** +* @doorbell_offset: 32-bit offset of the doorbell in the doorbell bo. +* Kernel will generate absolute doorbell offset using doorbell_handle +* and doorbell_offset in the doorbell bo. +*/ +__u32 doorbell_offset; +/** +* @queue_va: Virtual address of the GPU memory which holds the queue +* object. The queue holds the workload packets. +*/ +__u64 queue_va; +/** +* @queue_size: Size of the queue in bytes, this needs to be 256-byte +* aligned. +*/ +__u64 queue_size; +/** +* @rptr_va : Virtual address of the GPU memory which holds the ring RPTR. +* This object must be at least 8 byte in size and aligned to 8-byte offset. +*/ +__u64 rptr_va; +/** +* @wptr_va : Virtual address of the GPU memory which holds the ring WPTR. +* This object must be at least 8 byte in size and aligned to 8-byte offset. +* +* Queue, RPTR and WPTR can come from the same object, as long as the size +* and alignment related requirements are met. +*/ +__u64 wptr_va; +/** +* @shadow_va: Virtual address of the GPU memory to hold the shadow buffer. +* This must be a from a separate GPU object, and must be at least 4-page +* sized. +*/ +__u64 shadow_va; +}; + +/* +* MQD can be different for different GPU IP/engine. This union will +* contain structures of MQDs corresponding to different engines. +*/ +union drm_amdgpu_userq_mqd { +struct drm_amdgpu_userq_mqd_gfx gfx; +}; + +struct drm_amdgpu_userq_in { +/** AMDGPU_USERQ_OP_* */ +__u32 op; +/** Flags */ +__u32 flags; +/** Queue handle for USERQ_OP_FREE */ +__u32 queue_id; +/** the target GPU engine to execute workload (AMDGPU_HW_IP_*) */ +__u32 ip_type; + +/** Queue descriptor for USERQ_OP_CREATE */ +union 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
Re: [PATCH v4 01/10] drm/amdgpu: UAPI for user queue management
Quoted 102 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 toqueue_idV3: Integration with doorbell manager
V4:
- Updated the UAPI doc (Pierre-Eric)
- Created a Union for engine specific MQDs (Alex)
- Added Christian's R-BCc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Reviewed-by Christian König <[email protected]>Signed-off-by Alex Deucher <[email protected]>Signed-off-by Shashank Sharma <[email protected]>--- include/uapi/drm/amdgpu_drm.h | 95 +++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+)include/uapi/drm/amdgpu_drm.h +49
-0@@ -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 @@ -302,6 +304,99 @@ 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) + +/* +* MQD (memory queue descriptor) is a set of parameters which allow +* the GPU to uniquely define and identify a usermode queue. +*/ +struct drm_amdgpu_userq_mqd_gfx { +/** +* @flags: flags to indicate special function for queue like secure +* buffer (TMZ). Unused for now. +*/ +__u32 flags; +/** +* @doorbell_handle: the handle of doorbell GEM object +* associated to this client. +*/ +__u32 doorbell_handle; +/** +* @doorbell_offset: 32-bit offset of the doorbell in the doorbell bo. +* Kernel will generate absolute doorbell offset using doorbell_handle +* and doorbell_offset in the doorbell bo. +*/ +__u32 doorbell_offset; +/** +* @queue_va: Virtual address of the GPU memory which holds the queue +* object. The queue holds the workload packets. +*/ +__u64 queue_va; +/** +* @queue_size: Size of the queue in bytes, this needs to be 256-byte +* aligned. +*/ +__u64 queue_size; +/** +* @rptr_va : Virtual address of the GPU memory which holds the ring RPTR. +* This object must be at least 8 byte in size and aligned to 8-byte offset. +*/ +__u64 rptr_va; +/** +* @wptr_va : Virtual address of the GPU memory which holds the ring WPTR. +* This object must be at least 8 byte in size and aligned to 8-byte offset. +*
include/uapi/drm/amdgpu_drm.h union drm_amdgpu_ctx { · line 363
Quoted 10 lines
include/uapi/drm/amdgpu_drm.h +10
-0+* Queue, RPTR and WPTR can come from the same object, as long as the size +* and alignment related requirements are met. +*/ +__u64 wptr_va; +/** +* @shadow_va: Virtual address of the GPU memory to hold the shadow buffer. +* This must be a from a separate GPU object, and must be at least 4-page +* sized. +*/ +__u64 shadow_va;
You were planning to add the other pointers here as well for gds and csa right?
Quoted 12 lines
include/uapi/drm/amdgpu_drm.h +12
-0+}; + +/* +* MQD can be different for different GPU IP/engine. This union will +* contain structures of MQDs corresponding to different engines. +*/ +union drm_amdgpu_userq_mqd { +struct drm_amdgpu_userq_mqd_gfx gfx; +}; + +struct drm_amdgpu_userq_in { +/** AMDGPU_USERQ_OP_* */
include/uapi/drm/amdgpu_drm.h union drm_amdgpu_ctx { · line 385
Quoted 10 lines
include/uapi/drm/amdgpu_drm.h +10
-0+__u32 op; +/** Flags */ +__u32 flags; +/** Queue handle for USERQ_OP_FREE */ +__u32 queue_id; +/** the target GPU engine to execute workload (AMDGPU_HW_IP_*) */ +__u32 ip_type; + +/** Queue descriptor for USERQ_OP_CREATE */ +union drm_amdgpu_userq_mqd mqd;
Just thinking out loud here, I wonder if we should make this a pointer/size element so that we could make this variable sized in case some future MQD ends up being bigger. I guess we could always add a AMDGPU_USERQ_OP_CREATE2 if we ever need to expand it.
Alex
Quoted 20 lines
include/uapi/drm/amdgpu_drm.h +14
-1+}; + +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
Re: [PATCH v4 01/10] drm/amdgpu: UAPI for user queue management
Hey Alex,
Thanks for the review comments, please find mine inline.
- Shashank
Quoted 105 lines · Alex Deucher
Quoted 104 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 toqueue_idV3: Integration with doorbell manager
V4:
- Updated the UAPI doc (Pierre-Eric)
- Created a Union for engine specific MQDs (Alex)
- Added Christian's R-BCc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Reviewed-by Christian König <[email protected]>Signed-off-by Alex Deucher <[email protected]>Signed-off-by Shashank Sharma <[email protected]>--- include/uapi/drm/amdgpu_drm.h | 95 +++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+)include/uapi/drm/amdgpu_drm.h +52
-0@@ -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 @@ -302,6 +304,99 @@ 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) + +/* +* MQD (memory queue descriptor) is a set of parameters which allow +* the GPU to uniquely define and identify a usermode queue. +*/ +struct drm_amdgpu_userq_mqd_gfx { +/** +* @flags: flags to indicate special function for queue like secure +* buffer (TMZ). Unused for now. +*/ +__u32 flags; +/** +* @doorbell_handle: the handle of doorbell GEM object +* associated to this client. +*/ +__u32 doorbell_handle; +/** +* @doorbell_offset: 32-bit offset of the doorbell in the doorbell bo. +* Kernel will generate absolute doorbell offset using doorbell_handle +* and doorbell_offset in the doorbell bo. +*/ +__u32 doorbell_offset; +/** +* @queue_va: Virtual address of the GPU memory which holds the queue +* object. The queue holds the workload packets. +*/ +__u64 queue_va; +/** +* @queue_size: Size of the queue in bytes, this needs to be 256-byte +* aligned. +*/ +__u64 queue_size; +/** +* @rptr_va : Virtual address of the GPU memory which holds the ring RPTR. +* This object must be at least 8 byte in size and aligned to 8-byte offset. +*/ +__u64 rptr_va; +/** +* @wptr_va : Virtual address of the GPU memory which holds the ring WPTR. +* This object must be at least 8 byte in size and aligned to 8-byte offset. +* +* Queue, RPTR and WPTR can come from the same object, as long as the size +* and alignment related requirements are met. +*/
Quoted 8 lines
include/uapi/drm/amdgpu_drm.h union drm_amdgpu_ctx { · line 363
Quoted 7 lines
include/uapi/drm/amdgpu_drm.h +7
-0+__u64 wptr_va; +/** +* @shadow_va: Virtual address of the GPU memory to hold the shadow buffer. +* This must be a from a separate GPU object, and must be at least 4-page +* sized. +*/ +__u64 shadow_va;You were planning to add the other pointers here as well for gds and csa right?
That was decided in this patch set only, from a different review comment, so we are yet to work on it :)
Quoted 19 lines
Quoted 19 lines
include/uapi/drm/amdgpu_drm.h +18
-0+}; + +/* +* MQD can be different for different GPU IP/engine. This union will +* contain structures of MQDs corresponding to different engines. +*/ +union drm_amdgpu_userq_mqd { +struct drm_amdgpu_userq_mqd_gfx gfx; +}; + +struct drm_amdgpu_userq_in { +/** AMDGPU_USERQ_OP_* */ +__u32 op; +/** Flags */ +__u32 flags; +/** Queue handle for USERQ_OP_FREE */ +__u32 queue_id; +/** the target GPU engine to execute workload (AMDGPU_HW_IP_*) */
Quoted 8 lines
include/uapi/drm/amdgpu_drm.h union drm_amdgpu_ctx { · line 385
Quoted 4 lines
include/uapi/drm/amdgpu_drm.h +4
-0+__u32 ip_type; + +/** Queue descriptor for USERQ_OP_CREATE */ +union drm_amdgpu_userq_mqd mqd;Just thinking out loud here, I wonder if we should make this a pointer/size element so that we could make this variable sized in case some future MQD ends up being bigger. I guess we could always add a
AMDGPU_USERQ_OP_CREATE2if we ever need to expand it.
I think it is a good idea and sounds scalable as well. Then we might not even need a union, we can just define MQD size and a ptr.
- Shashank
Quoted 22 lines
Alex
Quoted 20 lines
include/uapi/drm/amdgpu_drm.h +14
-1+}; + +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
PATCH v4 2/10 drm/amdgpu: add usermode queue base code
In reply to Shashank SharmaFrom: 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
V4:
- Align the structure member names to the largest member's column (Luben)
- Added SPDX license (Luben)
--- 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 | 40 +++++++++++++++ .../gpu/drm/amd/include/amdgpu_userqueue.h | 50 +++++++++++++++++++ 6 files changed, 108 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
@@ -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
@@ -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
@@ -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
@@ -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, use legacy workload submission only\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 +40 -0
@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright 2023 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 +50 -0
50 lines not on this page · raw message
Signature · 1 line
2.40.0
Christian König
maintainerRe: [PATCH v4 02/10] drm/amdgpu: add usermode queue base code
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 56 lines
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 inamdgpu_ctxV2:
- Reformatted code, split the big patch into twoV3:
- Integration with doorbell managerV4:
- Align the structure member names to the largest member's column (Luben)
- Added SPDX license (Luben)Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[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 | 40 +++++++++++++++ .../gpu/drm/amd/include/amdgpu_userqueue.h | 50 +++++++++++++++++++ 6 files changed, 108 insertions(+), 1 deletion(-)create mode 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.ccreate mode 100644drivers/gpu/drm/amd/include/amdgpu_userqueue.hdrivers/gpu/drm/amd/amdgpu/Makefile +2
-0@@ -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 := ../amdkfddrivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0@@ -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 ]; +}; +
Please but that into amdgpu_userqueue.h as well. We want to decommission amdgpu.h over time.
Quoted 132 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-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@@ -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@@ -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, use legacy workload submission only\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 +40
-0@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright 2023 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 +18
-0@@ -0,0 +1,50 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright 2023 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
drivers/gpu/drm/amd/include/amdgpu_userqueue.h line 28
Quoted 10 lines
drivers/gpu/drm/amd/include/amdgpu_userqueue.h new file +10
-0+* 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"
Please don't include amdgpu.h here.
Most structures can be forward defined, only amdgpu_mqd_prop is really needed and that should be included separately.
Christian.
Quoted 22 lines
drivers/gpu/drm/amd/include/amdgpu_userqueue.h new file +22
-0+#define AMDGPU_MAX_USERQ 512 + +struct amdgpu_usermode_queue { +int queue_id; +int queue_type; +uint64_t doorbell_handle; +uint64_t flags; +struct amdgpu_mqd_prop userq_prop; +struct amdgpu_userq_mgr *userq_mgr; +struct amdgpu_vm *vm; +}; + +struct amdgpu_userq_funcs { +int (*mqd_create)(struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *uq); +void (*mqd_destroy)(struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *uq); +}; + +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
Re: [PATCH v4 02/10] drm/amdgpu: add usermode queue base code
Thanks for the review, Christian.
Inline,
Quoted 60 lines · Christian König
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 57 lines
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 inamdgpu_ctxV2:
- Reformatted code, split the big patch into twoV3:
- Integration with doorbell managerV4:
- Align the structure member names to the largest member's column (Luben)
- Added SPDX license (Luben)Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[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| 40 +++++++++++++++ .../gpu/drm/amd/include/amdgpu_userqueue.h | 50 +++++++++++++++++++6 files changed, 108 insertions(+), 1 deletion(-)create mode 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.ccreate mode 100644drivers/gpu/drm/amd/include/amdgpu_userqueue.hdrivers/gpu/drm/amd/amdgpu/Makefile +0
-0@@ -210,6 +210,8 @@ amdgpu-y += \ # add amdkfd interfacesamdgpu-y += amdgpu_amdkfd.o
+# add usermode queue
+amdgpu-y += amdgpu_userqueue.o
ifneq ($(CONFIG_HSA_AMD),)
AMDKFD_PATH:= ../amdkfddrivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0@@ -438,6 +438,14 @@ struct amdgpu_sa_manager { uint32_t align; };+/* Gfx usermode queues */
+structamdgpu_userq_mgr{
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h
Quoted 6 lines
+ struct idr
userq_idr;
+ struct mutexuserq_mutex;
+ structamdgpu_device*adev;
+ const structamdgpu_userq_funcs*userq_funcs[AMDGPU_HW_IP_NUM];drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0+}; +Please but that into
amdgpu_userqueue.has well. We want to decommissionamdgpu.hover time.
Noted,
Quoted 163 lines
Quoted 155 lines
/* sub-allocation buffer */
structamdgpu_sa_bo{
struct list_head olist;drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0@@ -470,7 +478,6 @@ struct amdgpu_flip_work { bool async; };-
/*
* file private structure
*/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; }; int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv **fpriv);drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-0@@ -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 +4
-0@@ -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, use legacy workload submission only\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 +5
-0@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright 2023 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.
+ *
+ */drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c new file +4
-0+ +#include "amdgpu.h" + +int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct
amdgpu_device*adev)drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c new file +13
-0+{ + 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 +5
-0@@ -0,0 +1,50 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright 2023 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.
+ *
+ */drivers/gpu/drm/amd/include/amdgpu_userqueue.h line 28
Quoted 5 lines
drivers/gpu/drm/amd/include/amdgpu_userqueue.h new file +5
-0+ +#ifndef AMDGPU_USERQUEUE_H_ +#define AMDGPU_USERQUEUE_H_ + +#include "amdgpu.h" Please don't include
amdgpu.hhere.
Quoted 4 lines
Most structures can be forward defined, only
amdgpu_mqd_propis really needed and that should be included separately.Christian.
Noted, let me try this out.
- Shashank
Quoted 26 lines
Quoted 25 lines
drivers/gpu/drm/amd/include/amdgpu_userqueue.h new file +14
-0+#define AMDGPU_MAX_USERQ 512 + +struct amdgpu_usermode_queue { + int queue_id; + int queue_type; + uint64_t doorbell_handle; + uint64_t flags; + struct amdgpu_mqd_prop userq_prop; + struct amdgpu_userq_mgr *userq_mgr; + struct amdgpu_vm *vm; +}; + +struct amdgpu_userq_funcs { + int (*mqd_create)(struct amdgpu_userq_mgr *uq_mgr, struct
amdgpu_usermode_queue*uq);
+ void (*mqd_destroy)(structamdgpu_userq_mgr*uq_mgr, structamdgpu_usermode_queue*uq);drivers/gpu/drm/amd/include/amdgpu_userqueue.h new file +3
-0+}; + +int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct
amdgpu_device*adev);drivers/gpu/drm/amd/include/amdgpu_userqueue.h new file +4
-0+ +void amdgpu_userq_mgr_fini (struct amdgpu_userq_mgr *userq_mgr); + +#endif
PATCH v4 3/10 drm/amdgpu: add new IOCTL for usermode queue
In reply to Shashank SharmaThis 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
V4:
- Accommodate MQD union related changes in UAPI (Alex)
- Do not set the queue size twice (Bas)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 126 ++++++++++++++++++ .../gpu/drm/amd/include/amdgpu_userqueue.h | 2 + 3 files changed, 129 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
@@ -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 +126 -0
132 lines not on this page · raw message
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +2 -0
@@ -43,6 +43,8 @@ struct amdgpu_userq_funcs {void (*mqd_destroy)(struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *uq); }; +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
Christian König
maintainerRe: [PATCH v4 03/10] drm/amdgpu: add new IOCTL for usermode queue
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 53 lines
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 inamdgpu_ctxV2: Worked on review comments:
- Christian:
- Formatting of text
- There is no need for queuing of userqueues, with idr in place
- Alex:
- Removeuse_doorbell, its unnecessary
- Reuseamdgpu_mqd_propsfor saving mqd fields- Code formatting and re-arrangement
V3:
- Integration with doorbell managerV4:
- Accommodate MQD union related changes in UAPI (Alex)
- Do not set the queue size twice (Bas)Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 126 ++++++++++++++++++ .../gpu/drm/amd/include/amdgpu_userqueue.h | 2 + 3 files changed, 129 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-0@@ -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 +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c line 30
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +5
-0@@ -23,6 +23,132 @@*/ #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)
Maybe call that handle instead of index. And I don't think you actually need those wrapper functions, see below.
Quoted 37 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +37
-0+{ +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_gfx (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_gfx *mqd_in = &args->in.mqd.gfx; +int r; + +/* Do we support usermode queues on this GFX IP ? */ +if (!uq_mgr->userq_funcs[AMDGPU_HW_IP_GFX ]) { +DRM_ERROR ("Usermode queue is not supported for this GFX IP\n" ); +return -EINVAL ; + } + + queue =kzalloc (sizeof (struct amdgpu_usermode_queue ),GFP_KERNEL ); +if (!queue) { +DRM_ERROR ("Failed to allocate memory for queue\n" ); +return -ENOMEM ; + } + +mutex_lock (&uq_mgr->userq_mutex);
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c line 77
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +10
-0+ 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->doorbell_handle = mqd_in->doorbell_handle; + queue->queue_type =AMDGPU_HW_IP_GFX ; + queue->flags = mqd_in->flags; + queue->vm = &fpriv->vm; + queue->queue_id =amdgpu_userqueue_index (uq_mgr, queue);
It is usually good practice to *not* store those handles inside the object they refer to, background is that this always creates a circle reference (handle->object, object->handle).
Additional to that I would move registering the userspace handle out of this function.
Quoted 17 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +17
-0+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; +} +
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c line 104
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +10
-0+static int amdgpu_userqueue_create (struct drm_file *filp,union drm_amdgpu_userq *args) +{ +u32 ip_type = args->in.ip_type; + +switch (ip_type) { +case AMDGPU_HW_IP_GFX : +return amdgpu_userqueue_create_gfx (filp, args); +default : +DRM_ERROR ("Usermode queue is not supported for this IP (%u)\n" , ip_type); + }
Instead insert the idr_alloc() or more generally handle alloc here.
Christian.
Quoted 63 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +47
-0+ +return -EINVAL ; +} + +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
-0@@ -43,6 +43,8 @@ struct amdgpu_userq_funcs {void (*mqd_destroy)(struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *uq); }; +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);
Re: [PATCH v4 03/10] drm/amdgpu: add new IOCTL for usermode queue
Quoted 119 lines · Christian König
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 54 lines
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 inamdgpu_ctxV2: Worked on review comments:
- Christian:
- Formatting of text
- There is no need for queuing of userqueues, with idr in place
- Alex:
- Removeuse_doorbell, its unnecessary
- Reuseamdgpu_mqd_propsfor saving mqd fields- Code formatting and re-arrangement
V3:
- Integration with doorbell managerV4:
- Accommodate MQD union related changes in UAPI (Alex)
- Do not set the queue size twice (Bas)Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 +drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c| 126 ++++++++++++++++++ .../gpu/drm/amd/include/amdgpu_userqueue.h | 2 +3 files changed, 129 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-0@@ -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_driveramdgpu_kms_driver= {drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c line 30
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +5
-0@@ -23,6 +23,132 @@*/ #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)Maybe call that handle instead of index. And I don't think you actually need those wrapper functions, see below.
Quoted 40 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +37
-0+{ + 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_gfx (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_gfx *mqd_in = &args->in.mqd.gfx; + int r; + + /* Do we support usermode queues on this GFX IP ? */ + if (!uq_mgr->userq_funcs[AMDGPU_HW_IP_GFX]) { + DRM_ERROR("Usermode queue is not supported for this GFX IP\n"); + return -EINVAL; + } + + queue = kzalloc(sizeof(struct amdgpu_usermode_queue), GFP_KERNEL); + if (!queue) { + DRM_ERROR("Failed to allocate memory for queue\n"); + return -ENOMEM; + } + + mutex_lock(&uq_mgr->userq_mutex);drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c line 77
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +10
-0+ 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->doorbell_handle = mqd_in->doorbell_handle; + queue->queue_type = AMDGPU_HW_IP_GFX; + queue->flags = mqd_in->flags; + queue->vm = &fpriv->vm; + queue->queue_id = amdgpu_userqueue_index(uq_mgr, queue);It is usually good practice to *not* store those handles inside the object they refer to, background is that this always creates a circle reference (
handle->object,object->handle).
Quoted 1 line
Additional to that I would move registering the userspace handle out of this function.
I guess idr should be good enough to get me the queue ptr, and I don't have to save the queue id in queue.
Quoted 24 lines
Quoted 24 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +18
-0+ 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 int amdgpu_userqueue_create(struct drm_file *filp, union
drm_amdgpu_userq*args)drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +4
-0+{ + u32 ip_type = args->in.ip_type; + + switch (ip_type) {
Quoted 8 lines
Quoted 6 lines
+ case
AMDGPU_HW_IP_GFX:
+ returnamdgpu_userqueue_create_gfx(filp, args); + default:
+DRM_ERROR("Usermode queue is not supported for this IP (%u)\n", ip_type);
+ }Instead insert the
idr_alloc()or more generally handle alloc here.
Noted,
- Shashank
Quoted 66 lines
Christian.
Quoted 62 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +5
-0+ + return -EINVAL; +} + +static void amdgpu_userqueue_destroy(struct drm_file *filp, int
queue_id)drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +36
-0+{ + 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;
+ }drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +4
-0+ + 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 +1
-0@@ -43,6 +43,8 @@ struct amdgpu_userq_funcs { void (*mqd_destroy)(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *uq); }; +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);
PATCH v4 4/10 drm/amdgpu: create GFX-gen11 MQD for userqueue
In reply to Shashank SharmaA Memory queue descriptor (MQD) of a userqueue defines it in the hw's context. As MQD format can vary between different graphics IPs, we need gfx GEN specific handlers to create MQDs.
This patch:
- Introduces MQD handler functions for the usermode queues.
- Adds new functions to create and destroy userqueue 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
V4: Review comments addressed:
- Do not create a new file for userq, reuse gfx_v11_0.c (Alex)
- Align name of structure members (Luben)
- Don't break up the Cc tag list and the Sob tag list in commit message (Luben)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 25 ++++++++ drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 57 +++++++++++++++++++ .../gpu/drm/amd/include/amdgpu_userqueue.h | 7 +++ 3 files changed, 89 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +25 -0
@@ -81,6 +81,14 @@ static int amdgpu_userqueue_create_gfx(struct drm_file *filp, union drm_amdgpu_u goto free_queue; } +if (uq_mgr->userq_funcs[queue->queue_type]->mqd_create) { + 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);
@@ -119,6 +127,8 @@ static void amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id) }mutex_lock (&uq_mgr->userq_mutex); +if (uq_mgr->userq_funcs[queue->queue_type]->mqd_destroy) + 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);
@@ -149,6 +159,20 @@ 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 ]; + +/* We support usermode queue only for GFX IP as of now */ + 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) {
@@ -156,6 +180,7 @@ int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_deviidr_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/gfx_v11_0.c +57 -0
66 lines not on this page · raw message
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +7 -0
@@ -28,6 +28,12 @@#include "amdgpu.h" #define AMDGPU_MAX_USERQ 512 +struct amdgpu_userq_ctx_space { +uint64_t gpu_addr; +void *cpu_ptr; +struct amdgpu_bo *obj; +}; +struct amdgpu_usermode_queue {int queue_id;int queue_type;
@@ -36,6 +42,7 @@ struct amdgpu_usermode_queue {struct amdgpu_mqd_prop userq_prop;struct amdgpu_userq_mgr *userq_mgr;struct amdgpu_vm *vm; +struct amdgpu_userq_ctx_space mqd; };struct amdgpu_userq_funcs {
Signature · 1 line
2.40.0
Christian König
maintainerRe: [PATCH v4 04/10] drm/amdgpu: create GFX-gen11 MQD for userqueue
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 124 lines
A Memory queue descriptor (MQD) of a userqueue defines it in the hw's context. As MQD format can vary between different graphics IPs, we need gfx GEN specific handlers to create MQDs.
This patch:
- Introduces MQD handler functions for the usermode queues.
- Adds new functions to create and destroy userqueue MQD for GFX-GEN-11 IPV1: Worked on review comments from Alex:
- Make MQD functions GEN and IP specificV2: Worked on review comments from Alex:
- Reuse the existing adev->mqd[ip] for MQD creation
- Formatting and arrangement of codeV3:
- Integration with doorbell managerV4: Review comments addressed:
- Do not create a new file for userq, reusegfx_v11_0.c(Alex)
- Align name of structure members (Luben)
- Don't break up the Cc tag list and the Sob tag list in commit message (Luben)Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>Signed-off-by Arvind Yadav <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 25 ++++++++ drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 57 +++++++++++++++++++ .../gpu/drm/amd/include/amdgpu_userqueue.h | 7 +++ 3 files changed, 89 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +25
-0@@ -81,6 +81,14 @@ static int amdgpu_userqueue_create_gfx(struct drm_file *filp, union drm_amdgpu_u goto free_queue; } +if (uq_mgr->userq_funcs[queue->queue_type]->mqd_create) { + 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);@@ -119,6 +127,8 @@ static void amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id) }mutex_lock (&uq_mgr->userq_mutex); +if (uq_mgr->userq_funcs[queue->queue_type]->mqd_destroy) + 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);@@ -149,6 +159,20 @@ 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 ]; + +/* We support usermode queue only for GFX IP as of now */ + 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) {@@ -156,6 +180,7 @@ int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_deviidr_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/gfx_v11_0.c +17
-0@@ -30,6 +30,7 @@#include "amdgpu_psp.h" #include "amdgpu_smu.h" #include "amdgpu_atomfirmware.h" +#include "amdgpu_userqueue.h" #include "imu_v11_0.h" #include "soc21.h" #include "nvd.h" @@ -6404,3 +6405,59 @@ const struct amdgpu_ip_block_version gfx_v11_0_ip_block = .rev = 0, .funcs = &gfx_v11_0_ip_funcs, }; + +static int +gfx_v11_userq_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) {
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c const struct amdgpu_ip_block_version gfx_v11_0_ip_block = · line 6433
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +10
-0+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; + }
This reserve/unreserve dance here doesn't seem to make much sense. Why do you do that?
Christian.
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c const struct amdgpu_ip_block_version gfx_v11_0_ip_block = · line 6436
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +3
-0+ + queue->userq_prop.use_doorbell = true; + queue->userq_prop.mqd_gpu_addr = mqd->gpu_addr;
Are those the only two parameters needed? If yes we should probably drop the userq_prop structure and give them directly.
Christian.
Quoted 52 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +27
-0+ 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 +gfx_v11_userq_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 = gfx_v11_userq_mqd_create, + .mqd_destroy = gfx_v11_userq_mqd_destroy, +};drivers/gpu/drm/amd/include/amdgpu_userqueue.h +7
-0@@ -28,6 +28,12 @@#include "amdgpu.h" #define AMDGPU_MAX_USERQ 512 +struct amdgpu_userq_ctx_space { +uint64_t gpu_addr; +void *cpu_ptr; +struct amdgpu_bo *obj; +}; +struct amdgpu_usermode_queue {int queue_id;int queue_type;@@ -36,6 +42,7 @@ struct amdgpu_usermode_queue {struct amdgpu_mqd_prop userq_prop;struct amdgpu_userq_mgr *userq_mgr;struct amdgpu_vm *vm; +struct amdgpu_userq_ctx_space mqd; };struct amdgpu_userq_funcs {
Re: [PATCH v4 04/10] drm/amdgpu: create GFX-gen11 MQD for userqueue
Quoted 130 lines · Christian König
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 129 lines
A Memory queue descriptor (MQD) of a userqueue defines it in the hw's context. As MQD format can vary between different graphics IPs, we need gfx GEN specific handlers to create MQDs.
This patch:
- Introduces MQD handler functions for the usermode queues.
- Adds new functions to create and destroy userqueue MQD for GFX-GEN-11 IPV1: Worked on review comments from Alex:
- Make MQD functions GEN and IP specificV2: Worked on review comments from Alex:
- Reuse the existing adev->mqd[ip] for MQD creation
- Formatting and arrangement of codeV3:
- Integration with doorbell managerV4: Review comments addressed:
- Do not create a new file for userq, reusegfx_v11_0.c(Alex)
- Align name of structure members (Luben)
- Don't break up the Cc tag list and the Sob tag list in commit message (Luben)Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>Signed-off-by Arvind Yadav <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c| 25 ++++++++ drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 57 +++++++++++++++++++ .../gpu/drm/amd/include/amdgpu_userqueue.h | 7 +++3 files changed, 89 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +0
-0@@ -81,6 +81,14 @@ static int amdgpu_userqueue_create_gfx(struct
drm_file*filp, uniondrm_amdgpu_u
gotofree_queue;
}
+ if (uq_mgr->userq_funcs[queue->queue_type]->mqd_create) { + r = uq_mgr->userq_funcs[queue->queue_type]->mqd_create(uq_mgr, queue); + if (r) {
+DRM_ERROR("Failed to create/map userqueue MQD\n"); + gotofree_queue;
+ }
+ }
+
args->out.queue_id=queue->queue_id;args->out.flags= 0;mutex_unlock(&uq_mgr->userq_mutex);drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +15
-0@@ -119,6 +127,8 @@ static void amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id) } mutex_lock(&uq_mgr->userq_mutex); + if (uq_mgr->userq_funcs[queue->queue_type]->mqd_destroy) + 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);@@ -149,6 +159,20 @@ 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]; + + /* We support usermode queue only for GFX IP as of now */ + 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) {@@ -156,6 +180,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; }diff --git
a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.cb/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.cindexa56c6e106d00..9f7b14966ac8100644drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0@@ -30,6 +30,7 @@ #include "amdgpu_psp.h" #include "amdgpu_smu.h" #include "amdgpu_atomfirmware.h" +#include "amdgpu_userqueue.h" #include "imu_v11_0.h" #include "soc21.h" #include "nvd.h"@@ -6404,3 +6405,59 @@ const struct amdgpu_ip_block_version
gfx_v11_0_ip_block=
.rev = 0,
.funcs =&gfx_v11_0_ip_funcs,
};drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +3
-0+ +static int +gfx_v11_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct
amdgpu_usermode_queue*queue)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +17
-0+{ + 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; + } +
Quoted 8 lines
Quoted 6 lines
+
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); + gotofree_mqd;
+ }This reserve/unreserve dance here doesn't seem to make much sense. Why do you do that?
We wanted to make sure that the MQD buffer is reserved until we fill it. Does it sound incorrect ?
Quoted 8 lines
Christian.
Quoted 3 lines
+
+queue->userq_prop.use_doorbell= true; +queue->userq_prop.mqd_gpu_addr=mqd->gpu_addr;Are those the only two parameters needed? If yes we should probably drop the
userq_propstructure and give them directly.
In patch set 1 and 2, everything was getting stored directly in the queue, but then we decided to re-use the existing init_mqd() functions from each of the IP engines.
If you see the prototype of mqd->init_mqd(), it expects userq_prop structure as input parameters, so we encapsulated a subset of queue to this structure.
- Shashank
Quoted 56 lines
Christian.
Quoted 52 lines
+ 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"); + gotofree_mqd;
+ }drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +11
-0+ + 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 +gfx_v11_userq_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct
amdgpu_usermode_queue*queue)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +10
-0+{ + 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 = gfx_v11_userq_mqd_create, + .mqd_destroy = gfx_v11_userq_mqd_destroy, +};drivers/gpu/drm/amd/include/amdgpu_userqueue.h +6
-0@@ -28,6 +28,12 @@ #include "amdgpu.h" #define AMDGPU_MAX_USERQ 512 +struct amdgpu_userq_ctx_space { + uint64_t gpu_addr; + void *cpu_ptr; + struct amdgpu_bo *obj; +}; + struct amdgpu_usermode_queue { int queue_id; int queue_type;@@ -36,6 +42,7 @@ struct amdgpu_usermode_queue { struct amdgpu_mqd_prop userq_prop; struct amdgpu_userq_mgr *userq_mgr; struct amdgpu_vm *vm; + struct amdgpu_userq_ctx_space mqd; }; struct amdgpu_userq_funcs {
Christian König
maintainerRe: [PATCH v4 04/10] drm/amdgpu: create GFX-gen11 MQD for userqueue
Am 25.04.23 um 15:10 schrieb Shashank Sharma:
Quoted 141 lines · Christian König
Quoted 131 lines
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 130 lines
A Memory queue descriptor (MQD) of a userqueue defines it in the hw's context. As MQD format can vary between different graphics IPs, we need gfx GEN specific handlers to create MQDs.
This patch:
- Introduces MQD handler functions for the usermode queues.
- Adds new functions to create and destroy userqueue MQD for GFX-GEN-11 IPV1: Worked on review comments from Alex:
- Make MQD functions GEN and IP specificV2: Worked on review comments from Alex:
- Reuse the existing adev->mqd[ip] for MQD creation
- Formatting and arrangement of codeV3:
- Integration with doorbell managerV4: Review comments addressed:
- Do not create a new file for userq, reusegfx_v11_0.c(Alex)
- Align name of structure members (Luben)
- Don't break up the Cc tag list and the Sob tag list in commit message (Luben)Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>Signed-off-by Arvind Yadav <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c| 25 ++++++++ drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 57
+++++++++++++++++++
.../gpu/drm/amd/include/amdgpu_userqueue.h | 7 +++3 files changed, 89 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +0
-0@@ -81,6 +81,14 @@ static int amdgpu_userqueue_create_gfx(struct
drm_file*filp, uniondrm_amdgpu_u
gotofree_queue;
}
+ if (uq_mgr->userq_funcs[queue->queue_type]->mqd_create) { + r = uq_mgr->userq_funcs[queue->queue_type]->mqd_create(uq_mgr, queue); + if (r) {
+DRM_ERROR("Failed to create/map userqueue MQD\n"); + gotofree_queue;
+ }
+ }
+
args->out.queue_id=queue->queue_id;args->out.flags= 0;mutex_unlock(&uq_mgr->userq_mutex);drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +15
-0@@ -119,6 +127,8 @@ static void amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id) } mutex_lock(&uq_mgr->userq_mutex); + if (uq_mgr->userq_funcs[queue->queue_type]->mqd_destroy) + 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);@@ -149,6 +159,20 @@ 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]; + + /* We support usermode queue only for GFX IP as of now */ + 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) {@@ -156,6 +180,7 @@ int amdgpu_userq_mgr_init(struct
amdgpu_userq_mgr*userq_mgr, structamdgpu_deviidr_init_base(&userq_mgr->userq_idr, 1);
userq_mgr->adev= adev;
+amdgpu_userqueue_setup_ip_funcs(userq_mgr);
return 0;
}
diff --gita/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.cb/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.cindexa56c6e106d00..9f7b14966ac8100644drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0@@ -30,6 +30,7 @@ #include "amdgpu_psp.h" #include "amdgpu_smu.h" #include "amdgpu_atomfirmware.h" +#include "amdgpu_userqueue.h" #include "imu_v11_0.h" #include "soc21.h" #include "nvd.h"@@ -6404,3 +6405,59 @@ const struct amdgpu_ip_block_version
gfx_v11_0_ip_block=
.rev = 0,
.funcs =&gfx_v11_0_ip_funcs,
};drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +3
-0+ +static int +gfx_v11_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct
amdgpu_usermode_queue*queue)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +17
-0+{ + 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; + } +Quoted 8 lines
Quoted 6 lines
+
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); + gotofree_mqd;
+ }This reserve/unreserve dance here doesn't seem to make much sense. Why do you do that?
Quoted 1 line
We wanted to make sure that the MQD buffer is reserved until we fill it. Does it sound incorrect ?
Yeah, that sounds strongly like we have some misunderstanding.
Reserving a buffer is needed for two thing:
1. Prevent that it moves around.
2. Change some parameters of the BO.
Since the BO is a pinned kernel BO neither of those two use cases seems to be the case here.
So why do you reserve the BO here?
Quoted 11 lines
Quoted 8 lines
Christian.
Quoted 3 lines
+
+queue->userq_prop.use_doorbell= true; +queue->userq_prop.mqd_gpu_addr=mqd->gpu_addr;Are those the only two parameters needed? If yes we should probably drop the
userq_propstructure and give them directly.In patch set 1 and 2, everything was getting stored directly in the queue, but then we decided to re-use the existing
init_mqd()functions from each of the IP engines.If you see the prototype of
mqd->init_mqd(), it expectsuserq_propstructure as input parameters, so we encapsulated a subset of queue to this structure.
Yeah, the question is if the init_mqd() interface is a good idea or if we should re-work that as well?
Christian.
Quoted 59 lines
- Shashank
Quoted 56 lines
Christian.
Quoted 52 lines
+ 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"); + gotofree_mqd;
+ }drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +11
-0+ + 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 +gfx_v11_userq_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct
amdgpu_usermode_queue*queue)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +10
-0+{ + 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 = gfx_v11_userq_mqd_create, + .mqd_destroy = gfx_v11_userq_mqd_destroy, +};drivers/gpu/drm/amd/include/amdgpu_userqueue.h +6
-0@@ -28,6 +28,12 @@ #include "amdgpu.h" #define AMDGPU_MAX_USERQ 512 +struct amdgpu_userq_ctx_space { + uint64_t gpu_addr; + void *cpu_ptr; + struct amdgpu_bo *obj; +}; + struct amdgpu_usermode_queue { int queue_id; int queue_type;@@ -36,6 +42,7 @@ struct amdgpu_usermode_queue { struct amdgpu_mqd_prop userq_prop; struct amdgpu_userq_mgr *userq_mgr; struct amdgpu_vm *vm; + struct amdgpu_userq_ctx_space mqd; }; struct amdgpu_userq_funcs {
Re: [PATCH v4 04/10] drm/amdgpu: create GFX-gen11 MQD for userqueue
Quoted 146 lines · Christian König
Am 25.04.23 um 15:10 schrieb Shashank Sharma:
Quoted 141 lines · Christian König
Quoted 131 lines
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 130 lines
A Memory queue descriptor (MQD) of a userqueue defines it in the hw's context. As MQD format can vary between different graphics IPs, we need gfx GEN specific handlers to create MQDs.
This patch:
- Introduces MQD handler functions for the usermode queues.
- Adds new functions to create and destroy userqueue MQD for GFX-GEN-11 IPV1: Worked on review comments from Alex:
- Make MQD functions GEN and IP specificV2: Worked on review comments from Alex:
- Reuse the existing adev->mqd[ip] for MQD creation
- Formatting and arrangement of codeV3:
- Integration with doorbell managerV4: Review comments addressed:
- Do not create a new file for userq, reusegfx_v11_0.c(Alex)
- Align name of structure members (Luben)
- Don't break up the Cc tag list and the Sob tag list in commit message (Luben)Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>Signed-off-by Arvind Yadav <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c| 25 ++++++++ drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 57
+++++++++++++++++++
.../gpu/drm/amd/include/amdgpu_userqueue.h | 7 +++3 files changed, 89 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +0
-0@@ -81,6 +81,14 @@ static int amdgpu_userqueue_create_gfx(struct
drm_file*filp, uniondrm_amdgpu_u
gotofree_queue;
}
+ if (uq_mgr->userq_funcs[queue->queue_type]->mqd_create) { + r = uq_mgr->userq_funcs[queue->queue_type]->mqd_create(uq_mgr, queue); + if (r) {
+DRM_ERROR("Failed to create/map userqueue MQD\n"); + gotofree_queue;
+ }
+ }
+
args->out.queue_id=queue->queue_id;args->out.flags= 0;mutex_unlock(&uq_mgr->userq_mutex);drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +15
-0@@ -119,6 +127,8 @@ static void amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id) } mutex_lock(&uq_mgr->userq_mutex); + if (uq_mgr->userq_funcs[queue->queue_type]->mqd_destroy) + 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);@@ -149,6 +159,20 @@ 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]; + + /* We support usermode queue only for GFX IP as of now */ + 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) {@@ -156,6 +180,7 @@ int amdgpu_userq_mgr_init(struct
amdgpu_userq_mgr*userq_mgr, structamdgpu_deviidr_init_base(&userq_mgr->userq_idr, 1);
userq_mgr->adev= adev;
+amdgpu_userqueue_setup_ip_funcs(userq_mgr);
return 0;
}
diff --gita/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.cb/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.cindexa56c6e106d00..9f7b14966ac8100644drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0@@ -30,6 +30,7 @@ #include "amdgpu_psp.h" #include "amdgpu_smu.h" #include "amdgpu_atomfirmware.h" +#include "amdgpu_userqueue.h" #include "imu_v11_0.h" #include "soc21.h" #include "nvd.h"@@ -6404,3 +6405,59 @@ const struct amdgpu_ip_block_version
gfx_v11_0_ip_block=
.rev = 0,
.funcs =&gfx_v11_0_ip_funcs,
};drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +3
-0+ +static int +gfx_v11_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct
amdgpu_usermode_queue*queue)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +17
-0+{ + 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; + } +Quoted 8 lines
Quoted 6 lines
+
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); + gotofree_mqd;
+ }This reserve/unreserve dance here doesn't seem to make much sense. Why do you do that?
Quoted 1 line
We wanted to make sure that the MQD buffer is reserved until we fill it. Does it sound incorrect ?
Yeah, that sounds strongly like we have some misunderstanding.
Quoted 8 lines
Reserving a buffer is needed for two thing:
1. Prevent that it moves around.
2. Change some parameters of the BO.Since the BO is a pinned kernel BO neither of those two use cases seems to be the case here.
So why do you reserve the BO here?
I guess I missed the fact that Kernel BOs are already pinned, so we don't need this. I will remove this.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Christian.
Quoted 3 lines
+
+queue->userq_prop.use_doorbell= true; +queue->userq_prop.mqd_gpu_addr=mqd->gpu_addr;
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Are those the only two parameters needed? If yes we should probably drop the
userq_propstructure and give them directly.In patch set 1 and 2, everything was getting stored directly in the queue, but then we decided to re-use the existing
init_mqd()functions from each of the IP engines.If you see the prototype of
mqd->init_mqd(), it expectsuserq_propstructure as input parameters, so we encapsulated a subset of queue to this structure.Yeah, the question is if the
init_mqd()interface is a good idea or if we should re-work that as well?
I think is a good idea and we should keep it. This makes sure that the same code gets executed with both usermode_queue MQD initialization and kernel level/KIQ queue init.
- Shashank
Quoted 63 lines
Christian.
Quoted 59 lines
- Shashank
Quoted 56 lines
Christian.
Quoted 52 lines
+ 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"); + gotofree_mqd;
+ }drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +11
-0+ + 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 +gfx_v11_userq_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct
amdgpu_usermode_queue*queue)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +10
-0+{ + 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 = gfx_v11_userq_mqd_create, + .mqd_destroy = gfx_v11_userq_mqd_destroy, +};drivers/gpu/drm/amd/include/amdgpu_userqueue.h +6
-0@@ -28,6 +28,12 @@ #include "amdgpu.h" #define AMDGPU_MAX_USERQ 512 +struct amdgpu_userq_ctx_space { + uint64_t gpu_addr; + void *cpu_ptr; + struct amdgpu_bo *obj; +}; + struct amdgpu_usermode_queue { int queue_id; int queue_type;@@ -36,6 +42,7 @@ struct amdgpu_usermode_queue { struct amdgpu_mqd_prop userq_prop; struct amdgpu_userq_mgr *userq_mgr; struct amdgpu_vm *vm; + struct amdgpu_userq_ctx_space mqd; }; struct amdgpu_userq_funcs {
Re: [PATCH v4 04/10] drm/amdgpu: create GFX-gen11 MQD for userqueue
In reply to Shashank SharmaQuoted 71 lines · Shashank Sharma
A Memory queue descriptor (MQD) of a userqueue defines it in the hw's context. As MQD format can vary between different graphics IPs, we need gfx GEN specific handlers to create MQDs.
This patch:
- Introduces MQD handler functions for the usermode queues.
- Adds new functions to create and destroy userqueue MQD for GFX-GEN-11 IPV1: Worked on review comments from Alex:
- Make MQD functions GEN and IP specificV2: Worked on review comments from Alex:
- Reuse the existing adev->mqd[ip] for MQD creation
- Formatting and arrangement of codeV3:
- Integration with doorbell managerV4: Review comments addressed:
- Do not create a new file for userq, reusegfx_v11_0.c(Alex)
- Align name of structure members (Luben)
- Don't break up the Cc tag list and the Sob tag list in commit message (Luben)Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>Signed-off-by Arvind Yadav <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 25 ++++++++ drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 57 +++++++++++++++++++ .../gpu/drm/amd/include/amdgpu_userqueue.h | 7 +++ 3 files changed, 89 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +13
-0@@ -81,6 +81,14 @@ static int amdgpu_userqueue_create_gfx(struct drm_file *filp, union drm_amdgpu_u goto free_queue; } +if (uq_mgr->userq_funcs[queue->queue_type]->mqd_create) { + 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);@@ -119,6 +127,8 @@ static void amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id) }mutex_lock (&uq_mgr->userq_mutex); +if (uq_mgr->userq_funcs[queue->queue_type]->mqd_destroy) + 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);@@ -149,6 +159,20 @@ 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 174
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 ]; + +/* We support usermode queue only for GFX IP as of now */ + maj =IP_VERSION_MAJ (version); +if (maj ==11 ) + uq_mgr->userq_funcs[AMDGPU_HW_IP_GFX ] = &userq_gfx_v11_funcs;
Do we need to keep function pointers in uq_mgr? It would be nice to keep the logic in the IPs directly. E.g, in gfx_v11_0.c, we could set adev->userq_funcs[AMDGPU_HW_IP_GFX] = &userq_gfx_v11_funcs; then the userq code can just check
if (adev->userq_funcs[queue->queue_type]->mqd_destroy)
adev->userq_funcs[queue->queue_type]->mqd_destroy(adev, queue);etc.
Quoted 74 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +2
-0+}int amdgpu_userq_mgr_init (struct amdgpu_userq_mgr *userq_mgr,struct amdgpu_device *adev) {@@ -156,6 +180,7 @@ int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_deviidr_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/gfx_v11_0.c +47
-0@@ -30,6 +30,7 @@#include "amdgpu_psp.h" #include "amdgpu_smu.h" #include "amdgpu_atomfirmware.h" +#include "amdgpu_userqueue.h" #include "imu_v11_0.h" #include "soc21.h" #include "nvd.h" @@ -6404,3 +6405,59 @@ const struct amdgpu_ip_block_version gfx_v11_0_ip_block = .rev = 0, .funcs = &gfx_v11_0_ip_funcs, }; + +static int +gfx_v11_userq_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 +gfx_v11_userq_mqd_destroy (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *queue)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c const struct amdgpu_ip_block_version gfx_v11_0_ip_block = · line 6463
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +10
-0+{ +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 = gfx_v11_userq_mqd_create, + .mqd_destroy = gfx_v11_userq_mqd_destroy, +};
These functions and structures should start with gfx_v11_0_ for consistency.
Quoted 28 lines
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +7
-1@@ -28,6 +28,12 @@#include "amdgpu.h" #define AMDGPU_MAX_USERQ 512 +struct amdgpu_userq_ctx_space { +uint64_t gpu_addr; +void *cpu_ptr; +struct amdgpu_bo *obj; +}; +struct amdgpu_usermode_queue {int queue_id;int queue_type;@@ -36,6 +42,7 @@ struct amdgpu_usermode_queue {struct amdgpu_mqd_prop userq_prop;struct amdgpu_userq_mgr *userq_mgr;struct amdgpu_vm *vm; +struct amdgpu_userq_ctx_space mqd; };struct amdgpu_userq_funcs { --2.40.0
Re: [PATCH v4 04/10] drm/amdgpu: create GFX-gen11 MQD for userqueue
Quoted 86 lines · Alex Deucher
Quoted 70 lines · Shashank Sharma
A Memory queue descriptor (MQD) of a userqueue defines it in the hw's context. As MQD format can vary between different graphics IPs, we need gfx GEN specific handlers to create MQDs.
This patch:
- Introduces MQD handler functions for the usermode queues.
- Adds new functions to create and destroy userqueue MQD for GFX-GEN-11 IPV1: Worked on review comments from Alex:
- Make MQD functions GEN and IP specificV2: Worked on review comments from Alex:
- Reuse the existing adev->mqd[ip] for MQD creation
- Formatting and arrangement of codeV3:
- Integration with doorbell managerV4: Review comments addressed:
- Do not create a new file for userq, reusegfx_v11_0.c(Alex)
- Align name of structure members (Luben)
- Don't break up the Cc tag list and the Sob tag list in commit message (Luben)Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>Signed-off-by Arvind Yadav <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 25 ++++++++ drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 57 +++++++++++++++++++ .../gpu/drm/amd/include/amdgpu_userqueue.h | 7 +++ 3 files changed, 89 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +13
-0@@ -81,6 +81,14 @@ static int amdgpu_userqueue_create_gfx(struct drm_file *filp, union drm_amdgpu_u goto free_queue; } +if (uq_mgr->userq_funcs[queue->queue_type]->mqd_create) { + 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);@@ -119,6 +127,8 @@ static void amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id) }mutex_lock (&uq_mgr->userq_mutex); +if (uq_mgr->userq_funcs[queue->queue_type]->mqd_destroy) + 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);@@ -149,6 +159,20 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,return r; } +extern const struct amdgpu_userq_funcs userq_gfx_v11_funcs; + +static voiddrivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c int amdgpu_userq_ioctl(struct drm_device *dev, void *data, · line 174
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 ]; + +/* We support usermode queue only for GFX IP as of now */ + maj =IP_VERSION_MAJ (version); +if (maj ==11 ) + uq_mgr->userq_funcs[AMDGPU_HW_IP_GFX ] = &userq_gfx_v11_funcs;Do we need to keep function pointers in
uq_mgr? It would be nice to keep the logic in the IPs directly. E.g, ingfx_v11_0.c, we could set adev->userq_funcs[AMDGPU_HW_IP_GFX] =&userq_gfx_v11_funcs; then the userq code can just check
Quoted 4 lines
if (adev->userq_funcs[queue->queue_type]->mqd_destroy) adev->userq_funcs[queue->queue_type]->mqd_destroy(adev, queue);etc.
We have discussed about this here as well: https://patchwork.freedesktop.org/patch/529513/?series=113675&rev=2 (which we probably could not follow up)
The problem is, in the discussion from first patch set we decided not to use adev for this, instead moved this in driver private from fptr.
Quoted 77 lines
Quoted 77 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +2
-0+}int amdgpu_userq_mgr_init (struct amdgpu_userq_mgr *userq_mgr,struct amdgpu_device *adev) {@@ -156,6 +180,7 @@ int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_deviidr_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/gfx_v11_0.c +50
-0@@ -30,6 +30,7 @@#include "amdgpu_psp.h" #include "amdgpu_smu.h" #include "amdgpu_atomfirmware.h" +#include "amdgpu_userqueue.h" #include "imu_v11_0.h" #include "soc21.h" #include "nvd.h" @@ -6404,3 +6405,59 @@ const struct amdgpu_ip_block_version gfx_v11_0_ip_block = .rev = 0, .funcs = &gfx_v11_0_ip_funcs, }; + +static int +gfx_v11_userq_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 +gfx_v11_userq_mqd_destroy (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *queue) +{ +struct amdgpu_userq_ctx_space *mqd = &queue->mqd; +
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c const struct amdgpu_ip_block_version gfx_v11_0_ip_block = · line 6463
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +7
-0+amdgpu_bo_free_kernel (&mqd->obj, &mqd->gpu_addr, &mqd->cpu_ptr); +} + +const struct amdgpu_userq_funcs userq_gfx_v11_funcs = { + .mqd_create = gfx_v11_userq_mqd_create, + .mqd_destroy = gfx_v11_userq_mqd_destroy, +};These functions and structures should start with
gfx_v11_0_for consistency.
Noted,
- Shashank
Quoted 29 lines
Quoted 29 lines
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +7
-1@@ -28,6 +28,12 @@#include "amdgpu.h" #define AMDGPU_MAX_USERQ 512 +struct amdgpu_userq_ctx_space { +uint64_t gpu_addr; +void *cpu_ptr; +struct amdgpu_bo *obj; +}; +struct amdgpu_usermode_queue {int queue_id;int queue_type;@@ -36,6 +42,7 @@ struct amdgpu_usermode_queue {struct amdgpu_mqd_prop userq_prop;struct amdgpu_userq_mgr *userq_mgr;struct amdgpu_vm *vm; +struct amdgpu_userq_ctx_space mqd; };struct amdgpu_userq_funcs { --2.40.0
PATCH v4 5/10 drm/amdgpu: create context space for usermode queue
In reply to Shashank SharmaThe FW expects us to allocate at least one page as context space to process gang, process, 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
V4: Review comments:
- Remove shadow from FW space list from cover letter (Alex)
- Alignment of macro (Luben)
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 57 ++++++++++++++++++- .../gpu/drm/amd/include/amdgpu_userqueue.h | 6 ++ 2 files changed, 61 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +55 -2
@@ -53,6 +53,11 @@#define GFX11_NUM_GFX_RINGS 1#define GFX11_MEC_HPD_SIZE 2048 +#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 +#define RLCG_UCODE_LOADING_START_ADDRESS 0x00002000L#define RLC_PG_DELAY_3_DEFAULT_GC_11_0_1 0x1388
@@ -6406,6 +6411,44 @@ const struct amdgpu_ip_block_version gfx_v11_0_ip_block = .funcs = &gfx_v11_0_ip_funcs, }; +static int gfx_v11_userq_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 at least one page space allocated for +* process ctx, gang ctx, gds ctx, fw ctx each. +*/ + size =AMDGPU_USERQ_PROC_CTX_SZ +AMDGPU_USERQ_FW_CTX_SZ + +AMDGPU_USERQ_GANG_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 gfx_v11_userq_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 gfx_v11_userq_mqd_create (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *queue) {
@@ -6426,10 +6469,16 @@ gfx_v11_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode }memset (mqd->cpu_ptr,0 , size); + r =gfx_v11_userq_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;
@@ -6438,12 +6487,15 @@ gfx_v11_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermodeamdgpu_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: +gfx_v11_userq_destroy_ctx_space (uq_mgr, queue); + free_mqd:amdgpu_bo_free_kernel (&mqd->obj, &mqd->gpu_addr, &mqd->cpu_ptr);return r;
@@ -6454,6 +6506,7 @@ gfx_v11_userq_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermod {struct amdgpu_userq_ctx_space *mqd = &queue->mqd; +gfx_v11_userq_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 +6 -0
@@ -38,11 +38,17 @@ struct amdgpu_usermode_queue {int queue_id;int queue_type;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;uint64_t flags;struct amdgpu_mqd_prop userq_prop;struct amdgpu_userq_mgr *userq_mgr;struct amdgpu_vm *vm;struct amdgpu_userq_ctx_space mqd; +struct amdgpu_userq_ctx_space fw_space; };struct amdgpu_userq_funcs {
Signature · 1 line
2.40.0
Christian König
maintainerRe: [PATCH v4 05/10] drm/amdgpu: create context space for usermode queue
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 53 lines
The FW expects us to allocate at least one page as context space to process gang, process, 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 specificV2: 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
V4: Review comments:
- Remove shadow from FW space list from cover letter (Alex)
- Alignment of macro (Luben)Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 57 ++++++++++++++++++- .../gpu/drm/amd/include/amdgpu_userqueue.h | 6 ++ 2 files changed, 61 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +13
-0@@ -53,6 +53,11 @@#define GFX11_NUM_GFX_RINGS 1#define GFX11_MEC_HPD_SIZE 2048 +#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 +#define RLCG_UCODE_LOADING_START_ADDRESS 0x00002000L#define RLC_PG_DELAY_3_DEFAULT_GC_11_0_1 0x1388@@ -6406,6 +6411,44 @@ const struct amdgpu_ip_block_version gfx_v11_0_ip_block = .funcs = &gfx_v11_0_ip_funcs, }; +static int gfx_v11_userq_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; + +/*
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c const struct amdgpu_ip_block_version gfx_v11_0_ip_block = · line 6431
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +10
-0+* The FW expects at least one page space allocated for +* process ctx, gang ctx, gds ctx, fw ctx each. +*/ + size =AMDGPU_USERQ_PROC_CTX_SZ +AMDGPU_USERQ_FW_CTX_SZ + +AMDGPU_USERQ_GANG_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);
Wasn't this stuff provided by userspace now?
Christian.
Quoted 88 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +32
-2+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 gfx_v11_userq_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 gfx_v11_userq_mqd_create (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *queue) {@@ -6426,10 +6469,16 @@ gfx_v11_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode }memset (mqd->cpu_ptr,0 , size); + r =gfx_v11_userq_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;@@ -6438,12 +6487,15 @@ gfx_v11_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermodeamdgpu_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: +gfx_v11_userq_destroy_ctx_space (uq_mgr, queue); + free_mqd:amdgpu_bo_free_kernel (&mqd->obj, &mqd->gpu_addr, &mqd->cpu_ptr);return r;@@ -6454,6 +6506,7 @@ gfx_v11_userq_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermod {struct amdgpu_userq_ctx_space *mqd = &queue->mqd; +gfx_v11_userq_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 +6
-0@@ -38,11 +38,17 @@ struct amdgpu_usermode_queue {int queue_id;int queue_type;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;uint64_t flags;struct amdgpu_mqd_prop userq_prop;struct amdgpu_userq_mgr *userq_mgr;struct amdgpu_vm *vm;struct amdgpu_userq_ctx_space mqd; +struct amdgpu_userq_ctx_space fw_space; };struct amdgpu_userq_funcs {
Re: [PATCH v4 05/10] drm/amdgpu: create context space for usermode queue
Quoted 55 lines · Christian König
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 54 lines
The FW expects us to allocate at least one page as context space to process gang, process, 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 specificV2: 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
V4: Review comments:
- Remove shadow from FW space list from cover letter (Alex)
- Alignment of macro (Luben)Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>---
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 57 ++++++++++++++++++- .../gpu/drm/amd/include/amdgpu_userqueue.h | 6 ++2 files changed, 61 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -53,6 +53,11 @@ #define GFX11_NUM_GFX_RINGS 1 #define GFX11_MEC_HPD_SIZE 2048+#define AMDGPU_USERQ_PROC_CTX_SZ
PAGE_SIZEdrivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4
-0+#define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE +#define AMDGPU_USERQ_FW_CTX_SZ PAGE_SIZE +#define AMDGPU_USERQ_GDS_CTX_SZ PAGE_SIZE +#define RLCG_UCODE_LOADING_START_ADDRESS
0x00002000L
#define RLC_PG_DELAY_3_DEFAULT_GC_11_0_10x1388
@@ -6406,6 +6411,44 @@ const structamdgpu_ip_block_versiongfx_v11_0_ip_block= .funcs =&gfx_v11_0_ip_funcs,
};
+static int gfx_v11_userq_create_ctx_space(structamdgpu_userq_mgr*uq_mgr, + structamdgpu_usermode_queue*queue)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +10
-0+{ + struct amdgpu_device *adev = uq_mgr->adev; + struct amdgpu_userq_ctx_space *ctx = &queue->fw_space; + int r, size; + + /* + * The FW expects at least one page space allocated for + * process ctx, gang ctx, gds ctx, fw ctx each. + */ + size = AMDGPU_USERQ_PROC_CTX_SZ + AMDGPU_USERQ_FW_CTX_SZ +
Quoted 9 lines
Quoted 6 lines
+
AMDGPU_USERQ_GANG_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);Wasn't this stuff provided by userspace now?
The last I checked, only the shadow buffer was coming from userspace, and we were thinking about other stuff. I might not be well updated if there any recent development here with the short term solution.
- Shashank
Quoted 93 lines
Christian.
Quoted 90 lines
+ 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;drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +3
-0+} + +static void gfx_v11_userq_destroy_ctx_space(struct amdgpu_userq_mgr
*uq_mgr,
+ structamdgpu_usermode_queue*queue)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +6
-0+{ + struct amdgpu_userq_ctx_space *ctx = &queue->fw_space; + + amdgpu_bo_free_kernel(&ctx->obj, &ctx->gpu_addr, &ctx->cpu_ptr); +} +static int
gfx_v11_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue){drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -6426,10 +6469,16 @@ gfx_v11_userq_mqd_create(struct
amdgpu_userq_mgr*uq_mgr, structamdgpu_usermode
}
memset(mqd->cpu_ptr, 0, size);
+ r =gfx_v11_userq_create_ctx_space(uq_mgr, queue);
+ if (r) {
+DRM_ERROR("Failed to create CTX space for userqueue (%d)\n", r);
+ gotofree_mqd;
+ }
+
r =amdgpu_bo_reserve(mqd->obj, false);
if (unlikely(r != 0)) {
DRM_ERROR("Failed to reserve mqd for userqueue (%d)", r); - gotofree_mqd;
+ gotofree_ctx;
}
queue->userq_prop.use_doorbell= true;drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -6438,12 +6487,15 @@ gfx_v11_userq_mqd_create(struct
amdgpu_userq_mgr*uq_mgr, structamdgpu_usermodeamdgpu_bo_unreserve(mqd->obj);
if (r) {
DRM_ERROR("Failed to init MQD for queue\n");
- gotofree_mqd;
+ gotofree_ctx;
}
DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id); return 0;
+free_ctx:
+gfx_v11_userq_destroy_ctx_space(uq_mgr, queue);
+
free_mqd:
amdgpu_bo_free_kernel(&mqd->obj, &mqd->gpu_addr, &mqd->cpu_ptr); return r;drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -6454,6 +6506,7 @@ gfx_v11_userq_mqd_destroy(struct
amdgpu_userq_mgr*uq_mgr, structamdgpu_usermod
{
structamdgpu_userq_ctx_space*mqd =&queue->mqd;
+gfx_v11_userq_destroy_ctx_space(uq_mgr, queue);
amdgpu_bo_free_kernel(&mqd->obj, &mqd->gpu_addr, &mqd->cpu_ptr);
}
diff --gita/drivers/gpu/drm/amd/include/amdgpu_userqueue.hb/drivers/gpu/drm/amd/include/amdgpu_userqueue.hindexe7da27918bd2..11e8ad649f6e100644drivers/gpu/drm/amd/include/amdgpu_userqueue.h +6
-0@@ -38,11 +38,17 @@ struct amdgpu_usermode_queue { int queue_id; int queue_type; 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; uint64_t flags; struct amdgpu_mqd_prop userq_prop; struct amdgpu_userq_mgr *userq_mgr; struct amdgpu_vm *vm; struct amdgpu_userq_ctx_space mqd; + struct amdgpu_userq_ctx_space fw_space; }; struct amdgpu_userq_funcs {
Deucher, Alexander
maintainerRE: [PATCH v4 05/10] drm/amdgpu: create context space for usermode queue
[Public]
Quoted 82 lines
-----Original Message-----
From: Sharma, Shashank <[email protected]>
Sent: Tuesday, April 25, 2023 9:13 AM
To: Koenig, Christian <[email protected]>; amd- [email protected]
Cc: Yadav, Arvind <[email protected]>; Pelloux-Prayer, Pierre-Eric <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>
Subject: Re: [PATCH v4 05/10] drm/amdgpu: create context space for usermode queueQuoted 27 lines · Christian König
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 26 lines
The FW expects us to allocate at least one page as context space to process gang, process, 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 specificV2: 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
V4: Review comments:
- Remove shadow from FW space list from cover letter (Alex)
- Alignment of macro (Luben)Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>---
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 57
++++++++++++++++++-
.../gpu/drm/amd/include/amdgpu_userqueue.h | 6 ++2 files changed, 61 insertions(+), 2 deletions(-)Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -53,6 +53,11 @@ #define GFX11_NUM_GFX_RINGS 1 #define GFX11_MEC_HPD_SIZE 2048+#define AMDGPU_USERQ_PROC_CTX_SZ
PAGE_SIZEdrivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+#define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE #define +AMDGPU_USERQ_FW_CTX_SZ PAGE_SIZE #define
AMDGPU_USERQ_GDS_CTX_SZQuoted 12 lines
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+PAGE_SIZE +#define RLCG_UCODE_LOADING_START_ADDRESS
0x00002000L#define RLC_PG_DELAY_3_DEFAULT_GC_11_0_10x1388
@@ -6406,6 +6411,44 @@ const structamdgpu_ip_block_versiongfx_v11_0_ip_block=
.funcs =&gfx_v11_0_ip_funcs,
};
+static int gfx_v11_userq_create_ctx_space(structamdgpu_userq_mgr*uq_mgr,
+ structamdgpu_usermode_queue*queue) { + structamdgpu_device*adev =uq_mgr->adev;Quoted 8 lines
Quoted 8 lines
+ struct
amdgpu_userq_ctx_space*ctx =&queue->fw_space; + int r, size;
+
+ /*
+ * The FW expects at least one page space allocated for + * process ctx, gang ctx, gds ctx, fw ctx each. + */
+ size =AMDGPU_USERQ_PROC_CTX_SZ+
AMDGPU_USERQ_FW_CTX_SZ+Quoted 1 line
Quoted 1 line
+
AMDGPU_USERQ_GANG_CTX_SZ+
AMDGPU_USERQ_GDS_CTX_SZ;Quoted 6 lines
Quoted 5 lines
+ r = amdgpu_bo_create_kernel(adev, size,
PAGE_SIZE, +AMDGPU_GEM_DOMAIN_GTT,
+&ctx->obj,
+&ctx->gpu_addr,
+&ctx->cpu_ptr);
Quoted 5 lines
Quoted 2 lines
Wasn't this stuff provided by userspace now?
The last I checked, only the shadow buffer was coming from userspace, and we were thinking about other stuff. I might not be well updated if there any recent development here with the short term solution.
CSA, GDS backup, and shadow are allocated by userspace now.
Alex
Quoted 103 lines
- Shashank
Quoted 11 lines
Christian.
Quoted 9 lines
+ 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;Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c const struct amdgpu_ip_block_version gfx_v11_0_ip_block =
Quoted 8 lines
+
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;drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +3
-0+} + +static void gfx_v11_userq_destroy_ctx_space(struct
amdgpu_userq_mgrQuoted 23 lines
Quoted 5 lines
*uq_mgr,
+ structamdgpu_usermode_queue*queue) { + structamdgpu_userq_ctx_space*ctx =&queue->fw_space; +
+ amdgpu_bo_free_kernel(&ctx->obj,&ctx->gpu_addr, &ctx-
cpu_ptr);Quoted 17 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+} +static int
gfx_v11_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
{drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -6426,10 +6469,16 @@ gfx_v11_userq_mqd_create(struct
amdgpu_userq_mgr*uq_mgr, structamdgpu_usermode
}
memset(mqd->cpu_ptr, 0, size);
+ r =gfx_v11_userq_create_ctx_space(uq_mgr, queue);
+ if (r) {
+DRM_ERROR("Failed to create CTX space for userqueue (%d)\n", r);
+ gotofree_mqd;
+ }
+Quoted 8 lines
Quoted 8 lines
r =
amdgpu_bo_reserve(mqd->obj, false);
if (unlikely(r != 0)) {
DRM_ERROR("Failed to reserve mqd for userqueue (%d)", r); - gotofree_mqd;
+ gotofree_ctx;
}
queue->userq_prop.use_doorbell= true; @@ -6438,12 +6487,15 @@ gfx_v11_userq_mqd_create(structamdgpu_userq_mgr*uq_mgr,struct
Quoted 48 lines
Quoted 47 lines
amdgpu_usermodeamdgpu_bo_unreserve(mqd->obj);
if (r) {
DRM_ERROR("Failed to init MQD for queue\n"); - gotofree_mqd;
+ gotofree_ctx;
}
DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
return 0;
+free_ctx:
+gfx_v11_userq_destroy_ctx_space(uq_mgr, queue); +
free_mqd:
amdgpu_bo_free_kernel(&mqd->obj, &mqd->gpu_addr, &mqd->cpu_ptr);
return r;drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -6454,6 +6506,7 @@ gfx_v11_userq_mqd_destroy(struct
amdgpu_userq_mgr*uq_mgr, structamdgpu_usermod
{
structamdgpu_userq_ctx_space*mqd =&queue->mqd; +gfx_v11_userq_destroy_ctx_space(uq_mgr, queue);amdgpu_bo_free_kernel(&mqd->obj, &mqd->gpu_addr, &mqd->cpu_ptr);
}
diff --gita/drivers/gpu/drm/amd/include/amdgpu_userqueue.hb/drivers/gpu/drm/amd/include/amdgpu_userqueue.hindexe7da27918bd2..11e8ad649f6e100644drivers/gpu/drm/amd/include/amdgpu_userqueue.h +6
-0@@ -38,11 +38,17 @@ struct amdgpu_usermode_queue { int queue_id; int queue_type; 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; uint64_t flags; struct amdgpu_mqd_prop userq_prop; struct amdgpu_userq_mgr *userq_mgr; struct amdgpu_vm *vm; struct amdgpu_userq_ctx_space mqd; + struct amdgpu_userq_ctx_space fw_space; }; struct amdgpu_userq_funcs {
RE: [PATCH v4 05/10] drm/amdgpu: create context space for usermode queue
[Public]
Quoted 1 line
CSA, GDS backup, and shadow are allocated by userspace now.
Noted Alex, thanks. I will update the patch series and userspace accordingly.
Regards
Shashank
-----Original Message-----
From: Deucher, Alexander <[email protected]>
Sent: 25 April 2023 19:38
To: Sharma, Shashank <[email protected]>; Koenig, Christian <[email protected]>; [email protected]
Cc: Yadav, Arvind <[email protected]>; Pelloux-Prayer, Pierre-Eric <[email protected]>; [email protected]
Subject: RE: [PATCH v4 05/10] drm/amdgpu: create context space for usermode queue
[Public]
Quoted 82 lines
-----Original Message-----
From: Sharma, Shashank <[email protected]>
Sent: Tuesday, April 25, 2023 9:13 AM
To: Koenig, Christian <[email protected]>; amd- [email protected]
Cc: Yadav, Arvind <[email protected]>; Pelloux-Prayer, Pierre-Eric <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>
Subject: Re: [PATCH v4 05/10] drm/amdgpu: create context space for usermode queueQuoted 27 lines · Christian König
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 26 lines
The FW expects us to allocate at least one page as context space to process gang, process, 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 specificV2: 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
V4: Review comments:
- Remove shadow from FW space list from cover letter (Alex)
- Alignment of macro (Luben)Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>---
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 57
++++++++++++++++++-
.../gpu/drm/amd/include/amdgpu_userqueue.h | 6 ++2 files changed, 61 insertions(+), 2 deletions(-)Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -53,6 +53,11 @@ #define GFX11_NUM_GFX_RINGS 1 #define GFX11_MEC_HPD_SIZE 2048+#define AMDGPU_USERQ_PROC_CTX_SZ
PAGE_SIZEdrivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+#define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE #define +AMDGPU_USERQ_FW_CTX_SZ PAGE_SIZE #define
AMDGPU_USERQ_GDS_CTX_SZQuoted 12 lines
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+PAGE_SIZE +#define RLCG_UCODE_LOADING_START_ADDRESS
0x00002000L#define RLC_PG_DELAY_3_DEFAULT_GC_11_0_10x1388@@ -6406,6 +6411,44 @@ const structamdgpu_ip_block_versiongfx_v11_0_ip_block=
.funcs =&gfx_v11_0_ip_funcs,
};
+static int gfx_v11_userq_create_ctx_space(structamdgpu_userq_mgr*uq_mgr,
+ structamdgpu_usermode_queue*queue) { + structamdgpu_device*adev =uq_mgr->adev;Quoted 8 lines
Quoted 8 lines
+ struct
amdgpu_userq_ctx_space*ctx =&queue->fw_space; + int r, size;
+
+ /*
+ * The FW expects at least one page space allocated for + * process ctx, gang ctx, gds ctx, fw ctx each. + */
+ size =AMDGPU_USERQ_PROC_CTX_SZ+
AMDGPU_USERQ_FW_CTX_SZ+Quoted 1 line
Quoted 1 line
+
AMDGPU_USERQ_GANG_CTX_SZ+
AMDGPU_USERQ_GDS_CTX_SZ;Quoted 6 lines
Quoted 5 lines
+ r = amdgpu_bo_create_kernel(adev, size,
PAGE_SIZE, +AMDGPU_GEM_DOMAIN_GTT,
+&ctx->obj,
+&ctx->gpu_addr,
+&ctx->cpu_ptr);
Quoted 5 lines
Quoted 2 lines
Wasn't this stuff provided by userspace now?
The last I checked, only the shadow buffer was coming from userspace, and we were thinking about other stuff. I might not be well updated if there any recent development here with the short term solution.
CSA, GDS backup, and shadow are allocated by userspace now.
Alex
Quoted 104 lines
- Shashank
Quoted 11 lines
Christian.
Quoted 9 lines
+ 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;Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c const struct amdgpu_ip_block_version gfx_v11_0_ip_block =
Quoted 8 lines
+
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;drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +3
-0+} + +static void gfx_v11_userq_destroy_ctx_space(struct
amdgpu_userq_mgrQuoted 24 lines
Quoted 5 lines
*uq_mgr,
+ structamdgpu_usermode_queue*queue) { + structamdgpu_userq_ctx_space*ctx =&queue->fw_space; +
+ amdgpu_bo_free_kernel(&ctx->obj,&ctx->gpu_addr, &ctx-
cpu_ptr);Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+} +static int
gfx_v11_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
{drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -6426,10 +6469,16 @@ gfx_v11_userq_mqd_create(struct
amdgpu_userq_mgr*uq_mgr, structamdgpu_usermode
}
memset(mqd->cpu_ptr, 0, size);
+ r =gfx_v11_userq_create_ctx_space(uq_mgr, queue); + if (r) {
+ DRM_ERROR("Failed to create CTX space for userqueue +(%d)\n",
r);
+ gotofree_mqd;
+ }
+Quoted 8 lines
Quoted 8 lines
r =
amdgpu_bo_reserve(mqd->obj, false);
if (unlikely(r != 0)) {
DRM_ERROR("Failed to reserve mqd for userqueue (%d)", r); - gotofree_mqd;
+ gotofree_ctx;
}
queue->userq_prop.use_doorbell= true; @@ -6438,12 +6487,15 @@ gfx_v11_userq_mqd_create(structamdgpu_userq_mgr*uq_mgr,struct
Quoted 48 lines
Quoted 47 lines
amdgpu_usermodeamdgpu_bo_unreserve(mqd->obj);
if (r) {
DRM_ERROR("Failed to init MQD for queue\n"); - gotofree_mqd;
+ gotofree_ctx;
}
DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
return 0;
+free_ctx:
+gfx_v11_userq_destroy_ctx_space(uq_mgr, queue); +
free_mqd:
amdgpu_bo_free_kernel(&mqd->obj, &mqd->gpu_addr, &mqd->cpu_ptr);
return r;drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -6454,6 +6506,7 @@ gfx_v11_userq_mqd_destroy(struct
amdgpu_userq_mgr*uq_mgr, structamdgpu_usermod
{
structamdgpu_userq_ctx_space*mqd =&queue->mqd; +gfx_v11_userq_destroy_ctx_space(uq_mgr, queue);amdgpu_bo_free_kernel(&mqd->obj, &mqd->gpu_addr, &mqd->cpu_ptr);
}
diff --gita/drivers/gpu/drm/amd/include/amdgpu_userqueue.hb/drivers/gpu/drm/amd/include/amdgpu_userqueue.hindexe7da27918bd2..11e8ad649f6e100644drivers/gpu/drm/amd/include/amdgpu_userqueue.h +6
-0@@ -38,11 +38,17 @@ struct amdgpu_usermode_queue { int queue_id; int queue_type; 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; uint64_t flags; struct amdgpu_mqd_prop userq_prop; struct amdgpu_userq_mgr *userq_mgr; struct amdgpu_vm *vm; struct amdgpu_userq_ctx_space mqd; + struct amdgpu_userq_ctx_space fw_space; }; struct amdgpu_userq_funcs {
Re: [PATCH v4 05/10] drm/amdgpu: create context space for usermode queue
In reply to Shashank SharmaQuoted 65 lines · Shashank Sharma
The FW expects us to allocate at least one page as context space to process gang, process, 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 specificV2: 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
V4: Review comments:
- Remove shadow from FW space list from cover letter (Alex)
- Alignment of macro (Luben)Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 57 ++++++++++++++++++- .../gpu/drm/amd/include/amdgpu_userqueue.h | 6 ++ 2 files changed, 61 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +24
-0@@ -53,6 +53,11 @@#define GFX11_NUM_GFX_RINGS 1#define GFX11_MEC_HPD_SIZE 2048 +#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 +#define RLCG_UCODE_LOADING_START_ADDRESS 0x00002000L#define RLC_PG_DELAY_3_DEFAULT_GC_11_0_1 0x1388@@ -6406,6 +6411,44 @@ const struct amdgpu_ip_block_version gfx_v11_0_ip_block = .funcs = &gfx_v11_0_ip_funcs, }; +static int gfx_v11_userq_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 at least one page space allocated for +* process ctx, gang ctx, gds ctx, fw ctx each. +*/ + size =AMDGPU_USERQ_PROC_CTX_SZ +AMDGPU_USERQ_FW_CTX_SZ + +AMDGPU_USERQ_GANG_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) {
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c const struct amdgpu_ip_block_version gfx_v11_0_ip_block = · line 6442
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +10
-0+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 ; +}
Please use gfx_v11_0_ naming for consistency.
Alex
Quoted 80 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +21
-2+ +static void gfx_v11_userq_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 gfx_v11_userq_mqd_create (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *queue) {@@ -6426,10 +6469,16 @@ gfx_v11_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode }memset (mqd->cpu_ptr,0 , size); + r =gfx_v11_userq_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;@@ -6438,12 +6487,15 @@ gfx_v11_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermodeamdgpu_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: +gfx_v11_userq_destroy_ctx_space (uq_mgr, queue); + free_mqd:amdgpu_bo_free_kernel (&mqd->obj, &mqd->gpu_addr, &mqd->cpu_ptr);return r;@@ -6454,6 +6506,7 @@ gfx_v11_userq_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermod {struct amdgpu_userq_ctx_space *mqd = &queue->mqd; +gfx_v11_userq_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 +6
-1@@ -38,11 +38,17 @@ struct amdgpu_usermode_queue {int queue_id;int queue_type;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;uint64_t flags;struct amdgpu_mqd_prop userq_prop;struct amdgpu_userq_mgr *userq_mgr;struct amdgpu_vm *vm;struct amdgpu_userq_ctx_space mqd; +struct amdgpu_userq_ctx_space fw_space; };struct amdgpu_userq_funcs { --2.40.0
Re: [PATCH v4 05/10] drm/amdgpu: create context space for usermode queue
Quoted 68 lines · Alex Deucher
Quoted 67 lines · Shashank Sharma
The FW expects us to allocate at least one page as context space to process gang, process, 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 specificV2: 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
V4: Review comments:
- Remove shadow from FW space list from cover letter (Alex)
- Alignment of macro (Luben)Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 57 ++++++++++++++++++- .../gpu/drm/amd/include/amdgpu_userqueue.h | 6 ++ 2 files changed, 61 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +27
-0@@ -53,6 +53,11 @@#define GFX11_NUM_GFX_RINGS 1#define GFX11_MEC_HPD_SIZE 2048 +#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 +#define RLCG_UCODE_LOADING_START_ADDRESS 0x00002000L#define RLC_PG_DELAY_3_DEFAULT_GC_11_0_1 0x1388@@ -6406,6 +6411,44 @@ const struct amdgpu_ip_block_version gfx_v11_0_ip_block = .funcs = &gfx_v11_0_ip_funcs, }; +static int gfx_v11_userq_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 at least one page space allocated for +* process ctx, gang ctx, gds ctx, fw ctx each. +*/ + size =AMDGPU_USERQ_PROC_CTX_SZ +AMDGPU_USERQ_FW_CTX_SZ + +AMDGPU_USERQ_GANG_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; + }
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c const struct amdgpu_ip_block_version gfx_v11_0_ip_block = · line 6442
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +7
-0+ + 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 ; +}Please use
gfx_v11_0_naming for consistency.
Noted,
- Shashank
Quoted 83 lines
Alex
Quoted 80 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +21
-2+ +static void gfx_v11_userq_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 gfx_v11_userq_mqd_create (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *queue) {@@ -6426,10 +6469,16 @@ gfx_v11_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode }memset (mqd->cpu_ptr,0 , size); + r =gfx_v11_userq_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;@@ -6438,12 +6487,15 @@ gfx_v11_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermodeamdgpu_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: +gfx_v11_userq_destroy_ctx_space (uq_mgr, queue); + free_mqd:amdgpu_bo_free_kernel (&mqd->obj, &mqd->gpu_addr, &mqd->cpu_ptr);return r;@@ -6454,6 +6506,7 @@ gfx_v11_userq_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermod {struct amdgpu_userq_ctx_space *mqd = &queue->mqd; +gfx_v11_userq_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 +6
-1@@ -38,11 +38,17 @@ struct amdgpu_usermode_queue {int queue_id;int queue_type;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;uint64_t flags;struct amdgpu_mqd_prop userq_prop;struct amdgpu_userq_mgr *userq_mgr;struct amdgpu_vm *vm;struct amdgpu_userq_ctx_space mqd; +struct amdgpu_userq_ctx_space fw_space; };struct amdgpu_userq_funcs { --2.40.0
PATCH v4 6/10 drm/amdgpu: set FW parameters in v11_struct
In reply to Shashank SharmaFrom: Arvind Yadav <[email protected]>
This patch sets new parameters defined in v11_struct for usermode queue with the respective allocated gpu context space addresses.
V4: Split the patch into two parts, keep only the set parameter
part in this series (Alex).
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +18 -1
@@ -6411,6 +6411,21 @@ const struct amdgpu_ip_block_version gfx_v11_0_ip_block = .funcs = &gfx_v11_0_ip_funcs, }; +static void gfx_v11_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 gfx_v11_userq_create_ctx_space (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *queue) {
@@ -6484,12 +6499,14 @@ gfx_v11_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode 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; } +gfx_v11_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 ;
Signature · 1 line
2.40.0
Christian König
maintainerRe: [PATCH v4 06/10] drm/amdgpu: set FW parameters in v11_struct
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 28 lines
From: Arvind Yadav <[email protected]>
This patch sets new parameters defined in
v11_structfor usermode queue with the respective allocated gpu context space addresses.V4: Split the patch into two parts, keep only the set parameter
part in this series (Alex).Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Cc Shashank Sharma <[email protected]>Signed-off-by Arvind Yadav <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +3
-0@@ -6411,6 +6411,21 @@ const struct amdgpu_ip_block_version gfx_v11_0_ip_block = .funcs = &gfx_v11_0_ip_funcs, }; +static void gfx_v11_userq_set_ctx_space (struct amdgpu_userq_mgr *uq_mgr, +struct amdgpu_usermode_queue *queue) +{
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c const struct amdgpu_ip_block_version gfx_v11_0_ip_block = · line 6426
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +10
-0+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);
Mhm, first of all please use lower_32_bits() here instead of the mask.
Then are you sure that is correct? The shadow, csa, gds are supposed to be VAs as far as I know, but you use MC addresses here.
Christian.
Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5
-1+} +static int gfx_v11_userq_create_ctx_space (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *queue) {@@ -6484,12 +6499,14 @@ gfx_v11_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode 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; } +gfx_v11_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 ;
Re: [PATCH v4 06/10] drm/amdgpu: set FW parameters in v11_struct
Quoted 33 lines · Christian König
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 32 lines
From: Arvind Yadav <[email protected]>
This patch sets new parameters defined in
v11_structfor usermode queue with the respective allocated gpu context space addresses.V4: Split the patch into two parts, keep only the set parameter part in this series (Alex).
Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Cc Shashank Sharma <[email protected]>Signed-off-by Arvind Yadav <[email protected]>---
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c| 19 ++++++++++++++++++-1 file changed, 18 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -6411,6 +6411,21 @@ const struct amdgpu_ip_block_version
gfx_v11_0_ip_block=
.funcs =&gfx_v11_0_ip_funcs,
};
+static void gfx_v11_userq_set_ctx_space(structamdgpu_userq_mgr*uq_mgr, + structamdgpu_usermode_queue*queue)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5
-0+{ + 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);
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c const struct amdgpu_ip_block_version gfx_v11_0_ip_block = · line 6426
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +6
-0+ + 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);Mhm, first of all please use
lower_32_bits()here instead of the mask.
Noted,
Quoted 1 line
Then are you sure that is correct? The shadow, csa, gds are supposed to be VAs as far as I know, but you use MC addresses here.
In my understanding, only the shadow area needs to be VA, which is true here as its being allocated by the user. We have tested the code and we did not see any problem yet, but I can cross check this and come back.
- Shashank
Quoted 25 lines
Christian.
Quoted 20 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+} +static int
gfx_v11_userq_create_ctx_space(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
{drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -6484,12 +6499,14 @@ gfx_v11_userq_mqd_create(struct
amdgpu_userq_mgr*uq_mgr, structamdgpu_usermodequeue->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");
gotofree_ctx;
}
+gfx_v11_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;
Re: [PATCH v4 06/10] drm/amdgpu: set FW parameters in v11_struct
In reply to Shashank SharmaQuoted 23 lines · Shashank Sharma
From: Arvind Yadav <[email protected]>
This patch sets new parameters defined in
v11_structfor usermode queue with the respective allocated gpu context space addresses.V4: Split the patch into two parts, keep only the set parameter
part in this series (Alex).Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Cc Shashank Sharma <[email protected]>Signed-off-by Arvind Yadav <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c const struct amdgpu_ip_block_version gfx_v11_0_ip_block = · line 6414
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0@@ -6411,6 +6411,21 @@ const struct amdgpu_ip_block_version gfx_v11_0_ip_block = .funcs = &gfx_v11_0_ip_funcs, }; +static void gfx_v11_userq_set_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
gfx_v11_0_ for consistency.
Alex
Quoted 36 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +17
-2+ 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 gfx_v11_userq_create_ctx_space (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *queue) {@@ -6484,12 +6499,14 @@ gfx_v11_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode 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; } +gfx_v11_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 ; --2.40.0
Re: [PATCH v4 06/10] drm/amdgpu: set FW parameters in v11_struct
Quoted 26 lines · Alex Deucher
Quoted 25 lines · Shashank Sharma
From: Arvind Yadav <[email protected]>
This patch sets new parameters defined in
v11_structfor usermode queue with the respective allocated gpu context space addresses.V4: Split the patch into two parts, keep only the set parameter
part in this series (Alex).Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Cc Shashank Sharma <[email protected]>Signed-off-by Arvind Yadav <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -6411,6 +6411,21 @@ const struct amdgpu_ip_block_version gfx_v11_0_ip_block = .funcs = &gfx_v11_0_ip_funcs, };
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c const struct amdgpu_ip_block_version gfx_v11_0_ip_block = · line 6414
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0+static void gfx_v11_userq_set_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
gfx_v11_0_for consistency.Alex
Noted,
Shashank
Quoted 36 lines
Quoted 36 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +17
-2+ 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 gfx_v11_userq_create_ctx_space (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *queue) {@@ -6484,12 +6499,14 @@ gfx_v11_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode 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; } +gfx_v11_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 ; --2.40.0
PATCH v4 7/10 drm/amdgpu: map usermode queue into MES
In reply to Shashank SharmaThis 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
V4: Rebase
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 67 ++++++++++++++++++++++++++ 1 file changed, 67 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +67 -0
@@ -31,6 +31,7 @@#include "amdgpu_smu.h" #include "amdgpu_atomfirmware.h" #include "amdgpu_userqueue.h" +#include "amdgpu_mes.h" #include "imu_v11_0.h" #include "soc21.h" #include "nvd.h"
@@ -6411,6 +6412,64 @@ const struct amdgpu_ip_block_version gfx_v11_0_ip_block = .funcs = &gfx_v11_0_ip_funcs, }; +static int gfx_v11_userq_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 gfx_v11_userq_unmap (struct amdgpu_userq_mgr *uq_mgr, +struct amdgpu_usermode_queue *queue) +{ +struct amdgpu_device *adev = uq_mgr->adev; +struct mes_remove_queue_input queue_input; +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 void gfx_v11_userq_set_ctx_space (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *queue) {
@@ -6507,6 +6566,13 @@ gfx_v11_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermodegfx_v11_userq_set_ctx_space (uq_mgr, queue);amdgpu_bo_unreserve (mqd->obj); + +/* Map the queue in HW using MES ring */ + r =gfx_v11_userq_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 ;
@@ -6523,6 +6589,7 @@ gfx_v11_userq_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermod {struct amdgpu_userq_ctx_space *mqd = &queue->mqd; +gfx_v11_userq_unmap (uq_mgr, queue);gfx_v11_userq_destroy_ctx_space (uq_mgr, queue);amdgpu_bo_free_kernel (&mqd->obj, &mqd->gpu_addr, &mqd->cpu_ptr); }
Signature · 1 line
2.40.0
Christian König
maintainerRe: [PATCH v4 07/10] drm/amdgpu: map usermode queue into MES
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 39 lines
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 thewptr_mc_addrcalculation (moved into another patch) Addressed review comments from Alex:
- Do not add fptrs for map/unmapV3: Integration with doorbell manager
V4: RebaseCc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 67 ++++++++++++++++++++++++++ 1 file changed, 67 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0@@ -31,6 +31,7 @@#include "amdgpu_smu.h" #include "amdgpu_atomfirmware.h" #include "amdgpu_userqueue.h" +#include "amdgpu_mes.h" #include "imu_v11_0.h" #include "soc21.h" #include "nvd.h" @@ -6411,6 +6412,64 @@ const struct amdgpu_ip_block_version gfx_v11_0_ip_block = .funcs = &gfx_v11_0_ip_funcs, }; +static int gfx_v11_userq_map(struct amdgpu_userq_mgr *uq_mgr,
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c const struct amdgpu_ip_block_version gfx_v11_0_ip_block = · line 6425
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +10
-0+ 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 ;
Could be that this is wrong. What is that value used for?
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +6
-0+ 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;
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c const struct amdgpu_ip_block_version gfx_v11_0_ip_block = · line 6441
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +10
-0+ 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);
You need to implement some mechanism to keep those page tables and all resources in place.
Christian.
Quoted 56 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +39
-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 ; +} + +static void gfx_v11_userq_unmap (struct amdgpu_userq_mgr *uq_mgr, +struct amdgpu_usermode_queue *queue) +{ +struct amdgpu_device *adev = uq_mgr->adev; +struct mes_remove_queue_input queue_input; +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 void gfx_v11_userq_set_ctx_space (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *queue) {@@ -6507,6 +6566,13 @@ gfx_v11_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermodegfx_v11_userq_set_ctx_space (uq_mgr, queue);amdgpu_bo_unreserve (mqd->obj); + +/* Map the queue in HW using MES ring */ + r =gfx_v11_userq_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 ;@@ -6523,6 +6589,7 @@ gfx_v11_userq_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermod {struct amdgpu_userq_ctx_space *mqd = &queue->mqd; +gfx_v11_userq_unmap (uq_mgr, queue);gfx_v11_userq_destroy_ctx_space (uq_mgr, queue);amdgpu_bo_free_kernel (&mqd->obj, &mqd->gpu_addr, &mqd->cpu_ptr); }
Re: [PATCH v4 07/10] drm/amdgpu: map usermode queue into MES
Quoted 45 lines · Christian König
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 44 lines
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 thewptr_mc_addrcalculation (moved into another patch) Addressed review comments from Alex:
- Do not add fptrs for map/unmapV3: Integration with doorbell manager
V4: RebaseCc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>---
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c| 67 ++++++++++++++++++++++++++1 file changed, 67 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0@@ -31,6 +31,7 @@ #include "amdgpu_smu.h" #include "amdgpu_atomfirmware.h" #include "amdgpu_userqueue.h" +#include "amdgpu_mes.h" #include "imu_v11_0.h" #include "soc21.h" #include "nvd.h"@@ -6411,6 +6412,64 @@ const struct amdgpu_ip_block_version
gfx_v11_0_ip_block=
.funcs =&gfx_v11_0_ip_funcs,
};
+static int gfx_v11_userq_map(structamdgpu_userq_mgr*uq_mgr, + structamdgpu_usermode_queue*queue) +{
+ structamdgpu_device*adev =uq_mgr->adev;
+ structmes_add_queue_inputqueue_input;
+ int r;
Quoted 9 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5
-0+ + 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;Could be that this is wrong. What is that value used for?
Both start and end are required by MES FW for mapping the MQD. The value here is generated same as in KFD userqueue.
Quoted 13 lines
Quoted 13 lines
+ 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;
Quoted 8 lines
Quoted 6 lines
+ 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);You need to implement some mechanism to keep those page tables and all resources in place.
I don't get it, would you mind elaborating this please ?
- Shashank
Quoted 59 lines
Christian.
Quoted 55 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.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/gfx_v11_0.c +20
-0+} + +static void gfx_v11_userq_unmap (struct amdgpu_userq_mgr *uq_mgr, + struct amdgpu_usermode_queue *queue) +{ + struct amdgpu_device *adev = uq_mgr->adev; + struct mes_remove_queue_input queue_input; + 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 void
gfx_v11_userq_set_ctx_space(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
{drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -6507,6 +6566,13 @@ gfx_v11_userq_mqd_create(struct
amdgpu_userq_mgr*uq_mgr, structamdgpu_usermode
gfx_v11_userq_set_ctx_space(uq_mgr, queue);
amdgpu_bo_unreserve(mqd->obj);
+
+ /* Map the queue in HW using MES ring */
+ r =gfx_v11_userq_map(uq_mgr, queue);
+ if (r) {
+DRM_ERROR("Failed to map userqueue (%d)\n", r);
+ gotofree_ctx;
+ }
DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
return 0;
@@ -6523,6 +6589,7 @@ gfx_v11_userq_mqd_destroy(structamdgpu_userq_mgr*uq_mgr, structamdgpu_usermod{
structamdgpu_userq_ctx_space*mqd =&queue->mqd;
+gfx_v11_userq_unmap(uq_mgr, queue);
gfx_v11_userq_destroy_ctx_space(uq_mgr, queue);
amdgpu_bo_free_kernel(&mqd->obj, &mqd->gpu_addr, &mqd->cpu_ptr);
}
Christian König
maintainerRe: [PATCH v4 07/10] drm/amdgpu: map usermode queue into MES
Am 25.04.23 um 15:31 schrieb Shashank Sharma:
Quoted 57 lines · Christian König
Quoted 46 lines
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 45 lines
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 thewptr_mc_addrcalculation (moved into another patch) Addressed review comments from Alex:
- Do not add fptrs for map/unmapV3: Integration with doorbell manager
V4: RebaseCc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>---
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c| 67
++++++++++++++++++++++++++1 file changed, 67 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0@@ -31,6 +31,7 @@ #include "amdgpu_smu.h" #include "amdgpu_atomfirmware.h" #include "amdgpu_userqueue.h" +#include "amdgpu_mes.h" #include "imu_v11_0.h" #include "soc21.h" #include "nvd.h"@@ -6411,6 +6412,64 @@ const struct amdgpu_ip_block_version
gfx_v11_0_ip_block=
.funcs =&gfx_v11_0_ip_funcs,
};
+static int gfx_v11_userq_map(structamdgpu_userq_mgr*uq_mgr, + structamdgpu_usermode_queue*queue) +{
+ structamdgpu_device*adev =uq_mgr->adev;
+ structmes_add_queue_inputqueue_input;
+ int r;Quoted 9 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5
-0+ + 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;Could be that this is wrong. What is that value used for?
Quoted 1 line
Both start and end are required by MES FW for mapping the MQD. The value here is generated same as in KFD userqueue.
Ok in this case then that's probably the values which will be written into the registers. So that's probably ok.
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
+ 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;Quoted 8 lines
Quoted 6 lines
+ 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);You need to implement some mechanism to keep those page tables and all resources in place.
Quoted 1 line
I don't get it, would you mind elaborating this please ?
We need something like the KFD eviction fence. Probably best if we have a call on that.
Christian.
Quoted 62 lines
- Shashank
Quoted 59 lines
Christian.
Quoted 55 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.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/gfx_v11_0.c +20
-0+} + +static void gfx_v11_userq_unmap (struct amdgpu_userq_mgr *uq_mgr, + struct amdgpu_usermode_queue *queue) +{ + struct amdgpu_device *adev = uq_mgr->adev; + struct mes_remove_queue_input queue_input; + 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 void
gfx_v11_userq_set_ctx_space(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
{drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -6507,6 +6566,13 @@ gfx_v11_userq_mqd_create(struct
amdgpu_userq_mgr*uq_mgr, structamdgpu_usermode
gfx_v11_userq_set_ctx_space(uq_mgr, queue);
amdgpu_bo_unreserve(mqd->obj);
+
+ /* Map the queue in HW using MES ring */
+ r =gfx_v11_userq_map(uq_mgr, queue);
+ if (r) {
+DRM_ERROR("Failed to map userqueue (%d)\n", r);
+ gotofree_ctx;
+ }
DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
return 0;
@@ -6523,6 +6589,7 @@ gfx_v11_userq_mqd_destroy(structamdgpu_userq_mgr*uq_mgr, structamdgpu_usermod{
structamdgpu_userq_ctx_space*mqd =&queue->mqd;
+gfx_v11_userq_unmap(uq_mgr, queue);
gfx_v11_userq_destroy_ctx_space(uq_mgr, queue);
amdgpu_bo_free_kernel(&mqd->obj, &mqd->gpu_addr, &mqd->cpu_ptr);
}
Re: [PATCH v4 07/10] drm/amdgpu: map usermode queue into MES
Quoted 84 lines · Christian König
Am 25.04.23 um 15:31 schrieb Shashank Sharma:
Quoted 57 lines · Christian König
Quoted 46 lines
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 45 lines
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 thewptr_mc_addrcalculation (moved into another patch) Addressed review comments from Alex:
- Do not add fptrs for map/unmapV3: Integration with doorbell manager
V4: RebaseCc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>---
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c| 67
++++++++++++++++++++++++++1 file changed, 67 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0@@ -31,6 +31,7 @@ #include "amdgpu_smu.h" #include "amdgpu_atomfirmware.h" #include "amdgpu_userqueue.h" +#include "amdgpu_mes.h" #include "imu_v11_0.h" #include "soc21.h" #include "nvd.h"@@ -6411,6 +6412,64 @@ const struct amdgpu_ip_block_version
gfx_v11_0_ip_block=
.funcs =&gfx_v11_0_ip_funcs,
};
+static int gfx_v11_userq_map(structamdgpu_userq_mgr*uq_mgr, + structamdgpu_usermode_queue*queue) +{
+ structamdgpu_device*adev =uq_mgr->adev;
+ structmes_add_queue_inputqueue_input;
+ int r;Quoted 9 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5
-0+ + 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;Could be that this is wrong. What is that value used for?
Quoted 1 line
Both start and end are required by MES FW for mapping the MQD. The value here is generated same as in KFD userqueue.
Ok in this case then that's probably the values which will be written into the registers. So that's probably ok.
Quoted 22 lines
Quoted 21 lines
Quoted 11 lines
+ 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;
+Quoted 8 lines
+ 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);You need to implement some mechanism to keep those page tables and all resources in place.
Quoted 3 lines
Quoted 1 line
I don't get it, would you mind elaborating this please ?
We need something like the KFD eviction fence. Probably best if we have a call on that.
Noted,
- Shashank
Quoted 66 lines
Christian.
Quoted 62 lines
- Shashank
Quoted 59 lines
Christian.
Quoted 55 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.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/gfx_v11_0.c +20
-0+} + +static void gfx_v11_userq_unmap (struct amdgpu_userq_mgr *uq_mgr, + struct amdgpu_usermode_queue *queue) +{ + struct amdgpu_device *adev = uq_mgr->adev; + struct mes_remove_queue_input queue_input; + 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 void
gfx_v11_userq_set_ctx_space(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
{drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -6507,6 +6566,13 @@ gfx_v11_userq_mqd_create(struct
amdgpu_userq_mgr*uq_mgr, structamdgpu_usermode
gfx_v11_userq_set_ctx_space(uq_mgr, queue);
amdgpu_bo_unreserve(mqd->obj);
+
+ /* Map the queue in HW using MES ring */
+ r =gfx_v11_userq_map(uq_mgr, queue);
+ if (r) {
+DRM_ERROR("Failed to map userqueue (%d)\n", r);
+ gotofree_ctx;
+ }
DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id);
return 0;
@@ -6523,6 +6589,7 @@ gfx_v11_userq_mqd_destroy(structamdgpu_userq_mgr*uq_mgr, structamdgpu_usermod{
structamdgpu_userq_ctx_space*mqd =&queue->mqd;
+gfx_v11_userq_unmap(uq_mgr, queue);
gfx_v11_userq_destroy_ctx_space(uq_mgr, queue);
amdgpu_bo_free_kernel(&mqd->obj, &mqd->gpu_addr, &mqd->cpu_ptr);
}
Re: [PATCH v4 07/10] drm/amdgpu: map usermode queue into MES
In reply to Shashank SharmaQuoted 86 lines · Shashank Sharma
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 thewptr_mc_addrcalculation (moved into another patch) Addressed review comments from Alex:
- Do not add fptrs for map/unmapV3: Integration with doorbell manager
V4: RebaseCc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 67 ++++++++++++++++++++++++++ 1 file changed, 67 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +48
-0@@ -31,6 +31,7 @@#include "amdgpu_smu.h" #include "amdgpu_atomfirmware.h" #include "amdgpu_userqueue.h" +#include "amdgpu_mes.h" #include "imu_v11_0.h" #include "soc21.h" #include "nvd.h" @@ -6411,6 +6412,64 @@ const struct amdgpu_ip_block_version gfx_v11_0_ip_block = .funcs = &gfx_v11_0_ip_funcs, }; +static int gfx_v11_userq_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 gfx_v11_userq_unmap (struct amdgpu_userq_mgr *uq_mgr, +struct amdgpu_usermode_queue *queue) +{ +struct amdgpu_device *adev = uq_mgr->adev; +struct mes_remove_queue_input queue_input; +int r; +
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c const struct amdgpu_ip_block_version gfx_v11_0_ip_block = · line 6471
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +10
-0+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); +}
gfx_v11_0_ for consistency.
Alex
Quoted 29 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +9
-1+static void gfx_v11_userq_set_ctx_space (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *queue) {@@ -6507,6 +6566,13 @@ gfx_v11_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermodegfx_v11_userq_set_ctx_space (uq_mgr, queue);amdgpu_bo_unreserve (mqd->obj); + +/* Map the queue in HW using MES ring */ + r =gfx_v11_userq_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 ;@@ -6523,6 +6589,7 @@ gfx_v11_userq_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermod {struct amdgpu_userq_ctx_space *mqd = &queue->mqd; +gfx_v11_userq_unmap (uq_mgr, queue);gfx_v11_userq_destroy_ctx_space (uq_mgr, queue);amdgpu_bo_free_kernel (&mqd->obj, &mqd->gpu_addr, &mqd->cpu_ptr); } --2.40.0
Re: [PATCH v4 07/10] drm/amdgpu: map usermode queue into MES
Quoted 98 lines · Alex Deucher
Quoted 85 lines · Shashank Sharma
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 thewptr_mc_addrcalculation (moved into another patch) Addressed review comments from Alex:
- Do not add fptrs for map/unmapV3: Integration with doorbell manager
V4: RebaseCc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 67 ++++++++++++++++++++++++++ 1 file changed, 67 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +48
-0@@ -31,6 +31,7 @@#include "amdgpu_smu.h" #include "amdgpu_atomfirmware.h" #include "amdgpu_userqueue.h" +#include "amdgpu_mes.h" #include "imu_v11_0.h" #include "soc21.h" #include "nvd.h" @@ -6411,6 +6412,64 @@ const struct amdgpu_ip_block_version gfx_v11_0_ip_block = .funcs = &gfx_v11_0_ip_funcs, }; +static int gfx_v11_userq_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 gfx_v11_userq_unmap (struct amdgpu_userq_mgr *uq_mgr, +struct amdgpu_usermode_queue *queue) +{ +struct amdgpu_device *adev = uq_mgr->adev; +struct mes_remove_queue_input queue_input; +int r; +drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c const struct amdgpu_ip_block_version gfx_v11_0_ip_block = · line 6471
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +10
-0+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); +}
gfx_v11_0_for consistency.
Quoted 1 line
Alex
Noted,
Shashank
Quoted 29 lines
Quoted 29 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +9
-1+static void gfx_v11_userq_set_ctx_space (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *queue) {@@ -6507,6 +6566,13 @@ gfx_v11_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermodegfx_v11_userq_set_ctx_space (uq_mgr, queue);amdgpu_bo_unreserve (mqd->obj); + +/* Map the queue in HW using MES ring */ + r =gfx_v11_userq_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 ;@@ -6523,6 +6589,7 @@ gfx_v11_userq_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermod {struct amdgpu_userq_ctx_space *mqd = &queue->mqd; +gfx_v11_userq_unmap (uq_mgr, queue);gfx_v11_userq_destroy_ctx_space (uq_mgr, queue);amdgpu_bo_free_kernel (&mqd->obj, &mqd->gpu_addr, &mqd->cpu_ptr); } --2.40.0
PATCH v4 8/10 drm/amdgpu: map wptr BO into GART
In reply to Shashank SharmaTo support oversubscription, MES FW expects WPTR BOs to be mapped into GART, before they are submitted to usermode queues. This patch adds a function for the same.
V4: fix the wptr value before mapping lookup (Bas, Christian).
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 90 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 1 + .../gpu/drm/amd/include/amdgpu_userqueue.h | 1 + 3 files changed, 92 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +90 -0
@@ -44,6 +44,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 &=AMDGPU_GMC_HOLE_MASK ; + 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_gfx (struct drm_file *filp,union drm_amdgpu_userq *args) {struct amdgpu_usermode_queue *queue;
@@ -81,6 +164,13 @@ static int amdgpu_userqueue_create_gfx(struct drm_file *filp, union drm_amdgpu_u 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; + } +if (uq_mgr->userq_funcs[queue->queue_type]->mqd_create) { r = uq_mgr->userq_funcs[queue->queue_type]->mqd_create (uq_mgr, queue);if (r) {
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1 -0
@@ -6439,6 +6439,7 @@ static int gfx_v11_userq_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
@@ -38,6 +38,7 @@ struct amdgpu_usermode_queue {int queue_id;int queue_type;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
Christian König
maintainerRe: [PATCH v4 08/10] drm/amdgpu: map wptr BO into GART
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 36 lines
To support oversubscription, MES FW expects WPTR BOs to be mapped into GART, before they are submitted to usermode queues. This patch adds a function for the same.
V4: fix the wptr value before mapping lookup (Bas, Christian).
Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Arvind Yadav <[email protected]>Signed-off-by Shashank Sharma <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 90 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 1 + .../gpu/drm/amd/include/amdgpu_userqueue.h | 1 + 3 files changed, 92 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +12
-0@@ -44,6 +44,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 );
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c amdgpu_userqueue_find(struct amdgpu_userq_mgr *uq_mgr, int qid) · line 68
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +10
-0+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; + }
Either pinning *or* allocating GART, but not both!
I think calling amdgpu_ttm_alloc_gart() is the right thing to do here.
Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +19
-0+ +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,
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c amdgpu_userqueue_find(struct amdgpu_userq_mgr *uq_mgr, int qid) · line 97
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +10
-0+ 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);
All the handling must be done with the VM and all resource locks held.
So this should be something the caller of the function does.
Regards,
Christian.
Quoted 73 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +39
-0+if (ret) + goto err_wptr_map_gart; + + wptr &=AMDGPU_GMC_HOLE_MASK ; + 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_gfx (struct drm_file *filp,union drm_amdgpu_userq *args) {struct amdgpu_usermode_queue *queue;@@ -81,6 +164,13 @@ static int amdgpu_userqueue_create_gfx(struct drm_file *filp, union drm_amdgpu_u 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; + } +if (uq_mgr->userq_funcs[queue->queue_type]->mqd_create) { r = uq_mgr->userq_funcs[queue->queue_type]->mqd_create (uq_mgr, queue);if (r) {drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0@@ -6439,6 +6439,7 @@ static int gfx_v11_userq_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@@ -38,6 +38,7 @@ struct amdgpu_usermode_queue {int queue_id;int queue_type;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;
Re: [PATCH v4 08/10] drm/amdgpu: map wptr BO into GART
Quoted 51 lines · Christian König
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 37 lines
To support oversubscription, MES FW expects WPTR BOs to be mapped into GART, before they are submitted to usermode queues. This patch adds a function for the same.
V4: fix the wptr value before mapping lookup (Bas, Christian).
Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Arvind Yadav <[email protected]>Signed-off-by Shashank Sharma <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c| 90 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 1 + .../gpu/drm/amd/include/amdgpu_userqueue.h | 1 +3 files changed, 92 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +0
-0@@ -44,6 +44,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, structamdgpu_bo*bo)drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +10
-0+{ + 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);drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c amdgpu_userqueue_find(struct amdgpu_userq_mgr *uq_mgr, int qid) · line 68
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +10
-0+ 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; + }Either pinning *or* allocating GART, but not both!
Quoted 2 lines
I think calling
amdgpu_ttm_alloc_gart()is the right thing to do here.
Ah, silly me :), Thanks for pointing this out.
Quoted 32 lines
Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +19
-0+ + 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,drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c amdgpu_userqueue_find(struct amdgpu_userq_mgr *uq_mgr, int qid) · line 97
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +10
-0+ 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);All the handling must be done with the VM and all resource locks held.
Quoted 1 line
So this should be something the caller of the function does.
Noted, will add the protections.
- Shashank
Quoted 80 lines
Regards,
Christian.Quoted 75 lines
+ if (ret)
+ gotoerr_wptr_map_gart;
+
+ wptr &=AMDGPU_GMC_HOLE_MASK;
+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;
+ gotoerr_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;
+ gotoerr_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_gfx(struct drm_file *filp, union drm_amdgpu_userq *args){
structamdgpu_usermode_queue*queue;drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +0
-0@@ -81,6 +164,13 @@ static int amdgpu_userqueue_create_gfx(struct
drm_file*filp, uniondrm_amdgpu_u
gotofree_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);
+ gotofree_queue;
+ }
+
if (uq_mgr->userq_funcs[queue->queue_type]->mqd_create) {
r = uq_mgr->userq_funcs[queue->queue_type]->mqd_create(uq_mgr, queue); if (r) {drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0@@ -6439,6 +6439,7 @@ static int gfx_v11_userq_map(structamdgpu_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@@ -38,6 +38,7 @@ struct amdgpu_usermode_queue { int queue_id; int queue_type; 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;
PATCH v4 9/10 drm/amdgpu: generate doorbell index for userqueue
In reply to Shashank SharmaThe 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/
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +33 -0
@@ -44,6 +44,30 @@ 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) {
@@ -133,6 +157,7 @@ static int amdgpu_userqueue_create_gfx(struct drm_file *filp, union drm_amdgpu_ustruct amdgpu_fpriv *fpriv = filp->driver_priv;struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;struct drm_amdgpu_userq_mqd_gfx *mqd_in = &args->in.mqd.gfx; +uint64_t index;int r;/* Do we support usermode queues on this GFX IP ? */
@@ -154,6 +179,14 @@ static int amdgpu_userqueue_create_gfx(struct drm_file *filp, union drm_amdgpu_u queue->userq_prop.hqd_base_gpu_addr = mqd_in->queue_va; 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->queue_type =AMDGPU_HW_IP_GFX ; queue->flags = mqd_in->flags; queue->vm = &fpriv->vm;
Signature · 1 line
2.40.0
Christian König
maintainerRe: [PATCH v4 09/10] drm/amdgpu: generate doorbell index for userqueue
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 30 lines
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]>Signed-off-by Shashank Sharma <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +7
-0@@ -44,6 +44,30 @@ 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;
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c amdgpu_userqueue_find(struct amdgpu_userq_mgr *uq_mgr, int qid) · line 63
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +10
-0+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));
That looks like we are leaking the object reference here.
Christian.
Quoted 33 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +16
-0+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) {@@ -133,6 +157,7 @@ static int amdgpu_userqueue_create_gfx(struct drm_file *filp, union drm_amdgpu_ustruct amdgpu_fpriv *fpriv = filp->driver_priv;struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;struct drm_amdgpu_userq_mqd_gfx *mqd_in = &args->in.mqd.gfx; +uint64_t index;int r;/* Do we support usermode queues on this GFX IP ? */ @@ -154,6 +179,14 @@ static int amdgpu_userqueue_create_gfx(struct drm_file *filp, union drm_amdgpu_u queue->userq_prop.hqd_base_gpu_addr = mqd_in->queue_va; 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->queue_type =AMDGPU_HW_IP_GFX ; queue->flags = mqd_in->flags; queue->vm = &fpriv->vm;
Re: [PATCH v4 09/10] drm/amdgpu: generate doorbell index for userqueue
Quoted 35 lines · Christian König
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 34 lines
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]>Signed-off-by Shashank Sharma <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c| 33 +++++++++++++++++++1 file changed, 33 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +0
-0@@ -44,6 +44,30 @@ amdgpu_userqueue_find(struct amdgpu_userq_mgr *uq_mgr, int qid) return idr_find(&uq_mgr->userq_idr, qid); }+static
uint64_tdrivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +10
-0+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);
Quoted 9 lines
Quoted 6 lines
+ 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));That looks like we are leaking the object reference here.
That's correct, I will fix it.
- Shashank
Quoted 38 lines
Christian.
Quoted 35 lines
+
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;drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +2
-0+} +static int
amdgpu_userqueue_map_gtt_bo_to_gart(struct amdgpu_device *adev, struct amdgpu_bo *bo){drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +0
-0@@ -133,6 +157,7 @@ static int amdgpu_userqueue_create_gfx(struct
drm_file*filp, uniondrm_amdgpu_u
structamdgpu_fpriv*fpriv =filp->driver_priv; structamdgpu_userq_mgr*uq_mgr=&fpriv->userq_mgr; structdrm_amdgpu_userq_mqd_gfx*mqd_in=&args->in.mqd.gfx; +uint64_tindex;
int r;
/* Do we support usermode queues on this GFX IP ? */drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +0
-0@@ -154,6 +179,14 @@ static int amdgpu_userqueue_create_gfx(struct
drm_file*filp, uniondrm_amdgpu_uqueue->userq_prop.hqd_base_gpu_addr=mqd_in->queue_va;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;
+ gotofree_queue;
+ }
+
+queue->userq_prop.doorbell_index= index;queue->queue_type=AMDGPU_HW_IP_GFX;
queue->flags=mqd_in->flags;
queue->vm=&fpriv->vm;
PATCH v4 10/10 drm/amdgpu: cleanup leftover queues
In reply to Shashank SharmaThis patch adds code to cleanup any leftover userqueues which a user might have missed to destroy due to a crash or any other programming error.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +25 -6
@@ -237,6 +237,18 @@ static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userqreturn -EINVAL ; } +static void +amdgpu_userqueue_cleanup (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *queue) +{ +mutex_lock (&uq_mgr->userq_mutex); +if (uq_mgr->userq_funcs[queue->queue_type]->mqd_destroy) + 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); +} +static void amdgpu_userqueue_destroy (struct drm_file *filp,int queue_id) {struct amdgpu_fpriv *fpriv = filp->driver_priv;
@@ -249,12 +261,7 @@ static void amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)return ; } -mutex_lock (&uq_mgr->userq_mutex); -if (uq_mgr->userq_funcs[queue->queue_type]->mqd_destroy) - 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); +amdgpu_userqueue_cleanup (uq_mgr, queue); } int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
@@ -307,8 +314,20 @@ int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_devireturn 0 ; } +static void amdgpu_userqueue_cleanup_residue (int queue_id,void *ptr,void *data) +{ +struct amdgpu_userq_mgr *uq_mgr = data; +struct amdgpu_usermode_queue *queue = ptr; + +amdgpu_userqueue_cleanup (uq_mgr, queue); +} +void amdgpu_userq_mgr_fini (struct amdgpu_userq_mgr *userq_mgr) { +idr_for_each (&userq_mgr->userq_idr, + amdgpu_userqueue_cleanup_residue, + userq_mgr); +idr_destroy (&userq_mgr->userq_idr);mutex_destroy (&userq_mgr->userq_mutex); }
Signature · 1 line
2.40.0
Christian König
maintainerRe: [PATCH v4 10/10] drm/amdgpu: cleanup leftover queues
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 58 lines
This patch adds code to cleanup any leftover userqueues which a user might have missed to destroy due to a crash or any other programming error.
Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Suggested-by Bas Nieuwenhuizen <[email protected]>Signed-off-by Bas Nieuwenhuizen <[email protected]>Signed-off-by Shashank Sharma <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +17
-6@@ -237,6 +237,18 @@ static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userqreturn -EINVAL ; } +static void +amdgpu_userqueue_cleanup (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *queue) +{ +mutex_lock (&uq_mgr->userq_mutex); +if (uq_mgr->userq_funcs[queue->queue_type]->mqd_destroy) + 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); +} +static void amdgpu_userqueue_destroy (struct drm_file *filp,int queue_id) {struct amdgpu_fpriv *fpriv = filp->driver_priv;@@ -249,12 +261,7 @@ static void amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)return ; } -mutex_lock (&uq_mgr->userq_mutex); -if (uq_mgr->userq_funcs[queue->queue_type]->mqd_destroy) - 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); +amdgpu_userqueue_cleanup (uq_mgr, queue); } int amdgpu_userq_ioctl(struct drm_device *dev, void *data,@@ -307,8 +314,20 @@ int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_devireturn 0 ; } +static void amdgpu_userqueue_cleanup_residue (int queue_id,void *ptr,void *data) +{ +struct amdgpu_userq_mgr *uq_mgr = data; +struct amdgpu_usermode_queue *queue = ptr;
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_devi · line 330
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +8
-0+ +amdgpu_userqueue_cleanup (uq_mgr, queue); +} +void amdgpu_userq_mgr_fini (struct amdgpu_userq_mgr *userq_mgr) { +idr_for_each (&userq_mgr->userq_idr, + amdgpu_userqueue_cleanup_residue, + userq_mgr); +
Better use idr_for_each_entry() here.
Christian.
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +0
-0idr_destroy (&userq_mgr->userq_idr);mutex_destroy (&userq_mgr->userq_mutex); }
Re: [PATCH v4 10/10] drm/amdgpu: cleanup leftover queues
Quoted 65 lines · Christian König
Am 24.04.23 um 19:38 schrieb Shashank Sharma:
Quoted 62 lines
This patch adds code to cleanup any leftover userqueues which a user might have missed to destroy due to a crash or any other programming error.
Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Suggested-by Bas Nieuwenhuizen <[email protected]>Signed-off-by Bas Nieuwenhuizen <[email protected]>Signed-off-by Shashank Sharma <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c| 31 +++++++++++++++----1 file changed, 25 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +0
-0@@ -237,6 +237,18 @@ static int amdgpu_userqueue_create(struct
drm_file*filp, uniondrm_amdgpu_userq
return-EINVAL;
}
+static void
+amdgpu_userqueue_cleanup(structamdgpu_userq_mgr*uq_mgr, structamdgpu_usermode_queue*queue)drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +10
-0+{ + mutex_lock(&uq_mgr->userq_mutex); + if (uq_mgr->userq_funcs[queue->queue_type]->mqd_destroy) + 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); +} +static void
amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id){
structamdgpu_fpriv*fpriv =filp->driver_priv;drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +1
-5@@ -249,12 +261,7 @@ static void amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id) return; } - mutex_lock(&uq_mgr->userq_mutex); - if (uq_mgr->userq_funcs[queue->queue_type]->mqd_destroy) - 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); + amdgpu_userqueue_cleanup(uq_mgr, queue); } int amdgpu_userq_ioctl(struct drm_device *dev, void *data,@@ -307,8 +314,20 @@ int amdgpu_userq_mgr_init(struct
amdgpu_userq_mgr*userq_mgr, structamdgpu_devi
return 0;
}
+static voidamdgpu_userqueue_cleanup_residue(int queue_id, void *ptr, void *data)drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +7
-0+{ + struct amdgpu_userq_mgr *uq_mgr = data; + struct amdgpu_usermode_queue *queue = ptr; + + amdgpu_userqueue_cleanup(uq_mgr, queue); +} +
Quoted 8 lines
Quoted 6 lines
void
amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr){
+ idr_for_each(&userq_mgr->userq_idr,
+amdgpu_userqueue_cleanup_residue,
+userq_mgr);
+Better use
idr_for_each_entry()here.
Noted, will update it.
- Shashank
Quoted 6 lines
Christian.
Quoted 3 lines
idr_destroy(&userq_mgr->userq_idr);
mutex_destroy(&userq_mgr->userq_mutex);
}