Reviewed-by: Evan Quan <evan.quan@xxxxxxx> > -----Original Message----- > From: amd-gfx <amd-gfx-bounces@xxxxxxxxxxxxxxxxxxxxx> On Behalf Of Alex > Deucher > Sent: Saturday, January 11, 2020 7:45 AM > To: amd-gfx@xxxxxxxxxxxxxxxxxxxxx > Cc: Deucher, Alexander <Alexander.Deucher@xxxxxxx> > Subject: [PATCH 2/2] drm/amdgpu/debugfs: properly handle runtime pm > > If driver debugfs files are accessed, power up the GPU when necessary. > > Signed-off-by: Alex Deucher <alexander.deucher@xxxxxxx> > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 133 > ++++++++++++++++++-- > drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 8 ++ > 2 files changed, 134 insertions(+), 7 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c > b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c > index 63343bb43049..f24ed9a1a3e5 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c > @@ -26,6 +26,7 @@ > #include <linux/kthread.h> > #include <linux/pci.h> > #include <linux/uaccess.h> > +#include <linux/pm_runtime.h> > > #include <drm/drm_debugfs.h> > > @@ -144,10 +145,17 @@ static int amdgpu_debugfs_process_reg_op(bool > read, struct file *f, > > *pos &= (1UL << 22) - 1; > > + r = pm_runtime_get_sync(adev->ddev->dev); > + if (r < 0) > + return r; > + > if (use_bank) { > if ((sh_bank != 0xFFFFFFFF && sh_bank >= adev- > >gfx.config.max_sh_per_se) || > - (se_bank != 0xFFFFFFFF && se_bank >= adev- > >gfx.config.max_shader_engines)) > + (se_bank != 0xFFFFFFFF && se_bank >= adev- > >gfx.config.max_shader_engines)) { > + pm_runtime_mark_last_busy(adev->ddev->dev); > + pm_runtime_put_autosuspend(adev->ddev->dev); > return -EINVAL; > + } > mutex_lock(&adev->grbm_idx_mutex); > amdgpu_gfx_select_se_sh(adev, se_bank, > sh_bank, instance_bank); > @@ -193,6 +201,9 @@ static int amdgpu_debugfs_process_reg_op(bool read, > struct file *f, > if (pm_pg_lock) > mutex_unlock(&adev->pm.mutex); > > + pm_runtime_mark_last_busy(adev->ddev->dev); > + pm_runtime_put_autosuspend(adev->ddev->dev); > + > return result; > } > > @@ -237,13 +248,20 @@ static ssize_t > amdgpu_debugfs_regs_pcie_read(struct file *f, char __user *buf, > if (size & 0x3 || *pos & 0x3) > return -EINVAL; > > + r = pm_runtime_get_sync(adev->ddev->dev); > + if (r < 0) > + return r; > + > while (size) { > uint32_t value; > > value = RREG32_PCIE(*pos >> 2); > r = put_user(value, (uint32_t *)buf); > - if (r) > + if (r) { > + pm_runtime_mark_last_busy(adev->ddev->dev); > + pm_runtime_put_autosuspend(adev->ddev->dev); > return r; > + } > > result += 4; > buf += 4; > @@ -251,6 +269,9 @@ static ssize_t amdgpu_debugfs_regs_pcie_read(struct > file *f, char __user *buf, > size -= 4; > } > > + pm_runtime_mark_last_busy(adev->ddev->dev); > + pm_runtime_put_autosuspend(adev->ddev->dev); > + > return result; > } > > @@ -276,12 +297,19 @@ static ssize_t > amdgpu_debugfs_regs_pcie_write(struct file *f, const char __user > if (size & 0x3 || *pos & 0x3) > return -EINVAL; > > + r = pm_runtime_get_sync(adev->ddev->dev); > + if (r < 0) > + return r; > + > while (size) { > uint32_t value; > > r = get_user(value, (uint32_t *)buf); > - if (r) > + if (r) { > + pm_runtime_mark_last_busy(adev->ddev->dev); > + pm_runtime_put_autosuspend(adev->ddev->dev); > return r; > + } > > WREG32_PCIE(*pos >> 2, value); > > @@ -291,6 +319,9 @@ static ssize_t amdgpu_debugfs_regs_pcie_write(struct > file *f, const char __user > size -= 4; > } > > + pm_runtime_mark_last_busy(adev->ddev->dev); > + pm_runtime_put_autosuspend(adev->ddev->dev); > + > return result; > } > > @@ -316,13 +347,20 @@ static ssize_t > amdgpu_debugfs_regs_didt_read(struct file *f, char __user *buf, > if (size & 0x3 || *pos & 0x3) > return -EINVAL; > > + r = pm_runtime_get_sync(adev->ddev->dev); > + if (r < 0) > + return r; > + > while (size) { > uint32_t value; > > value = RREG32_DIDT(*pos >> 2); > r = put_user(value, (uint32_t *)buf); > - if (r) > + if (r) { > + pm_runtime_mark_last_busy(adev->ddev->dev); > + pm_runtime_put_autosuspend(adev->ddev->dev); > return r; > + } > > result += 4; > buf += 4; > @@ -330,6 +368,9 @@ static ssize_t amdgpu_debugfs_regs_didt_read(struct > file *f, char __user *buf, > size -= 4; > } > > + pm_runtime_mark_last_busy(adev->ddev->dev); > + pm_runtime_put_autosuspend(adev->ddev->dev); > + > return result; > } > > @@ -355,12 +396,19 @@ static ssize_t > amdgpu_debugfs_regs_didt_write(struct file *f, const char __user > if (size & 0x3 || *pos & 0x3) > return -EINVAL; > > + r = pm_runtime_get_sync(adev->ddev->dev); > + if (r < 0) > + return r; > + > while (size) { > uint32_t value; > > r = get_user(value, (uint32_t *)buf); > - if (r) > + if (r) { > + pm_runtime_mark_last_busy(adev->ddev->dev); > + pm_runtime_put_autosuspend(adev->ddev->dev); > return r; > + } > > WREG32_DIDT(*pos >> 2, value); > > @@ -370,6 +418,9 @@ static ssize_t amdgpu_debugfs_regs_didt_write(struct > file *f, const char __user > size -= 4; > } > > + pm_runtime_mark_last_busy(adev->ddev->dev); > + pm_runtime_put_autosuspend(adev->ddev->dev); > + > return result; > } > > @@ -395,13 +446,20 @@ static ssize_t > amdgpu_debugfs_regs_smc_read(struct file *f, char __user *buf, > if (size & 0x3 || *pos & 0x3) > return -EINVAL; > > + r = pm_runtime_get_sync(adev->ddev->dev); > + if (r < 0) > + return r; > + > while (size) { > uint32_t value; > > value = RREG32_SMC(*pos); > r = put_user(value, (uint32_t *)buf); > - if (r) > + if (r) { > + pm_runtime_mark_last_busy(adev->ddev->dev); > + pm_runtime_put_autosuspend(adev->ddev->dev); > return r; > + } > > result += 4; > buf += 4; > @@ -409,6 +467,9 @@ static ssize_t amdgpu_debugfs_regs_smc_read(struct > file *f, char __user *buf, > size -= 4; > } > > + pm_runtime_mark_last_busy(adev->ddev->dev); > + pm_runtime_put_autosuspend(adev->ddev->dev); > + > return result; > } > > @@ -434,12 +495,19 @@ static ssize_t > amdgpu_debugfs_regs_smc_write(struct file *f, const char __user * > if (size & 0x3 || *pos & 0x3) > return -EINVAL; > > + r = pm_runtime_get_sync(adev->ddev->dev); > + if (r < 0) > + return r; > + > while (size) { > uint32_t value; > > r = get_user(value, (uint32_t *)buf); > - if (r) > + if (r) { > + pm_runtime_mark_last_busy(adev->ddev->dev); > + pm_runtime_put_autosuspend(adev->ddev->dev); > return r; > + } > > WREG32_SMC(*pos, value); > > @@ -449,6 +517,9 @@ static ssize_t amdgpu_debugfs_regs_smc_write(struct > file *f, const char __user * > size -= 4; > } > > + pm_runtime_mark_last_busy(adev->ddev->dev); > + pm_runtime_put_autosuspend(adev->ddev->dev); > + > return result; > } > > @@ -572,7 +643,16 @@ static ssize_t amdgpu_debugfs_sensor_read(struct file > *f, char __user *buf, > idx = *pos >> 2; > > valuesize = sizeof(values); > + > + r = pm_runtime_get_sync(adev->ddev->dev); > + if (r < 0) > + return r; > + > r = amdgpu_dpm_read_sensor(adev, idx, &values[0], &valuesize); > + > + pm_runtime_mark_last_busy(adev->ddev->dev); > + pm_runtime_put_autosuspend(adev->ddev->dev); > + > if (r) > return r; > > @@ -633,6 +713,10 @@ static ssize_t amdgpu_debugfs_wave_read(struct file > *f, char __user *buf, > wave = (*pos & GENMASK_ULL(36, 31)) >> 31; > simd = (*pos & GENMASK_ULL(44, 37)) >> 37; > > + r = pm_runtime_get_sync(adev->ddev->dev); > + if (r < 0) > + return r; > + > /* switch to the specific se/sh/cu */ > mutex_lock(&adev->grbm_idx_mutex); > amdgpu_gfx_select_se_sh(adev, se, sh, cu); @@ -644,6 +728,9 @@ > static ssize_t amdgpu_debugfs_wave_read(struct file *f, char __user *buf, > amdgpu_gfx_select_se_sh(adev, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); > mutex_unlock(&adev->grbm_idx_mutex); > > + pm_runtime_mark_last_busy(adev->ddev->dev); > + pm_runtime_put_autosuspend(adev->ddev->dev); > + > if (!x) > return -EINVAL; > > @@ -711,6 +798,10 @@ static ssize_t amdgpu_debugfs_gpr_read(struct file *f, > char __user *buf, > if (!data) > return -ENOMEM; > > + r = pm_runtime_get_sync(adev->ddev->dev); > + if (r < 0) > + return r; > + > /* switch to the specific se/sh/cu */ > mutex_lock(&adev->grbm_idx_mutex); > amdgpu_gfx_select_se_sh(adev, se, sh, cu); @@ -726,6 +817,9 @@ > static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf, > amdgpu_gfx_select_se_sh(adev, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); > mutex_unlock(&adev->grbm_idx_mutex); > > + pm_runtime_mark_last_busy(adev->ddev->dev); > + pm_runtime_put_autosuspend(adev->ddev->dev); > + > while (size) { > uint32_t value; > > @@ -859,6 +953,10 @@ static int amdgpu_debugfs_test_ib(struct seq_file *m, > void *data) > struct amdgpu_device *adev = dev->dev_private; > int r = 0, i; > > + r = pm_runtime_get_sync(dev->dev); > + if (r < 0) > + return r; > + > /* Avoid accidently unparking the sched thread during GPU reset */ > mutex_lock(&adev->lock_reset); > > @@ -889,6 +987,9 @@ static int amdgpu_debugfs_test_ib(struct seq_file *m, > void *data) > > mutex_unlock(&adev->lock_reset); > > + pm_runtime_mark_last_busy(dev->dev); > + pm_runtime_put_autosuspend(dev->dev); > + > return 0; > } > > @@ -907,8 +1008,17 @@ static int amdgpu_debugfs_evict_vram(struct > seq_file *m, void *data) > struct drm_info_node *node = (struct drm_info_node *)m->private; > struct drm_device *dev = node->minor->dev; > struct amdgpu_device *adev = dev->dev_private; > + int r; > + > + r = pm_runtime_get_sync(dev->dev); > + if (r < 0) > + return r; > > seq_printf(m, "(%d)\n", amdgpu_bo_evict_vram(adev)); > + > + pm_runtime_mark_last_busy(dev->dev); > + pm_runtime_put_autosuspend(dev->dev); > + > return 0; > } > > @@ -917,8 +1027,17 @@ static int amdgpu_debugfs_evict_gtt(struct seq_file > *m, void *data) > struct drm_info_node *node = (struct drm_info_node *)m->private; > struct drm_device *dev = node->minor->dev; > struct amdgpu_device *adev = dev->dev_private; > + int r; > + > + r = pm_runtime_get_sync(dev->dev); > + if (r < 0) > + return r; > > seq_printf(m, "(%d)\n", ttm_bo_evict_mm(&adev->mman.bdev, > TTM_PL_TT)); > + > + pm_runtime_mark_last_busy(dev->dev); > + pm_runtime_put_autosuspend(dev->dev); > + > return 0; > } > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c > b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c > index e9efee04ca23..3c01252b1e0e 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c > @@ -741,10 +741,18 @@ static int amdgpu_debugfs_gpu_recover(struct > seq_file *m, void *data) > struct drm_info_node *node = (struct drm_info_node *) m->private; > struct drm_device *dev = node->minor->dev; > struct amdgpu_device *adev = dev->dev_private; > + int r; > + > + r = pm_runtime_get_sync(dev->dev); > + if (r < 0) > + return 0; > > seq_printf(m, "gpu recover\n"); > amdgpu_device_gpu_recover(adev, NULL); > > + pm_runtime_mark_last_busy(dev->dev); > + pm_runtime_put_autosuspend(dev->dev); > + > return 0; > } > > -- > 2.24.1 > > _______________________________________________ > amd-gfx mailing list > amd-gfx@xxxxxxxxxxxxxxxxxxxxx > https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.free > desktop.org%2Fmailman%2Flistinfo%2Famd- > gfx&data=02%7C01%7Cevan.quan%40amd.com%7C8e6ecdab282646758a > de08d796272aa0%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637 > 142967348327101&sdata=KaUJb0eNiSNov6amPZ20oxPm6howvbmU093i2 > EAprO0%3D&reserved=0 _______________________________________________ amd-gfx mailing list amd-gfx@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/amd-gfx