From: "Christian König" <christian.koenig@amd.com>
To: Shashank Sharma <shashank.sharma@amd.com>, amd-gfx@lists.freedesktop.org
Cc: alexander.deucher@amd.com,
Shashank Sharma <contactshashanksharma@gmail.com>
Subject: Re: [PATCH 2/8] drm/amdgpu: add usermode queues
Date: Tue, 7 Feb 2023 08:08:52 +0100 [thread overview]
Message-ID: <ecb47e10-43db-af4e-ae3b-c0321dcd8e2a@amd.com> (raw)
In-Reply-To: <20230203215409.2021-3-shashank.sharma@amd.com>
Am 03.02.23 um 22:54 schrieb Shashank Sharma:
> From: Shashank Sharma <contactshashanksharma@gmail.com>
>
> This patch adds skeleton code for usermode queue creation. It
> typically contains:
> - A new structure to keep all the user queue data in one place.
> - An IOCTL function to create/free a usermode queue.
> - A function to generate unique index for the queue.
> - 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
>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: Christian Koenig <christian.koenig@amd.com>
> Signed-off-by: Shashank Sharma <contactshashanksharma@gmail.com>
> ---
> drivers/gpu/drm/amd/amdgpu/Makefile | 2 +
> drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 +
> drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +
> drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 5 +
> drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 155 ++++++++++++++++++
> .../gpu/drm/amd/include/amdgpu_userqueue.h | 64 ++++++++
> 6 files changed, 230 insertions(+)
> create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
> create mode 100644 drivers/gpu/drm/amd/include/amdgpu_userqueue.h
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile b/drivers/gpu/drm/amd/amdgpu/Makefile
> index 798d0e9a60b7..764801cc8203 100644
> --- a/drivers/gpu/drm/amd/amdgpu/Makefile
> +++ b/drivers/gpu/drm/amd/amdgpu/Makefile
> @@ -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
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index 6b74df446694..0625d6bdadf4 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -109,6 +109,7 @@
> #include "amdgpu_fdinfo.h"
> #include "amdgpu_mca.h"
> #include "amdgpu_ras.h"
> +#include "amdgpu_userqueue.h"
>
> #define MAX_GPU_INSTANCE 16
>
> @@ -482,6 +483,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);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> index b4f2d61ea0d5..229976a2d0e7 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> @@ -52,6 +52,7 @@
> #include "amdgpu_ras.h"
> #include "amdgpu_xgmi.h"
> #include "amdgpu_reset.h"
> +#include "amdgpu_userqueue.h"
>
> /*
> * KMS wrapper.
> @@ -2748,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 = {
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index 7aa7e52ca784..52e61e339a88 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -1187,6 +1187,10 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
>
> amdgpu_ctx_mgr_init(&fpriv->ctx_mgr, adev);
>
> + r = amdgpu_userq_mgr_init(&fpriv->userq_mgr, adev);
> + if (r)
> + DRM_WARN("Can't setup usermode queues, only legacy workload submission will work\n");
> +
> file_priv->driver_priv = fpriv;
> goto out_suspend;
>
> @@ -1254,6 +1258,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);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
> new file mode 100644
> index 000000000000..d5bc7fe81750
> --- /dev/null
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
> @@ -0,0 +1,155 @@
> +/*
> + * Copyright 2022 Advanced Micro Devices, Inc.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + *
> + */
> +
> +#include "amdgpu.h"
> +#include "amdgpu_vm.h"
> +
> +static inline int
> +amdgpu_userqueue_index(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
> +{
> + return idr_alloc(&uq_mgr->userq_idr, queue, 1, AMDGPU_MAX_USERQ, GFP_KERNEL);
> +}
> +
> +static inline void
> +amdgpu_userqueue_free_index(struct amdgpu_userq_mgr *uq_mgr, int queue_id)
> +{
> + idr_remove(&uq_mgr->userq_idr, queue_id);
> +}
> +
> +static struct amdgpu_usermode_queue
> +*amdgpu_userqueue_find(struct amdgpu_userq_mgr *uq_mgr, int qid)
Please put the * on the previous line, it took me a moment to realize
that you not return the queue by value here.
> +{
> + return idr_find(&uq_mgr->userq_idr, qid);
> +}
> +
> +static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
> +{
> + int r, pasid;
> + struct amdgpu_usermode_queue *queue;
> + struct amdgpu_fpriv *fpriv = filp->driver_priv;
> + struct amdgpu_vm *vm = &fpriv->vm;
> + struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;
> + struct drm_amdgpu_userq_mqd *mqd_in = &args->in.mqd;
We usually put variables like i and r last. The PCI maintainers even
require that you sort the variables in reverse xmas tree.
> +
> + pasid = vm->pasid;
> + if (vm->pasid < 0) {
> + DRM_WARN("No PASID info found\n");
> + pasid = 0;
> + }
> +
> + mutex_lock(&uq_mgr->userq_mutex);
> +
> + queue = kzalloc(sizeof(struct amdgpu_usermode_queue), GFP_KERNEL);
> + if (!queue) {
> + DRM_ERROR("Failed to allocate memory for queue\n");
> + mutex_unlock(&uq_mgr->userq_mutex);
> + return -ENOMEM;
> + }
> +
> + queue->vm = vm;
> + queue->pasid = pasid;
> + queue->wptr_gpu_addr = mqd_in->wptr_va;
> + queue->rptr_gpu_addr = mqd_in->rptr_va;
> + queue->queue_size = mqd_in->queue_size;
> + queue->queue_type = mqd_in->ip_type;
> + queue->queue_gpu_addr = mqd_in->queue_va;
> + queue->flags = mqd_in->flags;
> + queue->use_doorbell = true;
> + queue->queue_id = amdgpu_userqueue_index(uq_mgr, queue);
> + if (queue->queue_id < 0) {
> + DRM_ERROR("Failed to allocate a queue id\n");
> + r = queue->queue_id;
> + goto free_queue;
> + }
> +
> + list_add_tail(&queue->userq_node, &uq_mgr->userq_list);
> + args->out.q_id = queue->queue_id;
> + args->out.flags = 0;
> + mutex_unlock(&uq_mgr->userq_mutex);
> + return 0;
> +
> +free_queue:
> + mutex_unlock(&uq_mgr->userq_mutex);
> + kfree(queue);
> + return r;
> +}
> +
> +static void amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)
> +{
> + struct amdgpu_fpriv *fpriv = filp->driver_priv;
> + struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;
> + struct amdgpu_usermode_queue *queue;
> +
> + queue = amdgpu_userqueue_find(uq_mgr, queue_id);
> + if (!queue) {
> + DRM_DEBUG_DRIVER("Invalid queue id to destroy\n");
> + return;
> + }
> +
> + mutex_lock(&uq_mgr->userq_mutex);
> + amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
> + list_del(&queue->userq_node);
> + 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)
> +{
> + mutex_init(&userq_mgr->userq_mutex);
> + idr_init_base(&userq_mgr->userq_idr, 1);
> + INIT_LIST_HEAD(&userq_mgr->userq_list);
Why do you need an extra list when you already have the idr?
Apart from those nit picks looks good to me.
Christian.
> + 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);
> +}
> diff --git a/drivers/gpu/drm/amd/include/amdgpu_userqueue.h b/drivers/gpu/drm/amd/include/amdgpu_userqueue.h
> new file mode 100644
> index 000000000000..9557588fe34f
> --- /dev/null
> +++ b/drivers/gpu/drm/amd/include/amdgpu_userqueue.h
> @@ -0,0 +1,64 @@
> +/*
> + * Copyright 2022 Advanced Micro Devices, Inc.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + *
> + */
> +
> +#ifndef AMDGPU_USERQUEUE_H_
> +#define AMDGPU_USERQUEUE_H_
> +
> +#define AMDGPU_MAX_USERQ 512
> +
> +struct amdgpu_userq_mgr {
> + struct idr userq_idr;
> + struct mutex userq_mutex;
> + struct list_head userq_list;
> + struct amdgpu_device *adev;
> +};
> +
> +struct amdgpu_usermode_queue {
> + int queue_id;
> + int queue_type;
> + int queue_size;
> + int pasid;
> + int doorbell_index;
> + int use_doorbell;
> +
> + uint64_t wptr_gpu_addr;
> + uint64_t rptr_gpu_addr;
> + uint64_t queue_gpu_addr;
> + uint64_t flags;
> +
> + uint64_t mqd_gpu_addr;
> + void *mqd_cpu_ptr;
> +
> + struct amdgpu_bo *mqd_obj;
> + struct amdgpu_vm *vm;
> + struct amdgpu_userq_mgr *userq_mgr;
> + struct list_head userq_node;
> +};
> +
> +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);
> +
> +#endif
next prev parent reply other threads:[~2023-02-07 7:09 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-03 21:54 [PATCH 0/8] AMDGPU usermode queues Shashank Sharma
2023-02-03 21:54 ` [PATCH 1/8] drm/amdgpu: UAPI for user queue management Shashank Sharma
2023-02-03 22:07 ` Alex Deucher
2023-02-03 22:26 ` Shashank Sharma
2023-02-06 16:56 ` Alex Deucher
2023-02-06 17:01 ` Christian König
2023-02-06 21:03 ` Alex Deucher
2023-02-07 7:03 ` Christian König
2023-02-07 7:38 ` Shashank Sharma
2023-02-07 14:07 ` Alex Deucher
2023-02-07 14:11 ` Christian König
2023-02-07 14:17 ` Alex Deucher
2023-02-07 14:19 ` Christian König
2023-02-07 14:20 ` Alex Deucher
2023-02-07 14:36 ` Shashank Sharma
2023-02-03 21:54 ` [PATCH 2/8] drm/amdgpu: add usermode queues Shashank Sharma
2023-02-07 7:08 ` Christian König [this message]
2023-02-07 7:40 ` Shashank Sharma
2023-02-07 14:54 ` Alex Deucher
2023-02-07 15:02 ` Shashank Sharma
2023-02-03 21:54 ` [PATCH 3/8] drm/amdgpu: introduce userqueue MQD handlers Shashank Sharma
2023-02-07 7:11 ` Christian König
2023-02-07 7:41 ` Shashank Sharma
2023-02-07 14:59 ` Alex Deucher
2023-02-03 21:54 ` [PATCH 4/8] drm/amdgpu: Add V11 graphics MQD functions Shashank Sharma
2023-02-07 15:17 ` Alex Deucher
2023-02-07 15:43 ` Shashank Sharma
2023-02-07 16:05 ` Alex Deucher
2023-02-07 16:37 ` Shashank Sharma
2023-02-07 16:54 ` Alex Deucher
2023-02-07 17:13 ` Shashank Sharma
2023-02-07 17:57 ` Alex Deucher
2023-02-07 18:28 ` Shashank Sharma
2023-02-07 18:32 ` Alex Deucher
2023-02-03 21:54 ` [PATCH 5/8] drm/amdgpu: Create context for usermode queue Shashank Sharma
2023-02-07 7:14 ` Christian König
2023-02-07 7:51 ` Shashank Sharma
2023-02-07 7:55 ` Christian König
2023-02-07 8:13 ` Shashank Sharma
2023-02-07 16:51 ` Alex Deucher
2023-02-07 16:53 ` Alex Deucher
2023-02-03 21:54 ` [PATCH 6/8] drm/amdgpu: Map userqueue into HW Shashank Sharma
2023-02-07 7:20 ` Christian König
2023-02-07 7:55 ` Shashank Sharma
2023-02-03 21:54 ` [PATCH 7/8] drm/amdgpu: DO-NOT-MERGE add busy-waiting delay Shashank Sharma
2023-02-03 21:54 ` [PATCH 8/8] drm/amdgpu: DO-NOT-MERGE doorbell hack Shashank Sharma
2023-02-06 0:52 ` [PATCH 0/8] AMDGPU usermode queues Dave Airlie
2023-02-06 8:57 ` Christian König
2023-02-06 15:39 ` Michel Dänzer
2023-02-06 16:11 ` Alex Deucher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ecb47e10-43db-af4e-ae3b-c0321dcd8e2a@amd.com \
--to=christian.koenig@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=contactshashanksharma@gmail.com \
--cc=shashank.sharma@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.