* [PATCH v5 1/2] gpu/trace: make TRACE_GPU_MEM configurable
@ 2025-07-07 20:38 Juston Li
2025-07-07 20:38 ` [PATCH v5 2/2] drm/xe/bo: add GPU memory trace points Juston Li
2025-07-08 16:33 ` [PATCH v5 1/2] gpu/trace: make TRACE_GPU_MEM configurable Lucas De Marchi
0 siblings, 2 replies; 6+ messages in thread
From: Juston Li @ 2025-07-07 20:38 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Tvrtko Ursulin, Tvrtko Ursulin, Yiwei Zhang, Rodrigo Vivi,
Lucas De Marchi, Juston Li
Move the source to a better place in Device Drivers -> Graphics support
now that its configurable.
v4:
- Move source location (Tvrtko)
v3:
- Patch introduced to replace per-driver config (Lucas)
Signed-off-by: Juston Li <justonli@chromium.org>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
---
drivers/Kconfig | 2 --
drivers/gpu/trace/Kconfig | 11 ++++++++++-
drivers/video/Kconfig | 1 +
3 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/drivers/Kconfig b/drivers/Kconfig
index 7c556c5ac4fdd..c5edbd2288a19 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -209,8 +209,6 @@ source "drivers/thunderbolt/Kconfig"
source "drivers/android/Kconfig"
-source "drivers/gpu/trace/Kconfig"
-
source "drivers/nvdimm/Kconfig"
source "drivers/dax/Kconfig"
diff --git a/drivers/gpu/trace/Kconfig b/drivers/gpu/trace/Kconfig
index c24e9edd022e6..cd3d19c4a201c 100644
--- a/drivers/gpu/trace/Kconfig
+++ b/drivers/gpu/trace/Kconfig
@@ -1,4 +1,13 @@
# SPDX-License-Identifier: GPL-2.0-only
config TRACE_GPU_MEM
- bool
+ bool "Enable GPU memory usage tracepoints"
+ default n
+ help
+ Choose this option to enable tracepoints for tracking
+ global and per-process GPU memory usage. Intended for
+ performance profiling and required for Android.
+
+ Tracepoint availability varies by GPU driver.
+
+ If in doubt, say "N".
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 5df981920a945..96adceab2df00 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -70,5 +70,6 @@ if FB_CORE || SGI_NEWPORT_CONSOLE
endif
+source "drivers/gpu/trace/Kconfig"
endmenu
--
2.50.0.727.gbf7dc18ff4-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v5 2/2] drm/xe/bo: add GPU memory trace points
2025-07-07 20:38 [PATCH v5 1/2] gpu/trace: make TRACE_GPU_MEM configurable Juston Li
@ 2025-07-07 20:38 ` Juston Li
2025-07-08 14:45 ` Lucas De Marchi
2025-07-08 20:29 ` Lucas De Marchi
2025-07-08 16:33 ` [PATCH v5 1/2] gpu/trace: make TRACE_GPU_MEM configurable Lucas De Marchi
1 sibling, 2 replies; 6+ messages in thread
From: Juston Li @ 2025-07-07 20:38 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Tvrtko Ursulin, Tvrtko Ursulin, Yiwei Zhang, Rodrigo Vivi,
Lucas De Marchi, Juston Li
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@chromium.org>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
---
drivers/gpu/drm/xe/xe_bo.c | 22 ++++++++++++++++++++++
drivers/gpu/drm/xe/xe_device_types.h | 8 ++++++++
2 files changed, 30 insertions(+)
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 4e39188a021ab..950eef514c11c 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,24 @@ 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);
}
+#if IS_ENABLED(CONFIG_TRACE_GPU_MEM)
+static void update_global_total_pages(struct ttm_device *ttm_dev,
+ long num_pages)
+{
+ 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);
+}
+#else
+static inline void update_global_total_pages(struct ttm_device *ttm_dev,
+ long num_pages)
+{
+}
+#endif
+
static struct ttm_tt *xe_ttm_tt_create(struct ttm_buffer_object *ttm_bo,
u32 page_flags)
{
@@ -525,6 +545,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 +562,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 e5d02a47a5287..6f3698a0bc176 100644
--- a/drivers/gpu/drm/xe/xe_device_types.h
+++ b/drivers/gpu/drm/xe/xe_device_types.h
@@ -641,6 +641,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
};
/**
--
2.50.0.727.gbf7dc18ff4-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v5 2/2] drm/xe/bo: add GPU memory trace points
2025-07-07 20:38 ` [PATCH v5 2/2] drm/xe/bo: add GPU memory trace points Juston Li
@ 2025-07-08 14:45 ` Lucas De Marchi
2025-07-08 20:29 ` Lucas De Marchi
1 sibling, 0 replies; 6+ messages in thread
From: Lucas De Marchi @ 2025-07-08 14:45 UTC (permalink / raw)
To: Juston Li
Cc: intel-xe, dri-devel, Tvrtko Ursulin, Tvrtko Ursulin, Yiwei Zhang,
Rodrigo Vivi
On Mon, Jul 07, 2025 at 01:38:23PM -0700, Juston Li wrote:
>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@chromium.org>
>Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Lucas De Marchi
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v5 1/2] gpu/trace: make TRACE_GPU_MEM configurable
2025-07-07 20:38 [PATCH v5 1/2] gpu/trace: make TRACE_GPU_MEM configurable Juston Li
2025-07-07 20:38 ` [PATCH v5 2/2] drm/xe/bo: add GPU memory trace points Juston Li
@ 2025-07-08 16:33 ` Lucas De Marchi
1 sibling, 0 replies; 6+ messages in thread
From: Lucas De Marchi @ 2025-07-08 16:33 UTC (permalink / raw)
To: Juston Li
Cc: intel-xe, dri-devel, Tvrtko Ursulin, Tvrtko Ursulin, Yiwei Zhang,
Rodrigo Vivi
On Mon, Jul 07, 2025 at 01:38:22PM -0700, Juston Li wrote:
>Move the source to a better place in Device Drivers -> Graphics support
>now that its configurable.
>
>v4:
> - Move source location (Tvrtko)
>
>v3:
> - Patch introduced to replace per-driver config (Lucas)
>
>Signed-off-by: Juston Li <justonli@chromium.org>
>Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
This first patch is now applied to drm-misc-next.
Thanks
Lucas De Marchi
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v5 2/2] drm/xe/bo: add GPU memory trace points
2025-07-07 20:38 ` [PATCH v5 2/2] drm/xe/bo: add GPU memory trace points Juston Li
2025-07-08 14:45 ` Lucas De Marchi
@ 2025-07-08 20:29 ` Lucas De Marchi
2025-07-09 16:18 ` Juston Li
1 sibling, 1 reply; 6+ messages in thread
From: Lucas De Marchi @ 2025-07-08 20:29 UTC (permalink / raw)
To: Juston Li
Cc: intel-xe, dri-devel, Tvrtko Ursulin, Tvrtko Ursulin, Yiwei Zhang,
Rodrigo Vivi
On Mon, Jul 07, 2025 at 01:38:23PM -0700, Juston Li wrote:
>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@chromium.org>
>Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
>---
> drivers/gpu/drm/xe/xe_bo.c | 22 ++++++++++++++++++++++
> drivers/gpu/drm/xe/xe_device_types.h | 8 ++++++++
> 2 files changed, 30 insertions(+)
>
>diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
>index 4e39188a021ab..950eef514c11c 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,24 @@ 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);
> }
>
>+#if IS_ENABLED(CONFIG_TRACE_GPU_MEM)
>+static void update_global_total_pages(struct ttm_device *ttm_dev,
>+ long num_pages)
>+{
wouldn't it be better to move the ifdef inside the function?
Any compiler would remove the empty call regardless of the inline
annotation, so I think this would make it less error prone if we change
function signature.
No need to send a new version, I can move that while applying
if agreed.
Lucas De Marchi
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v5 2/2] drm/xe/bo: add GPU memory trace points
2025-07-08 20:29 ` Lucas De Marchi
@ 2025-07-09 16:18 ` Juston Li
0 siblings, 0 replies; 6+ messages in thread
From: Juston Li @ 2025-07-09 16:18 UTC (permalink / raw)
To: Lucas De Marchi
Cc: intel-xe, dri-devel, Tvrtko Ursulin, Tvrtko Ursulin, Yiwei Zhang,
Rodrigo Vivi
On Tue, 2025-07-08 at 15:29 -0500, Lucas De Marchi wrote:
> On Mon, Jul 07, 2025 at 01:38:23PM -0700, Juston Li wrote:
> > 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@chromium.org>
> > Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
> > ---
> > drivers/gpu/drm/xe/xe_bo.c | 22 ++++++++++++++++++++++
> > drivers/gpu/drm/xe/xe_device_types.h | 8 ++++++++
> > 2 files changed, 30 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/xe/xe_bo.c
> > b/drivers/gpu/drm/xe/xe_bo.c
> > index 4e39188a021ab..950eef514c11c 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,24 @@ 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);
> > }
> >
> > +#if IS_ENABLED(CONFIG_TRACE_GPU_MEM)
> > +static void update_global_total_pages(struct ttm_device *ttm_dev,
> > + long num_pages)
> > +{
>
> wouldn't it be better to move the ifdef inside the function?
> Any compiler would remove the empty call regardless of the inline
> annotation, so I think this would make it less error prone if we
> change
> function signature.
>
> No need to send a new version, I can move that while applying
> if agreed.
SGTM, thanks!
Juston
> Lucas De Marchi
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-07-09 16:19 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-07 20:38 [PATCH v5 1/2] gpu/trace: make TRACE_GPU_MEM configurable Juston Li
2025-07-07 20:38 ` [PATCH v5 2/2] drm/xe/bo: add GPU memory trace points Juston Li
2025-07-08 14:45 ` Lucas De Marchi
2025-07-08 20:29 ` Lucas De Marchi
2025-07-09 16:18 ` Juston Li
2025-07-08 16:33 ` [PATCH v5 1/2] gpu/trace: make TRACE_GPU_MEM configurable Lucas De Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).