Skip to content

Commit ce3d39f

Browse files
Juston Lilucasdemarchi
authored andcommitted
drm/xe/bo: add GPU memory trace points
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 <[email protected]> Reviewed-by: Tvrtko Ursulin <[email protected]> Reviewed-by: Lucas De Marchi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lucas De Marchi <[email protected]>
1 parent f5c5d29 commit ce3d39f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

drivers/gpu/drm/xe/xe_bo.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include <kunit/static_stub.h>
2121

22+
#include <trace/events/gpu_mem.h>
23+
2224
#include "xe_device.h"
2325
#include "xe_dma_buf.h"
2426
#include "xe_drm_client.h"
@@ -418,6 +420,19 @@ static void xe_ttm_tt_account_subtract(struct xe_device *xe, struct ttm_tt *tt)
418420
xe_shrinker_mod_pages(xe->mem.shrinker, -(long)tt->num_pages, 0);
419421
}
420422

423+
static void update_global_total_pages(struct ttm_device *ttm_dev,
424+
long num_pages)
425+
{
426+
#if IS_ENABLED(CONFIG_TRACE_GPU_MEM)
427+
struct xe_device *xe = ttm_to_xe_device(ttm_dev);
428+
u64 global_total_pages =
429+
atomic64_add_return(num_pages, &xe->global_total_pages);
430+
431+
trace_gpu_mem_total(xe->drm.primary->index, 0,
432+
global_total_pages << PAGE_SHIFT);
433+
#endif
434+
}
435+
421436
static struct ttm_tt *xe_ttm_tt_create(struct ttm_buffer_object *ttm_bo,
422437
u32 page_flags)
423438
{
@@ -525,6 +540,7 @@ static int xe_ttm_tt_populate(struct ttm_device *ttm_dev, struct ttm_tt *tt,
525540

526541
xe_tt->purgeable = false;
527542
xe_ttm_tt_account_add(ttm_to_xe_device(ttm_dev), tt);
543+
update_global_total_pages(ttm_dev, tt->num_pages);
528544

529545
return 0;
530546
}
@@ -541,6 +557,7 @@ static void xe_ttm_tt_unpopulate(struct ttm_device *ttm_dev, struct ttm_tt *tt)
541557

542558
ttm_pool_free(&ttm_dev->pool, tt);
543559
xe_ttm_tt_account_subtract(xe, tt);
560+
update_global_total_pages(ttm_dev, -(long)tt->num_pages);
544561
}
545562

546563
static void xe_ttm_tt_destroy(struct ttm_device *ttm_dev, struct ttm_tt *tt)

drivers/gpu/drm/xe/xe_device_types.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,14 @@ struct xe_device {
600600
u8 vm_inject_error_position;
601601
#endif
602602

603+
#if IS_ENABLED(CONFIG_TRACE_GPU_MEM)
604+
/**
605+
* @global_total_pages: global GPU page usage tracked for gpu_mem
606+
* tracepoints
607+
*/
608+
atomic64_t global_total_pages;
609+
#endif
610+
603611
/* private: */
604612

605613
#if IS_ENABLED(CONFIG_DRM_XE_DISPLAY)

0 commit comments

Comments
 (0)