[PATCH 1/3] drm/vmwgfx: Add debugfs entries for ttm placements
Daniel Vetter
daniel at ffwll.ch
Mon Apr 4 15:38:50 UTC 2022
On Fri, Apr 01, 2022 at 04:56:00PM -0400, Zack Rusin wrote:
> From: Zack Rusin <zackr at vmware.com>
>
> Add a few debugfs entries for every used TTM placement that vmwgfx is
> using. This allows basic tracking of memory usage inside vmwgfx, e.g.
> 'cat /sys/kernel/debug/dri/0/mob_ttm' will display mob memory usage.
>
> Signed-off-by: Zack Rusin <zackr at vmware.com>
> Reviewed-by: Martin Krastev <krastevm at vmware.com>
> ---
> drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 1 +
> drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 1 +
> drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 97 +++++++++++++++++++++-
> 3 files changed, 98 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> index 791f9a5f3868..6d675855f065 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> @@ -1632,6 +1632,7 @@ static int vmw_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
> goto out_unload;
>
> vmw_debugfs_gem_init(vmw);
> + vmw_ttm_debugfs_init(vmw);
>
> return 0;
> out_unload:
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
> index be19aa6e1f13..eabe3e8e9cf9 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
> @@ -1085,6 +1085,7 @@ vmw_bo_sg_table(struct ttm_buffer_object *bo);
> extern int vmw_bo_create_and_populate(struct vmw_private *dev_priv,
> unsigned long bo_size,
> struct ttm_buffer_object **bo_p);
> +void vmw_ttm_debugfs_init(struct vmw_private *vdev);
>
> extern void vmw_piter_start(struct vmw_piter *viter,
> const struct vmw_sg_table *vsgt,
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
> index b84ecc6d6611..355414595e52 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
> @@ -1,7 +1,7 @@
> // SPDX-License-Identifier: GPL-2.0 OR MIT
> /**************************************************************************
> *
> - * Copyright 2009-2015 VMware, Inc., Palo Alto, CA., USA
> + * Copyright 2009-2022 VMware, Inc., Palo Alto, CA., USA
> *
> * Permission is hereby granted, free of charge, to any person obtaining a
> * copy of this software and associated documentation files (the
> @@ -677,3 +677,98 @@ int vmw_bo_create_and_populate(struct vmw_private *dev_priv,
> *bo_p = bo;
> return ret;
> }
> +
> +#if defined(CONFIG_DEBUG_FS)
> +
> +static int vmw_ttm_vram_table_show(struct seq_file *m, void *unused)
> +{
> + struct vmw_private *vdev = (struct vmw_private *)m->private;
> + struct ttm_resource_manager *man = ttm_manager_type(&vdev->bdev,
> + TTM_PL_VRAM);
> + struct drm_printer p = drm_seq_file_printer(m);
> +
> + ttm_resource_manager_debug(man, &p);
> + return 0;
> +}
> +
> +static int vmw_ttm_page_pool_show(struct seq_file *m, void *unused)
> +{
> + struct vmw_private *vdev = (struct vmw_private *)m->private;
> +
> + return ttm_pool_debugfs(&vdev->bdev.pool, m);
> +}
> +
> +static int vmw_ttm_mob_table_show(struct seq_file *m, void *unused)
> +{
> + struct vmw_private *vdev = (struct vmw_private *)m->private;
> + struct ttm_resource_manager *man = ttm_manager_type(&vdev->bdev,
> + VMW_PL_MOB);
> + struct drm_printer p = drm_seq_file_printer(m);
> +
> + ttm_resource_manager_debug(man, &p);
> + return 0;
> +}
> +
> +static int vmw_ttm_gmr_table_show(struct seq_file *m, void *unused)
> +{
> + struct vmw_private *vdev = (struct vmw_private *)m->private;
> + struct ttm_resource_manager *man = ttm_manager_type(&vdev->bdev,
> + VMW_PL_GMR);
> + struct drm_printer p = drm_seq_file_printer(m);
> +
> + ttm_resource_manager_debug(man, &p);
> + return 0;
> +}
> +
> +static int vmw_ttm_system_table_show(struct seq_file *m, void *unused)
> +{
> + struct vmw_private *vdev = (struct vmw_private *)m->private;
> + struct ttm_resource_manager *man = ttm_manager_type(&vdev->bdev,
> + TTM_PL_SYSTEM);
> + struct drm_printer p = drm_seq_file_printer(m);
> +
> + ttm_resource_manager_debug(man, &p);
> + return 0;
> +}
> +
> +static int vmw_ttm_system_mob_table_show(struct seq_file *m, void *unused)
> +{
> + struct vmw_private *vdev = (struct vmw_private *)m->private;
> + struct ttm_resource_manager *man = ttm_manager_type(&vdev->bdev,
> + VMW_PL_SYSTEM);
> + struct drm_printer p = drm_seq_file_printer(m);
> +
> + ttm_resource_manager_debug(man, &p);
> + return 0;
> +}
> +
> +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_vram_table);
> +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_mob_table);
> +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_gmr_table);
> +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_system_table);
> +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_system_mob_table);
> +DEFINE_SHOW_ATTRIBUTE(vmw_ttm_page_pool);
> +
> +#endif
> +
> +void vmw_ttm_debugfs_init(struct vmw_private *vdev)
> +{
> +#if defined(CONFIG_DEBUG_FS)
> + struct drm_device *drm = &vdev->drm;
> + struct drm_minor *minor = drm->primary;
> + struct dentry *root = minor->debugfs_root;
> +
> + debugfs_create_file("vram_ttm", 0444, root, vdev,
> + &vmw_ttm_vram_table_fops);
> + debugfs_create_file("mob_ttm", 0444, root, vdev,
> + &vmw_ttm_mob_table_fops);
> + debugfs_create_file("gmr_ttm", 0444, root, vdev,
> + &vmw_ttm_gmr_table_fops);
> + debugfs_create_file("system_ttm", 0444, root, vdev,
> + &vmw_ttm_system_table_fops);
> + debugfs_create_file("system_mob_ttm", 0444, root, vdev,
> + &vmw_ttm_system_mob_table_fops);
> + debugfs_create_file("ttm_page_pool", 0444, root, vdev,
> + &vmw_ttm_page_pool_fops);
> +#endif
Bit orthogonal, but can't ttm create the debugfs files for all the regions
on its own when we set everything up? Or at least a "create me all the
regions debugfs files" helpers would be useful. It's just rather silly
amounts of boilerplate we're having here, and that in each driver.
-Daniel
> +}
> --
> 2.32.0
>
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
More information about the dri-devel
mailing list