2023-03-12 23:31:53

by Erico Nunes

[permalink] [raw]
Subject: [PATCH 0/3] drm/lima: expose usage statistics via fdinfo

Expose lima gp and pp usage stats through fdinfo, following
Documentation/gpu/drm-usage-stats.rst.
Borrowed from these previous implementations:

"df622729ddbf drm/scheduler: track GPU active time per entity" added
usage time accounting to drm scheduler, which is where the data used
here comes from.

Then the main implementation is based on these etnaviv commits:
"d306788b6e1b drm/etnaviv: allocate unique ID per drm_file" and
"97804a133c68 drm/etnaviv: export client GPU usage statistics via
fdinfo"

Also "874442541133 drm/amdgpu: Add show_fdinfo() interface" since lima
has a context manager very similar to amdgpu and all contexts created
(and released) at the ctx_mgr level need to be accounted for.

Tested with the generic "gputop" tool currently available as patches to
igt, a sample run with this patchset looks like this:

DRM minor 128
PID NAME gp pp
4322 glmark2-es2-way |█████▊ ||██████████████████ |
3561 weston |▎ ||███▌ |
4159 Xwayland |▏ ||▉ |
4154 glxgears |▏ ||▎ |
3661 firefox |▏ ||▏ |


Erico Nunes (3):
drm/lima: add usage counting method to ctx_mgr
drm/lima: allocate unique id per drm_file
drm/lima: add show_fdinfo for drm usage stats

drivers/gpu/drm/lima/lima_ctx.c | 30 ++++++++++++++++++++-
drivers/gpu/drm/lima/lima_ctx.h | 3 +++
drivers/gpu/drm/lima/lima_device.h | 3 +++
drivers/gpu/drm/lima/lima_drv.c | 43 +++++++++++++++++++++++++++++-
drivers/gpu/drm/lima/lima_drv.h | 1 +
5 files changed, 78 insertions(+), 2 deletions(-)

--
2.39.2



2023-03-12 23:31:55

by Erico Nunes

[permalink] [raw]
Subject: [PATCH 1/3] drm/lima: add usage counting method to ctx_mgr

lima maintains a context manager per drm_file, similar to amdgpu.
In order to account for the complete usage per drm_file, all of the
associated contexts need to be considered.
Previously released contexts also need to be accounted for but their
drm_sched_entity info is gone once they get released, so account for it
in the ctx_mgr.

Signed-off-by: Erico Nunes <[email protected]>
---
drivers/gpu/drm/lima/lima_ctx.c | 30 +++++++++++++++++++++++++++++-
drivers/gpu/drm/lima/lima_ctx.h | 3 +++
2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/lima/lima_ctx.c b/drivers/gpu/drm/lima/lima_ctx.c
index 891d5cd5019a..e008e586fad0 100644
--- a/drivers/gpu/drm/lima/lima_ctx.c
+++ b/drivers/gpu/drm/lima/lima_ctx.c
@@ -15,6 +15,7 @@ int lima_ctx_create(struct lima_device *dev, struct lima_ctx_mgr *mgr, u32 *id)
if (!ctx)
return -ENOMEM;
ctx->dev = dev;
+ ctx->mgr = mgr;
kref_init(&ctx->refcnt);

for (i = 0; i < lima_pipe_num; i++) {
@@ -42,10 +43,17 @@ int lima_ctx_create(struct lima_device *dev, struct lima_ctx_mgr *mgr, u32 *id)
static void lima_ctx_do_release(struct kref *ref)
{
struct lima_ctx *ctx = container_of(ref, struct lima_ctx, refcnt);
+ struct lima_ctx_mgr *mgr = ctx->mgr;
int i;

- for (i = 0; i < lima_pipe_num; i++)
+ for (i = 0; i < lima_pipe_num; i++) {
+ struct lima_sched_context *context = &ctx->context[i];
+ struct drm_sched_entity *entity = &context->base;
+
+ mgr->elapsed_ns[i] += entity->elapsed_ns;
+
lima_sched_context_fini(ctx->dev->pipe + i, ctx->context + i);
+ }
kfree(ctx);
}

@@ -99,3 +107,23 @@ void lima_ctx_mgr_fini(struct lima_ctx_mgr *mgr)
xa_destroy(&mgr->handles);
mutex_destroy(&mgr->lock);
}
+
+void lima_ctx_mgr_usage(struct lima_ctx_mgr *mgr, u64 usage[lima_pipe_num])
+{
+ struct lima_ctx *ctx;
+ unsigned long id;
+
+ for (int i = 0; i < lima_pipe_num; i++)
+ usage[i] = mgr->elapsed_ns[i];
+
+ mutex_lock(&mgr->lock);
+ xa_for_each(&mgr->handles, id, ctx) {
+ for (int i = 0; i < lima_pipe_num; i++) {
+ struct lima_sched_context *context = &ctx->context[i];
+ struct drm_sched_entity *entity = &context->base;
+
+ usage[i] += entity->elapsed_ns;
+ }
+ }
+ mutex_unlock(&mgr->lock);
+}
diff --git a/drivers/gpu/drm/lima/lima_ctx.h b/drivers/gpu/drm/lima/lima_ctx.h
index 74e2be09090f..6068863880eb 100644
--- a/drivers/gpu/drm/lima/lima_ctx.h
+++ b/drivers/gpu/drm/lima/lima_ctx.h
@@ -12,6 +12,7 @@
struct lima_ctx {
struct kref refcnt;
struct lima_device *dev;
+ struct lima_ctx_mgr *mgr;
struct lima_sched_context context[lima_pipe_num];
atomic_t guilty;

@@ -23,6 +24,7 @@ struct lima_ctx {
struct lima_ctx_mgr {
struct mutex lock;
struct xarray handles;
+ u64 elapsed_ns[lima_pipe_num];
};

int lima_ctx_create(struct lima_device *dev, struct lima_ctx_mgr *mgr, u32 *id);
@@ -31,5 +33,6 @@ struct lima_ctx *lima_ctx_get(struct lima_ctx_mgr *mgr, u32 id);
void lima_ctx_put(struct lima_ctx *ctx);
void lima_ctx_mgr_init(struct lima_ctx_mgr *mgr);
void lima_ctx_mgr_fini(struct lima_ctx_mgr *mgr);
+void lima_ctx_mgr_usage(struct lima_ctx_mgr *mgr, u64 usage[lima_pipe_num]);

#endif
--
2.39.2


2023-03-12 23:31:57

by Erico Nunes

[permalink] [raw]
Subject: [PATCH 2/3] drm/lima: allocate unique id per drm_file

To track if fds are pointing to the same execution context and export
the expected information to fdinfo, similar to what is done in other
drivers.

Signed-off-by: Erico Nunes <[email protected]>
---
drivers/gpu/drm/lima/lima_device.h | 3 +++
drivers/gpu/drm/lima/lima_drv.c | 12 ++++++++++++
drivers/gpu/drm/lima/lima_drv.h | 1 +
3 files changed, 16 insertions(+)

diff --git a/drivers/gpu/drm/lima/lima_device.h b/drivers/gpu/drm/lima/lima_device.h
index 41b9d7b4bcc7..71b2db60d161 100644
--- a/drivers/gpu/drm/lima/lima_device.h
+++ b/drivers/gpu/drm/lima/lima_device.h
@@ -106,6 +106,9 @@ struct lima_device {
struct lima_dump_head dump;
struct list_head error_task_list;
struct mutex error_task_list_lock;
+
+ struct xarray active_contexts;
+ u32 next_context_id;
};

static inline struct lima_device *
diff --git a/drivers/gpu/drm/lima/lima_drv.c b/drivers/gpu/drm/lima/lima_drv.c
index 7b8d7178d09a..d23c0b77a252 100644
--- a/drivers/gpu/drm/lima/lima_drv.c
+++ b/drivers/gpu/drm/lima/lima_drv.c
@@ -218,6 +218,11 @@ static int lima_drm_driver_open(struct drm_device *dev, struct drm_file *file)
if (!priv)
return -ENOMEM;

+ err = xa_alloc_cyclic(&ldev->active_contexts, &priv->id, priv,
+ xa_limit_32b, &ldev->next_context_id, GFP_KERNEL);
+ if (err < 0)
+ goto err_out0;
+
priv->vm = lima_vm_create(ldev);
if (!priv->vm) {
err = -ENOMEM;
@@ -237,6 +242,9 @@ static int lima_drm_driver_open(struct drm_device *dev, struct drm_file *file)
static void lima_drm_driver_postclose(struct drm_device *dev, struct drm_file *file)
{
struct lima_drm_priv *priv = file->driver_priv;
+ struct lima_device *ldev = to_lima_dev(dev);
+
+ xa_erase(&ldev->active_contexts, priv->id);

lima_ctx_mgr_fini(&priv->ctx_mgr);
lima_vm_put(priv->vm);
@@ -388,6 +396,8 @@ static int lima_pdev_probe(struct platform_device *pdev)
ldev->dev = &pdev->dev;
ldev->id = (enum lima_gpu_id)of_device_get_match_data(&pdev->dev);

+ xa_init_flags(&ldev->active_contexts, XA_FLAGS_ALLOC);
+
platform_set_drvdata(pdev, ldev);

/* Allocate and initialize the DRM device. */
@@ -444,6 +454,8 @@ static int lima_pdev_remove(struct platform_device *pdev)
struct lima_device *ldev = platform_get_drvdata(pdev);
struct drm_device *ddev = ldev->ddev;

+ xa_destroy(&ldev->active_contexts);
+
sysfs_remove_bin_file(&ldev->dev->kobj, &lima_error_state_attr);

drm_dev_unregister(ddev);
diff --git a/drivers/gpu/drm/lima/lima_drv.h b/drivers/gpu/drm/lima/lima_drv.h
index c738d288547b..e49b7ab651d0 100644
--- a/drivers/gpu/drm/lima/lima_drv.h
+++ b/drivers/gpu/drm/lima/lima_drv.h
@@ -20,6 +20,7 @@ struct lima_sched_task;
struct drm_lima_gem_submit_bo;

struct lima_drm_priv {
+ int id;
struct lima_vm *vm;
struct lima_ctx_mgr ctx_mgr;
};
--
2.39.2


2023-03-12 23:32:00

by Erico Nunes

[permalink] [raw]
Subject: [PATCH 3/3] drm/lima: add show_fdinfo for drm usage stats

This exposes an accumulated active time per client via the fdinfo
infrastructure per execution engine, following
Documentation/gpu/drm-usage-stats.rst.
In lima, the exposed execution engines are gp and pp.

Signed-off-by: Erico Nunes <[email protected]>
---
drivers/gpu/drm/lima/lima_drv.c | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/lima/lima_drv.c b/drivers/gpu/drm/lima/lima_drv.c
index d23c0b77a252..c044a31493a4 100644
--- a/drivers/gpu/drm/lima/lima_drv.c
+++ b/drivers/gpu/drm/lima/lima_drv.c
@@ -261,7 +261,36 @@ static const struct drm_ioctl_desc lima_drm_driver_ioctls[] = {
DRM_IOCTL_DEF_DRV(LIMA_CTX_FREE, lima_ioctl_ctx_free, DRM_RENDER_ALLOW),
};

-DEFINE_DRM_GEM_FOPS(lima_drm_driver_fops);
+static void lima_drm_driver_show_fdinfo(struct seq_file *m, struct file *filp)
+{
+ struct drm_file *file = filp->private_data;
+ struct drm_device *dev = file->minor->dev;
+ struct lima_device *ldev = dev->dev_private;
+ struct lima_drm_priv *priv = file->driver_priv;
+ struct lima_ctx_mgr *ctx_mgr = &priv->ctx_mgr;
+ u64 usage[lima_pipe_num];
+
+ lima_ctx_mgr_usage(ctx_mgr, usage);
+
+ /*
+ * For a description of the text output format used here, see
+ * Documentation/gpu/drm-usage-stats.rst.
+ */
+ seq_printf(m, "drm-driver:\t%s\n", dev->driver->name);
+ seq_printf(m, "drm-client-id:\t%u\n", priv->id);
+ for (int i = 0; i < lima_pipe_num; i++) {
+ struct lima_sched_pipe *pipe = &ldev->pipe[i];
+ struct drm_gpu_scheduler *sched = &pipe->base;
+
+ seq_printf(m, "drm-engine-%s:\t%llu ns\n", sched->name, usage[i]);
+ }
+}
+
+static const struct file_operations lima_drm_driver_fops = {
+ .owner = THIS_MODULE,
+ DRM_GEM_FOPS,
+ .show_fdinfo = lima_drm_driver_show_fdinfo,
+};

/*
* Changelog:
--
2.39.2


2023-03-13 02:38:13

by Qiang Yu

[permalink] [raw]
Subject: Re: [PATCH 3/3] drm/lima: add show_fdinfo for drm usage stats

On Mon, Mar 13, 2023 at 7:31 AM Erico Nunes <[email protected]> wrote:
>
> This exposes an accumulated active time per client via the fdinfo
> infrastructure per execution engine, following
> Documentation/gpu/drm-usage-stats.rst.
> In lima, the exposed execution engines are gp and pp.
>
> Signed-off-by: Erico Nunes <[email protected]>
> ---
> drivers/gpu/drm/lima/lima_drv.c | 31 ++++++++++++++++++++++++++++++-
> 1 file changed, 30 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/lima/lima_drv.c b/drivers/gpu/drm/lima/lima_drv.c
> index d23c0b77a252..c044a31493a4 100644
> --- a/drivers/gpu/drm/lima/lima_drv.c
> +++ b/drivers/gpu/drm/lima/lima_drv.c
> @@ -261,7 +261,36 @@ static const struct drm_ioctl_desc lima_drm_driver_ioctls[] = {
> DRM_IOCTL_DEF_DRV(LIMA_CTX_FREE, lima_ioctl_ctx_free, DRM_RENDER_ALLOW),
> };
>
> -DEFINE_DRM_GEM_FOPS(lima_drm_driver_fops);
> +static void lima_drm_driver_show_fdinfo(struct seq_file *m, struct file *filp)
> +{
> + struct drm_file *file = filp->private_data;
> + struct drm_device *dev = file->minor->dev;
> + struct lima_device *ldev = dev->dev_private;
Can use to_lima_dev().

> + struct lima_drm_priv *priv = file->driver_priv;
> + struct lima_ctx_mgr *ctx_mgr = &priv->ctx_mgr;
> + u64 usage[lima_pipe_num];
> +
> + lima_ctx_mgr_usage(ctx_mgr, usage);
> +
> + /*
> + * For a description of the text output format used here, see
> + * Documentation/gpu/drm-usage-stats.rst.
> + */
> + seq_printf(m, "drm-driver:\t%s\n", dev->driver->name);
> + seq_printf(m, "drm-client-id:\t%u\n", priv->id);
> + for (int i = 0; i < lima_pipe_num; i++) {
> + struct lima_sched_pipe *pipe = &ldev->pipe[i];
> + struct drm_gpu_scheduler *sched = &pipe->base;
> +
> + seq_printf(m, "drm-engine-%s:\t%llu ns\n", sched->name, usage[i]);
> + }
> +}
> +
> +static const struct file_operations lima_drm_driver_fops = {
> + .owner = THIS_MODULE,
> + DRM_GEM_FOPS,
> + .show_fdinfo = lima_drm_driver_show_fdinfo,
> +};
>
> /*
> * Changelog:
> --
> 2.39.2
>

2023-03-13 03:10:09

by Qiang Yu

[permalink] [raw]
Subject: Re: [PATCH 0/3] drm/lima: expose usage statistics via fdinfo

Patch set is:
Reviewed-by: Qiang Yu <[email protected]>

Looks like drm-misc-next does not contain "df622729ddbf drm/scheduler:
track GPU active time per entity" yet.
Will apply later.

Regards,
Qiang

On Mon, Mar 13, 2023 at 7:31 AM Erico Nunes <[email protected]> wrote:
>
> Expose lima gp and pp usage stats through fdinfo, following
> Documentation/gpu/drm-usage-stats.rst.
> Borrowed from these previous implementations:
>
> "df622729ddbf drm/scheduler: track GPU active time per entity" added
> usage time accounting to drm scheduler, which is where the data used
> here comes from.
>
> Then the main implementation is based on these etnaviv commits:
> "d306788b6e1b drm/etnaviv: allocate unique ID per drm_file" and
> "97804a133c68 drm/etnaviv: export client GPU usage statistics via
> fdinfo"
>
> Also "874442541133 drm/amdgpu: Add show_fdinfo() interface" since lima
> has a context manager very similar to amdgpu and all contexts created
> (and released) at the ctx_mgr level need to be accounted for.
>
> Tested with the generic "gputop" tool currently available as patches to
> igt, a sample run with this patchset looks like this:
>
> DRM minor 128
> PID NAME gp pp
> 4322 glmark2-es2-way |█████▊ ||██████████████████ |
> 3561 weston |▎ ||███▌ |
> 4159 Xwayland |▏ ||▉ |
> 4154 glxgears |▏ ||▎ |
> 3661 firefox |▏ ||▏ |
>
>
> Erico Nunes (3):
> drm/lima: add usage counting method to ctx_mgr
> drm/lima: allocate unique id per drm_file
> drm/lima: add show_fdinfo for drm usage stats
>
> drivers/gpu/drm/lima/lima_ctx.c | 30 ++++++++++++++++++++-
> drivers/gpu/drm/lima/lima_ctx.h | 3 +++
> drivers/gpu/drm/lima/lima_device.h | 3 +++
> drivers/gpu/drm/lima/lima_drv.c | 43 +++++++++++++++++++++++++++++-
> drivers/gpu/drm/lima/lima_drv.h | 1 +
> 5 files changed, 78 insertions(+), 2 deletions(-)
>
> --
> 2.39.2
>

2023-04-02 10:25:39

by Qiang Yu

[permalink] [raw]
Subject: Re: [PATCH 0/3] drm/lima: expose usage statistics via fdinfo

Applied to drm-misc-next.

On Mon, Mar 13, 2023 at 11:09 AM Qiang Yu <[email protected]> wrote:
>
> Patch set is:
> Reviewed-by: Qiang Yu <[email protected]>
>
> Looks like drm-misc-next does not contain "df622729ddbf drm/scheduler:
> track GPU active time per entity" yet.
> Will apply later.
>
> Regards,
> Qiang
>
> On Mon, Mar 13, 2023 at 7:31 AM Erico Nunes <[email protected]> wrote:
> >
> > Expose lima gp and pp usage stats through fdinfo, following
> > Documentation/gpu/drm-usage-stats.rst.
> > Borrowed from these previous implementations:
> >
> > "df622729ddbf drm/scheduler: track GPU active time per entity" added
> > usage time accounting to drm scheduler, which is where the data used
> > here comes from.
> >
> > Then the main implementation is based on these etnaviv commits:
> > "d306788b6e1b drm/etnaviv: allocate unique ID per drm_file" and
> > "97804a133c68 drm/etnaviv: export client GPU usage statistics via
> > fdinfo"
> >
> > Also "874442541133 drm/amdgpu: Add show_fdinfo() interface" since lima
> > has a context manager very similar to amdgpu and all contexts created
> > (and released) at the ctx_mgr level need to be accounted for.
> >
> > Tested with the generic "gputop" tool currently available as patches to
> > igt, a sample run with this patchset looks like this:
> >
> > DRM minor 128
> > PID NAME gp pp
> > 4322 glmark2-es2-way |█████▊ ||██████████████████ |
> > 3561 weston |▎ ||███▌ |
> > 4159 Xwayland |▏ ||▉ |
> > 4154 glxgears |▏ ||▎ |
> > 3661 firefox |▏ ||▏ |
> >
> >
> > Erico Nunes (3):
> > drm/lima: add usage counting method to ctx_mgr
> > drm/lima: allocate unique id per drm_file
> > drm/lima: add show_fdinfo for drm usage stats
> >
> > drivers/gpu/drm/lima/lima_ctx.c | 30 ++++++++++++++++++++-
> > drivers/gpu/drm/lima/lima_ctx.h | 3 +++
> > drivers/gpu/drm/lima/lima_device.h | 3 +++
> > drivers/gpu/drm/lima/lima_drv.c | 43 +++++++++++++++++++++++++++++-
> > drivers/gpu/drm/lima/lima_drv.h | 1 +
> > 5 files changed, 78 insertions(+), 2 deletions(-)
> >
> > --
> > 2.39.2
> >

2023-04-02 11:31:24

by Lucas Stach

[permalink] [raw]
Subject: Re: [PATCH 0/3] drm/lima: expose usage statistics via fdinfo

Am Sonntag, dem 02.04.2023 um 18:22 +0800 schrieb Qiang Yu:
> Applied to drm-misc-next.
>
"df622729ddbf drm/scheduler: track GPU active time per entity" had to
be reverted due to it introducing a use after free. I guess this
patchset now conflicts with the revert.

Regards,
Lucas

> On Mon, Mar 13, 2023 at 11:09 AM Qiang Yu <[email protected]> wrote:
> >
> > Patch set is:
> > Reviewed-by: Qiang Yu <[email protected]>
> >
> > Looks like drm-misc-next does not contain "df622729ddbf drm/scheduler:
> > track GPU active time per entity" yet.
> > Will apply later.
> >
> > Regards,
> > Qiang
> >
> > On Mon, Mar 13, 2023 at 7:31 AM Erico Nunes <[email protected]> wrote:
> > >
> > > Expose lima gp and pp usage stats through fdinfo, following
> > > Documentation/gpu/drm-usage-stats.rst.
> > > Borrowed from these previous implementations:
> > >
> > > "df622729ddbf drm/scheduler: track GPU active time per entity" added
> > > usage time accounting to drm scheduler, which is where the data used
> > > here comes from.
> > >
> > > Then the main implementation is based on these etnaviv commits:
> > > "d306788b6e1b drm/etnaviv: allocate unique ID per drm_file" and
> > > "97804a133c68 drm/etnaviv: export client GPU usage statistics via
> > > fdinfo"
> > >
> > > Also "874442541133 drm/amdgpu: Add show_fdinfo() interface" since lima
> > > has a context manager very similar to amdgpu and all contexts created
> > > (and released) at the ctx_mgr level need to be accounted for.
> > >
> > > Tested with the generic "gputop" tool currently available as patches to
> > > igt, a sample run with this patchset looks like this:
> > >
> > > DRM minor 128
> > > PID NAME gp pp
> > > 4322 glmark2-es2-way |█████▊ ||██████████████████ |
> > > 3561 weston |▎ ||███▌ |
> > > 4159 Xwayland |▏ ||▉ |
> > > 4154 glxgears |▏ ||▎ |
> > > 3661 firefox |▏ ||▏ |
> > >
> > >
> > > Erico Nunes (3):
> > > drm/lima: add usage counting method to ctx_mgr
> > > drm/lima: allocate unique id per drm_file
> > > drm/lima: add show_fdinfo for drm usage stats
> > >
> > > drivers/gpu/drm/lima/lima_ctx.c | 30 ++++++++++++++++++++-
> > > drivers/gpu/drm/lima/lima_ctx.h | 3 +++
> > > drivers/gpu/drm/lima/lima_device.h | 3 +++
> > > drivers/gpu/drm/lima/lima_drv.c | 43 +++++++++++++++++++++++++++++-
> > > drivers/gpu/drm/lima/lima_drv.h | 1 +
> > > 5 files changed, 78 insertions(+), 2 deletions(-)
> > >
> > > --
> > > 2.39.2
> > >

2023-04-02 14:31:46

by Qiang Yu

[permalink] [raw]
Subject: Re: [PATCH 0/3] drm/lima: expose usage statistics via fdinfo

> "df622729ddbf drm/scheduler: track GPU active time per entity" had to
> be reverted due to it introducing a use after free. I guess this
> patchset now conflicts with the revert.
>
I do get some build fail message on other branch. Do I need to revert this
patchset on drm-misc-next or left to branch maintainer to decide whether
to pick this patchset upstream?

Regards,
Qiang

>
> > On Mon, Mar 13, 2023 at 11:09 AM Qiang Yu <[email protected]> wrote:
> > >
> > > Patch set is:
> > > Reviewed-by: Qiang Yu <[email protected]>
> > >
> > > Looks like drm-misc-next does not contain "df622729ddbf drm/scheduler:
> > > track GPU active time per entity" yet.
> > > Will apply later.
> > >
> > > Regards,
> > > Qiang
> > >
> > > On Mon, Mar 13, 2023 at 7:31 AM Erico Nunes <[email protected]> wrote:
> > > >
> > > > Expose lima gp and pp usage stats through fdinfo, following
> > > > Documentation/gpu/drm-usage-stats.rst.
> > > > Borrowed from these previous implementations:
> > > >
> > > > "df622729ddbf drm/scheduler: track GPU active time per entity" added
> > > > usage time accounting to drm scheduler, which is where the data used
> > > > here comes from.
> > > >
> > > > Then the main implementation is based on these etnaviv commits:
> > > > "d306788b6e1b drm/etnaviv: allocate unique ID per drm_file" and
> > > > "97804a133c68 drm/etnaviv: export client GPU usage statistics via
> > > > fdinfo"
> > > >
> > > > Also "874442541133 drm/amdgpu: Add show_fdinfo() interface" since lima
> > > > has a context manager very similar to amdgpu and all contexts created
> > > > (and released) at the ctx_mgr level need to be accounted for.
> > > >
> > > > Tested with the generic "gputop" tool currently available as patches to
> > > > igt, a sample run with this patchset looks like this:
> > > >
> > > > DRM minor 128
> > > > PID NAME gp pp
> > > > 4322 glmark2-es2-way |█████▊ ||██████████████████ |
> > > > 3561 weston |▎ ||███▌ |
> > > > 4159 Xwayland |▏ ||▉ |
> > > > 4154 glxgears |▏ ||▎ |
> > > > 3661 firefox |▏ ||▏ |
> > > >
> > > >
> > > > Erico Nunes (3):
> > > > drm/lima: add usage counting method to ctx_mgr
> > > > drm/lima: allocate unique id per drm_file
> > > > drm/lima: add show_fdinfo for drm usage stats
> > > >
> > > > drivers/gpu/drm/lima/lima_ctx.c | 30 ++++++++++++++++++++-
> > > > drivers/gpu/drm/lima/lima_ctx.h | 3 +++
> > > > drivers/gpu/drm/lima/lima_device.h | 3 +++
> > > > drivers/gpu/drm/lima/lima_drv.c | 43 +++++++++++++++++++++++++++++-
> > > > drivers/gpu/drm/lima/lima_drv.h | 1 +
> > > > 5 files changed, 78 insertions(+), 2 deletions(-)
> > > >
> > > > --
> > > > 2.39.2
> > > >
>

2023-04-03 21:17:05

by Ville Syrjälä

[permalink] [raw]
Subject: Re: [PATCH 1/3] drm/lima: add usage counting method to ctx_mgr

On Mon, Mar 13, 2023 at 12:30:50AM +0100, Erico Nunes wrote:
> lima maintains a context manager per drm_file, similar to amdgpu.
> In order to account for the complete usage per drm_file, all of the
> associated contexts need to be considered.
> Previously released contexts also need to be accounted for but their
> drm_sched_entity info is gone once they get released, so account for it
> in the ctx_mgr.
>
> Signed-off-by: Erico Nunes <[email protected]>
> ---
> drivers/gpu/drm/lima/lima_ctx.c | 30 +++++++++++++++++++++++++++++-
> drivers/gpu/drm/lima/lima_ctx.h | 3 +++
> 2 files changed, 32 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/lima/lima_ctx.c b/drivers/gpu/drm/lima/lima_ctx.c
> index 891d5cd5019a..e008e586fad0 100644
> --- a/drivers/gpu/drm/lima/lima_ctx.c
> +++ b/drivers/gpu/drm/lima/lima_ctx.c
> @@ -15,6 +15,7 @@ int lima_ctx_create(struct lima_device *dev, struct lima_ctx_mgr *mgr, u32 *id)
> if (!ctx)
> return -ENOMEM;
> ctx->dev = dev;
> + ctx->mgr = mgr;
> kref_init(&ctx->refcnt);
>
> for (i = 0; i < lima_pipe_num; i++) {
> @@ -42,10 +43,17 @@ int lima_ctx_create(struct lima_device *dev, struct lima_ctx_mgr *mgr, u32 *id)
> static void lima_ctx_do_release(struct kref *ref)
> {
> struct lima_ctx *ctx = container_of(ref, struct lima_ctx, refcnt);
> + struct lima_ctx_mgr *mgr = ctx->mgr;
> int i;
>
> - for (i = 0; i < lima_pipe_num; i++)
> + for (i = 0; i < lima_pipe_num; i++) {
> + struct lima_sched_context *context = &ctx->context[i];
> + struct drm_sched_entity *entity = &context->base;
> +
> + mgr->elapsed_ns[i] += entity->elapsed_ns;

drm-tip build is now broken because of this vs.
commit baad10973fdb ("Revert "drm/scheduler: track GPU active time per entity"")

../drivers/gpu/drm/lima/lima_ctx.c: In function ‘lima_ctx_do_release’:
../drivers/gpu/drm/lima/lima_ctx.c:53:45: error: ‘struct
drm_sched_entity’ has no member named ‘elapsed_ns’
53 | mgr->elapsed_ns[i] += entity->elapsed_ns;

--
Ville Syrjälä
Intel