[PATCH] drm/ttm: nuke ttm_bo_evict_mm and rename mgr function v2
Daniel Vetter
daniel at ffwll.ch
Mon Oct 5 15:38:23 UTC 2020
On Mon, Oct 5, 2020 at 4:27 PM Christian König
<ckoenig.leichtzumerken at gmail.com> wrote:
>
> Make it more clear what the resource manager function
> does and nuke the wrapper function.
>
> v2: nuke the wrapper
>
> Signed-off-by: Christian König <christian.koenig at amd.com>
Reviewed-by: Daniel Vetter <daniel.vetter at ffwll.ch>
I think adding a bdev back pointer to res_man would be nice and would
allow us to drop that pointer too, for some really pretty object
oriented feel in the api :-) But maybe follow up patch.
-Daniel
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 5 ++++-
> drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 2 +-
> drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 6 +++++-
> drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 2 +-
> drivers/gpu/drm/nouveau/nouveau_drm.c | 5 ++++-
> drivers/gpu/drm/nouveau/nouveau_ttm.c | 4 ++--
> drivers/gpu/drm/qxl/qxl_object.c | 10 ++++++++--
> drivers/gpu/drm/radeon/radeon_object.c | 6 +++++-
> drivers/gpu/drm/ttm/ttm_bo.c | 18 -----------------
> drivers/gpu/drm/ttm/ttm_range_manager.c | 2 +-
> drivers/gpu/drm/ttm/ttm_resource.c | 10 +++++-----
> drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 12 ++++++++---
> drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c | 2 +-
> drivers/gpu/drm/vmwgfx/vmwgfx_thp.c | 2 +-
> include/drm/ttm/ttm_bo_api.h | 20 -------------------
> include/drm/ttm/ttm_resource.h | 4 ++--
> 16 files changed, 49 insertions(+), 61 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> index abe0c2729e1c..a5e08dc54e4a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> @@ -1319,6 +1319,7 @@ 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 = drm_to_adev(dev);
> + struct ttm_resource_manager *man;
> int r;
>
> r = pm_runtime_get_sync(dev->dev);
> @@ -1327,7 +1328,9 @@ static int amdgpu_debugfs_evict_gtt(struct seq_file *m, void *data)
> return r;
> }
>
> - seq_printf(m, "(%d)\n", ttm_bo_evict_mm(&adev->mman.bdev, TTM_PL_TT));
> + man = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT);
> + r = ttm_resource_manager_evict_all(&adev->mman.bdev, man);
> + seq_printf(m, "(%d)\n", r);
>
> pm_runtime_mark_last_busy(dev->dev);
> pm_runtime_put_autosuspend(dev->dev);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> index f203e4a6a3f2..1721739def84 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> @@ -136,7 +136,7 @@ void amdgpu_gtt_mgr_fini(struct amdgpu_device *adev)
>
> ttm_resource_manager_set_used(man, false);
>
> - ret = ttm_resource_manager_force_list_clean(&adev->mman.bdev, man);
> + ret = ttm_resource_manager_evict_all(&adev->mman.bdev, man);
> if (ret)
> return;
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index 964f9512dd6e..1aa516429c80 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -1019,6 +1019,8 @@ void amdgpu_bo_unpin(struct amdgpu_bo *bo)
> */
> int amdgpu_bo_evict_vram(struct amdgpu_device *adev)
> {
> + struct ttm_resource_manager *man;
> +
> /* late 2.6.33 fix IGP hibernate - we need pm ops to do this correct */
> #ifndef CONFIG_HIBERNATION
> if (adev->flags & AMD_IS_APU) {
> @@ -1026,7 +1028,9 @@ int amdgpu_bo_evict_vram(struct amdgpu_device *adev)
> return 0;
> }
> #endif
> - return ttm_bo_evict_mm(&adev->mman.bdev, TTM_PL_VRAM);
> +
> + man = ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM);
> + return ttm_resource_manager_evict_all(&adev->mman.bdev, man);
> }
>
> static const char *amdgpu_vram_names[] = {
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> index 01c1171afbe0..7747be644dd0 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> @@ -212,7 +212,7 @@ void amdgpu_vram_mgr_fini(struct amdgpu_device *adev)
>
> ttm_resource_manager_set_used(man, false);
>
> - ret = ttm_resource_manager_force_list_clean(&adev->mman.bdev, man);
> + ret = ttm_resource_manager_evict_all(&adev->mman.bdev, man);
> if (ret)
> return;
>
> diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouveau/nouveau_drm.c
> index 72640bca1617..d141a5f004af 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_drm.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_drm.c
> @@ -820,6 +820,7 @@ static int
> nouveau_do_suspend(struct drm_device *dev, bool runtime)
> {
> struct nouveau_drm *drm = nouveau_drm(dev);
> + struct ttm_resource_manager *man;
> int ret;
>
> nouveau_svm_suspend(drm);
> @@ -836,7 +837,9 @@ nouveau_do_suspend(struct drm_device *dev, bool runtime)
> }
>
> NV_DEBUG(drm, "evicting buffers...\n");
> - ttm_bo_evict_mm(&drm->ttm.bdev, TTM_PL_VRAM);
> +
> + man = ttm_manager_type(&drm->ttm.bdev, TTM_PL_VRAM);
> + ttm_resource_manager_evict_all(&drm->ttm.bdev, man);
>
> NV_DEBUG(drm, "waiting for kernel channels to go idle...\n");
> if (drm->cechan) {
> diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
> index 2fb127da0208..0f1a1141e526 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
> @@ -222,7 +222,7 @@ nouveau_ttm_fini_vram(struct nouveau_drm *drm)
>
> if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
> ttm_resource_manager_set_used(man, false);
> - ttm_resource_manager_force_list_clean(&drm->ttm.bdev, man);
> + ttm_resource_manager_evict_all(&drm->ttm.bdev, man);
> ttm_resource_manager_cleanup(man);
> ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_VRAM, NULL);
> kfree(man);
> @@ -267,7 +267,7 @@ nouveau_ttm_fini_gtt(struct nouveau_drm *drm)
> ttm_range_man_fini(&drm->ttm.bdev, TTM_PL_TT);
> else {
> ttm_resource_manager_set_used(man, false);
> - ttm_resource_manager_force_list_clean(&drm->ttm.bdev, man);
> + ttm_resource_manager_evict_all(&drm->ttm.bdev, man);
> ttm_resource_manager_cleanup(man);
> ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_TT, NULL);
> kfree(man);
> diff --git a/drivers/gpu/drm/qxl/qxl_object.c b/drivers/gpu/drm/qxl/qxl_object.c
> index 5ba8aac00f5c..547d46c14d56 100644
> --- a/drivers/gpu/drm/qxl/qxl_object.c
> +++ b/drivers/gpu/drm/qxl/qxl_object.c
> @@ -351,10 +351,16 @@ int qxl_bo_check_id(struct qxl_device *qdev, struct qxl_bo *bo)
>
> int qxl_surf_evict(struct qxl_device *qdev)
> {
> - return ttm_bo_evict_mm(&qdev->mman.bdev, TTM_PL_PRIV);
> + struct ttm_resource_manager *man;
> +
> + man = ttm_manager_type(&qdev->mman.bdev, TTM_PL_PRIV);
> + return ttm_resource_manager_evict_all(&qdev->mman.bdev, man);
> }
>
> int qxl_vram_evict(struct qxl_device *qdev)
> {
> - return ttm_bo_evict_mm(&qdev->mman.bdev, TTM_PL_VRAM);
> + struct ttm_resource_manager *man;
> +
> + man = ttm_manager_type(&qdev->mman.bdev, TTM_PL_VRAM);
> + return ttm_resource_manager_evict_all(&qdev->mman.bdev, man);
> }
> diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c
> index a0b2c4541a2a..36d260e302a1 100644
> --- a/drivers/gpu/drm/radeon/radeon_object.c
> +++ b/drivers/gpu/drm/radeon/radeon_object.c
> @@ -374,6 +374,9 @@ void radeon_bo_unpin(struct radeon_bo *bo)
>
> int radeon_bo_evict_vram(struct radeon_device *rdev)
> {
> + struct ttm_device *bdev = &rdev->mman.bdev;
> + struct ttm_resource_manager *man;
> +
> /* late 2.6.33 fix IGP hibernate - we need pm ops to do this correct */
> #ifndef CONFIG_HIBERNATION
> if (rdev->flags & RADEON_IS_IGP) {
> @@ -382,7 +385,8 @@ int radeon_bo_evict_vram(struct radeon_device *rdev)
> return 0;
> }
> #endif
> - return ttm_bo_evict_mm(&rdev->mman.bdev, TTM_PL_VRAM);
> + man = ttm_manager_type(bdev, TTM_PL_VRAM);
> + ttm_resource_manager_evict_all(bdev, man);
> }
>
> void radeon_bo_force_delete(struct radeon_device *rdev)
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 40d1ac91c9bf..61311f69f9f8 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -1173,24 +1173,6 @@ size_t ttm_bo_dma_acc_size(struct ttm_device *bdev,
> }
> EXPORT_SYMBOL(ttm_bo_dma_acc_size);
>
> -int ttm_bo_evict_mm(struct ttm_device *bdev, unsigned mem_type)
> -{
> - struct ttm_resource_manager *man = ttm_manager_type(bdev, mem_type);
> -
> - if (mem_type == 0 || mem_type >= TTM_NUM_MEM_TYPES) {
> - pr_err("Illegal memory manager memory type %u\n", mem_type);
> - return -EINVAL;
> - }
> -
> - if (!man) {
> - pr_err("Memory type %u has not been initialized\n", mem_type);
> - return 0;
> - }
> -
> - return ttm_resource_manager_force_list_clean(bdev, man);
> -}
> -EXPORT_SYMBOL(ttm_bo_evict_mm);
> -
> /*
> * buffer object vm functions.
> */
> diff --git a/drivers/gpu/drm/ttm/ttm_range_manager.c b/drivers/gpu/drm/ttm/ttm_range_manager.c
> index bd3c6c6b4328..9d08728bd98e 100644
> --- a/drivers/gpu/drm/ttm/ttm_range_manager.c
> +++ b/drivers/gpu/drm/ttm/ttm_range_manager.c
> @@ -149,7 +149,7 @@ int ttm_range_man_fini(struct ttm_device *bdev,
>
> ttm_resource_manager_set_used(man, false);
>
> - ret = ttm_resource_manager_force_list_clean(bdev, man);
> + ret = ttm_resource_manager_evict_all(bdev, man);
> if (ret)
> return ret;
>
> diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c
> index 7faa4a6ae28f..e2ee66c7f39c 100644
> --- a/drivers/gpu/drm/ttm/ttm_resource.c
> +++ b/drivers/gpu/drm/ttm/ttm_resource.c
> @@ -75,16 +75,16 @@ void ttm_resource_manager_init(struct ttm_resource_manager *man,
> EXPORT_SYMBOL(ttm_resource_manager_init);
>
> /*
> - * ttm_resource_manager_force_list_clean
> + * ttm_resource_manager_evict_all
> *
> * @bdev - device to use
> * @man - manager to use
> *
> - * Force all the objects out of a memory manager until clean.
> + * Evict all the objects out of a memory manager until it is empty.
> * Part of memory manager cleanup sequence.
> */
> -int ttm_resource_manager_force_list_clean(struct ttm_device *bdev,
> - struct ttm_resource_manager *man)
> +int ttm_resource_manager_evict_all(struct ttm_device *bdev,
> + struct ttm_resource_manager *man)
> {
> struct ttm_operation_ctx ctx = {
> .interruptible = false,
> @@ -126,7 +126,7 @@ int ttm_resource_manager_force_list_clean(struct ttm_device *bdev,
>
> return 0;
> }
> -EXPORT_SYMBOL(ttm_resource_manager_force_list_clean);
> +EXPORT_SYMBOL(ttm_resource_manager_evict_all);
>
> /**
> * ttm_resource_manager_debug
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> index fcda3b76e0df..ff82c3395bfa 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> @@ -468,7 +468,10 @@ static int vmw_request_device(struct vmw_private *dev_priv)
> if (dev_priv->cman)
> vmw_cmdbuf_remove_pool(dev_priv->cman);
> if (dev_priv->has_mob) {
> - (void) ttm_bo_evict_mm(&dev_priv->bdev, VMW_PL_MOB);
> + struct ttm_resource_manager *man;
> +
> + man = ttm_manager_type(&dev_priv->bdev, VMW_PL_MOB);
> + ttm_resource_manager_evict_all(&dev_priv->bdev, man);
> vmw_otables_takedown(dev_priv);
> }
> if (dev_priv->cman)
> @@ -501,7 +504,10 @@ static void vmw_release_device_early(struct vmw_private *dev_priv)
> vmw_cmdbuf_remove_pool(dev_priv->cman);
>
> if (dev_priv->has_mob) {
> - ttm_bo_evict_mm(&dev_priv->bdev, VMW_PL_MOB);
> + struct ttm_resource_manager *man;
> +
> + man = ttm_manager_type(&dev_priv->bdev, VMW_PL_MOB);
> + ttm_resource_manager_evict_all(&dev_priv->bdev, man);
> vmw_otables_takedown(dev_priv);
> }
> }
> @@ -1257,7 +1263,7 @@ void vmw_svga_disable(struct vmw_private *dev_priv)
> if (ttm_resource_manager_used(man)) {
> ttm_resource_manager_set_used(man, false);
> spin_unlock(&dev_priv->svga_lock);
> - if (ttm_bo_evict_mm(&dev_priv->bdev, TTM_PL_VRAM))
> + if (ttm_resource_manager_evict_all(&dev_priv->bdev, man))
> DRM_ERROR("Failed evicting VRAM buffers.\n");
> vmw_write(dev_priv, SVGA_REG_ENABLE,
> SVGA_REG_ENABLE_HIDE |
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
> index db64c3a90285..9e8a3e337b96 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
> @@ -143,7 +143,7 @@ void vmw_gmrid_man_fini(struct vmw_private *dev_priv, int type)
>
> ttm_resource_manager_set_used(man, false);
>
> - ttm_resource_manager_force_list_clean(&dev_priv->bdev, man);
> + ttm_resource_manager_evict_all(&dev_priv->bdev, man);
>
> ttm_resource_manager_cleanup(man);
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
> index 63fe7da4cbf4..328d332a55e2 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
> @@ -149,7 +149,7 @@ void vmw_thp_fini(struct vmw_private *dev_priv)
>
> ttm_resource_manager_set_used(man, false);
>
> - ret = ttm_resource_manager_force_list_clean(&dev_priv->bdev, man);
> + ret = ttm_resource_manager_evict_all(&dev_priv->bdev, man);
> if (ret)
> return;
> spin_lock(&rman->lock);
> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
> index a02935e0d121..f4014f45bd8b 100644
> --- a/include/drm/ttm/ttm_bo_api.h
> +++ b/include/drm/ttm/ttm_bo_api.h
> @@ -448,26 +448,6 @@ int ttm_bo_init(struct ttm_device *bdev, struct ttm_buffer_object *bo,
> struct sg_table *sg, struct dma_resv *resv,
> void (*destroy) (struct ttm_buffer_object *));
>
> -/**
> - * ttm_bo_evict_mm
> - *
> - * @bdev: Pointer to a ttm_device struct.
> - * @mem_type: The memory type.
> - *
> - * Evicts all buffers on the lru list of the memory type.
> - * This is normally part of a VT switch or an
> - * out-of-memory-space-due-to-fragmentation handler.
> - * The caller must make sure that there are no other processes
> - * currently validating buffers, and can do that by taking the
> - * struct ttm_device::ttm_lock in write mode.
> - *
> - * Returns:
> - * -EINVAL: Invalid or uninitialized memory type.
> - * -ERESTARTSYS: The call was interrupted by a signal while waiting to
> - * evict a buffer.
> - */
> -int ttm_bo_evict_mm(struct ttm_device *bdev, unsigned mem_type);
> -
> /**
> * ttm_kmap_obj_virtual
> *
> diff --git a/include/drm/ttm/ttm_resource.h b/include/drm/ttm/ttm_resource.h
> index a60ffe409b60..ce6846c03698 100644
> --- a/include/drm/ttm/ttm_resource.h
> +++ b/include/drm/ttm/ttm_resource.h
> @@ -230,8 +230,8 @@ void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource *res);
> void ttm_resource_manager_init(struct ttm_resource_manager *man,
> unsigned long p_size);
>
> -int ttm_resource_manager_force_list_clean(struct ttm_device *bdev,
> - struct ttm_resource_manager *man);
> +int ttm_resource_manager_evict_all(struct ttm_device *bdev,
> + struct ttm_resource_manager *man);
>
> void ttm_resource_manager_debug(struct ttm_resource_manager *man,
> struct drm_printer *p);
> --
> 2.17.1
>
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
More information about the dri-devel
mailing list