From: Steven Price <steven.price@arm.com>
To: "Adrián Larumbe" <adrian.larumbe@collabora.com>,
robh@kernel.org, airlied@gmail.com, daniel@ffwll.ch
Cc: dri-devel@lists.freedesktop.org, kernel@collabora.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] drm/panfrost: Add drm memory stats display through fdinfo
Date: Mon, 21 Aug 2023 16:56:27 +0100 [thread overview]
Message-ID: <10cf2a19-01b9-c742-088f-4f63a0ca0a48@arm.com> (raw)
In-Reply-To: <20230808222240.1016623-3-adrian.larumbe@collabora.com>
On 08/08/2023 23:22, Adrián Larumbe wrote:
> For drm_show_memory_stats to produce a more accurate report, provide a new
> Panfrost DRM object callback that decides whether an object is resident in
> memory or eligible for purging.
>
> Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
> ---
> drivers/gpu/drm/panfrost/panfrost_drv.c | 8 ++++++--
> drivers/gpu/drm/panfrost/panfrost_gem.c | 16 ++++++++++++++++
> drivers/gpu/drm/panfrost/panfrost_gem.h | 1 +
> 3 files changed, 23 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c
> index 65fdc0e4c7cb..46e8e69479c0 100644
> --- a/drivers/gpu/drm/panfrost/panfrost_drv.c
> +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c
> @@ -441,11 +441,14 @@ static int panfrost_ioctl_madvise(struct drm_device *dev, void *data,
> args->retained = drm_gem_shmem_madvise(&bo->base, args->madv);
>
> if (args->retained) {
> - if (args->madv == PANFROST_MADV_DONTNEED)
> + if (args->madv == PANFROST_MADV_DONTNEED) {
> list_move_tail(&bo->base.madv_list,
> &pfdev->shrinker_list);
> - else if (args->madv == PANFROST_MADV_WILLNEED)
> + bo->is_purgable = true;
> + } else if (args->madv == PANFROST_MADV_WILLNEED) {
> list_del_init(&bo->base.madv_list);
> + bo->is_purgable = false;
> + }
> }
>
> out_unlock_mappings:
> @@ -546,6 +549,7 @@ static void panfrost_show_fdinfo(struct drm_printer *p, struct drm_file *file)
>
> panfrost_gpu_show_fdinfo(pfdev, file->driver_priv, p);
>
> + drm_show_memory_stats(p, file);
> }
>
> static const struct file_operations panfrost_drm_driver_fops = {
> diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.c b/drivers/gpu/drm/panfrost/panfrost_gem.c
> index 3c812fbd126f..80ab1521a14e 100644
> --- a/drivers/gpu/drm/panfrost/panfrost_gem.c
> +++ b/drivers/gpu/drm/panfrost/panfrost_gem.c
> @@ -195,6 +195,21 @@ static int panfrost_gem_pin(struct drm_gem_object *obj)
> return drm_gem_shmem_pin(&bo->base);
> }
>
> +static enum drm_gem_object_status panfrost_gem_status(struct drm_gem_object *obj)
> +{
> + struct panfrost_gem_object *bo = to_panfrost_bo(obj);
> + struct panfrost_device *pfdev = obj->dev->dev_private;
> + unsigned int res = 0;
> +
> + mutex_lock(&pfdev->shrinker_lock);
This function is called by drm_show_memory_stats() while holding a
spin_lock, so we can't take the mutex here.
However, given this is racy anyway (the status could change before the
data is returned to user space), I don't think we need to have the mutex
held anyway.
Otherwise this looks good.
Steve
> + res |= (bo->is_purgable) ? DRM_GEM_OBJECT_PURGEABLE : 0;
> + mutex_unlock(&pfdev->shrinker_lock);
> +
> + res |= (bo->base.pages) ? DRM_GEM_OBJECT_RESIDENT : 0;
> +
> + return res;
> +}
> +
> static const struct drm_gem_object_funcs panfrost_gem_funcs = {
> .free = panfrost_gem_free_object,
> .open = panfrost_gem_open,
> @@ -206,6 +221,7 @@ static const struct drm_gem_object_funcs panfrost_gem_funcs = {
> .vmap = drm_gem_shmem_object_vmap,
> .vunmap = drm_gem_shmem_object_vunmap,
> .mmap = drm_gem_shmem_object_mmap,
> + .status = panfrost_gem_status,
> .vm_ops = &drm_gem_shmem_vm_ops,
> };
>
> diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.h b/drivers/gpu/drm/panfrost/panfrost_gem.h
> index ad2877eeeccd..e06f7ceb8f73 100644
> --- a/drivers/gpu/drm/panfrost/panfrost_gem.h
> +++ b/drivers/gpu/drm/panfrost/panfrost_gem.h
> @@ -38,6 +38,7 @@ struct panfrost_gem_object {
>
> bool noexec :1;
> bool is_heap :1;
> + bool is_purgable :1;
> };
>
> struct panfrost_gem_mapping {
prev parent reply other threads:[~2023-08-21 15:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-08 22:22 [PATCH 0/2] Add fdinfo support to Panfrost Adrián Larumbe
2023-08-08 22:22 ` [PATCH 1/2] drm/panfrost: " Adrián Larumbe
2023-08-21 15:56 ` Steven Price
2023-08-23 12:55 ` Adrián Larumbe
2023-08-08 22:22 ` [PATCH 2/2] drm/panfrost: Add drm memory stats display through fdinfo Adrián Larumbe
2023-08-21 15:56 ` Steven Price [this message]
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=10cf2a19-01b9-c742-088f-4f63a0ca0a48@arm.com \
--to=steven.price@arm.com \
--cc=adrian.larumbe@collabora.com \
--cc=airlied@gmail.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=kernel@collabora.com \
--cc=linux-kernel@vger.kernel.org \
--cc=robh@kernel.org \
/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
all inboxes | Powered by JetHome®