Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Ghimiray, Himal Prasad" <himal.prasad.ghimiray@intel.com>
To: Tejas Upadhyay <tejas.upadhyay@intel.com>,
	<intel-xe@lists.freedesktop.org>
Subject: Re: [Intel-xe] [PATCH 3/7] drm/xe: Add tracking support for bos per client
Date: Wed, 6 Sep 2023 15:08:35 +0530	[thread overview]
Message-ID: <42fb6950-bc66-449b-bd9b-138f25f2354d@intel.com> (raw)
In-Reply-To: <20230831090536.2949934-4-tejas.upadhyay@intel.com>

[-- Attachment #1: Type: text/plain, Size: 6201 bytes --]


On 31-08-2023 14:35, Tejas Upadhyay wrote:
> In order to show per client memory consumption, we
> need tracking support APIs to add at every bo consumption
> and removal. Adding APIs here to add tracking calls at
> places wherever it is applicable.
>
> Signed-off-by: Tejas Upadhyay<tejas.upadhyay@intel.com>
> ---
>   drivers/gpu/drm/xe/xe_bo.c         |  7 ++++
>   drivers/gpu/drm/xe/xe_bo_types.h   | 10 ++++++
>   drivers/gpu/drm/xe/xe_drm_client.c | 58 ++++++++++++++++++++++++++++++
>   drivers/gpu/drm/xe/xe_drm_client.h | 26 ++++++++++++++
>   4 files changed, 101 insertions(+)
>
> diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> index 6a8a41dafe88..cde91c3601d1 100644
> --- a/drivers/gpu/drm/xe/xe_bo.c
> +++ b/drivers/gpu/drm/xe/xe_bo.c
> @@ -16,6 +16,7 @@
>   
>   #include "xe_device.h"
>   #include "xe_dma_buf.h"
> +#include "xe_drm_client.h"
>   #include "xe_ggtt.h"
>   #include "xe_gt.h"
>   #include "xe_map.h"
> @@ -1051,6 +1052,9 @@ static void xe_ttm_bo_destroy(struct ttm_buffer_object *ttm_bo)
>   	if (bo->vm && xe_bo_is_user(bo))
>   		xe_vm_put(bo->vm);
>   
> +	if (bo->client)
> +		xe_drm_client_remove_bo(bo);
API returns bool, handle it or use void return type.
> +
>   	kfree(bo);
>   }
>   
> @@ -1230,6 +1234,9 @@ struct xe_bo *__xe_bo_create_locked(struct xe_device *xe, struct xe_bo *bo,
>   	bo->ttm.priority = DRM_XE_VMA_PRIORITY_NORMAL;
>   	INIT_LIST_HEAD(&bo->vmas);
>   	INIT_LIST_HEAD(&bo->pinned_link);
> +#ifdef CONFIG_PROC_FS
> +	INIT_LIST_HEAD(&bo->client_link);
> +#endif
>   
>   	drm_gem_private_object_init(&xe->drm, &bo->ttm.base, size);
>   
> diff --git a/drivers/gpu/drm/xe/xe_bo_types.h b/drivers/gpu/drm/xe/xe_bo_types.h
> index f6ee920303af..1aef413b6f8a 100644
> --- a/drivers/gpu/drm/xe/xe_bo_types.h
> +++ b/drivers/gpu/drm/xe/xe_bo_types.h
> @@ -45,6 +45,16 @@ struct xe_bo {
>   	struct ttm_bo_kmap_obj kmap;
>   	/** @pinned_link: link to present / evicted list of pinned BO */
>   	struct list_head pinned_link;
> +#ifdef CONFIG_PROC_FS
> +	/**
> +	 * @client: @xe_drm_client which created the bo
> +	 */
> +	struct xe_drm_client *client;
> +	/**
> +	 * @client_link: Link into @xe_drm_client.objects_list
> +	 */
> +	struct list_head client_link;
> +#endif
>   	/** @props: BO user controlled properties */
>   	struct {
>   		/** @preferred_mem: preferred memory class for this BO */
> diff --git a/drivers/gpu/drm/xe/xe_drm_client.c b/drivers/gpu/drm/xe/xe_drm_client.c
> index b5dc024b5dd0..00b28a08909f 100644
> --- a/drivers/gpu/drm/xe/xe_drm_client.c
> +++ b/drivers/gpu/drm/xe/xe_drm_client.c
> @@ -8,8 +8,11 @@
>   #include <linux/slab.h>
>   #include <linux/types.h>
>   
> +#include "xe_bo_types.h"
>   #include "xe_device_types.h"
>   #include "xe_drm_client.h"
> +#include "xe_device_types.h"
> +#include "xe_trace.h"
>   
>   /**
>    * xe_drm_client_alloc() - Allocate drm client
> @@ -31,6 +34,10 @@ struct xe_drm_client *xe_drm_client_alloc(void)
>   
>   	kref_init(&client->kref);
>   
> +#ifdef CONFIG_PROC_FS
> +	spin_lock_init(&client->bos_lock);
> +	INIT_LIST_HEAD(&client->bos_list);
> +#endif
>   	return client;
>   }
>   
> @@ -52,6 +59,57 @@ void __xe_drm_client_free(struct kref *kref)
>   }
>   
>   #ifdef CONFIG_PROC_FS
> +/**
> + * xe_drm_client_add_bo() - Add BO for tracking client mem usage
> + * @client: The drm client ptr
> + * @bo: The xe BO ptr
> + *
> + * Add all BO created by individual drm client by calling this function.
> + * This helps in tracking client memory usage.
> + *
> + * Return: void
> + */
> +void xe_drm_client_add_bo(struct xe_drm_client *client,
> +			  struct xe_bo *bo)
> +{
> +	unsigned long flags;
> +
> +	XE_WARN_ON(bo->client);
> +	XE_WARN_ON(!list_empty(&bo->client_link));
> +
> +	spin_lock_irqsave(&client->bos_lock, flags);
> +	bo->client = xe_drm_client_get(client);
> +	list_add_tail_rcu(&bo->client_link, &client->bos_list);
> +	spin_unlock_irqrestore(&client->bos_lock, flags);
> +}
> +
> +/**
> + * xe_drm_client_remove_bo() - Remove BO for tracking client mem usage
> + * @bo: The xe BO ptr
> + *
> + * Remove all BO removed by individual drm client by calling this function.
> + * This helps in tracking client memory usage.
> + *
> + * Return: void
Wrong return type in comment.
> + */
> +bool xe_drm_client_remove_bo(struct xe_bo *bo)
> +{
> +	struct xe_drm_client *client = bo->client;
> +	unsigned long flags;
> +
> +	/* Object may not be associated with a client. */
> +	if (!client)
> +		return false;

This call is redundant.  API is being called only if client exists, make 
sure to check for bo->client_link too.

Himal

> +
> +	spin_lock_irqsave(&client->bos_lock, flags);
> +	list_del_rcu(&bo->client_link);
> +	spin_unlock_irqrestore(&client->bos_lock, flags);
> +
> +	xe_drm_client_put(client);
> +
> +	return true;
> +}
> +
>   /**
>    * xe_drm_client_fdinfo() - Callback for fdinfo interface
>    * @p: The drm_printer ptr
> diff --git a/drivers/gpu/drm/xe/xe_drm_client.h b/drivers/gpu/drm/xe/xe_drm_client.h
> index dbe3a083c9df..bbbc5d6ce3ae 100644
> --- a/drivers/gpu/drm/xe/xe_drm_client.h
> +++ b/drivers/gpu/drm/xe/xe_drm_client.h
> @@ -15,10 +15,23 @@
>   
>   struct drm_file;
>   struct drm_printer;
> +struct xe_bo;
>   
>   struct xe_drm_client {
>   	struct kref kref;
>   	unsigned int id;
> +#ifdef CONFIG_PROC_FS
> +	/**
> +	 * @bos_lock: lock protecting @bos_list
> +	 */
> +	spinlock_t bos_lock;
> +	/**
> +	 * @bos_list: list of bos created by this client
> +	 *
> +	 * Protected by @bos_lock.
> +	 */
> +	struct list_head bos_list;
> +#endif
>   };
>   
>   	static inline struct xe_drm_client *
> @@ -41,5 +54,18 @@ xe_drm_client_get(struct xe_drm_client *client);
>   static inline void xe_drm_client_put(struct xe_drm_client *client);
>   #ifdef CONFIG_PROC_FS
>   void xe_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file);
> +void xe_drm_client_add_bo(struct xe_drm_client *client,
> +		struct xe_bo *bo);
> +bool xe_drm_client_remove_bo(struct xe_bo *bo);
> +#else
> +static inline void xe_drm_client_add_bo(struct xe_drm_client *client,
> +		struct xe_bo *bo)
> +{
> +}
> +
> +static inline bool xe_drm_client_remove_bo(struct xe_bo *bo)
> +{
> +}
>   #endif
> +
>   #endif

[-- Attachment #2: Type: text/html, Size: 7056 bytes --]

  reply	other threads:[~2023-09-06  9:38 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-31  9:05 [Intel-xe] [PATCH 0/7] drm/xe: fdinfo memory stats Tejas Upadhyay
2023-08-31  9:05 ` [Intel-xe] [PATCH 1/7] drm/xe: Add drm-client infrastructure Tejas Upadhyay
2023-09-06  4:14   ` Ghimiray, Himal Prasad
2023-09-07  8:57     ` Upadhyay, Tejas
2023-09-12  8:24       ` Ghimiray, Himal Prasad
2023-08-31  9:05 ` [Intel-xe] [PATCH 2/7] drm/xe: Interface xe drm client with fdinfo interface Tejas Upadhyay
2023-09-06  4:21   ` Ghimiray, Himal Prasad
2023-08-31  9:05 ` [Intel-xe] [PATCH 3/7] drm/xe: Add tracking support for bos per client Tejas Upadhyay
2023-09-06  9:38   ` Ghimiray, Himal Prasad [this message]
2023-09-07  8:52     ` Upadhyay, Tejas
2023-08-31  9:05 ` [Intel-xe] [PATCH 4/7] drm/xe: Record each drm client with its VM Tejas Upadhyay
2023-09-06  9:47   ` Ghimiray, Himal Prasad
2023-09-07  8:49     ` Upadhyay, Tejas
2023-09-07  9:28       ` Ghimiray, Himal Prasad
2023-09-07  9:44         ` Upadhyay, Tejas
2023-08-31  9:05 ` [Intel-xe] [PATCH 5/7] drm/xe: Track page table memory usage for client Tejas Upadhyay
2023-09-06  9:54   ` Ghimiray, Himal Prasad
2023-09-07  8:40     ` Upadhyay, Tejas
2023-08-31  9:05 ` [Intel-xe] [PATCH 6/7] drm/xe: Account ring buffer and context state storage Tejas Upadhyay
2023-09-06 11:19   ` Ghimiray, Himal Prasad
2023-08-31  9:05 ` [Intel-xe] [PATCH 7/7] drm/xe: Implement fdinfo memory stats printing Tejas Upadhyay
2023-08-31 12:19   ` Upadhyay, Tejas
2023-09-12  6:22   ` Ghimiray, Himal Prasad
2023-09-12 11:14     ` Jani Nikula
2023-08-31  9:21 ` [Intel-xe] ✓ CI.Patch_applied: success for drm/xe: fdinfo memory stats Patchwork
2023-08-31  9:21 ` [Intel-xe] ✗ CI.checkpatch: warning " Patchwork
2023-08-31  9:22 ` [Intel-xe] ✓ CI.KUnit: success " Patchwork
2023-08-31  9:29 ` [Intel-xe] ✓ CI.Build: " Patchwork
2023-08-31  9:30 ` [Intel-xe] ✗ CI.Hooks: failure " Patchwork
2023-08-31  9:30 ` [Intel-xe] ✗ CI.checksparse: warning " Patchwork
2023-08-31 10:04 ` [Intel-xe] ✓ CI.BAT: success " Patchwork
2023-08-31 11:23 ` Patchwork
2023-09-07  9:22 ` [Intel-xe] [PATCH 0/7] " Ghimiray, Himal Prasad
2023-09-07  9:35   ` Upadhyay, Tejas

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=42fb6950-bc66-449b-bd9b-138f25f2354d@intel.com \
    --to=himal.prasad.ghimiray@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=tejas.upadhyay@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