dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: "Christian König" <ckoenig.leichtzumerken@gmail.com>
Cc: thomas.hellstrom@linux.intel.com,
	dri-devel@lists.freedesktop.org, andrey.grodzovsky@amd.com
Subject: Re: [PATCH 04/12] drm/ttm: add common accounting to the resource mgr
Date: Tue, 31 Aug 2021 14:52:24 +0200	[thread overview]
Message-ID: <YS4mCPDUQSE1PK0t@phenom.ffwll.local> (raw)
In-Reply-To: <20210830085707.209508-4-christian.koenig@amd.com>

On Mon, Aug 30, 2021 at 10:56:59AM +0200, Christian König wrote:
> It makes sense to have this in the common manager for debugging and
> accounting of how much resources are used.
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
>  drivers/gpu/drm/ttm/ttm_resource.c |  8 ++++++++
>  include/drm/ttm/ttm_resource.h     | 18 ++++++++++++++++++
>  2 files changed, 26 insertions(+)
> 
> diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c
> index a4c495da0040..426e6841fc89 100644
> --- a/drivers/gpu/drm/ttm/ttm_resource.c
> +++ b/drivers/gpu/drm/ttm/ttm_resource.c
> @@ -33,6 +33,8 @@ void ttm_resource_init(struct ttm_buffer_object *bo,
>                         const struct ttm_place *place,
>                         struct ttm_resource *res)
>  {
> +	struct ttm_resource_manager *man;
> +
>  	res->start = 0;
>  	res->num_pages = PFN_UP(bo->base.size);
>  	res->mem_type = place->mem_type;
> @@ -42,12 +44,16 @@ void ttm_resource_init(struct ttm_buffer_object *bo,
>  	res->bus.is_iomem = false;
>  	res->bus.caching = ttm_cached;
>  	res->bo = bo;
> +
> +	man = ttm_manager_type(bo->bdev, place->mem_type);
> +	atomic64_add(bo->base.size, &man->usage);
>  }
>  EXPORT_SYMBOL(ttm_resource_init);
>  
>  void ttm_resource_fini(struct ttm_resource_manager *man,
>  		       struct ttm_resource *res)
>  {
> +	atomic64_sub(res->bo->base.size, &man->usage);
>  }
>  EXPORT_SYMBOL(ttm_resource_fini);
>  
> @@ -100,6 +106,7 @@ void ttm_resource_manager_init(struct ttm_resource_manager *man,
>  	spin_lock_init(&man->move_lock);
>  	man->bdev = bdev;
>  	man->size = p_size;
> +	atomic64_set(&man->usage, 0);
>  
>  	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i)
>  		INIT_LIST_HEAD(&man->lru[i]);
> @@ -172,6 +179,7 @@ void ttm_resource_manager_debug(struct ttm_resource_manager *man,
>  	drm_printf(p, "  use_type: %d\n", man->use_type);
>  	drm_printf(p, "  use_tt: %d\n", man->use_tt);
>  	drm_printf(p, "  size: %llu\n", man->size);
> +	drm_printf(p, "  usage: %llu\n", atomic64_read(&man->usage));
>  	if (man->func->debug)
>  		man->func->debug(man, p);
>  }
> diff --git a/include/drm/ttm/ttm_resource.h b/include/drm/ttm/ttm_resource.h
> index e8080192cae4..526fe359c603 100644
> --- a/include/drm/ttm/ttm_resource.h
> +++ b/include/drm/ttm/ttm_resource.h
> @@ -27,6 +27,7 @@
>  
>  #include <linux/types.h>
>  #include <linux/mutex.h>
> +#include <linux/atomic.h>
>  #include <linux/dma-buf-map.h>
>  #include <linux/dma-fence.h>
>  #include <drm/drm_print.h>
> @@ -110,6 +111,7 @@ struct ttm_resource_manager_func {
>   * static information. bdev::driver::io_mem_free is never used.
>   * @lru: The lru list for this memory type.
>   * @move: The fence of the last pipelined move operation.
> + * @usage: How much of the region is used.
>   *
>   * This structure is used to identify and manage memory types for a device.
>   */
> @@ -134,6 +136,9 @@ struct ttm_resource_manager {
>  	 * Protected by @move_lock.
>  	 */
>  	struct dma_fence *move;
> +
> +	/* Own protection */
> +	atomic64_t usage;

Shouldn't we keep track of this together with the lru updates, under the
same spinlock?

Otherwise this usage here just becomes kinda meaningless I think, and just
for some debugging. I really don't like sprinkling random atomic_t around
(mostly because i915-gem code has gone totally overboard with them, with
complete disregard to complexity of the result).
-Daniel

>  };
>  
>  /**
> @@ -260,6 +265,19 @@ ttm_resource_manager_cleanup(struct ttm_resource_manager *man)
>  	man->move = NULL;
>  }
>  
> +/**
> + * ttm_resource_manager_usage
> + *
> + * @man: A memory manager object.
> + *
> + * Return how many resources are currently used.
> + */
> +static inline uint64_t
> +ttm_resource_manager_usage(struct ttm_resource_manager *man)
> +{
> +	return atomic64_read(&man->usage);
> +}
> +
>  void ttm_resource_init(struct ttm_buffer_object *bo,
>                         const struct ttm_place *place,
>                         struct ttm_resource *res);
> -- 
> 2.25.1
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

  reply	other threads:[~2021-08-31 12:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-30  8:56 [PATCH 01/12] drm/ttm: add ttm_resource_fini Christian König
2021-08-30  8:56 ` [PATCH 02/12] drm/ttm: add back a reference to the bdev to the res manager Christian König
2021-08-30  8:56 ` [PATCH 03/12] drm/ttm: add a weak BO reference to the resource v3 Christian König
2021-08-30  8:56 ` [PATCH 04/12] drm/ttm: add common accounting to the resource mgr Christian König
2021-08-31 12:52   ` Daniel Vetter [this message]
2021-08-31 12:57     ` Christian König
2021-08-31 13:15       ` Daniel Vetter
2021-08-30  8:57 ` [PATCH 05/12] drm/ttm: move the LRU into resource handling Christian König
2021-08-30 16:53   ` Andrey Grodzovsky
2021-08-30 16:55     ` Christian König
2021-08-30 17:00       ` Andrey Grodzovsky
2021-08-30 17:02         ` Christian König
2021-08-30  8:57 ` [PATCH 06/12] drm/ttm: add resource iterator Christian König
2021-08-30  8:57 ` [PATCH 07/12] drm/radeon: use ttm_resource_manager_debug Christian König
2021-08-30  8:57 ` [PATCH 08/12] drm/radeon: remove resource accounting Christian König
2021-08-30  8:57 ` [PATCH 09/12] drm/amdgpu: use ttm_resource_manager_debug Christian König
2021-08-30  8:57 ` [PATCH 10/12] drm/amdgpu: remove GTT accounting Christian König
2021-08-30  8:57 ` [PATCH 11/12] drm/amdgpu: remove VRAM accounting Christian König
2021-08-30  8:57 ` [PATCH 12/12] drm/amdgpu: drop amdgpu_gtt_node Christian König

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=YS4mCPDUQSE1PK0t@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=andrey.grodzovsky@amd.com \
    --cc=ckoenig.leichtzumerken@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=thomas.hellstrom@linux.intel.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