[Intel-xe] [PATCH V3 7/7] drm/xe: Implement fdinfo memory stats printing

Ghimiray, Himal Prasad himal.prasad.ghimiray at intel.com
Fri Sep 15 04:39:57 UTC 2023


On 14-09-2023 17:49, Tejas Upadhyay wrote:
> Use the newly added drm_print_memory_stats helper to show memory
> utilisation of our objects in drm/driver specific fdinfo output.
>
> To collect the stats we walk the per memory regions object lists
> and accumulate object size into the respective drm_memory_stats
> categories.
>
> Objects with multiple possible placements are reported in multiple
> regions for total and shared sizes, while other categories are
> counted only for the currently active region.
>
> V3:
>    - dont use xe_bo_get/put, not needed
>    - use designated initializer - Jani
>    - use list_for_each_entry_rcu
>    - Fix Checkpatch err - CI
> V2:
>    - Use static initializer for mem_type - Himal/Jani
>
> Signed-off-by: Tejas Upadhyay<tejas.upadhyay at intel.com>
> ---
>   drivers/gpu/drm/xe/xe_bo.h         | 11 ++++
>   drivers/gpu/drm/xe/xe_drm_client.c | 84 +++++++++++++++++++++++++++++-
>   2 files changed, 94 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h
> index 4a68d869b3b5..b4c371f17bfb 100644
> --- a/drivers/gpu/drm/xe/xe_bo.h
> +++ b/drivers/gpu/drm/xe/xe_bo.h
> @@ -6,6 +6,8 @@
>   #ifndef _XE_BO_H_
>   #define _XE_BO_H_
>   
> +#include <drm/ttm/ttm_tt.h>
> +
>   #include "xe_bo_types.h"
>   #include "xe_macros.h"
>   #include "xe_vm_types.h"
> @@ -238,6 +240,15 @@ static inline size_t xe_bo_ccs_pages_start(struct xe_bo *bo)
>   	return PAGE_ALIGN(bo->ttm.base.size);
>   }
>   
> +static inline bool xe_bo_has_pages(struct xe_bo *bo)
> +{
> +	if ((bo->ttm.ttm && ttm_tt_is_populated(bo->ttm.ttm)) ||
> +	    xe_bo_is_vram(bo))
> +		return true;
> +
> +	return false;
> +}
> +
>   void __xe_bo_release_dummy(struct kref *kref);
>   
>   /**
> diff --git a/drivers/gpu/drm/xe/xe_drm_client.c b/drivers/gpu/drm/xe/xe_drm_client.c
> index 7abc1db1dc9c..0ff23708f51b 100644
> --- a/drivers/gpu/drm/xe/xe_drm_client.c
> +++ b/drivers/gpu/drm/xe/xe_drm_client.c
> @@ -4,10 +4,12 @@
>    */
>   
>   #include <drm/drm_print.h>
> +#include <drm/xe_drm.h>
>   #include <linux/kernel.h>
>   #include <linux/slab.h>
>   #include <linux/types.h>
>   
> +#include "xe_bo.h"
>   #include "xe_bo_types.h"
>   #include "xe_device_types.h"
>   #include "xe_drm_client.h"
> @@ -103,6 +105,86 @@ void xe_drm_client_remove_bo(struct xe_bo *bo)
>   	xe_drm_client_put(client);
>   }
>   
> +static void bo_meminfo(struct xe_bo *bo,
> +		       struct drm_memory_stats stats[TTM_NUM_MEM_TYPES])
> +{
> +	u64 sz = bo->size;
> +	u32 mem_type;
> +
> +	if (bo->placement.placement)
> +		mem_type = bo->placement.placement->mem_type;
> +	else
> +		mem_type = XE_PL_TT;
> +
> +	if (bo->ttm.base.handle_count > 1)
> +		stats[mem_type].shared += sz;
> +	else
> +		stats[mem_type].private += sz;
> +
> +	if (xe_bo_has_pages(bo)) {
> +		stats[mem_type].resident += sz;
> +
> +		if (!dma_resv_test_signaled(bo->ttm.base.resv,
> +					    dma_resv_usage_rw(true) |
> +					    DMA_RESV_USAGE_BOOKKEEP))
> +			stats[mem_type].active += sz;
> +		else if (mem_type == XE_PL_SYSTEM)
> +			stats[mem_type].purgeable += sz;
> +	}
> +}
> +
> +static void show_meminfo(struct drm_printer *p, struct drm_file *file)
> +{
> +	static const char *const mem_type_to_name[TTM_NUM_MEM_TYPES]  = {
> +		[XE_PL_SYSTEM] = "system",
> +		[XE_PL_TT] = "gtt",
> +		[XE_PL_VRAM0] = "vram0",
> +		[XE_PL_VRAM1] = "vram1",
> +		[4 ... 6] = NULL,
> +		[XE_PL_STOLEN] = "stolen"
> +	};
> +	struct drm_memory_stats stats[TTM_NUM_MEM_TYPES] = {};
> +	struct xe_file *xef = file->driver_priv;
> +	struct ttm_device *bdev = &xef->xe->ttm;
> +	struct ttm_resource_manager *man;
> +	struct xe_drm_client *client;
> +	struct xe_bo *bo;
> +	unsigned int id;
> +	u32 mem_type;
> +
> +	client = xef->client;
> +
> +	/* Public objects. */
> +	spin_lock(&file->table_lock);
> +	idr_for_each_entry(&file->object_idr, bo, id)
> +		bo_meminfo(bo, stats);
> +	spin_unlock(&file->table_lock);
> +
> +	/* Internal objects. */
> +	rcu_read_lock();
> +	list_for_each_entry_rcu(bo, &client->bos_list, client_link) {
> +		if (!bo)
> +			continue;
> +		bo_meminfo(bo, stats);
> +	}
> +	rcu_read_unlock();
> +	for (mem_type = XE_PL_SYSTEM; mem_type < TTM_NUM_MEM_TYPES; ++mem_type) {
> +		if (!mem_type_to_name[mem_type])
> +			continue;
> +
> +		man = ttm_manager_type(bdev, mem_type);
> +
> +		if (man) {
> +			drm_print_memory_stats(p,
> +					       &stats[mem_type],
> +					       DRM_GEM_OBJECT_RESIDENT |
> +					       (mem_type != XE_PL_SYSTEM ? 0 :
> +					       DRM_GEM_OBJECT_PURGEABLE),
> +					       mem_type_to_name[mem_type]);
> +		}
> +	}
> +}
> +

LGTM. Reviewed-by: Himal Prasad Ghimiray 
<himal.prasad.ghimiray at intel.com> <mailto:himal.prasad.ghimiray at intel.com>

>   /**
>    * xe_drm_client_fdinfo() - Callback for fdinfo interface
>    * @p: The drm_printer ptr
> @@ -115,6 +197,6 @@ void xe_drm_client_remove_bo(struct xe_bo *bo)
>    */
>   void xe_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file)
>   {
> -	/* show_meminfo() will be developed here */
> +	show_meminfo(p, file);
>   }
>   #endif
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/intel-xe/attachments/20230915/2b165fd8/attachment-0001.htm>


More information about the Intel-xe mailing list