drm/amdkfd: Don't require a VM for the profiler PMC lock
Subsystems (3)
PATCH 1/1 drm/amdkfd: Don't require a VM for the profiler PMC lock
The profiler PMC requests now go through kfd_bind_process_to_device() for a runtime PM reference, but that also requires a VM on the GPU. A process that takes the lock before AMDKFD_IOC_ACQUIRE_VM, as rocprofiler-sdk can, now gets -ENODEV.
Take only the runtime PM reference, through a new kfd_process_device_runtime_get() method that kfd_bind_process_to_device() uses as well.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 17 ++++---- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 1 + drivers/gpu/drm/amd/amdkfd/kfd_process.c | 54 ++++++++++++++++-------- 3 files changed, 46 insertions(+), 26 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +9 -8
@@ -3396,19 +3396,20 @@ static inline int profile_lock_device(struct kfd_process *p,struct kfd_dev *kfd;int status = -EINVAL ;struct amdgpu_ptl *ptl; +int r =0 ;if (!p)return -EINVAL ;mutex_lock (&p->mutex); pdd =kfd_process_device_data_by_id (p, gpu_id); -/* Bind for the runtime PM reference before programming the perfmon clock */ +/* Runtime PM reference only: the caller may have no VM on this GPU yet */ if (pdd && op ==1 ) - pdd =kfd_bind_process_to_device (pdd->dev, p); + r =kfd_process_device_runtime_get (pdd);mutex_unlock (&p->mutex); -if (IS_ERR (pdd)) -return PTR_ERR (pdd); +if (r) +return r;if (!pdd || !pdd->dev || !pdd->dev->kfd)return -EINVAL ;
@@ -3474,13 +3475,13 @@ static int kfd_profiler_perfmon_clk(struct kfd_process *p, uint32_t gpu_id,mutex_lock (&p->mutex); pdd =kfd_process_device_data_by_id (p, gpu_id); -/* Bind for the runtime PM reference before programming the perfmon clock */ +/* Runtime PM reference only: the caller may have no VM on this GPU yet */ if (pdd && enable) - pdd =kfd_bind_process_to_device (pdd->dev, p); + r =kfd_process_device_runtime_get (pdd);mutex_unlock (&p->mutex); -if (IS_ERR (pdd)) -return PTR_ERR (pdd); +if (r) +return r;if (!pdd || !pdd->dev || !pdd->dev->kfd)return -EINVAL ;
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -0
@@ -1152,6 +1152,7 @@ int kfd_process_device_init_vm(struct kfd_process_device *pdd, struct file *drm_file);struct kfd_process_device *kfd_bind_process_to_device (struct kfd_node *dev,struct kfd_process *p); +int kfd_process_device_runtime_get (struct kfd_process_device *pdd);struct kfd_process_device *kfd_get_process_device_data (struct kfd_node *dev,struct kfd_process *p); struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev,
drivers/gpu/drm/amd/amdkfd/kfd_process.c +36 -18
66 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] drm/amdkfd: missing Fixes trailer for commit 8a2a98891184 --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] drm/amdkfd: missing Fixes trailer for commit 8a2a98891184 --
commit 28d61bf0c9928d470a0760fe0edf0322918e49c9
Author: Apurv Mishra <[email protected]>
Quoted 7 lines
drm/amdkfd: Don't require a VM for the profiler PMC lock
The profiler PMC requests now go through
kfd_bind_process_to_device()for a runtime PM reference, but that also requires a VM on the GPU. A process that takes the lock beforeAMDKFD_IOC_ACQUIRE_VM, as rocprofiler-sdk can, now gets-ENODEV.
Quoted 5 lines
Take only the runtime PM reference, through a new
kfd_process_device_runtime_get()method thatkfd_bind_process_to_device()uses as well.Signed-off-by Apurv Mishra <[email protected]>
[Severity: Low]
This fixes the -ENODEV failure introduced when profile_lock_device() and kfd_profiler_perfmon_clk() began calling kfd_bind_process_to_device(). Should the commit message include a Fixes tag?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 147 lines · Apurv Mishra
The profiler PMC requests now go through
kfd_bind_process_to_device()for a runtime PM reference, but that also requires a VM on the GPU. A process that takes the lock beforeAMDKFD_IOC_ACQUIRE_VM, as rocprofiler-sdk can, now gets-ENODEV.Take only the runtime PM reference, through a new
kfd_process_device_runtime_get()method thatkfd_bind_process_to_device()uses as well.Signed-off-by Apurv Mishra<[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 17 ++++---- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 1 + drivers/gpu/drm/amd/amdkfd/kfd_process.c | 54 ++++++++++++++++-------- 3 files changed, 46 insertions(+), 26 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +9
-8@@ -3396,19 +3396,20 @@ static inline int profile_lock_device(struct kfd_process *p,struct kfd_dev *kfd;int status = -EINVAL ;struct amdgpu_ptl *ptl; +int r =0 ;if (!p)return -EINVAL ;mutex_lock (&p->mutex); pdd =kfd_process_device_data_by_id (p, gpu_id); -/* Bind for the runtime PM reference before programming the perfmon clock */ +/* Runtime PM reference only: the caller may have no VM on this GPU yet */ if (pdd && op ==1 ) - pdd =kfd_bind_process_to_device (pdd->dev, p); + r =kfd_process_device_runtime_get (pdd);mutex_unlock (&p->mutex); -if (IS_ERR (pdd)) -return PTR_ERR (pdd); +if (r) +return r;if (!pdd || !pdd->dev || !pdd->dev->kfd)return -EINVAL ;@@ -3474,13 +3475,13 @@ static int kfd_profiler_perfmon_clk(struct kfd_process *p, uint32_t gpu_id,mutex_lock (&p->mutex); pdd =kfd_process_device_data_by_id (p, gpu_id); -/* Bind for the runtime PM reference before programming the perfmon clock */ +/* Runtime PM reference only: the caller may have no VM on this GPU yet */ if (pdd && enable) - pdd =kfd_bind_process_to_device (pdd->dev, p); + r =kfd_process_device_runtime_get (pdd);mutex_unlock (&p->mutex); -if (IS_ERR (pdd)) -return PTR_ERR (pdd); +if (r) +return r;if (!pdd || !pdd->dev || !pdd->dev->kfd)return -EINVAL ;drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1
-0@@ -1152,6 +1152,7 @@ int kfd_process_device_init_vm(struct kfd_process_device *pdd, struct file *drm_file);struct kfd_process_device *kfd_bind_process_to_device (struct kfd_node *dev,struct kfd_process *p); +int kfd_process_device_runtime_get (struct kfd_process_device *pdd);struct kfd_process_device *kfd_get_process_device_data (struct kfd_node *dev,struct kfd_process *p); struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev,drivers/gpu/drm/amd/amdkfd/kfd_process.c +36
-18@@ -2010,6 +2010,39 @@ int kfd_process_device_init_vm(struct kfd_process_device *pdd,return ret; } +/* +* Keep the device out of runtime suspend until the pdd is destroyed. Unlike +* kfd_bind_process_to_device(), this doesn't need a VM on the device. +* +* Assumes that the process lock is held. +*/ +int kfd_process_device_runtime_get (struct kfd_process_device *pdd) +{ +struct device *dev =adev_to_drm (pdd->dev->adev)->dev; +int err; + +/* +* make sure that runtime_usage counter is incremented just once +* per pdd +*/ +if (pdd->runtime_inuse) +return 0 ; + +/* +* signal runtime-pm system to auto resume and prevent +* further runtime suspend once device pdd is created until +* pdd is destroyed. +*/ + err =pm_runtime_get_sync (dev); +if (err <0 ) { +pm_runtime_put_autosuspend (dev); +return err; + } + pdd->runtime_inuse = true; + +return 0 ; +} +/* * Direct the IOMMU to bind the process (specifically the pasid->mm) * to the device. @@ -2032,24 +2065,9 @@ struct kfd_process_device *kfd_bind_process_to_device(struct kfd_node *dev,if (!pdd->drm_priv)return ERR_PTR (-ENODEV ); -/* -* signal runtime-pm system to auto resume and prevent -* further runtime suspend once device pdd is created until -* pdd is destroyed. -*/ -if (!pdd->runtime_inuse) { - err =pm_runtime_get_sync (adev_to_drm (dev->adev)->dev); -if (err <0 ) { -pm_runtime_put_autosuspend (adev_to_drm (dev->adev)->dev); -return ERR_PTR (err); - } - } - -/* -* make sure that runtime_usage counter is incremented just once -* per pdd -*/ - pdd->runtime_inuse = true; + err =kfd_process_device_runtime_get (pdd); +if (err) +return ERR_PTR (err);return pdd; }