[CI] drm/xe/bo: add GPU memory trace points
Juston Li
justonli at chromium.org
Thu Jul 10 18:25:30 UTC 2025
On Thu, 2025-07-10 at 09:56 -0500, Lucas De Marchi wrote:
> On Wed, Jul 09, 2025 at 12:23:14PM -0700, Lucas De Marchi wrote:
> > From: Juston Li <justonli at chromium.org>
> >
> > Add TRACE_GPU_MEM tracepoints for tracking global GPU memory usage.
> >
> > These are required by VSR on Android 12+ for reporting GPU driver
> > memory
> > allocations.
> >
> > v5:
> > - Drop process_mem tracking
> > - Set the gpu_id field to dev->primary->index (Lucas, Tvrtko)
> > - Formatting cleanup under 80 columns
> >
> > v3:
> > - Use now configurable CONFIG_TRACE_GPU_MEM instead of adding a
> > per-driver Kconfig (Lucas)
> >
> > v2:
> > - Use u64 as preferred by checkpatch (Tvrtko)
> > - Fix errors in comments/Kconfig description (Tvrtko)
> > - drop redundant "CONFIG" in Kconfig
> >
> > Signed-off-by: Juston Li <justonli at chromium.org>
> > Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin at igalia.com>
> > Reviewed-by: Lucas De Marchi <lucas.demarchi at intel.com>
> > Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>
> > ---
> > drivers/gpu/drm/xe/xe_bo.c | 17 +++++++++++++++++
> > drivers/gpu/drm/xe/xe_device_types.h | 8 ++++++++
> > 2 files changed, 25 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/xe/xe_bo.c
> > b/drivers/gpu/drm/xe/xe_bo.c
> > index 7f8470b22dc99..4e0355d0f406b 100644
> > --- a/drivers/gpu/drm/xe/xe_bo.c
> > +++ b/drivers/gpu/drm/xe/xe_bo.c
> > @@ -19,6 +19,8 @@
> >
> > #include <kunit/static_stub.h>
> >
> > +#include <trace/events/gpu_mem.h>
> > +
> > #include "xe_device.h"
> > #include "xe_dma_buf.h"
> > #include "xe_drm_client.h"
> > @@ -418,6 +420,19 @@ static void xe_ttm_tt_account_subtract(struct
> > xe_device *xe, struct ttm_tt *tt)
> > xe_shrinker_mod_pages(xe->mem.shrinker, -(long)tt-
> > >num_pages, 0);
> > }
> >
> > +static void update_global_total_pages(struct ttm_device *ttm_dev,
> > + long num_pages)
> > +{
> > +#if IS_ENABLED(CONFIG_TRACE_GPU_MEM)
> > + struct xe_device *xe = ttm_to_xe_device(ttm_dev);
> > + u64 global_total_pages =
> > + atomic64_add_return(num_pages, &xe-
> > >global_total_pages);
> > +
> > + trace_gpu_mem_total(xe->drm.primary->index, 0,
> > + global_total_pages << PAGE_SHIFT);
> > +#endif
> > +}
> > +
> > static struct ttm_tt *xe_ttm_tt_create(struct ttm_buffer_object
> > *ttm_bo,
> > u32 page_flags)
> > {
> > @@ -525,6 +540,7 @@ static int xe_ttm_tt_populate(struct ttm_device
> > *ttm_dev, struct ttm_tt *tt,
> >
> > xe_tt->purgeable = false;
> > xe_ttm_tt_account_add(ttm_to_xe_device(ttm_dev), tt);
> > + update_global_total_pages(ttm_dev, tt->num_pages);
> >
> > return 0;
> > }
> > @@ -541,6 +557,7 @@ static void xe_ttm_tt_unpopulate(struct
> > ttm_device *ttm_dev, struct ttm_tt *tt)
> >
> > ttm_pool_free(&ttm_dev->pool, tt);
> > xe_ttm_tt_account_subtract(xe, tt);
> > + update_global_total_pages(ttm_dev, -(long)tt->num_pages);
> > }
> >
> > static void xe_ttm_tt_destroy(struct ttm_device *ttm_dev, struct
> > ttm_tt *tt)
> > diff --git a/drivers/gpu/drm/xe/xe_device_types.h
> > b/drivers/gpu/drm/xe/xe_device_types.h
> > index 78c4acafd268b..5b48b9604fc0d 100644
> > --- a/drivers/gpu/drm/xe/xe_device_types.h
> > +++ b/drivers/gpu/drm/xe/xe_device_types.h
> > @@ -632,6 +632,14 @@ struct xe_device {
> > unsigned int fsb_freq, mem_freq, is_ddr3;
> > };
> > #endif
> > +
> > +#if IS_ENABLED(CONFIG_TRACE_GPU_MEM)
> > + /**
> > + * @global_total_pages: global GPU page usage tracked for
> > gpu_mem
> > + * tracepoints
> > + */
> > + atomic64_t global_total_pages;
> > +#endif
>
> I also had to move this up, above /* private: */, otherwise kernel-
> doc
> shows a warning:
>
> Warning: drivers/gpu/drm/xe/xe_device_types.h:642 Excess
> struct member 'global_total_pages' description in 'xe_device'
>
> Applied to drm-xe-next, thanks.
Thanks for your feedback and guidance getting this landed!
Juston
> Lucas De Marchi
>
> > };
> >
> > /**
> > --
> > 2.49.0
> >
More information about the Intel-xe
mailing list