[Public]

Here it may need to test the uq_mgr list to see whether it is a fresh list 
before adding it to the userq_mgr_list; otherwise, it may add a duplicated 
uq_mgr list. I have sent a patch for that check.

Regards,
      Prike

> -----Original Message-----
> From: amd-gfx <amd-gfx-boun...@lists.freedesktop.org> On Behalf Of Alex
> Deucher
> Sent: Friday, March 21, 2025 12:53 AM
> To: amd-gfx@lists.freedesktop.org; Paneer Selvam, Arunpravin
> <arunpravin.paneersel...@amd.com>
> Cc: Deucher, Alexander <alexander.deuc...@amd.com>
> Subject: [PATCH 1/2] drm/amdgpu: store userq_managers in a list in adev
>
> So we can iterate across them when we need to manage all user queues.
>
> Signed-off-by: Alex Deucher <alexander.deuc...@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu.h           |  3 +++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |  3 +++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 15 ++++++++++++++-
> drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h |  1 +
>  4 files changed, 21 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index 4f770a362048a..28cfa600b798f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -1228,6 +1228,9 @@ struct amdgpu_device {
>        * in KFD: VRAM or GTT.
>        */
>       bool                            apu_prefer_gtt;
> +
> +     struct list_head                userq_mgr_list;
> +     struct mutex                    userq_mutex;
>  };
>
>  static inline uint32_t amdgpu_ip_version(const struct amdgpu_device *adev, 
> diff --
> git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 0396ac30c2a4f..526c5aa32825a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -4299,6 +4299,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
>       mutex_init(&adev->gfx.kfd_sch_mutex);
>       mutex_init(&adev->gfx.workload_profile_mutex);
>       mutex_init(&adev->vcn.workload_profile_mutex);
> +     mutex_init(&adev->userq_mutex);
>
>       amdgpu_device_init_apu_flags(adev);
>
> @@ -4326,6 +4327,8 @@ int amdgpu_device_init(struct amdgpu_device *adev,
>
>       INIT_LIST_HEAD(&adev->pm.od_kobj_list);
>
> +     INIT_LIST_HEAD(&adev->userq_mgr_list);
> +
>       INIT_DELAYED_WORK(&adev->delayed_init_work,
>                         amdgpu_device_delayed_init_work_handler);
>       INIT_DELAYED_WORK(&adev->gfx.gfx_off_delay_work,
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
> index a02614cbda36e..b89bfad52abd5 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
> @@ -365,6 +365,9 @@ amdgpu_userqueue_create(struct drm_file *filp, union
> drm_amdgpu_userq *args)
>               goto unlock;
>       }
>       args->out.queue_id = qid;
> +     mutex_lock(&adev->userq_mutex);
> +     list_add(&uq_mgr->list, &adev->userq_mgr_list);
> +     mutex_unlock(&adev->userq_mutex);
>
>  unlock:
>       mutex_unlock(&uq_mgr->userq_mutex);
> @@ -661,14 +664,24 @@ int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr
> *userq_mgr, struct amdgpu_devi
>
>  void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr)  {
> -     uint32_t queue_id;
> +     struct amdgpu_device *adev = userq_mgr->adev;
>       struct amdgpu_usermode_queue *queue;
> +     struct amdgpu_userq_mgr *uqm, *tmp;
> +     uint32_t queue_id;
>
>       cancel_delayed_work(&userq_mgr->resume_work);
>
>       mutex_lock(&userq_mgr->userq_mutex);
>       idr_for_each_entry(&userq_mgr->userq_idr, queue, queue_id)
>               amdgpu_userqueue_cleanup(userq_mgr, queue, queue_id);
> +     mutex_lock(&adev->userq_mutex);
> +     list_for_each_entry_safe(uqm, tmp, &adev->userq_mgr_list, list) {
> +             if (uqm == userq_mgr) {
> +                     list_del(&uqm->list);
> +                     break;
> +             }
> +     }
> +     mutex_unlock(&adev->userq_mutex);
>       idr_destroy(&userq_mgr->userq_idr);
>       mutex_unlock(&userq_mgr->userq_mutex);
>       mutex_destroy(&userq_mgr->userq_mutex);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h
> index 0f358f77f2d9b..ec1a4ca6f6321 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h
> @@ -76,6 +76,7 @@ struct amdgpu_userq_mgr {
>       struct mutex                    userq_mutex;
>       struct amdgpu_device            *adev;
>       struct delayed_work             resume_work;
> +     struct list_head                list;
>  };
>
>  struct amdgpu_db_info {
> --
> 2.49.0

Reply via email to