drm: fdinfo memory stats
Subsystems (6)
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.
TODO gputop support?
[1] https://patchwork.freedesktop.org/series/112397/
Rob Clark (2):
drm: Add fdinfo memory stats
drm/msm: Add memory stats to fdinfo
Documentation/gpu/drm-usage-stats.rst | 21 +++++++ drivers/gpu/drm/drm_file.c | 79 +++++++++++++++++++++++++++ drivers/gpu/drm/msm/msm_drv.c | 26 ++++++++- drivers/gpu/drm/msm/msm_gpu.c | 2 - include/drm/drm_file.h | 10 ++++ 5 files changed, 135 insertions(+), 3 deletions(-)
Signature · 1 line
2.39.2
RFC 1/2 drm: Add fdinfo memory stats
From: Rob Clark <[email protected]>
Add a helper to dump memory stats to fdinfo. For the things the drm core isn't aware of, use a callback.
--- Documentation/gpu/drm-usage-stats.rst | 21 +++++++ drivers/gpu/drm/drm_file.c | 79 +++++++++++++++++++++++++++ include/drm/drm_file.h | 10 ++++ 3 files changed, 110 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 purgable. + +- 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 +79 -0
91 lines not on this page · raw message
include/drm/drm_file.h +10 -0
@@ -41,6 +41,7 @@struct dma_fence ;struct drm_file ;struct drm_device ; +struct drm_printer ;struct device ;struct file ;
@@ -438,6 +439,15 @@ void drm_send_event_timestamp_locked(struct drm_device *dev,struct drm_pending_event *e, ktime_t timestamp); +enum drm_gem_object_status { +DRM_GEM_OBJECT_RESIDENT =BIT (0 ), +DRM_GEM_OBJECT_PURGEABLE =BIT (1 ), +DRM_GEM_OBJECT_ACTIVE =BIT (2 ), +}; + +void drm_print_memory_stats (struct drm_file *file,struct drm_printer *p, +enum drm_gem_object_status (*status)(struct drm_gem_object *)); +struct file *mock_drm_getfile (struct drm_minor *minor,unsigned int flags);#endif /* _DRM_FILE_H_ */
Signature · 1 line
2.39.2
RFC 2/2 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.
--- drivers/gpu/drm/msm/msm_drv.c | 26 +++++++++++++++++++++++++- drivers/gpu/drm/msm/msm_gpu.c | 2 -- 2 files changed, 25 insertions(+), 3 deletions(-)
drivers/gpu/drm/msm/msm_drv.c +25 -1
@@ -1043,17 +1043,40 @@ static const struct drm_ioctl_desc msm_ioctls[] = { DRM_IOCTL_DEF_DRV(MSM_SUBMITQUEUE_QUERY, msm_ioctl_submitqueue_query, DRM_RENDER_ALLOW), }; +enum drm_gem_object_status 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 (!dma_resv_test_signaled (obj->resv,dma_resv_usage_rw (true))) + status |=DRM_GEM_OBJECT_ACTIVE ; + +if (msm_obj->pages) + status |=DRM_GEM_OBJECT_RESIDENT ; + +if (msm_obj->madv ==MSM_MADV_DONTNEED ) + status |=DRM_GEM_OBJECT_PURGEABLE ; + +return status; +} +static void msm_fop_show_fdinfo (struct seq_file *m,struct file *f) {struct drm_file *file = f->private_data;struct drm_device *dev = file->minor->dev;struct msm_drm_private *priv = dev->dev_private; +struct msm_file_private *ctx = file->driver_priv;struct drm_printer p =drm_seq_file_printer (m);if (!priv->gpu)return ; -msm_gpu_show_fdinfo (priv->gpu, file->driver_priv, &p); +drm_printf (&p,"drm-driver:\t%s\n" , dev->driver->name); +drm_printf (&p,"drm-client-id:\t%u\n" , ctx->seqno); + +msm_gpu_show_fdinfo (priv->gpu, ctx, &p); + +drm_print_memory_stats (file, &p, gem_status); }static const struct file_operations fops = {
@@ -1067,6 +1090,7 @@ static const struct drm_driver msm_driver = {DRIVER_RENDER |DRIVER_ATOMIC |DRIVER_MODESET | +DRIVER_SYNCOBJ_TIMELINE | DRIVER_SYNCOBJ, .open = msm_open, .postclose = msm_postclose,
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
kernel test robot
build botRe: [RFC 1/2] drm: Add fdinfo memory stats
In reply to Rob Clarkkernel test robot noticed the following build warnings:
Hi Rob,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on drm/drm-next drm-exynos/exynos-drm-next drm-intel/for-linux-next drm-intel/for-linux-next-fixes drm-tip/drm-tip linus/master v6.3-rc5 next-20230406] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Rob-Clark/drm-Add-fdinfo-memory-stats/20230407-060118 base: git://anongit.freedesktop.org/drm/drm-misc drm-misc-next patch link: https://lore.kernel.org/r/20230406215917.1475704-2-robdclark%40gmail.com patch subject: [RFC 1/2] drm: Add fdinfo memory stats config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20230407/[email protected]/config) compiler: m68k-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/eebbb3ec0a196240e1084554563ac4ae7e85dbb3
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Rob-Clark/drm-Add-fdinfo-memory-stats/20230407-060118
git checkout eebbb3ec0a196240e1084554563ac4ae7e85dbb3
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k SHELL=/bin/bash drivers/gpu/drm/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
drivers/gpu/drm/drm_file.c: In function 'print_size':
>> drivers/gpu/drm/drm_file.c:883:31: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'size_t' {aka 'unsigned int'} [-Wformat=]
883 | drm_printf(p, "%s:\t%lu %s\n", stat, sz, units[u]);
| ~~^ ~~
| | |
| | size_t {aka unsigned int}
| long unsigned int
| %uvim +883 drivers/gpu/drm/drm_file.c
871
872 static void print_size(struct drm_printer *p, const char *stat, size_t sz)
873 {
874 const char *units[] = {"B", "KiB", "MiB", "GiB"};
875 unsigned u;
876
877 for (u = 0; u < ARRAY_SIZE(units) - 1; u++) {
878 if (sz < SZ_1K)
879 break;
880 sz /= SZ_1K;
881 }
882
> 883 drm_printf(p, "%s:\t%lu %s\n", stat, sz, units[u]);
884 }
885
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
kernel test robot
build botRe: [RFC 1/2] drm: Add fdinfo memory stats
In reply to Rob Clarkkernel test robot noticed the following build warnings:
Hi Rob,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on drm/drm-next drm-exynos/exynos-drm-next drm-intel/for-linux-next drm-intel/for-linux-next-fixes drm-tip/drm-tip linus/master v6.3-rc5 next-20230406] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Rob-Clark/drm-Add-fdinfo-memory-stats/20230407-060118 base: git://anongit.freedesktop.org/drm/drm-misc drm-misc-next patch link: https://lore.kernel.org/r/20230406215917.1475704-2-robdclark%40gmail.com patch subject: [RFC 1/2] drm: Add fdinfo memory stats config: i386-randconfig-a002-20230403 (https://download.01.org/0day-ci/archive/20230407/[email protected]/config) compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/eebbb3ec0a196240e1084554563ac4ae7e85dbb3
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Rob-Clark/drm-Add-fdinfo-memory-stats/20230407-060118
git checkout eebbb3ec0a196240e1084554563ac4ae7e85dbb3
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/gpu/drm/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/gpu/drm/drm_file.c:883:39: warning: format specifies type 'unsigned long' but the argument has type 'size_t' (aka 'unsigned int') [-Wformat]
drm_printf(p, "%s:\t%lu %s\n", stat, sz, units[u]);
~~~ ^~
%zu1 warning generated.
vim +883 drivers/gpu/drm/drm_file.c
871
872 static void print_size(struct drm_printer *p, const char *stat, size_t sz)
873 {
874 const char *units[] = {"B", "KiB", "MiB", "GiB"};
875 unsigned u;
876
877 for (u = 0; u < ARRAY_SIZE(units) - 1; u++) {
878 if (sz < SZ_1K)
879 break;
880 sz /= SZ_1K;
881 }
882
> 883 drm_printf(p, "%s:\t%lu %s\n", stat, sz, units[u]);
884 }
885
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
Re: [RFC 1/2] drm: Add fdinfo memory stats
In reply to Rob ClarkHey Rob,
Review
Quoted 3 lines · Rob Clark
+- drm-purgeable-memory: <uint> [KiB|MiB]
(quoted diff) +2
-0+ +The total size of buffers that are purgable.
s/purgable/purgeable/
drivers/gpu/drm/drm_file.c void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) · line 874
Quoted 3 lines
drivers/gpu/drm/drm_file.c +3
-0+static void print_size (struct drm_printer *p,const char *stat,size_t sz) +{ +const char *units[] = {"B" ,"KiB" ,"MiB" ,"GiB" };
The documentation says:
Quoted 2 lines
Default unit shall be bytes with optional unit specifiers of 'KiB' or 'MiB' indicating kibi- or mebi-bytes.
So I would drop the B and/or update the documentation to mention B && GiB.
drivers/gpu/drm/drm_file.c void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) · line 880
Quoted 6 lines
drivers/gpu/drm/drm_file.c +6
-0+unsigned u; + +for (u =0 ; u <ARRAY_SIZE (units) -1 ; u++) { +if (sz <SZ_1K ) +break ; + sz /=SZ_1K ;
IIRC size_t can be 64bit, so we should probably use do_div() here.
drivers/gpu/drm/drm_file.c void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) · line 893
Quoted 13 lines
drivers/gpu/drm/drm_file.c +13
-0+ } + +drm_printf (p,"%s:\t%lu %s\n" , stat, sz, units[u]); +} + +/** +* drm_print_memory_stats - Helper to print standard fdinfo memory stats +* @file: the DRM file +* @p: the printer to print output to +* @status: callback to get driver tracked object status +* +* Helper to iterate over GEM objects with a handle allocated in the specified +* file. The optional status callback can return additional object state which
s/return additional/return an additional/
Quoted 3 lines
+ * determines which stats the object is counted against. The callback is called
+ * undertable_lock. Racing against object status change is "harmless", and the
+ * callback can expect to not race against object destroy.
s/destroy/destruction/
drivers/gpu/drm/drm_file.c void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) · line 926
Quoted 8 lines
+ */
drivers/gpu/drm/drm_file.c +6
-0+void drm_print_memory_stats (struct drm_file *file,struct drm_printer *p, +enum drm_gem_object_status (*status)(struct drm_gem_object *)) +{ +if (s &DRM_GEM_OBJECT_RESIDENT ) { + size.resident += obj->size; + s &= ~DRM_GEM_OBJECT_PURGEABLE ;
Is MSM capable of marking the object as both purgeable and resident or is this to catch other drivers? Should we add a note to the documentation above - resident memory cannot be purgeable
drivers/gpu/drm/drm_file.c void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) · line 931
Quoted 5 lines
drivers/gpu/drm/drm_file.c +5
-0+ } + +if (s &DRM_GEM_OBJECT_ACTIVE ) { + size.active += obj->size; + s &= ~DRM_GEM_OBJECT_PURGEABLE ;
Ditto.
With the above nits, the patch is:
HTH
Emil
Re: [RFC 2/2] drm/msm: Add memory stats to fdinfo
In reply to Rob ClarkQuoted 58 lines · Rob Clark
From: Rob Clark <[email protected]>
Use the new helper to export stats about memory usage.
Signed-off-by Rob Clark <[email protected]>--- drivers/gpu/drm/msm/msm_drv.c | 26 +++++++++++++++++++++++++- drivers/gpu/drm/msm/msm_gpu.c | 2 -- 2 files changed, 25 insertions(+), 3 deletions(-)drivers/gpu/drm/msm/msm_drv.c +24
-1@@ -1043,17 +1043,40 @@ static const struct drm_ioctl_desc msm_ioctls[] = { DRM_IOCTL_DEF_DRV(MSM_SUBMITQUEUE_QUERY, msm_ioctl_submitqueue_query, DRM_RENDER_ALLOW), }; +enum drm_gem_object_status 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 (!dma_resv_test_signaled (obj->resv,dma_resv_usage_rw (true))) + status |=DRM_GEM_OBJECT_ACTIVE ; + +if (msm_obj->pages) + status |=DRM_GEM_OBJECT_RESIDENT ; + +if (msm_obj->madv ==MSM_MADV_DONTNEED ) + status |=DRM_GEM_OBJECT_PURGEABLE ; + +return status; +} +static void msm_fop_show_fdinfo (struct seq_file *m,struct file *f) {struct drm_file *file = f->private_data;struct drm_device *dev = file->minor->dev;struct msm_drm_private *priv = dev->dev_private; +struct msm_file_private *ctx = file->driver_priv;struct drm_printer p =drm_seq_file_printer (m);if (!priv->gpu)return ; -msm_gpu_show_fdinfo (priv->gpu, file->driver_priv, &p); +drm_printf (&p,"drm-driver:\t%s\n" , dev->driver->name); +drm_printf (&p,"drm-client-id:\t%u\n" , ctx->seqno); + +msm_gpu_show_fdinfo (priv->gpu, ctx, &p); + +drm_print_memory_stats (file, &p, gem_status); }static const struct file_operations fops = {
drivers/gpu/drm/msm/msm_drv.c static const struct drm_driver msm_driver = { · line 1093
Quoted 4 lines
drivers/gpu/drm/msm/msm_drv.c +1
-0@@ -1067,6 +1090,7 @@ static const struct drm_driver msm_driver = {DRIVER_RENDER |DRIVER_ATOMIC |DRIVER_MODESET | + DRIVER_SYNCOBJ_TIMELINE |
This line should probably be its own patch. AFAICT it was supported since ab723b7a992a19b843f798b183f53f7472f598c8, although explicitly kept disabled until there's userspace/turnip support.
With the above line removed, the patch is:
HTH
Emil
Re: [RFC 2/2] drm/msm: Add memory stats to fdinfo
Quoted 58 lines · Emil Velikov
Quoted 56 lines · Rob Clark
From: Rob Clark <[email protected]>
Use the new helper to export stats about memory usage.
Signed-off-by Rob Clark <[email protected]>--- drivers/gpu/drm/msm/msm_drv.c | 26 +++++++++++++++++++++++++- drivers/gpu/drm/msm/msm_gpu.c | 2 -- 2 files changed, 25 insertions(+), 3 deletions(-)drivers/gpu/drm/msm/msm_drv.c +24
-1@@ -1043,17 +1043,40 @@ static const struct drm_ioctl_desc msm_ioctls[] = { DRM_IOCTL_DEF_DRV(MSM_SUBMITQUEUE_QUERY, msm_ioctl_submitqueue_query, DRM_RENDER_ALLOW), }; +enum drm_gem_object_status 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 (!dma_resv_test_signaled (obj->resv,dma_resv_usage_rw (true))) + status |=DRM_GEM_OBJECT_ACTIVE ; + +if (msm_obj->pages) + status |=DRM_GEM_OBJECT_RESIDENT ; + +if (msm_obj->madv ==MSM_MADV_DONTNEED ) + status |=DRM_GEM_OBJECT_PURGEABLE ; + +return status; +} +static void msm_fop_show_fdinfo (struct seq_file *m,struct file *f) {struct drm_file *file = f->private_data;struct drm_device *dev = file->minor->dev;struct msm_drm_private *priv = dev->dev_private; +struct msm_file_private *ctx = file->driver_priv;struct drm_printer p =drm_seq_file_printer (m);if (!priv->gpu)return ; -msm_gpu_show_fdinfo (priv->gpu, file->driver_priv, &p); +drm_printf (&p,"drm-driver:\t%s\n" , dev->driver->name); +drm_printf (&p,"drm-client-id:\t%u\n" , ctx->seqno); + +msm_gpu_show_fdinfo (priv->gpu, ctx, &p); + +drm_print_memory_stats (file, &p, gem_status); }
Quoted 10 lines
drivers/gpu/drm/msm/msm_drv.c static const struct drm_driver msm_driver = { · line 1093
Quoted 6 lines
drivers/gpu/drm/msm/msm_drv.c +1
-0static const struct file_operations fops = {@@ -1067,6 +1090,7 @@ static const struct drm_driver msm_driver = {DRIVER_RENDER |DRIVER_ATOMIC |DRIVER_MODESET | + DRIVER_SYNCOBJ_TIMELINE |This line should probably be its own patch. AFAICT it was supported since
ab723b7a992a19b843f798b183f53f7472f598c8, although explicitly kept disabled until there's userspace/turnip support.
ahh, yes, that wasn't intended to be part of this patch, just a local thing I happened to be testing
BR,
-R
Quoted 5 lines
With the above line removed, the patch is:
Reviewed-by Emil Velikov <[email protected]>HTH
Emil
Re: [RFC 1/2] drm: Add fdinfo memory stats
In reply to Emil VelikovQuoted 32 lines · Emil Velikov
Hey Rob,
Review
Quoted 3 lines · Rob Clark
+- drm-purgeable-memory: <uint> [KiB|MiB]
(quoted diff) +2
-0+ +The total size of buffers that are purgable.s/purgable/purgeable/
drivers/gpu/drm/drm_file.c void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) · line 874
Quoted 3 lines
drivers/gpu/drm/drm_file.c +3
-0+static void print_size (struct drm_printer *p,const char *stat,size_t sz) +{ +const char *units[] = {"B" ,"KiB" ,"MiB" ,"GiB" };The documentation says:
Quoted 2 lines
Default unit shall be bytes with optional unit specifiers of 'KiB' or 'MiB' indicating kibi- or mebi-bytes.
So I would drop the B and/or update the documentation to mention B && GiB.
drivers/gpu/drm/drm_file.c void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) · line 880
Quoted 6 lines
drivers/gpu/drm/drm_file.c +6
-0+unsigned u; + +for (u =0 ; u <ARRAY_SIZE (units) -1 ; u++) { +if (sz <SZ_1K ) +break ; + sz /=SZ_1K ;IIRC
size_tcan be 64bit, so we should probably usedo_div()here.
Quoted 15 lines
drivers/gpu/drm/drm_file.c void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) · line 893
Quoted 13 lines
drivers/gpu/drm/drm_file.c +13
-0+ } + +drm_printf (p,"%s:\t%lu %s\n" , stat, sz, units[u]); +} + +/** +* drm_print_memory_stats - Helper to print standard fdinfo memory stats +* @file: the DRM file +* @p: the printer to print output to +* @status: callback to get driver tracked object status +* +* Helper to iterate over GEM objects with a handle allocated in the specified +* file. The optional status callback can return additional object state which s/return additional/return an additional/
"an" reads funny to me, as the state is plural (bitmask).. but agreed on the other things
Quoted 11 lines
Quoted 3 lines
+ * determines which stats the object is counted against. The callback is called
+ * undertable_lock. Racing against object status change is "harmless", and the
+ * callback can expect to not race against object destroy.s/destroy/destruction/
Quoted 4 lines
+ */
drivers/gpu/drm/drm_file.c +3
-0+void drm_print_memory_stats (struct drm_file *file,struct drm_printer *p, +enum drm_gem_object_status (*status)(struct drm_gem_object *)) +{
Quoted 7 lines
drivers/gpu/drm/drm_file.c void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) · line 926
Quoted 3 lines
drivers/gpu/drm/drm_file.c +3
-0+if (s &DRM_GEM_OBJECT_RESIDENT ) { + size.resident += obj->size; + s &= ~DRM_GEM_OBJECT_PURGEABLE ;Is MSM capable of marking the object as both purgeable and resident or is this to catch other drivers? Should we add a note to the documentation above - resident memory cannot be purgeable
It is just to simplify drivers so they don't have to repeat this logic. Ie. an object can be marked purgeable while it is still active (so it will be eventually purgeable when it becomes idle). Likewise it doesn't make sense to count an object that has already been purged (is no longer resident) as purgeable.
BR,
-R
Quoted 13 lines
drivers/gpu/drm/drm_file.c void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) · line 931
Quoted 5 lines
drivers/gpu/drm/drm_file.c +5
-0+ } + +if (s &DRM_GEM_OBJECT_ACTIVE ) { + size.active += obj->size; + s &= ~DRM_GEM_OBJECT_PURGEABLE ;Ditto.
With the above nits, the patch is:
Reviewed-by Emil Velikov <[email protected]>HTH
Emil
Re: [RFC 1/2] drm: Add fdinfo memory stats
In reply to Rob ClarkHi Rob,
Quoted 78 lines · On Thu, 6 Apr 2023 14:59:16 -0700 Rob Clark <[email protected]> wrote:
From: Rob Clark <[email protected]>
Add a helper to dump memory stats to fdinfo. For the things the drm core isn't aware of, use a callback.
Signed-off-by Rob Clark <[email protected]>--- Documentation/gpu/drm-usage-stats.rst | 21 +++++++ drivers/gpu/drm/drm_file.c | 79 +++++++++++++++++++++++++++ include/drm/drm_file.h | 10 ++++ 3 files changed, 110 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 purgable. + +- 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 thedrivers/gpu/drm/drm_file.c +19
-0@@ -42,6 +42,7 @@#include <drm/drm_client.h> #include <drm/drm_drv.h> #include <drm/drm_file.h> +#include <drm/drm_gem.h> #include <drm/drm_print.h> #include "drm_crtc_internal.h" @@ -868,6 +869,84 @@ void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) }EXPORT_SYMBOL (drm_send_event); +static void print_size (struct drm_printer *p,const char *stat,size_t sz) +{ +const char *units[] = {"B" ,"KiB" ,"MiB" ,"GiB" }; +unsigned u; + +for (u =0 ; u <ARRAY_SIZE (units) -1 ; u++) { +if (sz <SZ_1K ) +break ; + sz /=SZ_1K ; + } + +drm_printf (p,"%s:\t%lu %s\n" , stat, sz, units[u]); +} + +/** +* drm_print_memory_stats - Helper to print standard fdinfo memory stats +* @file: the DRM file +* @p: the printer to print output to
drivers/gpu/drm/drm_file.c void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) · line 899
Quoted 10 lines
drivers/gpu/drm/drm_file.c +10
-0+* @status: callback to get driver tracked object status +* +* Helper to iterate over GEM objects with a handle allocated in the specified +* file. 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 destroy. +*/ +void drm_print_memory_stats (struct drm_file *file,struct drm_printer *p, +enum drm_gem_object_status (*status)(struct drm_gem_object *))
Nit: status() returning an 'enum drm_gem_object_status' makes it look like it can only return one of the DRM_GEM_OBJECT_* flag, when it can actually be a combination of flags. Should we make it return an u32 instead? At the very least this should be clarified in the function doc.
Quoted 37 lines
drivers/gpu/drm/drm_file.c +37
-0+{ +struct drm_gem_object *obj; +struct { +size_t shared; +size_t private; +size_t resident; +size_t purgeable; +size_t active; + } size = {0 }; +int id; + +spin_lock (&file->table_lock); + idr_for_each_entry (&file->object_idr, obj, id) { +enum drm_gem_object_status s =0 ; + +if (status) + s =status (obj); + +if (obj->handle_count >1 ) { + size.shared += obj->size; + }else { + size.private += obj->size; + } + +if (s &DRM_GEM_OBJECT_RESIDENT ) { + size.resident += obj->size; + s &= ~DRM_GEM_OBJECT_PURGEABLE ; + } + +if (s &DRM_GEM_OBJECT_ACTIVE ) { + size.active += obj->size; + s &= ~DRM_GEM_OBJECT_PURGEABLE ; + } + +if (s &DRM_GEM_OBJECT_PURGEABLE ) + size.purgeable += obj->size; + }
drivers/gpu/drm/drm_file.c void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) · line 946
Quoted 10 lines
drivers/gpu/drm/drm_file.c +10
-0+spin_unlock (&file->table_lock); + +print_size (p,"drm-shared-memory" , size.shared); +print_size (p,"drm-private-memory" , size.private); + +if (status) { +print_size (p,"drm-resident-memory" , size.resident); +print_size (p,"drm-purgeable-memory" , size.purgeable); +print_size (p,"drm-active-memory" , size.active); + }
Should we assume that all users of this drm_print_memory_stats() helper support tracking all these non-standard stats as soon as they provide a status callback? If not, we should probably not print the drm-xxx-memory line when the driver is not tracking this state (can be done with a 'supported_status' mask passed to drm_print_memory_stats()).
Other than these 2 minor things, I think it's a perfect match for panfrost mem-tracking, and I certainly intend to use this helper in panfrost.
Thanks,
Boris