drm: fdinfo memory stats
Subsystems (8)
v4 cover drm: fdinfo memory stats
From: Rob Clark <[email protected]>
Similar motivation to other similar recent attempt[1]. But with an attempt to have some shared code for this. As well as documentation.
It is probably a bit UMA-centric, I guess devices with VRAM might want some placement stats as well. But this seems like a reasonable start.
Basic gputop support: https://patchwork.freedesktop.org/series/116236/
And already nvtop support: https://github.com/Syllo/nvtop/pull/204
[1] https://patchwork.freedesktop.org/series/112397/
Rob Clark (6):
drm: Add common fdinfo helper
drm/msm: Switch to fdinfo helper
drm/amdgpu: Switch to fdinfo helper
drm/i915: Switch to fdinfo helper
drm: Add fdinfo memory stats
drm/msm: Add memory stats to fdinfo
Documentation/gpu/drm-usage-stats.rst | 31 +++++- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c | 16 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.h | 2 +- drivers/gpu/drm/drm_file.c | 111 +++++++++++++++++++++ drivers/gpu/drm/i915/i915_driver.c | 3 +- drivers/gpu/drm/i915/i915_drm_client.c | 18 +--- drivers/gpu/drm/i915/i915_drm_client.h | 2 +- drivers/gpu/drm/msm/msm_drv.c | 11 +- drivers/gpu/drm/msm/msm_gem.c | 15 +++ drivers/gpu/drm/msm/msm_gpu.c | 2 - include/drm/drm_drv.h | 7 ++ include/drm/drm_file.h | 5 + include/drm/drm_gem.h | 30 ++++++ 14 files changed, 220 insertions(+), 36 deletions(-)
Signature · 1 line
2.39.2
PATCH v4 1/6 drm: Add common fdinfo helper
From: Rob Clark <[email protected]>
Handle a bit of the boiler-plate in a single case, and make it easier to add some core tracked stats.
v2: Update drm-usage-stats.rst, 64b client-id, rename drm_show_fdinfo
--- Documentation/gpu/drm-usage-stats.rst | 10 +++++++- drivers/gpu/drm/drm_file.c | 35 +++++++++++++++++++++++++++ include/drm/drm_drv.h | 7 ++++++ include/drm/drm_file.h | 4 +++ 4 files changed, 55 insertions(+), 1 deletion(-)
Documentation/gpu/drm-usage-stats.rst +9 -1
@@ -126,7 +126,15 @@ percentage utilization of the engine, whereas drm-engine-<str> only reflects time active without considering what frequency the engine is operating as a percentage of it's maximum frequency. +Implementation Details +====================== + +Drivers should use drm_show_fdinfo() in their `struct file_operations`, and +implement &drm_driver.show_fdinfo if they wish to provide any stats which +are not provided by drm_show_fdinfo(). But even driver specific stats should +be documented above and where possible, aligned with other drivers. + Driver specific implementations -=============================== +------------------------------- :ref:`i915-usage-stats`
drivers/gpu/drm/drm_file.c +35 -0
@@ -148,6 +148,7 @@ bool drm_dev_needs_global_mutex(struct drm_device *dev)*/ struct drm_file *drm_file_alloc (struct drm_minor *minor) { +static atomic64_t ident =ATOMIC_INIT (0 );struct drm_device *dev = minor->dev;struct drm_file *file;int ret;
@@ -156,6 +157,8 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor)if (!file)return ERR_PTR (-ENOMEM ); +/* Get a unique identifier for fdinfo: */ + file->client_id =atomic64_inc_return (&ident); file->pid =get_pid (task_pid (current)); file->minor = minor;
@@ -868,6 +871,38 @@ void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) }EXPORT_SYMBOL (drm_send_event); +/** +* drm_show_fdinfo - helper for drm file fops +* @seq_file: output stream +* @f: the device file instance +* +* Helper to implement fdinfo, for userspace to query usage stats, etc, of a +* process using the GPU. See also &drm_driver.show_fdinfo. +* +* For text output format description please see Documentation/gpu/drm-usage-stats.rst +*/ +void drm_show_fdinfo (struct seq_file *m,struct file *f) +{ +struct drm_file *file = f->private_data; +struct drm_device *dev = file->minor->dev; +struct drm_printer p =drm_seq_file_printer (m); + +drm_printf (&p,"drm-driver:\t%s\n" , dev->driver->name); +drm_printf (&p,"drm-client-id:\t%llu\n" , file->client_id); + +if (dev_is_pci (dev->dev)) { +struct pci_dev *pdev =to_pci_dev (dev->dev); + +drm_printf (&p,"drm-pdev:\t%04x:%02x:%02x.%d\n" , +pci_domain_nr (pdev->bus), pdev->bus->number, +PCI_SLOT (pdev->devfn),PCI_FUNC (pdev->devfn)); + } + +if (dev->driver->show_fdinfo) + dev->driver->show_fdinfo (&p, file); +} +EXPORT_SYMBOL (drm_show_fdinfo); +/** * mock_drm_getfile - Create a new struct file for the drm device * @minor: drm minor to wrap (e.g. #drm_device.primary)
include/drm/drm_drv.h +7 -0
@@ -401,6 +401,13 @@ struct drm_driver { struct drm_device *dev, uint32_t handle, uint64_t *offset); +/** +* @show_fdinfo: +* +* Print device specific fdinfo. See Documentation/gpu/drm-usage-stats.rst. +*/ +void (*show_fdinfo)(struct drm_printer *p,struct drm_file *f); +/** @major: driver major number */ int major;/** @minor: driver minor number */
include/drm/drm_file.h +4 -0
@@ -258,6 +258,9 @@ struct drm_file {/** @pid: Process that opened this file. */ struct pid *pid; +/** @client_id: A unique id for fdinfo */ +u64 client_id; +/** @magic: Authentication magic, see @authenticated. */ drm_magic_t magic;
@@ -437,6 +440,7 @@ void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);void drm_send_event_timestamp_locked (struct drm_device *dev,struct drm_pending_event *e,ktime_t timestamp); +void drm_show_fdinfo (struct seq_file *m,struct file *f);struct file *mock_drm_getfile (struct drm_minor *minor,unsigned int flags);
Signature · 1 line
2.39.2
PATCH v4 2/6 drm/msm: Switch to fdinfo helper
In reply to Rob ClarkFrom: Rob Clark <[email protected]>
--- drivers/gpu/drm/msm/msm_drv.c | 11 +++++------ drivers/gpu/drm/msm/msm_gpu.c | 2 -- 2 files changed, 5 insertions(+), 8 deletions(-)
drivers/gpu/drm/msm/msm_drv.c +5 -6
@@ -1043,23 +1043,21 @@ static const struct drm_ioctl_desc msm_ioctls[] = { DRM_IOCTL_DEF_DRV(MSM_SUBMITQUEUE_QUERY, msm_ioctl_submitqueue_query, DRM_RENDER_ALLOW), }; -static void msm_fop_show_fdinfo (struct seq_file *m,struct file *f) +static void msm_show_fdinfo (struct drm_printer *p,struct drm_file *file) { -struct drm_file *file = f->private_data;struct drm_device *dev = file->minor->dev;struct msm_drm_private *priv = dev->dev_private; -struct drm_printer p =drm_seq_file_printer (m);if (!priv->gpu)return ; -msm_gpu_show_fdinfo (priv->gpu, file->driver_priv, &p); +msm_gpu_show_fdinfo (priv->gpu, file->driver_priv, p); }static const struct file_operations fops = { .owner =THIS_MODULE ,DRM_GEM_FOPS , - .show_fdinfo = msm_fop_show_fdinfo, + .show_fdinfo = drm_show_fdinfo, };static const struct drm_driver msm_driver = {
@@ -1070,7 +1068,7 @@ static const struct drm_driver msm_driver = {DRIVER_SYNCOBJ_TIMELINE | DRIVER_SYNCOBJ, .open = msm_open, - .postclose = msm_postclose, + .postclose = msm_postclose, .lastclose = drm_fb_helper_lastclose, .dumb_create = msm_gem_dumb_create, .dumb_map_offset = msm_gem_dumb_map_offset,
@@ -1081,6 +1079,7 @@ static const struct drm_driver msm_driver = {#ifdef CONFIG_DEBUG_FS .debugfs_init = msm_debugfs_init, #endif + .show_fdinfo = msm_show_fdinfo, .ioctls = msm_ioctls, .num_ioctls = ARRAY_SIZE(msm_ioctls), .fops = &fops,
drivers/gpu/drm/msm/msm_gpu.c +0 -2
@@ -151,8 +151,6 @@ int msm_gpu_pm_suspend(struct msm_gpu *gpu)void msm_gpu_show_fdinfo (struct msm_gpu *gpu,struct msm_file_private *ctx,struct drm_printer *p) { -drm_printf (p,"drm-driver:\t%s\n" , gpu->dev->driver->name); -drm_printf (p,"drm-client-id:\t%u\n" , ctx->seqno);drm_printf (p,"drm-engine-gpu:\t%llu ns\n" , ctx->elapsed_ns);drm_printf (p,"drm-cycles-gpu:\t%llu\n" , ctx->cycles);drm_printf (p,"drm-maxfreq-gpu:\t%u Hz\n" , gpu->fast_rate);
Signature · 1 line
2.39.2
PATCH v4 3/6 drm/amdgpu: Switch to fdinfo helper
In reply to Rob ClarkFrom: Rob Clark <[email protected]>
--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c | 16 ++++++---------- drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.h | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -1
@@ -2752,7 +2752,7 @@ static const struct file_operations amdgpu_driver_kms_fops = { .compat_ioctl = amdgpu_kms_compat_ioctl,#endif #ifdef CONFIG_PROC_FS - .show_fdinfo = amdgpu_show_fdinfo + .show_fdinfo = drm_show_fdinfo,#endif };
@@ -2807,6 +2807,7 @@ static const struct drm_driver amdgpu_kms_driver = { .dumb_map_offset = amdgpu_mode_dumb_mmap, .fops = &amdgpu_driver_kms_fops, .release = &amdgpu_driver_release_kms, + .show_fdinfo = amdgpu_show_fdinfo, .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c +6 -10
@@ -53,9 +53,8 @@ static const char *amdgpu_ip_name[AMDGPU_HW_IP_NUM] = { [AMDGPU_HW_IP_VCN_JPEG] = "jpeg", }; -void amdgpu_show_fdinfo (struct seq_file *m,struct file *f) +void amdgpu_show_fdinfo (struct drm_printer *p,struct drm_file *file) { -struct drm_file *file = f->private_data;struct amdgpu_device *adev =drm_to_adev (file->minor->dev);struct amdgpu_fpriv *fpriv = file->driver_priv;struct amdgpu_vm *vm = &fpriv->vm;
@@ -86,18 +85,15 @@ void amdgpu_show_fdinfo(struct seq_file *m, struct file *f)* ****************************************************************** */ -seq_printf (m,"pasid:\t%u\n" , fpriv->vm.pasid); -seq_printf (m,"drm-driver:\t%s\n" , file->minor->dev->driver->name); -seq_printf (m,"drm-pdev:\t%04x:%02x:%02x.%d\n" , domain, bus, dev, fn); -seq_printf (m,"drm-client-id:\t%Lu\n" , vm->immediate.fence_context); -seq_printf (m,"drm-memory-vram:\t%llu KiB\n" , vram_mem/1024UL ); -seq_printf (m,"drm-memory-gtt: \t%llu KiB\n" , gtt_mem/1024UL ); -seq_printf (m,"drm-memory-cpu: \t%llu KiB\n" , cpu_mem/1024UL ); +drm_printf (p,"pasid:\t%u\n" , fpriv->vm.pasid); +drm_printf (p,"drm-memory-vram:\t%llu KiB\n" , vram_mem/1024UL ); +drm_printf (p,"drm-memory-gtt: \t%llu KiB\n" , gtt_mem/1024UL ); +drm_printf (p,"drm-memory-cpu: \t%llu KiB\n" , cpu_mem/1024UL );for (hw_ip =0 ; hw_ip <AMDGPU_HW_IP_NUM ; ++hw_ip) {if (!usage[hw_ip])continue ; -seq_printf (m,"drm-engine-%s:\t%Ld ns\n" , amdgpu_ip_name[hw_ip], +drm_printf (p,"drm-engine-%s:\t%Ld ns\n" , amdgpu_ip_name[hw_ip],ktime_to_ns (usage[hw_ip])); } }
drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.h +1 -1
@@ -37,6 +37,6 @@#include "amdgpu_ids.h" uint32_t amdgpu_get_ip_count (struct amdgpu_device *adev,int id); -void amdgpu_show_fdinfo (struct seq_file *m,struct file *f); +void amdgpu_show_fdinfo (struct drm_printer *p,struct drm_file *file);#endif
Signature · 1 line
2.39.2
PATCH v4 4/6 drm/i915: Switch to fdinfo helper
In reply to Rob ClarkFrom: Rob Clark <[email protected]>
--- drivers/gpu/drm/i915/i915_driver.c | 3 ++- drivers/gpu/drm/i915/i915_drm_client.c | 18 +++++------------- drivers/gpu/drm/i915/i915_drm_client.h | 2 +- 3 files changed, 8 insertions(+), 15 deletions(-)
drivers/gpu/drm/i915/i915_driver.c +2 -1
@@ -1696,7 +1696,7 @@ static const struct file_operations i915_driver_fops = { .compat_ioctl = i915_ioc32_compat_ioctl, .llseek = noop_llseek, #ifdef CONFIG_PROC_FS - .show_fdinfo = i915_drm_client_fdinfo, + .show_fdinfo = drm_show_fdinfo,#endif };
@@ -1796,6 +1796,7 @@ static const struct drm_driver i915_drm_driver = { .open = i915_driver_open, .lastclose = i915_driver_lastclose, .postclose = i915_driver_postclose, + .show_fdinfo = i915_drm_client_fdinfo, .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
drivers/gpu/drm/i915/i915_drm_client.c +5 -13
@@ -101,7 +101,7 @@ static u64 busy_add(struct i915_gem_context *ctx, unsigned int class) }static void -show_client_class (struct seq_file *m, +show_client_class (struct drm_printer *p,struct i915_drm_client *client,unsigned int class) {
@@ -117,22 +117,20 @@ show_client_class(struct seq_file *m,rcu_read_unlock ();if (capacity) -seq_printf (m,"drm-engine-%s:\t%llu ns\n" , +drm_printf (p,"drm-engine-%s:\t%llu ns\n" , uabi_class_names[class], total);if (capacity >1 ) -seq_printf (m,"drm-engine-capacity-%s:\t%u\n" , +drm_printf (p,"drm-engine-capacity-%s:\t%u\n" , uabi_class_names[class], capacity); } -void i915_drm_client_fdinfo (struct seq_file *m,struct file *f) +void i915_drm_client_fdinfo (struct drm_printer *p,struct drm_file *file) { -struct drm_file *file = f->private_data;struct drm_i915_file_private *file_priv = file->driver_priv;struct drm_i915_private *i915 = file_priv->dev_priv;struct i915_drm_client *client = file_priv->client; -struct pci_dev *pdev =to_pci_dev (i915->drm.dev);unsigned int i;/*
@@ -141,12 +139,6 @@ void i915_drm_client_fdinfo(struct seq_file *m, struct file *f)* ****************************************************************** */ -seq_printf (m,"drm-driver:\t%s\n" , i915->drm.driver->name); -seq_printf (m,"drm-pdev:\t%04x:%02x:%02x.%d\n" , -pci_domain_nr (pdev->bus), pdev->bus->number, -PCI_SLOT (pdev->devfn),PCI_FUNC (pdev->devfn)); -seq_printf (m,"drm-client-id:\t%u\n" , client->id); -/* * Temporarily skip showing client engine information with GuC submission till * fetching engine busyness is implemented in the GuC submission backend
@@ -155,6 +147,6 @@ void i915_drm_client_fdinfo(struct seq_file *m, struct file *f)return ;for (i =0 ; i <ARRAY_SIZE (uabi_class_names); i++) - show_client_class(m, client, i); + show_client_class(p, client, i); }#endif
drivers/gpu/drm/i915/i915_drm_client.h +1 -1
@@ -60,7 +60,7 @@ static inline void i915_drm_client_put(struct i915_drm_client *client)struct i915_drm_client *i915_drm_client_add (struct i915_drm_clients *clients);#ifdef CONFIG_PROC_FS -void i915_drm_client_fdinfo (struct seq_file *m,struct file *f); +void i915_drm_client_fdinfo (struct drm_printer *p,struct drm_file *file);#endif void i915_drm_clients_fini (struct i915_drm_clients *clients);
Signature · 1 line
2.39.2
PATCH v4 6/6 drm/msm: Add memory stats to fdinfo
In reply to Rob ClarkFrom: Rob Clark <[email protected]>
Use the new helper to export stats about memory usage.
v2: Drop unintended hunk
v3: Rebase
--- drivers/gpu/drm/msm/msm_gem.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/gpu/drm/msm/msm_gem.c +15 -0
@@ -1096,6 +1096,20 @@ int msm_gem_new_handle(struct drm_device *dev, struct drm_file *file,return ret; } +static enum drm_gem_object_status msm_gem_status (struct drm_gem_object *obj) +{ +struct msm_gem_object *msm_obj =to_msm_bo (obj); +enum drm_gem_object_status status =0 ; + +if (msm_obj->pages) + status |=DRM_GEM_OBJECT_RESIDENT ; + +if (msm_obj->madv ==MSM_MADV_DONTNEED ) + status |=DRM_GEM_OBJECT_PURGEABLE ; + +return status; +} +static const struct vm_operations_struct vm_ops = { .fault = msm_gem_fault, .open = drm_gem_vm_open,
@@ -1110,6 +1124,7 @@ static const struct drm_gem_object_funcs msm_gem_object_funcs = { .vmap = msm_gem_prime_vmap, .vunmap = msm_gem_prime_vunmap, .mmap = msm_gem_object_mmap, + .status = msm_gem_status, .vm_ops = &vm_ops, };
Signature · 1 line
2.39.2
PATCH v4 5/6 drm: Add fdinfo memory stats
In reply to Rob ClarkFrom: Rob Clark <[email protected]>
Add support to dump GEM stats to fdinfo.
v2: Fix typos, change size units to match docs, use div_u64
v3: Do it in core
v4: more kerneldoc
--- Documentation/gpu/drm-usage-stats.rst | 21 ++++++++ drivers/gpu/drm/drm_file.c | 76 +++++++++++++++++++++++++++ include/drm/drm_file.h | 1 + include/drm/drm_gem.h | 30 +++++++++++ 4 files changed, 128 insertions(+)
Documentation/gpu/drm-usage-stats.rst +21 -0
@@ -105,6 +105,27 @@ object belong to this client, in the respective memory region. Default unit shall be bytes with optional unit specifiers of 'KiB' or 'MiB' indicating kibi- or mebi-bytes. +- drm-shared-memory: <uint> [KiB|MiB] + +The total size of buffers that are shared with another file (ie. have more +than a single handle). + +- drm-private-memory: <uint> [KiB|MiB] + +The total size of buffers that are not shared with another file. + +- drm-resident-memory: <uint> [KiB|MiB] + +The total size of buffers that are resident in system memory. + +- drm-purgeable-memory: <uint> [KiB|MiB] + +The total size of buffers that are purgeable. + +- drm-active-memory: <uint> [KiB|MiB] + +The total size of buffers that are active on one or more rings. + - drm-cycles-<str> <uint> Engine identifier string must be the same as the one specified in the
drivers/gpu/drm/drm_file.c +76 -0
94 lines not on this page · raw message
include/drm/drm_file.h +1 -0
@@ -41,6 +41,7 @@struct dma_fence ;struct drm_file ;struct drm_device ; +struct drm_printer ;struct device ;struct file ;
include/drm/drm_gem.h +30 -0
@@ -42,6 +42,25 @@struct iosys_map ;struct drm_gem_object ; +/** +* enum drm_gem_object_status - bitmask of object state for fdinfo reporting +* @DRM_GEM_OBJECT_RESIDENT: object is resident in memory (ie. not unpinned) +* @DRM_GEM_OBJECT_PURGEABLE: object marked as purgeable by userspace +* +* Bitmask of status used for fdinfo memory stats, see &drm_gem_object_funcs.status +* and drm_show_fdinfo(). Note that an object can DRM_GEM_OBJECT_PURGEABLE if +* it still active or not resident, in which case drm_show_fdinfo() will not +* account for it as purgeable. So drivers do not need to check if the buffer +* is idle and resident to return this bit. (Ie. userspace can mark a buffer +* as purgeable even while it is still busy on the GPU.. it does not _actually_ +* become puregeable until it becomes idle. The status gem object func does +* not need to consider this.) +*/ +enum drm_gem_object_status { +DRM_GEM_OBJECT_RESIDENT =BIT (0 ), +DRM_GEM_OBJECT_PURGEABLE =BIT (1 ), +}; +/** * struct drm_gem_object_funcs - GEM object functions */
@@ -174,6 +193,17 @@ struct drm_gem_object_funcs {*/ int (*evict)(struct drm_gem_object *obj); +/** +* @status: +* +* The optional status callback can return additional object state +* which determines which stats the object is counted against. The +* callback is called under table_lock. Racing against object status +* change is "harmless", and the callback can expect to not race +* against object destruction. +*/ +enum drm_gem_object_status (*status)(struct drm_gem_object *obj); +/** * @vm_ops: *
Signature · 1 line
2.39.2
Christian König
maintainerRe: [PATCH v4 1/6] drm: Add common fdinfo helper
In reply to Rob ClarkAm 13.04.23 um 00:42 schrieb Rob Clark:
Quoted 21 lines
From: Rob Clark <[email protected]>
Handle a bit of the boiler-plate in a single case, and make it easier to add some core tracked stats.
v2: Update
drm-usage-stats.rst, 64b client-id, renamedrm_show_fdinfoReviewed-by Daniel Vetter <[email protected]>Signed-off-by Rob Clark <[email protected]>--- Documentation/gpu/drm-usage-stats.rst | 10 +++++++- drivers/gpu/drm/drm_file.c | 35 +++++++++++++++++++++++++++ include/drm/drm_drv.h | 7 ++++++ include/drm/drm_file.h | 4 +++ 4 files changed, 55 insertions(+), 1 deletion(-)Documentation/gpu/drm-usage-stats.rst +0
-0
Documentation/gpu/drm-usage-stats.rst percentage utilization of the engine, whereas drm-engine-<str> only reflects · line 135
Quoted 10 lines
Documentation/gpu/drm-usage-stats.rst +7
-0@@ -126,7 +126,15 @@ percentage utilization of the engine, whereas drm-engine-<str> only reflects time active without considering what frequency the engine is operating as a percentage of it's maximum frequency. +Implementation Details +====================== + +Drivers should use drm_show_fdinfo() in their `struct file_operations`, and +implement &drm_driver.show_fdinfo if they wish to provide any stats which +are not provided by drm_show_fdinfo(). But even driver specific stats should +be documented above and where possible, aligned with other drivers.
I'm really wondering if it wouldn't be less mid-layering if we let the drivers call the drm function to print the common values instead of the other way around?
Apart from that question the patch looks good to me.
Christian.
Quoted 106 lines
Documentation/gpu/drm-usage-stats.rst +2
-1+ Driver specific implementations -=============================== +------------------------------- :ref:`i915-usage-stats`drivers/gpu/drm/drm_file.c +35
-0@@ -148,6 +148,7 @@ bool drm_dev_needs_global_mutex(struct drm_device *dev)*/ struct drm_file *drm_file_alloc (struct drm_minor *minor) { +static atomic64_t ident =ATOMIC_INIT (0 );struct drm_device *dev = minor->dev;struct drm_file *file;int ret;@@ -156,6 +157,8 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor)if (!file)return ERR_PTR (-ENOMEM ); +/* Get a unique identifier for fdinfo: */ + file->client_id =atomic64_inc_return (&ident); file->pid =get_pid (task_pid (current)); file->minor = minor;@@ -868,6 +871,38 @@ void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) }EXPORT_SYMBOL (drm_send_event); +/** +* drm_show_fdinfo - helper for drm file fops +* @seq_file: output stream +* @f: the device file instance +* +* Helper to implement fdinfo, for userspace to query usage stats, etc, of a +* process using the GPU. See also &drm_driver.show_fdinfo. +* +* For text output format description please see Documentation/gpu/drm-usage-stats.rst +*/ +void drm_show_fdinfo (struct seq_file *m,struct file *f) +{ +struct drm_file *file = f->private_data; +struct drm_device *dev = file->minor->dev; +struct drm_printer p =drm_seq_file_printer (m); + +drm_printf (&p,"drm-driver:\t%s\n" , dev->driver->name); +drm_printf (&p,"drm-client-id:\t%llu\n" , file->client_id); + +if (dev_is_pci (dev->dev)) { +struct pci_dev *pdev =to_pci_dev (dev->dev); + +drm_printf (&p,"drm-pdev:\t%04x:%02x:%02x.%d\n" , +pci_domain_nr (pdev->bus), pdev->bus->number, +PCI_SLOT (pdev->devfn),PCI_FUNC (pdev->devfn)); + } + +if (dev->driver->show_fdinfo) + dev->driver->show_fdinfo (&p, file); +} +EXPORT_SYMBOL (drm_show_fdinfo); +/** * mock_drm_getfile - Create a new struct file for the drm device * @minor: drm minor to wrap (e.g. #drm_device.primary) include/drm/drm_drv.h +7
-0@@ -401,6 +401,13 @@ struct drm_driver { struct drm_device *dev, uint32_t handle, uint64_t *offset); +/** +* @show_fdinfo: +* +* Print device specific fdinfo. See Documentation/gpu/drm-usage-stats.rst. +*/ +void (*show_fdinfo)(struct drm_printer *p,struct drm_file *f); +/** @major: driver major number */ int major;/** @minor: driver minor number */ include/drm/drm_file.h +4
-0@@ -258,6 +258,9 @@ struct drm_file {/** @pid: Process that opened this file. */ struct pid *pid; +/** @client_id: A unique id for fdinfo */ +u64 client_id; +/** @magic: Authentication magic, see @authenticated. */ drm_magic_t magic;@@ -437,6 +440,7 @@ void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);void drm_send_event_timestamp_locked (struct drm_device *dev,struct drm_pending_event *e,ktime_t timestamp); +void drm_show_fdinfo (struct seq_file *m,struct file *f);struct file *mock_drm_getfile (struct drm_minor *minor,unsigned int flags);
Re: [PATCH v4 1/6] drm: Add common fdinfo helper
Quoted 27 lines · Christian König
Am 13.04.23 um 00:42 schrieb Rob Clark:
Quoted 26 lines
From: Rob Clark <[email protected]>
Handle a bit of the boiler-plate in a single case, and make it easier to add some core tracked stats.
v2: Update
drm-usage-stats.rst, 64b client-id, renamedrm_show_fdinfoReviewed-by Daniel Vetter <[email protected]>Signed-off-by Rob Clark <[email protected]>--- Documentation/gpu/drm-usage-stats.rst | 10 +++++++- drivers/gpu/drm/drm_file.c | 35 +++++++++++++++++++++++++++ include/drm/drm_drv.h | 7 ++++++ include/drm/drm_file.h | 4 +++ 4 files changed, 55 insertions(+), 1 deletion(-)Documentation/gpu/drm-usage-stats.rst +3
-0@@ -126,7 +126,15 @@ percentage utilization of the engine, whereas drm-engine-<str> only reflects time active without considering what frequency the engine is operating as a percentage of it's maximum frequency. +Implementation Details +====================== +
Quoted 8 lines
Documentation/gpu/drm-usage-stats.rst percentage utilization of the engine, whereas drm-engine-<str> only reflects · line 135
Quoted 4 lines
Documentation/gpu/drm-usage-stats.rst +4
-0+Drivers should use drm_show_fdinfo() in their `struct file_operations`, and +implement &drm_driver.show_fdinfo if they wish to provide any stats which +are not provided by drm_show_fdinfo(). But even driver specific stats should +be documented above and where possible, aligned with other drivers.I'm really wondering if it wouldn't be less mid-layering if we let the drivers call the drm function to print the common values instead of the other way around?
The idea is that we plug this into DRM_GEM_FOPS and then everyone gets it by default. So it's a bit a tradeoff between midlayering and having inconsistent uapi between drivers. And there's generic tools that parse this, so consistency across drivers is good.
My gut feeling was that after a bit of experimenting with lots of different drivers for fdinfo stuff it's time to push for a bit more standardization and less fragmentation.
We can of course later on course-correct and shuffle things around again, e.g. by pushing more things into the gem_bo_fops->status hook (ttm and other memory manager libs could implement a decent one by default), or moving more into the drm_driver->show_fdinfo callback again.
If you look at kms we also shuffle things back&forth between core (for more consistency) and drivers (for more flexibility where needed).
The important part here imo is that we start with some scaffolding to be able to do this. Like another thing that I think we want is some drm_fdinfo_print functions that make sure the formatting is guaranteed consistents and we don't trip up parsers (like some drivers use " \t" as separator instead of just "\t", I guess by accident).
Quoted 1 line
Apart from thatquestion the patch looks good to me.
Ack? Or want the above recorded in the commit message, I think it'd make sense to put it there.
-Daniel
Quoted 101 lines
Christian.
Quoted 97 lines
Documentation/gpu/drm-usage-stats.rst +2
-1+ Driver specific implementations -=============================== +------------------------------- :ref:`i915-usage-stats`drivers/gpu/drm/drm_file.c +35
-0@@ -148,6 +148,7 @@ bool drm_dev_needs_global_mutex(struct drm_device *dev)*/ struct drm_file *drm_file_alloc (struct drm_minor *minor) { +static atomic64_t ident =ATOMIC_INIT (0 );struct drm_device *dev = minor->dev;struct drm_file *file;int ret;@@ -156,6 +157,8 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor)if (!file)return ERR_PTR (-ENOMEM ); +/* Get a unique identifier for fdinfo: */ + file->client_id =atomic64_inc_return (&ident); file->pid =get_pid (task_pid (current)); file->minor = minor;@@ -868,6 +871,38 @@ void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) }EXPORT_SYMBOL (drm_send_event); +/** +* drm_show_fdinfo - helper for drm file fops +* @seq_file: output stream +* @f: the device file instance +* +* Helper to implement fdinfo, for userspace to query usage stats, etc, of a +* process using the GPU. See also &drm_driver.show_fdinfo. +* +* For text output format description please see Documentation/gpu/drm-usage-stats.rst +*/ +void drm_show_fdinfo (struct seq_file *m,struct file *f) +{ +struct drm_file *file = f->private_data; +struct drm_device *dev = file->minor->dev; +struct drm_printer p =drm_seq_file_printer (m); + +drm_printf (&p,"drm-driver:\t%s\n" , dev->driver->name); +drm_printf (&p,"drm-client-id:\t%llu\n" , file->client_id); + +if (dev_is_pci (dev->dev)) { +struct pci_dev *pdev =to_pci_dev (dev->dev); + +drm_printf (&p,"drm-pdev:\t%04x:%02x:%02x.%d\n" , +pci_domain_nr (pdev->bus), pdev->bus->number, +PCI_SLOT (pdev->devfn),PCI_FUNC (pdev->devfn)); + } + +if (dev->driver->show_fdinfo) + dev->driver->show_fdinfo (&p, file); +} +EXPORT_SYMBOL (drm_show_fdinfo); +/** * mock_drm_getfile - Create a new struct file for the drm device * @minor: drm minor to wrap (e.g. #drm_device.primary) include/drm/drm_drv.h +7
-0@@ -401,6 +401,13 @@ struct drm_driver { struct drm_device *dev, uint32_t handle, uint64_t *offset); +/** +* @show_fdinfo: +* +* Print device specific fdinfo. See Documentation/gpu/drm-usage-stats.rst. +*/ +void (*show_fdinfo)(struct drm_printer *p,struct drm_file *f); +/** @major: driver major number */ int major;/** @minor: driver minor number */ include/drm/drm_file.h +4
-0@@ -258,6 +258,9 @@ struct drm_file {/** @pid: Process that opened this file. */ struct pid *pid; +/** @client_id: A unique id for fdinfo */ +u64 client_id; +/** @magic: Authentication magic, see @authenticated. */ drm_magic_t magic;@@ -437,6 +440,7 @@ void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);void drm_send_event_timestamp_locked (struct drm_device *dev,struct drm_pending_event *e,ktime_t timestamp); +void drm_show_fdinfo (struct seq_file *m,struct file *f);struct file *mock_drm_getfile (struct drm_minor *minor,unsigned int flags);
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Christian König
maintainerRe: [PATCH v4 1/6] drm: Add common fdinfo helper
Am 13.04.23 um 10:46 schrieb Daniel Vetter:
Quoted 35 lines · Christian König
Quoted 26 lines
Am 13.04.23 um 00:42 schrieb Rob Clark:
Quoted 25 lines
From: Rob Clark <[email protected]>
Handle a bit of the boiler-plate in a single case, and make it easier to add some core tracked stats.
v2: Update
drm-usage-stats.rst, 64b client-id, renamedrm_show_fdinfoReviewed-by Daniel Vetter <[email protected]>Signed-off-by Rob Clark <[email protected]>--- Documentation/gpu/drm-usage-stats.rst | 10 +++++++- drivers/gpu/drm/drm_file.c | 35 +++++++++++++++++++++++++++ include/drm/drm_drv.h | 7 ++++++ include/drm/drm_file.h | 4 +++ 4 files changed, 55 insertions(+), 1 deletion(-)Documentation/gpu/drm-usage-stats.rst +2
-0@@ -126,7 +126,15 @@ percentage utilization of the engine, whereas drm-engine-<str> only reflects time active without considering what frequency the engine is operating as a percentage of it's maximum frequency. +Implementation Details +======================Quoted 8 lines
Documentation/gpu/drm-usage-stats.rst percentage utilization of the engine, whereas drm-engine-<str> only reflects · line 135
Quoted 5 lines
Documentation/gpu/drm-usage-stats.rst +5
-0+ +Drivers should use drm_show_fdinfo() in their `struct file_operations`, and +implement &drm_driver.show_fdinfo if they wish to provide any stats which +are not provided by drm_show_fdinfo(). But even driver specific stats should +be documented above and where possible, aligned with other drivers.I'm really wondering if it wouldn't be less mid-layering if we let the drivers call the drm function to print the common values instead of the other way around?
Quoted 8 lines
The idea is that we plug this into
DRM_GEM_FOPSand then everyone gets it by default. So it's a bit a tradeoff between midlayering and having inconsistent uapi between drivers. And there's generic tools that parse this, so consistency across drivers is good.My gut feeling was that after a bit of experimenting with lots of different drivers for fdinfo stuff it's time to push for a bit more standardization and less fragmentation.
Yeah, that's indeed a trade of.
Quoted 6 lines
We can of course later on course-correct and shuffle things around again, e.g. by pushing more things into the
gem_bo_fops->statushook (ttm and other memory manager libs could implement a decent one by default), or moving more into thedrm_driver->show_fdinfocallback again.
Quoted 8 lines
If you look at kms we also shuffle things back&forth between core (for more consistency) and drivers (for more flexibility where needed).
The important part here imo is that we start with some scaffolding to be able to do this. Like another thing that I think we want is some
drm_fdinfo_printfunctions that make sure the formatting is guaranteed consistents and we don't trip up parsers (like some drivers use " \t" as separator instead of just "\t", I guess by accident).
That's indeed a bit ugly and should probably be fixed on a higher level in the fs code.
Something like fdinfo_print(seq, name, format, value);
Quoted 4 lines
Quoted 2 lines
Apart from thatquestion the patch looks good to me.
Ack? Or want the above recorded in the commit message, I think it'd make sense to put it there.
Well if Rob mentions this trade of in the commit message or even better code document feel free to add my rb to the patch.
Christian.
Quoted 101 lines
-Daniel
Quoted 99 lines
Christian.
Quoted 97 lines
Documentation/gpu/drm-usage-stats.rst +2
-1+ Driver specific implementations -=============================== +------------------------------- :ref:`i915-usage-stats`drivers/gpu/drm/drm_file.c +35
-0@@ -148,6 +148,7 @@ bool drm_dev_needs_global_mutex(struct drm_device *dev)*/ struct drm_file *drm_file_alloc (struct drm_minor *minor) { +static atomic64_t ident =ATOMIC_INIT (0 );struct drm_device *dev = minor->dev;struct drm_file *file;int ret;@@ -156,6 +157,8 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor)if (!file)return ERR_PTR (-ENOMEM ); +/* Get a unique identifier for fdinfo: */ + file->client_id =atomic64_inc_return (&ident); file->pid =get_pid (task_pid (current)); file->minor = minor;@@ -868,6 +871,38 @@ void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) }EXPORT_SYMBOL (drm_send_event); +/** +* drm_show_fdinfo - helper for drm file fops +* @seq_file: output stream +* @f: the device file instance +* +* Helper to implement fdinfo, for userspace to query usage stats, etc, of a +* process using the GPU. See also &drm_driver.show_fdinfo. +* +* For text output format description please see Documentation/gpu/drm-usage-stats.rst +*/ +void drm_show_fdinfo (struct seq_file *m,struct file *f) +{ +struct drm_file *file = f->private_data; +struct drm_device *dev = file->minor->dev; +struct drm_printer p =drm_seq_file_printer (m); + +drm_printf (&p,"drm-driver:\t%s\n" , dev->driver->name); +drm_printf (&p,"drm-client-id:\t%llu\n" , file->client_id); + +if (dev_is_pci (dev->dev)) { +struct pci_dev *pdev =to_pci_dev (dev->dev); + +drm_printf (&p,"drm-pdev:\t%04x:%02x:%02x.%d\n" , +pci_domain_nr (pdev->bus), pdev->bus->number, +PCI_SLOT (pdev->devfn),PCI_FUNC (pdev->devfn)); + } + +if (dev->driver->show_fdinfo) + dev->driver->show_fdinfo (&p, file); +} +EXPORT_SYMBOL (drm_show_fdinfo); +/** * mock_drm_getfile - Create a new struct file for the drm device * @minor: drm minor to wrap (e.g. #drm_device.primary) include/drm/drm_drv.h +7
-0@@ -401,6 +401,13 @@ struct drm_driver { struct drm_device *dev, uint32_t handle, uint64_t *offset); +/** +* @show_fdinfo: +* +* Print device specific fdinfo. See Documentation/gpu/drm-usage-stats.rst. +*/ +void (*show_fdinfo)(struct drm_printer *p,struct drm_file *f); +/** @major: driver major number */ int major;/** @minor: driver minor number */ include/drm/drm_file.h +4
-0@@ -258,6 +258,9 @@ struct drm_file {/** @pid: Process that opened this file. */ struct pid *pid; +/** @client_id: A unique id for fdinfo */ +u64 client_id; +/** @magic: Authentication magic, see @authenticated. */ drm_magic_t magic;@@ -437,6 +440,7 @@ void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);void drm_send_event_timestamp_locked (struct drm_device *dev,struct drm_pending_event *e,ktime_t timestamp); +void drm_show_fdinfo (struct seq_file *m,struct file *f);struct file *mock_drm_getfile (struct drm_minor *minor,unsigned int flags);
Re: [PATCH v4 3/6] drm/amdgpu: Switch to fdinfo helper
In reply to Rob ClarkAm 13.04.23 um 00:42 schrieb Rob Clark:
Quoted 3 lines
From: Rob Clark <[email protected]>
Signed-off-by Rob Clark <[email protected]>
Quoted 78 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c | 16 ++++++---------- drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.h | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-1@@ -2752,7 +2752,7 @@ static const struct file_operations amdgpu_driver_kms_fops = { .compat_ioctl = amdgpu_kms_compat_ioctl,#endif #ifdef CONFIG_PROC_FS - .show_fdinfo = amdgpu_show_fdinfo + .show_fdinfo = drm_show_fdinfo,#endif };@@ -2807,6 +2807,7 @@ static const struct drm_driver amdgpu_kms_driver = { .dumb_map_offset = amdgpu_mode_dumb_mmap, .fops = &amdgpu_driver_kms_fops, .release = &amdgpu_driver_release_kms, + .show_fdinfo = amdgpu_show_fdinfo, .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle,drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c +6
-10@@ -53,9 +53,8 @@ static const char *amdgpu_ip_name[AMDGPU_HW_IP_NUM] = { [AMDGPU_HW_IP_VCN_JPEG] = "jpeg", }; -void amdgpu_show_fdinfo (struct seq_file *m,struct file *f) +void amdgpu_show_fdinfo (struct drm_printer *p,struct drm_file *file) { -struct drm_file *file = f->private_data;struct amdgpu_device *adev =drm_to_adev (file->minor->dev);struct amdgpu_fpriv *fpriv = file->driver_priv;struct amdgpu_vm *vm = &fpriv->vm;@@ -86,18 +85,15 @@ void amdgpu_show_fdinfo(struct seq_file *m, struct file *f)* ****************************************************************** */ -seq_printf (m,"pasid:\t%u\n" , fpriv->vm.pasid); -seq_printf (m,"drm-driver:\t%s\n" , file->minor->dev->driver->name); -seq_printf (m,"drm-pdev:\t%04x:%02x:%02x.%d\n" , domain, bus, dev, fn); -seq_printf (m,"drm-client-id:\t%Lu\n" , vm->immediate.fence_context); -seq_printf (m,"drm-memory-vram:\t%llu KiB\n" , vram_mem/1024UL ); -seq_printf (m,"drm-memory-gtt: \t%llu KiB\n" , gtt_mem/1024UL ); -seq_printf (m,"drm-memory-cpu: \t%llu KiB\n" , cpu_mem/1024UL ); +drm_printf (p,"pasid:\t%u\n" , fpriv->vm.pasid); +drm_printf (p,"drm-memory-vram:\t%llu KiB\n" , vram_mem/1024UL ); +drm_printf (p,"drm-memory-gtt: \t%llu KiB\n" , gtt_mem/1024UL ); +drm_printf (p,"drm-memory-cpu: \t%llu KiB\n" , cpu_mem/1024UL );for (hw_ip =0 ; hw_ip <AMDGPU_HW_IP_NUM ; ++hw_ip) {if (!usage[hw_ip])continue ; -seq_printf (m,"drm-engine-%s:\t%Ld ns\n" , amdgpu_ip_name[hw_ip], +drm_printf (p,"drm-engine-%s:\t%Ld ns\n" , amdgpu_ip_name[hw_ip],ktime_to_ns (usage[hw_ip])); } }drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.h +1
-1@@ -37,6 +37,6 @@#include "amdgpu_ids.h" uint32_t amdgpu_get_ip_count (struct amdgpu_device *adev,int id); -void amdgpu_show_fdinfo (struct seq_file *m,struct file *f); +void amdgpu_show_fdinfo (struct drm_printer *p,struct drm_file *file);#endif
Re: [PATCH v4 1/6] drm: Add common fdinfo helper
In reply to Daniel VetterQuoted 51 lines · Daniel Vetter
Quoted 27 lines · Christian König
Am 13.04.23 um 00:42 schrieb Rob Clark:
Quoted 26 lines
From: Rob Clark <[email protected]>
Handle a bit of the boiler-plate in a single case, and make it easier to add some core tracked stats.
v2: Update
drm-usage-stats.rst, 64b client-id, renamedrm_show_fdinfoReviewed-by Daniel Vetter <[email protected]>Signed-off-by Rob Clark <[email protected]>--- Documentation/gpu/drm-usage-stats.rst | 10 +++++++- drivers/gpu/drm/drm_file.c | 35 +++++++++++++++++++++++++++ include/drm/drm_drv.h | 7 ++++++ include/drm/drm_file.h | 4 +++ 4 files changed, 55 insertions(+), 1 deletion(-)Documentation/gpu/drm-usage-stats.rst +3
-0@@ -126,7 +126,15 @@ percentage utilization of the engine, whereas drm-engine-<str> only reflects time active without considering what frequency the engine is operating as a percentage of it's maximum frequency. +Implementation Details +====================== +Quoted 8 lines
Documentation/gpu/drm-usage-stats.rst percentage utilization of the engine, whereas drm-engine-<str> only reflects · line 135
Quoted 4 lines
Documentation/gpu/drm-usage-stats.rst +4
-0+Drivers should use drm_show_fdinfo() in their `struct file_operations`, and +implement &drm_driver.show_fdinfo if they wish to provide any stats which +are not provided by drm_show_fdinfo(). But even driver specific stats should +be documented above and where possible, aligned with other drivers.I'm really wondering if it wouldn't be less mid-layering if we let the drivers call the drm function to print the common values instead of the other way around?
The idea is that we plug this into
DRM_GEM_FOPSand then everyone gets it by default. So it's a bit a tradeoff between midlayering and having inconsistent uapi between drivers. And there's generic tools that parse this, so consistency across drivers is good.My gut feeling was that after a bit of experimenting with lots of different drivers for fdinfo stuff it's time to push for a bit more standardization and less fragmentation.
We can of course later on course-correct and shuffle things around again, e.g. by pushing more things into the
gem_bo_fops->statushook (ttm and other memory manager libs could implement a decent one by default), or moving more into thedrm_driver->show_fdinfocallback again.
Quoted 8 lines
If you look at kms we also shuffle things back&forth between core (for more consistency) and drivers (for more flexibility where needed).
The important part here imo is that we start with some scaffolding to be able to do this. Like another thing that I think we want is some
drm_fdinfo_printfunctions that make sure the formatting is guaranteed consistents and we don't trip up parsers (like some drivers use " \t" as separator instead of just "\t", I guess by accident).
On this particular part I'd say it's even better to keep userspace on their toes and not let them hardcode assumption about how much and what whitespace characters to expect.
Otherwise I agree that mid-layer or not can be changed later, as long as my opens from elsewhere in the thread are closed before merging.
Regards,
Tvrtko
Quoted 108 lines
Quoted 1 line
Apart from thatquestion the patch looks good to me.
Ack? Or want the above recorded in the commit message, I think it'd make sense to put it there.
-DanielQuoted 101 lines
Christian.
Quoted 97 lines
Documentation/gpu/drm-usage-stats.rst +2
-1+ Driver specific implementations -=============================== +------------------------------- :ref:`i915-usage-stats`drivers/gpu/drm/drm_file.c +35
-0@@ -148,6 +148,7 @@ bool drm_dev_needs_global_mutex(struct drm_device *dev)*/ struct drm_file *drm_file_alloc (struct drm_minor *minor) { +static atomic64_t ident =ATOMIC_INIT (0 );struct drm_device *dev = minor->dev;struct drm_file *file;int ret;@@ -156,6 +157,8 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor)if (!file)return ERR_PTR (-ENOMEM ); +/* Get a unique identifier for fdinfo: */ + file->client_id =atomic64_inc_return (&ident); file->pid =get_pid (task_pid (current)); file->minor = minor;@@ -868,6 +871,38 @@ void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) }EXPORT_SYMBOL (drm_send_event); +/** +* drm_show_fdinfo - helper for drm file fops +* @seq_file: output stream +* @f: the device file instance +* +* Helper to implement fdinfo, for userspace to query usage stats, etc, of a +* process using the GPU. See also &drm_driver.show_fdinfo. +* +* For text output format description please see Documentation/gpu/drm-usage-stats.rst +*/ +void drm_show_fdinfo (struct seq_file *m,struct file *f) +{ +struct drm_file *file = f->private_data; +struct drm_device *dev = file->minor->dev; +struct drm_printer p =drm_seq_file_printer (m); + +drm_printf (&p,"drm-driver:\t%s\n" , dev->driver->name); +drm_printf (&p,"drm-client-id:\t%llu\n" , file->client_id); + +if (dev_is_pci (dev->dev)) { +struct pci_dev *pdev =to_pci_dev (dev->dev); + +drm_printf (&p,"drm-pdev:\t%04x:%02x:%02x.%d\n" , +pci_domain_nr (pdev->bus), pdev->bus->number, +PCI_SLOT (pdev->devfn),PCI_FUNC (pdev->devfn)); + } + +if (dev->driver->show_fdinfo) + dev->driver->show_fdinfo (&p, file); +} +EXPORT_SYMBOL (drm_show_fdinfo); +/** * mock_drm_getfile - Create a new struct file for the drm device * @minor: drm minor to wrap (e.g. #drm_device.primary) include/drm/drm_drv.h +7
-0@@ -401,6 +401,13 @@ struct drm_driver { struct drm_device *dev, uint32_t handle, uint64_t *offset); +/** +* @show_fdinfo: +* +* Print device specific fdinfo. See Documentation/gpu/drm-usage-stats.rst. +*/ +void (*show_fdinfo)(struct drm_printer *p,struct drm_file *f); +/** @major: driver major number */ int major;/** @minor: driver minor number */ include/drm/drm_file.h +4
-0@@ -258,6 +258,9 @@ struct drm_file {/** @pid: Process that opened this file. */ struct pid *pid; +/** @client_id: A unique id for fdinfo */ +u64 client_id; +/** @magic: Authentication magic, see @authenticated. */ drm_magic_t magic;@@ -437,6 +440,7 @@ void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);void drm_send_event_timestamp_locked (struct drm_device *dev,struct drm_pending_event *e,ktime_t timestamp); +void drm_show_fdinfo (struct seq_file *m,struct file *f);struct file *mock_drm_getfile (struct drm_minor *minor,unsigned int flags);
Re: [PATCH v4 4/6] drm/i915: Switch to fdinfo helper
In reply to Rob ClarkQuoted 1 line · Rob Clark
From: Rob Clark <[email protected]>
There is more do to here to remove my client->id fully (would now be dead code) so maybe easiest if you drop this patch and I do it after you land this and it propagates to our branches? I'd like to avoid pain with conflicts if possible..
Regards,
Tvrtko
Quoted 102 lines
Signed-off-by Rob Clark <[email protected]>--- drivers/gpu/drm/i915/i915_driver.c | 3 ++- drivers/gpu/drm/i915/i915_drm_client.c | 18 +++++------------- drivers/gpu/drm/i915/i915_drm_client.h | 2 +- 3 files changed, 8 insertions(+), 15 deletions(-)drivers/gpu/drm/i915/i915_driver.c +2
-1@@ -1696,7 +1696,7 @@ static const struct file_operations i915_driver_fops = { .compat_ioctl = i915_ioc32_compat_ioctl, .llseek = noop_llseek, #ifdef CONFIG_PROC_FS - .show_fdinfo = i915_drm_client_fdinfo, + .show_fdinfo = drm_show_fdinfo,#endif };@@ -1796,6 +1796,7 @@ static const struct drm_driver i915_drm_driver = { .open = i915_driver_open, .lastclose = i915_driver_lastclose, .postclose = i915_driver_postclose, + .show_fdinfo = i915_drm_client_fdinfo, .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle,drivers/gpu/drm/i915/i915_drm_client.c +5
-13@@ -101,7 +101,7 @@ static u64 busy_add(struct i915_gem_context *ctx, unsigned int class) }static void -show_client_class (struct seq_file *m, +show_client_class (struct drm_printer *p,struct i915_drm_client *client,unsigned int class) {@@ -117,22 +117,20 @@ show_client_class(struct seq_file *m,rcu_read_unlock ();if (capacity) -seq_printf (m,"drm-engine-%s:\t%llu ns\n" , +drm_printf (p,"drm-engine-%s:\t%llu ns\n" , uabi_class_names[class], total);if (capacity >1 ) -seq_printf (m,"drm-engine-capacity-%s:\t%u\n" , +drm_printf (p,"drm-engine-capacity-%s:\t%u\n" , uabi_class_names[class], capacity); } -void i915_drm_client_fdinfo (struct seq_file *m,struct file *f) +void i915_drm_client_fdinfo (struct drm_printer *p,struct drm_file *file) { -struct drm_file *file = f->private_data;struct drm_i915_file_private *file_priv = file->driver_priv;struct drm_i915_private *i915 = file_priv->dev_priv;struct i915_drm_client *client = file_priv->client; -struct pci_dev *pdev =to_pci_dev (i915->drm.dev);unsigned int i;/* @@ -141,12 +139,6 @@ void i915_drm_client_fdinfo(struct seq_file *m, struct file *f)* ****************************************************************** */ -seq_printf (m,"drm-driver:\t%s\n" , i915->drm.driver->name); -seq_printf (m,"drm-pdev:\t%04x:%02x:%02x.%d\n" , -pci_domain_nr (pdev->bus), pdev->bus->number, -PCI_SLOT (pdev->devfn),PCI_FUNC (pdev->devfn)); -seq_printf (m,"drm-client-id:\t%u\n" , client->id); -/* * Temporarily skip showing client engine information with GuC submission till * fetching engine busyness is implemented in the GuC submission backend @@ -155,6 +147,6 @@ void i915_drm_client_fdinfo(struct seq_file *m, struct file *f)return ;for (i =0 ; i <ARRAY_SIZE (uabi_class_names); i++) - show_client_class(m, client, i); + show_client_class(p, client, i); }#endif drivers/gpu/drm/i915/i915_drm_client.h +1
-1@@ -60,7 +60,7 @@ static inline void i915_drm_client_put(struct i915_drm_client *client)struct i915_drm_client *i915_drm_client_add (struct i915_drm_clients *clients);#ifdef CONFIG_PROC_FS -void i915_drm_client_fdinfo (struct seq_file *m,struct file *f); +void i915_drm_client_fdinfo (struct drm_printer *p,struct drm_file *file);#endif void i915_drm_clients_fini (struct i915_drm_clients *clients);
Re: [PATCH v4 4/6] drm/i915: Switch to fdinfo helper
Quoted 9 lines · Tvrtko Ursulin
Quoted 1 line · Rob Clark
From: Rob Clark <[email protected]>
There is more do to here to remove my
client->idfully (would now be dead code) so maybe easiest if you drop this patch and I do it after you land this and it propagates to our branches? I'd like to avoid pain with conflicts if possible..
That is fine by me
BR,
-R
Quoted 106 lines
Regards,
Tvrtko
Quoted 102 lines
Signed-off-by Rob Clark <[email protected]>--- drivers/gpu/drm/i915/i915_driver.c | 3 ++- drivers/gpu/drm/i915/i915_drm_client.c | 18 +++++------------- drivers/gpu/drm/i915/i915_drm_client.h | 2 +- 3 files changed, 8 insertions(+), 15 deletions(-)drivers/gpu/drm/i915/i915_driver.c +2
-1@@ -1696,7 +1696,7 @@ static const struct file_operations i915_driver_fops = { .compat_ioctl = i915_ioc32_compat_ioctl, .llseek = noop_llseek, #ifdef CONFIG_PROC_FS - .show_fdinfo = i915_drm_client_fdinfo, + .show_fdinfo = drm_show_fdinfo,#endif };@@ -1796,6 +1796,7 @@ static const struct drm_driver i915_drm_driver = { .open = i915_driver_open, .lastclose = i915_driver_lastclose, .postclose = i915_driver_postclose, + .show_fdinfo = i915_drm_client_fdinfo, .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle,drivers/gpu/drm/i915/i915_drm_client.c +5
-13@@ -101,7 +101,7 @@ static u64 busy_add(struct i915_gem_context *ctx, unsigned int class) }static void -show_client_class (struct seq_file *m, +show_client_class (struct drm_printer *p,struct i915_drm_client *client,unsigned int class) {@@ -117,22 +117,20 @@ show_client_class(struct seq_file *m,rcu_read_unlock ();if (capacity) -seq_printf (m,"drm-engine-%s:\t%llu ns\n" , +drm_printf (p,"drm-engine-%s:\t%llu ns\n" , uabi_class_names[class], total);if (capacity >1 ) -seq_printf (m,"drm-engine-capacity-%s:\t%u\n" , +drm_printf (p,"drm-engine-capacity-%s:\t%u\n" , uabi_class_names[class], capacity); } -void i915_drm_client_fdinfo (struct seq_file *m,struct file *f) +void i915_drm_client_fdinfo (struct drm_printer *p,struct drm_file *file) { -struct drm_file *file = f->private_data;struct drm_i915_file_private *file_priv = file->driver_priv;struct drm_i915_private *i915 = file_priv->dev_priv;struct i915_drm_client *client = file_priv->client; -struct pci_dev *pdev =to_pci_dev (i915->drm.dev);unsigned int i;/* @@ -141,12 +139,6 @@ void i915_drm_client_fdinfo(struct seq_file *m, struct file *f)* ****************************************************************** */ -seq_printf (m,"drm-driver:\t%s\n" , i915->drm.driver->name); -seq_printf (m,"drm-pdev:\t%04x:%02x:%02x.%d\n" , -pci_domain_nr (pdev->bus), pdev->bus->number, -PCI_SLOT (pdev->devfn),PCI_FUNC (pdev->devfn)); -seq_printf (m,"drm-client-id:\t%u\n" , client->id); -/* * Temporarily skip showing client engine information with GuC submission till * fetching engine busyness is implemented in the GuC submission backend @@ -155,6 +147,6 @@ void i915_drm_client_fdinfo(struct seq_file *m, struct file *f)return ;for (i =0 ; i <ARRAY_SIZE (uabi_class_names); i++) - show_client_class(m, client, i); + show_client_class(p, client, i); }#endif drivers/gpu/drm/i915/i915_drm_client.h +1
-1@@ -60,7 +60,7 @@ static inline void i915_drm_client_put(struct i915_drm_client *client)struct i915_drm_client *i915_drm_client_add (struct i915_drm_clients *clients);#ifdef CONFIG_PROC_FS -void i915_drm_client_fdinfo (struct seq_file *m,struct file *f); +void i915_drm_client_fdinfo (struct drm_printer *p,struct drm_file *file);#endif void i915_drm_clients_fini (struct i915_drm_clients *clients);
Re: [PATCH v4 2/6] drm/msm: Switch to fdinfo helper
In reply to Rob ClarkQuoted 7 lines · Rob Clark
From: Rob Clark <[email protected]>
Signed-off-by Rob Clark <[email protected]>--- drivers/gpu/drm/msm/msm_drv.c | 11 +++++------ drivers/gpu/drm/msm/msm_gpu.c | 2 -- 2 files changed, 5 insertions(+), 8 deletions(-)
Signature · 2 lines
With best wishes Dmitry
Re: [PATCH v4 5/6] drm: Add fdinfo memory stats
In reply to Rob ClarkQuoted 8 lines · Rob Clark
+/**
+ * enumdrm_gem_object_status- bitmask of object state for fdinfo reporting
+ * @DRM_GEM_OBJECT_RESIDENT: object is resident in memory (ie. not unpinned)
+ * @DRM_GEM_OBJECT_PURGEABLE: object marked as purgeable by userspace
+ *
+ * Bitmask of status used for fdinfo memory stats, see &drm_gem_object_funcs.status
+ * anddrm_show_fdinfo(). Note that an object canDRM_GEM_OBJECT_PURGEABLEif
+ * it still active or not resident, in which casedrm_show_fdinfo()will not
nit: s/can/can be/;s/if it still/if it is still/
Quoted 4 lines
+ * account for it as purgeable. So drivers do not need to check if the buffer
+ * is idle and resident to return this bit. (Ie. userspace can mark a buffer
+ * as purgeable even while it is still busy on the GPU.. it does not _actually_
+ * become puregeable until it becomes idle. The status gem object func does
nit: s/puregeable/purgeable/
I think we want a similar note in the drm-usage-stats.rst file.
With the above the whole series is:
Fwiw: Keeping the i915 patch as part of this series would be great. Sure i915_drm_client->id becomes dead code, but it's a piece one can live with for a release or two. Then again it's not my call to make.
HTH
Emil
Re: [PATCH v4 5/6] drm: Add fdinfo memory stats
Quoted 18 lines · Emil Velikov
Quoted 8 lines · Rob Clark
+/**
+ * enumdrm_gem_object_status- bitmask of object state for fdinfo reporting
+ * @DRM_GEM_OBJECT_RESIDENT: object is resident in memory (ie. not unpinned)
+ * @DRM_GEM_OBJECT_PURGEABLE: object marked as purgeable by userspace
+ *
+ * Bitmask of status used for fdinfo memory stats, see &drm_gem_object_funcs.status
+ * anddrm_show_fdinfo(). Note that an object canDRM_GEM_OBJECT_PURGEABLEif
+ * it still active or not resident, in which casedrm_show_fdinfo()will notnit: s/can/can be/;s/if it still/if it is still/
Quoted 4 lines
+ * account for it as purgeable. So drivers do not need to check if the buffer
+ * is idle and resident to return this bit. (Ie. userspace can mark a buffer
+ * as purgeable even while it is still busy on the GPU.. it does not _actually_
+ * become puregeable until it becomes idle. The status gem object func does
Quoted 7 lines
nit: s/puregeable/purgeable/
I think we want a similar note in the
drm-usage-stats.rstfile.With the above the whole series is:
Reviewed-by Emil Velikov <[email protected]>
Have you maybe noticed my slightly alternative proposal? (*) I am not a fan of putting this flavour of accounting into the core with no way to opt out. I think it leaves no option but to add more keys in the future for any driver which will not be happy with the core accounting.
*) https://patchwork.freedesktop.org/series/116581/
Quoted 3 lines
Fwiw: Keeping the i915 patch as part of this series would be great. Sure
i915_drm_client->idbecomes dead code, but it's a piece one can live with for a release or two. Then again it's not my call to make.
Rob can take the i915 patch from my RFC too.
Regards,
Tvrtko
Re: [PATCH v4 5/6] drm: Add fdinfo memory stats
Quoted 27 lines · Tvrtko Ursulin
Quoted 18 lines · Emil Velikov
Quoted 8 lines · Rob Clark
+/**
+ * enumdrm_gem_object_status- bitmask of object state for fdinfo reporting
+ * @DRM_GEM_OBJECT_RESIDENT: object is resident in memory (ie. not unpinned)
+ * @DRM_GEM_OBJECT_PURGEABLE: object marked as purgeable by userspace
+ *
+ * Bitmask of status used for fdinfo memory stats, see &drm_gem_object_funcs.status
+ * anddrm_show_fdinfo(). Note that an object canDRM_GEM_OBJECT_PURGEABLEif
+ * it still active or not resident, in which casedrm_show_fdinfo()will notnit: s/can/can be/;s/if it still/if it is still/
Quoted 4 lines
+ * account for it as purgeable. So drivers do not need to check if the buffer
+ * is idle and resident to return this bit. (Ie. userspace can mark a buffer
+ * as purgeable even while it is still busy on the GPU.. it does not _actually_
+ * become puregeable until it becomes idle. The status gem object func doesQuoted 7 lines
nit: s/puregeable/purgeable/
I think we want a similar note in the
drm-usage-stats.rstfile.With the above the whole series is:
Reviewed-by Emil Velikov <[email protected]>
Quoted 7 lines
Have you maybe noticed my slightly alternative proposal? (*) I am not a fan of putting this flavour of accounting into the core with no way to opt out. I think it leaves no option but to add more keys in the future for any driver which will not be happy with the core accounting.
Indeed I saw it. Not a fan of it, I'm afraid.
Quoted 6 lines
Quoted 3 lines
Fwiw: Keeping the i915 patch as part of this series would be great. Sure
i915_drm_client->idbecomes dead code, but it's a piece one can live with for a release or two. Then again it's not my call to make.Rob can take the i915 patch from my RFC too.
Indeed.
-Emil
Re: [PATCH v4 5/6] drm: Add fdinfo memory stats
Quoted 35 lines · Emil Velikov
Quoted 32 lines · Tvrtko Ursulin
Quoted 18 lines · Emil Velikov
Quoted 8 lines · Rob Clark
+/**
+ * enumdrm_gem_object_status- bitmask of object state for fdinfo reporting
+ * @DRM_GEM_OBJECT_RESIDENT: object is resident in memory (ie. not unpinned)
+ * @DRM_GEM_OBJECT_PURGEABLE: object marked as purgeable by userspace
+ *
+ * Bitmask of status used for fdinfo memory stats, see &drm_gem_object_funcs.status
+ * anddrm_show_fdinfo(). Note that an object canDRM_GEM_OBJECT_PURGEABLEif
+ * it still active or not resident, in which casedrm_show_fdinfo()will notnit: s/can/can be/;s/if it still/if it is still/
Quoted 4 lines
+ * account for it as purgeable. So drivers do not need to check if the buffer
+ * is idle and resident to return this bit. (Ie. userspace can mark a buffer
+ * as purgeable even while it is still busy on the GPU.. it does not _actually_
+ * become puregeable until it becomes idle. The status gem object func doesQuoted 7 lines
nit: s/puregeable/purgeable/
I think we want a similar note in the
drm-usage-stats.rstfile.With the above the whole series is:
Reviewed-by Emil Velikov <[email protected]>Have you maybe noticed my slightly alternative proposal? (*) I am not a fan of putting this flavour of accounting into the core with no way to opt out. I think it leaves no option but to add more keys in the future for any driver which will not be happy with the core accounting.
Quoted 4 lines
Quoted 2 lines
Indeed I saw it. Not a fan of it, I'm afraid.
Hard to guess the reasons. :)
Anyway, at a minimum I suggest that if the no opt out version has to go in, it is clearly documented drm-*-memory-* is *not* about the full memory use of the client, but about memory belonging to user visible buffer objects *only*. Possibly going as far as naming the keys as drm-user-bo-memory-... That way there is a way to implement proper drm-*-memory- in the future.
Regards,
Tvrtko
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
Fwiw: Keeping the i915 patch as part of this series would be great. Sure
i915_drm_client->idbecomes dead code, but it's a piece one can live with for a release or two. Then again it's not my call to make.Rob can take the i915 patch from my RFC too.
Indeed.
-Emil
Re: [PATCH v4 5/6] drm: Add fdinfo memory stats
Quoted 43 lines · Tvrtko Ursulin
Quoted 35 lines · Emil Velikov
Quoted 32 lines · Tvrtko Ursulin
Quoted 18 lines · Emil Velikov
Quoted 8 lines · Rob Clark
+/**
+ * enumdrm_gem_object_status- bitmask of object state for fdinfo reporting
+ * @DRM_GEM_OBJECT_RESIDENT: object is resident in memory (ie. not unpinned)
+ * @DRM_GEM_OBJECT_PURGEABLE: object marked as purgeable by userspace
+ *
+ * Bitmask of status used for fdinfo memory stats, see &drm_gem_object_funcs.status
+ * anddrm_show_fdinfo(). Note that an object canDRM_GEM_OBJECT_PURGEABLEif
+ * it still active or not resident, in which casedrm_show_fdinfo()will notnit: s/can/can be/;s/if it still/if it is still/
Quoted 4 lines
+ * account for it as purgeable. So drivers do not need to check if the buffer
+ * is idle and resident to return this bit. (Ie. userspace can mark a buffer
+ * as purgeable even while it is still busy on the GPU.. it does not _actually_
+ * become puregeable until it becomes idle. The status gem object func doesQuoted 7 lines
nit: s/puregeable/purgeable/
I think we want a similar note in the
drm-usage-stats.rstfile.With the above the whole series is:
Reviewed-by Emil Velikov <[email protected]>Have you maybe noticed my slightly alternative proposal? (*) I am not a fan of putting this flavour of accounting into the core with no way to opt out. I think it leaves no option but to add more keys in the future for any driver which will not be happy with the core accounting.
Quoted 4 lines
Quoted 2 lines
Indeed I saw it. Not a fan of it, I'm afraid.
Quoted 8 lines
Hard to guess the reasons. :)
Anyway, at a minimum I suggest that if the no opt out version has to go in, it is clearly documented drm-*-memory-* is *not* about the full memory use of the client, but about memory belonging to user visible buffer objects *only*. Possibly going as far as naming the keys as drm-user-bo-memory-... That way there is a way to implement proper drm-*-memory- in the future.
I'll go back to the helper approach, just been distracted by a few other balls in the air.. should hopefully get to it in the next couple days
BR,
-R
Quoted 14 lines
Regards,
Tvrtko
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
Fwiw: Keeping the i915 patch as part of this series would be great. Sure
i915_drm_client->idbecomes dead code, but it's a piece one can live with for a release or two. Then again it's not my call to make.Rob can take the i915 patch from my RFC too.
Indeed.
-Emil