Panthor BO tagging and GEMS debug display
Subsystems (5)
v2 cover Panthor BO tagging and GEMS debug display
This patch series is aimed at providing UM with detailed memory profiling information in debug builds. It is achieved through a device-wide list of DRM GEM objects, and also implementing the ability to label BO's from UM through a new IOCTL.
The new debugfs file shows a list of driver DRM GEM objects in tabular mode. To visualise it, cat sudo cat /sys/kernel/debug/dri/*.gpu/gems.
Previous discussion mail archive:
https://lore.kernel.org/dri-devel/[email protected]/
Changelog:
v2:
- Consolidated some debugfs and labelling struct members into nested structs
- Added helpers for handling the debugfs gems linked list
- Fixed ioctl naming scheme in the uapi header file
- Added label length limit and param consistency checks in BO labelling ioctl
Adrián Larumbe (4):
drm/panthor: Introduce BO labeling
drm/panthor: Add driver IOCTL for setting BO labels drm/panthor: show device-wide list of DRM GEM objects over DebugFS drm/panthor: Display heap chunk entries in DebugFS GEMS file
drivers/gpu/drm/panthor/panthor_device.c | 5 + drivers/gpu/drm/panthor/panthor_device.h | 11 ++ drivers/gpu/drm/panthor/panthor_drv.c | 63 ++++++++++ drivers/gpu/drm/panthor/panthor_gem.c | 154 +++++++++++++++++++++++ drivers/gpu/drm/panthor/panthor_gem.h | 48 +++++++ drivers/gpu/drm/panthor/panthor_heap.c | 3 + include/uapi/drm/panthor_drm.h | 19 +++ 7 files changed, 303 insertions(+)
--
2.48.1
PATCH v2 1/4 drm/panthor: Introduce BO labeling
Add a new character string Panthor BO field, and a function that allows setting it from within the driver.
Driver takes care of freeing the string when it's replaced or no longer needed at object destruction time, but allocating it is the responsibility of callers.
--- drivers/gpu/drm/panthor/panthor_gem.c | 24 ++++++++++++++++++++++++ drivers/gpu/drm/panthor/panthor_gem.h | 17 +++++++++++++++++ 2 files changed, 41 insertions(+)
drivers/gpu/drm/panthor/panthor_gem.c +24 -0
@@ -18,6 +18,9 @@ static void panthor_gem_free_object(struct drm_gem_object *obj)struct panthor_gem_object *bo =to_panthor_bo (obj);struct drm_gem_object *vm_root_gem = bo->exclusive_vm_root_gem; +kfree (bo->label.str); +mutex_destroy (&bo->label.lock); +drm_gem_free_mmap_offset (&bo->base.base);mutex_destroy (&bo->gpuva_list_lock);drm_gem_shmem_free (&bo->base);
@@ -196,6 +199,7 @@ struct drm_gem_object *panthor_gem_create_object(struct drm_device *ddev, size_t obj->base.map_wc = !ptdev->coherent;mutex_init (&obj->gpuva_list_lock);drm_gem_gpuva_set_lock (&obj->base.base, &obj->gpuva_list_lock); +mutex_init (&obj->label.lock);return &obj->base.base; }
@@ -247,3 +251,23 @@ panthor_gem_create_with_handle(struct drm_file *file,return ret; } + +void +panthor_gem_bo_set_label (struct drm_gem_object *obj,const char *label) +{ +struct panthor_gem_object *bo =to_panthor_bo (obj); +const char *old_label; + +mutex_lock (&bo->label.lock); + old_label = bo->label.str; + bo->label.str = label; +mutex_unlock (&bo->label.lock); + +kfree (old_label); +} + +void +panthor_gem_kernel_bo_set_label (struct panthor_kernel_bo *bo,const char *label) +{ +panthor_gem_bo_set_label (bo->obj,kstrdup_const (label,GFP_KERNEL )); +}
drivers/gpu/drm/panthor/panthor_gem.h +17 -0
@@ -46,6 +46,20 @@ struct panthor_gem_object {/** @flags: Combination of drm_panthor_bo_flags flags. */ u32 flags; + +/** +* @label: BO tagging fields. The label can be assigned within the +* driver itself or through a specific IOCTL. +*/ +struct { +/** +* @label.str: Pointer to NULL-terminated string, +*/ +const char *str; + +/** @lock.str: Protects access to the @label.str field. */ +struct mutex lock; + } label; };/**
@@ -91,6 +105,9 @@ panthor_gem_create_with_handle(struct drm_file *file,struct panthor_vm *exclusive_vm, u64 *size, u32 flags, uint32_t *handle); +void panthor_gem_bo_set_label (struct drm_gem_object *obj,const char *label); +void panthor_gem_kernel_bo_set_label (struct panthor_kernel_bo *bo,const char *label); +static inline u64 panthor_kernel_bo_gpuva (struct panthor_kernel_bo *bo) {
Signature · 1 line
2.48.1
Boris Brezillon
maintainerRe: [PATCH v2 1/4] drm/panthor: Introduce BO labeling
Quoted 18 lines · On Wed, 19 Mar 2025 15:03:16 +0000 Adrián Larumbe…
Add a new character string Panthor BO field, and a function that allows setting it from within the driver.
Driver takes care of freeing the string when it's replaced or no longer needed at object destruction time, but allocating it is the responsibility of callers.
Signed-off-by Adrián Larumbe <[email protected]>--- drivers/gpu/drm/panthor/panthor_gem.c | 24 ++++++++++++++++++++++++ drivers/gpu/drm/panthor/panthor_gem.h | 17 +++++++++++++++++ 2 files changed, 41 insertions(+)drivers/gpu/drm/panthor/panthor_gem.c +0
-0
drivers/gpu/drm/panthor/panthor_gem.c static void panthor_gem_free_object(struct drm_gem_object *obj) · line 21
Quoted 4 lines
drivers/gpu/drm/panthor/panthor_gem.c +1
-0@@ -18,6 +18,9 @@ static void panthor_gem_free_object(struct drm_gem_object *obj)struct panthor_gem_object *bo =to_panthor_bo (obj);struct drm_gem_object *vm_root_gem = bo->exclusive_vm_root_gem; +kfree (bo->label.str);
/* Label might have been allocated with kstrdup_const(), * we need to take that into account when freeing the memory. */ kfree_const(bo->label.str);
Quoted 26 lines
drivers/gpu/drm/panthor/panthor_gem.c +12
-0+mutex_destroy (&bo->label.lock); +drm_gem_free_mmap_offset (&bo->base.base);mutex_destroy (&bo->gpuva_list_lock);drm_gem_shmem_free (&bo->base);@@ -196,6 +199,7 @@ struct drm_gem_object *panthor_gem_create_object(struct drm_device *ddev, size_t obj->base.map_wc = !ptdev->coherent;mutex_init (&obj->gpuva_list_lock);drm_gem_gpuva_set_lock (&obj->base.base, &obj->gpuva_list_lock); +mutex_init (&obj->label.lock);return &obj->base.base; }@@ -247,3 +251,23 @@ panthor_gem_create_with_handle(struct drm_file *file,return ret; } + +void +panthor_gem_bo_set_label (struct drm_gem_object *obj,const char *label) +{ +struct panthor_gem_object *bo =to_panthor_bo (obj); +const char *old_label; + +mutex_lock (&bo->label.lock); + old_label = bo->label.str;
drivers/gpu/drm/panthor/panthor_gem.c panthor_gem_create_with_handle(struct drm_file *file, · line 272
Quoted 10 lines
drivers/gpu/drm/panthor/panthor_gem.c +10
-0+ bo->label.str = label; +mutex_unlock (&bo->label.lock); + +kfree (old_label); +} + +void +panthor_gem_kernel_bo_set_label (struct panthor_kernel_bo *bo,const char *label) +{ +panthor_gem_bo_set_label (bo->obj,kstrdup_const (label,GFP_KERNEL ));
You ignore the OOM case. Not sure it can happen in practice, and it's probably okay if we keep going in that case, because this is just debug information, but maybe this should be documented here.
Quoted 36 lines
drivers/gpu/drm/panthor/panthor_gem.c +1
-0+}drivers/gpu/drm/panthor/panthor_gem.h +17
-0@@ -46,6 +46,20 @@ struct panthor_gem_object {/** @flags: Combination of drm_panthor_bo_flags flags. */ u32 flags; + +/** +* @label: BO tagging fields. The label can be assigned within the +* driver itself or through a specific IOCTL. +*/ +struct { +/** +* @label.str: Pointer to NULL-terminated string, +*/ +const char *str; + +/** @lock.str: Protects access to the @label.str field. */ +struct mutex lock; + } label; };/** @@ -91,6 +105,9 @@ panthor_gem_create_with_handle(struct drm_file *file,struct panthor_vm *exclusive_vm, u64 *size, u32 flags, uint32_t *handle); +void panthor_gem_bo_set_label (struct drm_gem_object *obj,const char *label); +void panthor_gem_kernel_bo_set_label (struct panthor_kernel_bo *bo,const char *label); +static inline u64 panthor_kernel_bo_gpuva (struct panthor_kernel_bo *bo) {
PATCH v2 2/4 drm/panthor: Add driver IOCTL for setting BO labels
In reply to Adrián LarumbeAllow UM to label a BO for which it possesses a DRM handle.
--- drivers/gpu/drm/panthor/panthor_drv.c | 37 +++++++++++++++++++++++++++ include/uapi/drm/panthor_drm.h | 19 ++++++++++++++ 2 files changed, 56 insertions(+)
drivers/gpu/drm/panthor/panthor_drv.c +37 -0
@@ -1330,6 +1330,41 @@ static int panthor_ioctl_vm_get_state(struct drm_device *ddev, void *data,return 0 ; } +static int panthor_ioctl_bo_set_label (struct drm_device *ddev,void *data, +struct drm_file *file) +{ +struct drm_panthor_bo_set_label *args = data; +struct drm_gem_object *obj; +const char *label; +unsigned long len; +int ret =0 ; + + obj =drm_gem_object_lookup (file, args->handle); +if (!obj) +return -ENOENT ; + +if (args->size && args->label) { + len = (args->size <PAGE_SIZE ) ? args->size :PAGE_SIZE ; + label =strndup_user (u64_to_user_ptr (args->label), len); +if (IS_ERR (label)) { + ret =PTR_ERR (label); + goto err_label; + } + }else if (args->size && !args->label) { + ret = -EINVAL ; + goto err_label; + }else { + label =NULL ; + } + +panthor_gem_bo_set_label (obj, label); + +err_label: +drm_gem_object_put (obj); + +return ret; +} +static int panthor_open (struct drm_device *ddev,struct drm_file *file) {
@@ -1399,6 +1434,7 @@ static const struct drm_ioctl_desc panthor_drm_driver_ioctls[] = {PANTHOR_IOCTL (TILER_HEAP_CREATE , tiler_heap_create,DRM_RENDER_ALLOW ),PANTHOR_IOCTL (TILER_HEAP_DESTROY , tiler_heap_destroy,DRM_RENDER_ALLOW ),PANTHOR_IOCTL (GROUP_SUBMIT , group_submit,DRM_RENDER_ALLOW ), + PANTHOR_IOCTL(BO_SET_LABEL, bo_set_label, DRM_RENDER_ALLOW), };static int panthor_mmap (struct file *filp,struct vm_area_struct *vma)
@@ -1508,6 +1544,7 @@ static void panthor_debugfs_init(struct drm_minor *minor)* - 1.2 - adds DEV_QUERY_GROUP_PRIORITIES_INFO query * - adds PANTHOR_GROUP_PRIORITY_REALTIME priority * - 1.3 - adds DRM_PANTHOR_GROUP_STATE_INNOCENT flag +* - 1.4 - adds DRM_IOCTL_PANTHOR_BO_SET_LABEL ioctl */ static const struct drm_driver panthor_drm_driver = { .driver_features = DRIVER_RENDER | DRIVER_GEM | DRIVER_SYNCOBJ |
include/uapi/drm/panthor_drm.h +19 -0
@@ -127,6 +127,9 @@ enum drm_panthor_ioctl_id {/** @DRM_PANTHOR_TILER_HEAP_DESTROY: Destroy a tiler heap. */ DRM_PANTHOR_TILER_HEAP_DESTROY , + +/** @DRM_PANTHOR_BO_SET_LABEL: Label a BO. */ + DRM_PANTHOR_BO_SET_LABEL, };/**
@@ -977,6 +980,20 @@ struct drm_panthor_tiler_heap_destroy {__u32 pad; }; +/** +* struct drm_panthor_bo_set_label - Arguments passed to DRM_IOCTL_PANTHOR_BO_SET_LABEL +*/ +struct drm_panthor_bo_set_label { +/** @handle: Handle of the buffer object to label. */ +__u32 handle; + +/** @size: Length of the label, including the NULL terminator. */ +__u32 size; + +/** @label: User pointer to a NULL-terminated string */ +__u64 label; +}; +/** * DRM_IOCTL_PANTHOR() - Build a Panthor IOCTL number * @__access: Access type. Must be R, W or RW.
@@ -1019,6 +1036,8 @@ enum {DRM_IOCTL_PANTHOR (WR ,TILER_HEAP_CREATE , tiler_heap_create),DRM_IOCTL_PANTHOR_TILER_HEAP_DESTROY =DRM_IOCTL_PANTHOR (WR ,TILER_HEAP_DESTROY , tiler_heap_destroy), +DRM_IOCTL_PANTHOR_BO_SET_LABEL = + DRM_IOCTL_PANTHOR(WR, BO_SET_LABEL, bo_set_label), };#if defined(__cplusplus)
Signature · 1 line
2.48.1
Boris Brezillon
maintainerRe: [PATCH v2 2/4] drm/panthor: Add driver IOCTL for setting BO labels
Quoted 21 lines · On Wed, 19 Mar 2025 15:03:17 +0000 Adrián Larumbe…
Allow UM to label a BO for which it possesses a DRM handle.
Signed-off-by Adrián Larumbe <[email protected]>--- drivers/gpu/drm/panthor/panthor_drv.c | 37 +++++++++++++++++++++++++++ include/uapi/drm/panthor_drm.h | 19 ++++++++++++++ 2 files changed, 56 insertions(+)drivers/gpu/drm/panthor/panthor_drv.c +5
-0@@ -1330,6 +1330,41 @@ static int panthor_ioctl_vm_get_state(struct drm_device *ddev, void *data,return 0 ; } +static int panthor_ioctl_bo_set_label (struct drm_device *ddev,void *data, +struct drm_file *file) +{ +struct drm_panthor_bo_set_label *args = data; +struct drm_gem_object *obj;
drivers/gpu/drm/panthor/panthor_drv.c static int panthor_ioctl_vm_get_state(struct drm_device *ddev, void *data, · line 1347
Quoted 10 lines
drivers/gpu/drm/panthor/panthor_drv.c +10
-0+const char *label; +unsigned long len; +int ret =0 ; + + obj =drm_gem_object_lookup (file, args->handle); +if (!obj) +return -ENOENT ; + +if (args->size && args->label) { + len = (args->size <PAGE_SIZE ) ? args->size :PAGE_SIZE ;
Let's return -E2BIG or -EINVAL if args->size is bigger exceeds our limit instead of pretending the label was stored.
Quoted 83 lines
drivers/gpu/drm/panthor/panthor_drv.c +22
-0+ label =strndup_user (u64_to_user_ptr (args->label), len); +if (IS_ERR (label)) { + ret =PTR_ERR (label); + goto err_label; + } + }else if (args->size && !args->label) { + ret = -EINVAL ; + goto err_label; + }else { + label =NULL ; + } + +panthor_gem_bo_set_label (obj, label); + +err_label: +drm_gem_object_put (obj); + +return ret; +} +static int panthor_open (struct drm_device *ddev,struct drm_file *file) {@@ -1399,6 +1434,7 @@ static const struct drm_ioctl_desc panthor_drm_driver_ioctls[] = {PANTHOR_IOCTL (TILER_HEAP_CREATE , tiler_heap_create,DRM_RENDER_ALLOW ),PANTHOR_IOCTL (TILER_HEAP_DESTROY , tiler_heap_destroy,DRM_RENDER_ALLOW ),PANTHOR_IOCTL (GROUP_SUBMIT , group_submit,DRM_RENDER_ALLOW ), + PANTHOR_IOCTL(BO_SET_LABEL, bo_set_label, DRM_RENDER_ALLOW), };static int panthor_mmap (struct file *filp,struct vm_area_struct *vma)@@ -1508,6 +1544,7 @@ static void panthor_debugfs_init(struct drm_minor *minor)* - 1.2 - adds DEV_QUERY_GROUP_PRIORITIES_INFO query * - adds PANTHOR_GROUP_PRIORITY_REALTIME priority * - 1.3 - adds DRM_PANTHOR_GROUP_STATE_INNOCENT flag +* - 1.4 - adds DRM_IOCTL_PANTHOR_BO_SET_LABEL ioctl */ static const struct drm_driver panthor_drm_driver = { .driver_features = DRIVER_RENDER | DRIVER_GEM | DRIVER_SYNCOBJ |include/uapi/drm/panthor_drm.h +19
-0@@ -127,6 +127,9 @@ enum drm_panthor_ioctl_id {/** @DRM_PANTHOR_TILER_HEAP_DESTROY: Destroy a tiler heap. */ DRM_PANTHOR_TILER_HEAP_DESTROY , + +/** @DRM_PANTHOR_BO_SET_LABEL: Label a BO. */ + DRM_PANTHOR_BO_SET_LABEL, };/** @@ -977,6 +980,20 @@ struct drm_panthor_tiler_heap_destroy {__u32 pad; }; +/** +* struct drm_panthor_bo_set_label - Arguments passed to DRM_IOCTL_PANTHOR_BO_SET_LABEL +*/ +struct drm_panthor_bo_set_label { +/** @handle: Handle of the buffer object to label. */ +__u32 handle; + +/** @size: Length of the label, including the NULL terminator. */ +__u32 size; + +/** @label: User pointer to a NULL-terminated string */ +__u64 label; +}; +/** * DRM_IOCTL_PANTHOR() - Build a Panthor IOCTL number * @__access: Access type. Must be R, W or RW. @@ -1019,6 +1036,8 @@ enum {DRM_IOCTL_PANTHOR (WR ,TILER_HEAP_CREATE , tiler_heap_create),DRM_IOCTL_PANTHOR_TILER_HEAP_DESTROY =DRM_IOCTL_PANTHOR (WR ,TILER_HEAP_DESTROY , tiler_heap_destroy), +DRM_IOCTL_PANTHOR_BO_SET_LABEL = + DRM_IOCTL_PANTHOR(WR, BO_SET_LABEL, bo_set_label), };#if defined(__cplusplus)
PATCH v2 3/4 drm/panthor: show device-wide list of DRM GEM objects over DebugFS
In reply to Adrián LarumbeAdd a device DebugFS file that displays a complete list of all the DRM GEM objects that are exposed to UM through a DRM handle.
Since leaking object identifiers that might belong to a different NS is inadmissible, this functionality is only made available in debug builds with DEBUGFS support enabled.
File format is that of a table, with each entry displaying a variety of fields with information about each GEM object.
Each GEM object entry in the file displays the following information
fields: Client PID, BO's global name, reference count, BO virtual size, BO resize size, VM address in its DRM-managed range, BO label and a flag bitmask.
--- drivers/gpu/drm/panthor/panthor_device.c | 5 + drivers/gpu/drm/panthor/panthor_device.h | 11 ++ drivers/gpu/drm/panthor/panthor_drv.c | 26 +++++ drivers/gpu/drm/panthor/panthor_gem.c | 130 +++++++++++++++++++++++ drivers/gpu/drm/panthor/panthor_gem.h | 29 +++++ 5 files changed, 201 insertions(+)
drivers/gpu/drm/panthor/panthor_device.c +5 -0
@@ -263,6 +263,11 @@ int panthor_device_init(struct panthor_device *ptdev)pm_runtime_set_autosuspend_delay (ptdev->base.dev,50 );pm_runtime_use_autosuspend (ptdev->base.dev); +#ifdef CONFIG_DEBUG_FS +drmm_mutex_init (&ptdev->base, &ptdev->gems.lock); +INIT_LIST_HEAD (&ptdev->gems.node); +#endif + ret =drm_dev_register (&ptdev->base,0 );if (ret) goto err_disable_autosuspend;
drivers/gpu/drm/panthor/panthor_device.h +11 -0
@@ -205,6 +205,17 @@ struct panthor_device {/** @fast_rate: Maximum device clock frequency. Set by DVFS */ unsigned long fast_rate; + +#ifdef CONFIG_DEBUG_FS +/** @gems: Device-wide list of GEM objects owned by at least one file. */ +struct { +/** @gems.lock: Protects the device-wide list of GEM objects. */ +struct mutex lock; + +/** @node: Used to keep track of all the device's DRM objects */ +struct list_head node; + } gems; +#endif };struct panthor_gpu_usage {
drivers/gpu/drm/panthor/panthor_drv.c +26 -0
@@ -1531,9 +1531,35 @@ static const struct file_operations panthor_drm_driver_fops = { };#ifdef CONFIG_DEBUG_FS +static int panthor_gems_show (struct seq_file *m,void *data) +{ +struct drm_info_node *node = m->private; +struct drm_device *dev = node->minor->dev; + struct panthor_device *ptdev = container_of(dev, struct panthor_device, base); + +panthor_gem_debugfs_print_bos (ptdev, m); + +return 0 ; +} + + +static struct drm_info_list panthor_debugfs_list[] = { + {"gems" , panthor_gems_show,0 ,NULL }, +}; + +static int panthor_gems_debugfs_init (struct drm_minor *minor) +{ +drm_debugfs_create_files (panthor_debugfs_list, +ARRAY_SIZE (panthor_debugfs_list), + minor->debugfs_root, minor); + +return 0 ; +} +static void panthor_debugfs_init (struct drm_minor *minor) {panthor_mmu_debugfs_init (minor); +panthor_gems_debugfs_init (minor); }#endif
drivers/gpu/drm/panthor/panthor_gem.c +130 -0
162 lines not on this page · raw message
drivers/gpu/drm/panthor/panthor_gem.h +29 -0
@@ -13,6 +13,26 @@struct panthor_vm ; +/** +* struct panthor_gem_debugfs - GEM object's DebugFS list information +*/ +struct panthor_gem_debugfs { +/** +* @node: Node used to insert the object in the device-wide list of +* GEM objects, to display information about it through a DebugFS file. +*/ +struct list_head node; + +/** @creator: Information about the UM process which created the GEM. */ +struct { +/** @creator.process_name: Group leader name in owning thread's process */ +char process_name[TASK_COMM_LEN ]; + +/** @creator.tgid: PID of the thread's group leader within its process */ +pid_t tgid; + } creator; +}; +/** * struct panthor_gem_object - Driver specific GEM object. */
@@ -60,6 +80,10 @@ struct panthor_gem_object {/** @lock.str: Protects access to the @label.str field. */ struct mutex lock; } label; + +#ifdef CONFIG_DEBUG_FS +struct panthor_gem_debugfs gems; +#endif };/**
@@ -155,4 +179,9 @@ panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,void panthor_kernel_bo_destroy (struct panthor_kernel_bo *bo); +#ifdef CONFIG_DEBUG_FS +void panthor_gem_debugfs_print_bos (struct panthor_device *pfdev, +struct seq_file *m); +#endif +#endif /* __PANTHOR_GEM_H__ */
Signature · 1 line
2.48.1
PATCH v2 4/4 drm/panthor: Display heap chunk entries in DebugFS GEMS file
In reply to Adrián LarumbeExpand the driver's DebugFS GEMS file to display entries for the heap chunks' GEM objects, both those allocated at heap creation time through an ioctl(), or in response to a tiler OOM event.
--- drivers/gpu/drm/panthor/panthor_gem.c | 22 +++++++++++----------- drivers/gpu/drm/panthor/panthor_gem.h | 2 ++ drivers/gpu/drm/panthor/panthor_heap.c | 3 +++ 3 files changed, 16 insertions(+), 11 deletions(-)
drivers/gpu/drm/panthor/panthor_gem.c +11 -11
@@ -22,16 +22,6 @@ static void panthor_gem_debugfs_bo_init(struct panthor_gem_object *bo)get_task_comm (bo->gems.creator.process_name, current->group_leader); } -static void panthor_gem_debugfs_bo_add (struct panthor_gem_object *bo) -{ -struct panthor_device *ptdev =container_of (bo->base.base.dev, - struct panthor_device, base); - -mutex_lock (&ptdev->gems.lock); -list_add_tail (&bo->gems.node, &ptdev->gems.node); -mutex_unlock (&ptdev->gems.lock); -} -static void panthor_gem_debugfs_bo_rm (struct panthor_gem_object *bo) { struct panthor_device *ptdev = container_of(bo->base.base.dev,
@@ -44,10 +34,20 @@ static void panthor_gem_debugfs_bo_rm(struct panthor_gem_object *bo)list_del_init (&bo->gems.node);mutex_unlock (&ptdev->gems.lock); } + +void panthor_gem_debugfs_bo_add (struct panthor_gem_object *bo) +{ +struct panthor_device *ptdev =container_of (bo->base.base.dev, + struct panthor_device, base); + +mutex_lock (&ptdev->gems.lock); +list_add_tail (&bo->gems.node, &ptdev->gems.node); +mutex_unlock (&ptdev->gems.lock); +}#else static void panthor_gem_debugfs_bo_init (struct panthor_gem_object *bo) {} -static void panthor_gem_debugfs_bo_add (struct panthor_gem_object *bo) {}static void panthor_gem_debugfs_bo_rm (struct panthor_gem_object *bo) {} +void panthor_gem_debugfs_bo_add (struct panthor_gem_object *bo) {}#endif static void panthor_gem_free_object (struct drm_gem_object *obj)
drivers/gpu/drm/panthor/panthor_gem.h +2 -0
@@ -132,6 +132,8 @@ panthor_gem_create_with_handle(struct drm_file *file,void panthor_gem_bo_set_label (struct drm_gem_object *obj,const char *label);void panthor_gem_kernel_bo_set_label (struct panthor_kernel_bo *bo,const char *label); +void panthor_gem_debugfs_bo_add (struct panthor_gem_object *bo); +static inline u64 panthor_kernel_bo_gpuva (struct panthor_kernel_bo *bo) {
drivers/gpu/drm/panthor/panthor_heap.c +3 -0
@@ -180,6 +180,9 @@ static int panthor_alloc_heap_chunk(struct panthor_device *ptdev, heap->chunk_count++;mutex_unlock (&heap->lock); +panthor_gem_kernel_bo_set_label (chunk->bo,"\"Tiler heap chunk\"" ); +panthor_gem_debugfs_bo_add (to_panthor_bo (chunk->bo->obj)); +return 0 ; err_destroy_bo:
Signature · 1 line
2.48.1
Boris Brezillon
maintainerRe: [PATCH v2 4/4] drm/panthor: Display heap chunk entries in DebugFS GEMS file
Quoted 41 lines · On Wed, 19 Mar 2025 15:03:19 +0000 Adrián Larumbe…
Expand the driver's DebugFS GEMS file to display entries for the heap chunks' GEM objects, both those allocated at heap creation time through an
ioctl(), or in response to a tiler OOM event.Signed-off-by Adrián Larumbe <[email protected]>--- drivers/gpu/drm/panthor/panthor_gem.c | 22 +++++++++++----------- drivers/gpu/drm/panthor/panthor_gem.h | 2 ++ drivers/gpu/drm/panthor/panthor_heap.c | 3 +++ 3 files changed, 16 insertions(+), 11 deletions(-)drivers/gpu/drm/panthor/panthor_gem.c +5
-10@@ -22,16 +22,6 @@ static void panthor_gem_debugfs_bo_init(struct panthor_gem_object *bo)get_task_comm (bo->gems.creator.process_name, current->group_leader); } -static void panthor_gem_debugfs_bo_add (struct panthor_gem_object *bo) -{ -struct panthor_device *ptdev =container_of (bo->base.base.dev, - struct panthor_device, base); - -mutex_lock (&ptdev->gems.lock); -list_add_tail (&bo->gems.node, &ptdev->gems.node); -mutex_unlock (&ptdev->gems.lock); -} -static void panthor_gem_debugfs_bo_rm (struct panthor_gem_object *bo) { struct panthor_device *ptdev = container_of(bo->base.base.dev,@@ -44,10 +34,20 @@ static void panthor_gem_debugfs_bo_rm(struct panthor_gem_object *bo)list_del_init (&bo->gems.node);mutex_unlock (&ptdev->gems.lock); } + +void panthor_gem_debugfs_bo_add (struct panthor_gem_object *bo) +{ +struct panthor_device *ptdev =container_of (bo->base.base.dev, + struct panthor_device, base);
drivers/gpu/drm/panthor/panthor_gem.c static void panthor_gem_debugfs_bo_rm(struct panthor_gem_object *bo) · line 50
Quoted 10 lines
drivers/gpu/drm/panthor/panthor_gem.c +6
-1+ +mutex_lock (&ptdev->gems.lock); +list_add_tail (&bo->gems.node, &ptdev->gems.node); + mutex_unlock(&ptdev->gems.lock); +}#else static void panthor_gem_debugfs_bo_init (struct panthor_gem_object *bo) {} -static void panthor_gem_debugfs_bo_add (struct panthor_gem_object *bo) {}static void panthor_gem_debugfs_bo_rm (struct panthor_gem_object *bo) {} +void panthor_gem_debugfs_bo_add (struct panthor_gem_object *bo) {}
Let's just define all these helpers as inline functions in panthor_gem.h in patch 3.
Quoted 21 lines
drivers/gpu/drm/panthor/panthor_gem.c +0
-0#endif static void panthor_gem_free_object (struct drm_gem_object *obj)drivers/gpu/drm/panthor/panthor_gem.h +2
-0@@ -132,6 +132,8 @@ panthor_gem_create_with_handle(struct drm_file *file,void panthor_gem_bo_set_label (struct drm_gem_object *obj,const char *label);void panthor_gem_kernel_bo_set_label (struct panthor_kernel_bo *bo,const char *label); +void panthor_gem_debugfs_bo_add (struct panthor_gem_object *bo); +static inline u64 panthor_kernel_bo_gpuva (struct panthor_kernel_bo *bo) {drivers/gpu/drm/panthor/panthor_heap.c +0
-0
drivers/gpu/drm/panthor/panthor_heap.c static int panthor_alloc_heap_chunk(struct panthor_device *ptdev, · line 184
Quoted 5 lines
drivers/gpu/drm/panthor/panthor_heap.c +2
-0@@ -180,6 +180,9 @@ static int panthor_alloc_heap_chunk(struct panthor_device *ptdev, heap->chunk_count++;mutex_unlock (&heap->lock); +panthor_gem_kernel_bo_set_label (chunk->bo,"\"Tiler heap chunk\"" ); +panthor_gem_debugfs_bo_add (to_panthor_bo (chunk->bo->obj));
I'd be tempted to label all the kernel BOs, not just the heap chunks, and if we do that, we're probably better off changing the kernel_bo_create() prototype to pass a label.
Quoted 4 lines
drivers/gpu/drm/panthor/panthor_heap.c +1
-0+return 0 ; err_destroy_bo:
Re: [PATCH v2 4/4] drm/panthor: Display heap chunk entries in DebugFS GEMS file
Quoted 49 lines · Boris Brezillon
Quoted 46 lines · On Wed, 19 Mar 2025 15:03:19 +0000 Adrián Larumbe…
Expand the driver's DebugFS GEMS file to display entries for the heap chunks' GEM objects, both those allocated at heap creation time through an
ioctl(), or in response to a tiler OOM event.Signed-off-by Adrián Larumbe <[email protected]>--- drivers/gpu/drm/panthor/panthor_gem.c | 22 +++++++++++----------- drivers/gpu/drm/panthor/panthor_gem.h | 2 ++ drivers/gpu/drm/panthor/panthor_heap.c | 3 +++ 3 files changed, 16 insertions(+), 11 deletions(-)drivers/gpu/drm/panthor/panthor_gem.c +10
-10@@ -22,16 +22,6 @@ static void panthor_gem_debugfs_bo_init(struct panthor_gem_object *bo)get_task_comm (bo->gems.creator.process_name, current->group_leader); } -static void panthor_gem_debugfs_bo_add (struct panthor_gem_object *bo) -{ -struct panthor_device *ptdev =container_of (bo->base.base.dev, - struct panthor_device, base); - -mutex_lock (&ptdev->gems.lock); -list_add_tail (&bo->gems.node, &ptdev->gems.node); -mutex_unlock (&ptdev->gems.lock); -} -static void panthor_gem_debugfs_bo_rm (struct panthor_gem_object *bo) { struct panthor_device *ptdev = container_of(bo->base.base.dev,@@ -44,10 +34,20 @@ static void panthor_gem_debugfs_bo_rm(struct panthor_gem_object *bo)list_del_init (&bo->gems.node);mutex_unlock (&ptdev->gems.lock); } + +void panthor_gem_debugfs_bo_add (struct panthor_gem_object *bo) +{ +struct panthor_device *ptdev =container_of (bo->base.base.dev, + struct panthor_device, base); + +mutex_lock (&ptdev->gems.lock); +list_add_tail (&bo->gems.node, &ptdev->gems.node); +mutex_unlock (&ptdev->gems.lock); +}
Quoted 8 lines
drivers/gpu/drm/panthor/panthor_gem.c static void panthor_gem_debugfs_bo_rm(struct panthor_gem_object *bo) · line 50
Quoted 5 lines
drivers/gpu/drm/panthor/panthor_gem.c +1
-1#else static void panthor_gem_debugfs_bo_init (struct panthor_gem_object *bo) {} -static void panthor_gem_debugfs_bo_add (struct panthor_gem_object *bo) {}static void panthor_gem_debugfs_bo_rm (struct panthor_gem_object *bo) {} +void panthor_gem_debugfs_bo_add (struct panthor_gem_object *bo) {}Let's just define all these helpers as inline functions in
panthor_gem.hin patch 3.
The only function that can so far be used from a different compilation unit is 'add'. The other two are internal to panthor_gem.c, so I'm incluned to keep them there as static functions, but move 'add' into the header file as a static inline function instead.
Quoted 24 lines
Quoted 24 lines
drivers/gpu/drm/panthor/panthor_gem.c +0
-0#endif static void panthor_gem_free_object (struct drm_gem_object *obj)drivers/gpu/drm/panthor/panthor_gem.h +2
-0@@ -132,6 +132,8 @@ panthor_gem_create_with_handle(struct drm_file *file,void panthor_gem_bo_set_label (struct drm_gem_object *obj,const char *label);void panthor_gem_kernel_bo_set_label (struct panthor_kernel_bo *bo,const char *label); +void panthor_gem_debugfs_bo_add (struct panthor_gem_object *bo); +static inline u64 panthor_kernel_bo_gpuva (struct panthor_kernel_bo *bo) {drivers/gpu/drm/panthor/panthor_heap.c +0
-0@@ -180,6 +180,9 @@ static int panthor_alloc_heap_chunk(struct panthor_device *ptdev, heap->chunk_count++;mutex_unlock (&heap->lock);
Quoted 6 lines
drivers/gpu/drm/panthor/panthor_heap.c static int panthor_alloc_heap_chunk(struct panthor_device *ptdev, · line 184
Quoted 2 lines
drivers/gpu/drm/panthor/panthor_heap.c +2
-0+panthor_gem_kernel_bo_set_label (chunk->bo,"\"Tiler heap chunk\"" ); +panthor_gem_debugfs_bo_add (to_panthor_bo (chunk->bo->obj));I'd be tempted to label all the kernel BOs, not just the heap chunks, and if we do that, we're probably better off changing the
kernel_bo_create()prototype to pass a label.
I think is a good idea going forward, but in keeping things tight I'd say doing it now might be an overkill, since the only user of tagged BO's at the moment is the gem debugfs knob.
I think if in the future we find new ways of accounting or displaying labelled kernel BO's other than heap chunks, then we can expand the kernel_bo_create() argument list and then tag every single one of them at creation time.
Quoted 4 lines
drivers/gpu/drm/panthor/panthor_heap.c static int panthor_alloc_heap_chunk(struct panthor_device *ptdev, · line 188
Quoted 4 lines
drivers/gpu/drm/panthor/panthor_heap.c +1
-0+return 0 ; err_destroy_bo:
Adrian Larumbe
Boris Brezillon
maintainerRe: [PATCH v2 4/4] drm/panthor: Display heap chunk entries in DebugFS GEMS file
Quoted 59 lines · On Thu, 27 Mar 2025 13:18:47 +0000 Adrián Larumbe…
Quoted 49 lines · Boris Brezillon
Quoted 46 lines · On Wed, 19 Mar 2025 15:03:19 +0000 Adrián Larumbe…
Expand the driver's DebugFS GEMS file to display entries for the heap chunks' GEM objects, both those allocated at heap creation time through an
ioctl(), or in response to a tiler OOM event.Signed-off-by Adrián Larumbe <[email protected]>--- drivers/gpu/drm/panthor/panthor_gem.c | 22 +++++++++++----------- drivers/gpu/drm/panthor/panthor_gem.h | 2 ++ drivers/gpu/drm/panthor/panthor_heap.c | 3 +++ 3 files changed, 16 insertions(+), 11 deletions(-)drivers/gpu/drm/panthor/panthor_gem.c +10
-10@@ -22,16 +22,6 @@ static void panthor_gem_debugfs_bo_init(struct panthor_gem_object *bo)get_task_comm (bo->gems.creator.process_name, current->group_leader); } -static void panthor_gem_debugfs_bo_add (struct panthor_gem_object *bo) -{ -struct panthor_device *ptdev =container_of (bo->base.base.dev, - struct panthor_device, base); - -mutex_lock (&ptdev->gems.lock); -list_add_tail (&bo->gems.node, &ptdev->gems.node); -mutex_unlock (&ptdev->gems.lock); -} -static void panthor_gem_debugfs_bo_rm (struct panthor_gem_object *bo) { struct panthor_device *ptdev = container_of(bo->base.base.dev,@@ -44,10 +34,20 @@ static void panthor_gem_debugfs_bo_rm(struct panthor_gem_object *bo)list_del_init (&bo->gems.node);mutex_unlock (&ptdev->gems.lock); } + +void panthor_gem_debugfs_bo_add (struct panthor_gem_object *bo) +{ +struct panthor_device *ptdev =container_of (bo->base.base.dev, + struct panthor_device, base); + +mutex_lock (&ptdev->gems.lock); +list_add_tail (&bo->gems.node, &ptdev->gems.node); +mutex_unlock (&ptdev->gems.lock); +}Quoted 8 lines
drivers/gpu/drm/panthor/panthor_gem.c static void panthor_gem_debugfs_bo_rm(struct panthor_gem_object *bo) · line 50
Quoted 5 lines
drivers/gpu/drm/panthor/panthor_gem.c +1
-1#else static void panthor_gem_debugfs_bo_init (struct panthor_gem_object *bo) {} -static void panthor_gem_debugfs_bo_add (struct panthor_gem_object *bo) {}static void panthor_gem_debugfs_bo_rm (struct panthor_gem_object *bo) {} +void panthor_gem_debugfs_bo_add (struct panthor_gem_object *bo) {}Let's just define all these helpers as inline functions in
panthor_gem.hin patch 3.
Quoted 3 lines
The only function that can so far be used from a different compilation unit is 'add'. The other two are internal to
panthor_gem.c, so I'm incluned to keep them there as static functions, but move 'add' into the header file as a static inline function instead.
I'd really prefer if those were defined next to each other, and given how short/simple they are, I don't see a good reason to hide them.
Quoted 32 lines
Quoted 25 lines
Quoted 25 lines
drivers/gpu/drm/panthor/panthor_gem.c +0
-0#endif static void panthor_gem_free_object (struct drm_gem_object *obj)drivers/gpu/drm/panthor/panthor_gem.h +2
-0@@ -132,6 +132,8 @@ panthor_gem_create_with_handle(struct drm_file *file,void panthor_gem_bo_set_label (struct drm_gem_object *obj,const char *label);void panthor_gem_kernel_bo_set_label (struct panthor_kernel_bo *bo,const char *label); +void panthor_gem_debugfs_bo_add (struct panthor_gem_object *bo); +static inline u64 panthor_kernel_bo_gpuva (struct panthor_kernel_bo *bo) {drivers/gpu/drm/panthor/panthor_heap.c +0
-0@@ -180,6 +180,9 @@ static int panthor_alloc_heap_chunk(struct panthor_device *ptdev, heap->chunk_count++;mutex_unlock (&heap->lock);Quoted 6 lines
drivers/gpu/drm/panthor/panthor_heap.c static int panthor_alloc_heap_chunk(struct panthor_device *ptdev, · line 184
Quoted 2 lines
drivers/gpu/drm/panthor/panthor_heap.c +2
-0+panthor_gem_kernel_bo_set_label (chunk->bo,"\"Tiler heap chunk\"" ); +panthor_gem_debugfs_bo_add (to_panthor_bo (chunk->bo->obj));I'd be tempted to label all the kernel BOs, not just the heap chunks, and if we do that, we're probably better off changing the
kernel_bo_create()prototype to pass a label.
Quoted 7 lines
I think is a good idea going forward, but in keeping things tight I'd say doing it now might be an overkill, since the only user of tagged BO's at the moment is the gem debugfs knob.
I think if in the future we find new ways of accounting or displaying labelled kernel BO's other than heap chunks, then we can expand the
kernel_bo_create()argument list and then tag every single one of them at creation time.
Yeah, actually I'm questioning the fact we don't register all BOs to the debugfs list now. If it's going to be a debugfs interface, I don't really see a good reason for hiding some but exposing others. important to show.