dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Zack Rusin <zackr@vmware.com>
Cc: krastevm@vmware.com, mombasawalam@vmware.com,
	dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 1/3] drm/vmwgfx: Add debugfs entries for ttm placements
Date: Mon, 4 Apr 2022 17:38:50 +0200	[thread overview]
Message-ID: <YksRCsiQtCp74y/A@phenom.ffwll.local> (raw)
In-Reply-To: <20220401205602.1172975-1-zack@kde.org>

On Fri, Apr 01, 2022 at 04:56:00PM -0400, Zack Rusin wrote:
> From: Zack Rusin <zackr@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@vmware.com>
> Reviewed-by: Martin Krastev <krastevm@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

  parent reply	other threads:[~2022-04-04 15:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-01 20:56 [PATCH 1/3] drm/vmwgfx: Add debugfs entries for ttm placements Zack Rusin
2022-04-01 20:56 ` [PATCH 2/3] drm/vmwgfx: Write the driver id registers Zack Rusin
2022-04-01 20:56 ` [PATCH 3/3] drm/vmwgfx: Fix gem refcounting on prime exported surfaces Zack Rusin
2022-04-04 15:38 ` Daniel Vetter [this message]
2022-04-05 14:00   ` [PATCH 1/3] drm/vmwgfx: Add debugfs entries for ttm placements Zack Rusin
2022-04-05 20:05     ` Daniel Vetter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YksRCsiQtCp74y/A@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=krastevm@vmware.com \
    --cc=mombasawalam@vmware.com \
    --cc=zackr@vmware.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox