This commit introduces a new function amdgpu_profiler_set_perfcount which sets the device-wide PMC enablement indicator.
Signed-off-by: Zhu Lingshan <[email protected]> Reviewed-by: Benjamin Welton <[email protected]> --- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c | 32 +++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h | 2 ++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c index e441eb171c1b..f10d6ac49bd7 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c @@ -2988,6 +2988,7 @@ static int amdgpu_drm_release(struct inode *inode, struct file *filp) amdgpu_evf_mgr_flush_suspend(&fpriv->evf_mgr); amdgpu_userq_mgr_fini(&fpriv->userq_mgr); amdgpu_evf_mgr_fini(&fpriv->evf_mgr); + amdgpu_profiler_set_perfcount(drm_to_adev(dev), file_priv, false); amdgpu_profiler_release_device(drm_to_adev(dev), file_priv); drm_dev_exit(idx); } diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c index a15149720d52..276dc75f0e7d 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c @@ -79,6 +79,36 @@ static void amdgpu_profiler_clear_reservation(struct amdgpu_device *adev) mutex_unlock(&adev->pmc_profiler.lock); } +int amdgpu_profiler_set_perfcount(struct amdgpu_device *adev, + struct drm_file *filp, bool enable) +{ + int ret = 0; + + mutex_lock(&adev->pmc_profiler.lock); + + if (adev->pmc_profiler.owner != filp) { + ret = -EBUSY; + goto out; + } + + if (amdgpu_in_reset(adev)) { + ret = -EIO; + goto out; + } + + if (adev->userq_halt_for_enforce_isolation) { + ret = -EAGAIN; + goto out; + } + + adev->pmc_profiler.enable = enable; + +out: + mutex_unlock(&adev->pmc_profiler.lock); + + return ret; +} + static int amdgpu_profiler_check_access(struct drm_device *dev) { if (!perfmon_capable()) @@ -127,7 +157,7 @@ static int amdgpu_profiler_pmc(struct drm_device *dev, struct drm_file *filp, if (ret) return ret; - return -EOPNOTSUPP; + return amdgpu_profiler_set_perfcount(adev, filp, enable); } int amdgpu_profiler_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h index 048ce84f0ef2..532aa7881191 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h @@ -30,6 +30,8 @@ struct amdgpu_device; +int amdgpu_profiler_set_perfcount(struct amdgpu_device *adev, struct drm_file *filp, + bool enable); int amdgpu_profiler_release_device(struct amdgpu_device *adev, struct drm_file *filp); int amdgpu_profiler_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); -- 2.53.0
