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]> --- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c | 23 +++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.h | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c index 3dc563a64639..5b86fa50a95e 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 6464af0d1b10..254fb8d77d80 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_profiler.c @@ -77,6 +77,27 @@ 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; + + mutex_lock(&adev->pmc_profiler.lock); + + if (adev->pmc_profiler.owner == filp) { + /* set device-wide PMC enablement bit, + * new created queues inherit it. + */ + adev->pmc_profiler.enable = enable; + ret = 0; + } else + ret = -EBUSY; + + mutex_unlock(&adev->pmc_profiler.lock); + + return ret; +} + static int amdgpu_profiler_check_access(struct drm_device *dev) { if (!perfmon_capable()) @@ -120,7 +141,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(drm_to_adev(dev), 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.55.0
