Message ID | 20230922134700.235039-7-tvrtko.ursulin@linux.intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | fdinfo memory stats | expand |
On 22-09-2023 19:17, Tvrtko Ursulin wrote: > From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> > > Use the newly added drm_print_memory_stats helper to show memory > utilisation of our objects in drm/driver specific fdinfo output. > > To collect the stats we walk the per memory regions object lists > and accumulate object size into the respective drm_memory_stats > categories. > > v2: > * Only account against the active region. > * Use DMA_RESV_USAGE_BOOKKEEP when testing for active. (Tejas) > > v3: > * Update commit text. (Aravind) > * Update to use memory regions uabi names. > > Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> > Cc: Aravind Iddamsetty <aravind.iddamsetty@intel.com> > Cc: Rob Clark <robdclark@gmail.com> > Cc: Andi Shyti <andi.shyti@linux.intel.com> > Cc: Tejas Upadhyay <tejas.upadhyay@intel.com> > Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> # v1 > Reviewed-by: Aravind Iddamsetty <aravind.iddamsetty@intel.com> # v2 Reviewed-by: Aravind Iddamsetty <aravind.iddamsetty@intel.com> Thanks, Aravind. > --- > drivers/gpu/drm/i915/i915_drm_client.c | 64 ++++++++++++++++++++++++++ > 1 file changed, 64 insertions(+) > > diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c > index a61356012df8..7efffdaa508d 100644 > --- a/drivers/gpu/drm/i915/i915_drm_client.c > +++ b/drivers/gpu/drm/i915/i915_drm_client.c > @@ -45,6 +45,68 @@ void __i915_drm_client_free(struct kref *kref) > } > > #ifdef CONFIG_PROC_FS > +static void > +obj_meminfo(struct drm_i915_gem_object *obj, > + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN]) > +{ > + const enum intel_region_id id = obj->mm.region ? > + obj->mm.region->id : INTEL_REGION_SMEM; > + const u64 sz = obj->base.size; > + > + if (obj->base.handle_count > 1) > + stats[id].shared += sz; > + else > + stats[id].private += sz; > + > + if (i915_gem_object_has_pages(obj)) { > + stats[id].resident += sz; > + > + if (!dma_resv_test_signaled(obj->base.resv, > + DMA_RESV_USAGE_BOOKKEEP)) > + stats[id].active += sz; > + else if (i915_gem_object_is_shrinkable(obj) && > + obj->mm.madv == I915_MADV_DONTNEED) > + stats[id].purgeable += sz; > + } > +} > + > +static void show_meminfo(struct drm_printer *p, struct drm_file *file) > +{ > + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN] = {}; > + struct drm_i915_file_private *fpriv = file->driver_priv; > + struct i915_drm_client *client = fpriv->client; > + struct drm_i915_private *i915 = fpriv->i915; > + struct drm_i915_gem_object *obj; > + struct intel_memory_region *mr; > + struct list_head *pos; > + unsigned int id; > + > + /* Public objects. */ > + spin_lock(&file->table_lock); > + idr_for_each_entry(&file->object_idr, obj, id) > + obj_meminfo(obj, stats); > + spin_unlock(&file->table_lock); > + > + /* Internal objects. */ > + rcu_read_lock(); > + list_for_each_rcu(pos, &client->objects_list) { > + obj = i915_gem_object_get_rcu(list_entry(pos, typeof(*obj), > + client_link)); > + if (!obj) > + continue; > + obj_meminfo(obj, stats); > + i915_gem_object_put(obj); > + } > + rcu_read_unlock(); > + > + for_each_memory_region(mr, i915, id) > + drm_print_memory_stats(p, > + &stats[id], > + DRM_GEM_OBJECT_RESIDENT | > + DRM_GEM_OBJECT_PURGEABLE, > + mr->uabi_name); > +} > + > static const char * const uabi_class_names[] = { > [I915_ENGINE_CLASS_RENDER] = "render", > [I915_ENGINE_CLASS_COPY] = "copy", > @@ -106,6 +168,8 @@ void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file) > * ****************************************************************** > */ > > + show_meminfo(p, file); > + > if (GRAPHICS_VER(i915) < 8) > return; >
Hi Tvrtko, > Use the newly added drm_print_memory_stats helper to show memory > utilisation of our objects in drm/driver specific fdinfo output. > > To collect the stats we walk the per memory regions object lists > and accumulate object size into the respective drm_memory_stats > categories. > > v2: > * Only account against the active region. > * Use DMA_RESV_USAGE_BOOKKEEP when testing for active. (Tejas) > > v3: > * Update commit text. (Aravind) > * Update to use memory regions uabi names. > > Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> > Cc: Aravind Iddamsetty <aravind.iddamsetty@intel.com> > Cc: Rob Clark <robdclark@gmail.com> > Cc: Andi Shyti <andi.shyti@linux.intel.com> > Cc: Tejas Upadhyay <tejas.upadhyay@intel.com> > Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> # v1 > Reviewed-by: Aravind Iddamsetty <aravind.iddamsetty@intel.com> # v2 Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> Andi
Hi Tvrtko, kernel test robot noticed the following build warnings: [auto build test WARNING on drm-tip/drm-tip] url: https://github.com/intel-lab-lkp/linux/commits/Tvrtko-Ursulin/drm-i915-Add-ability-for-tracking-buffer-objects-per-client/20230922-214929 base: git://anongit.freedesktop.org/drm/drm-tip drm-tip patch link: https://lore.kernel.org/r/20230922134700.235039-7-tvrtko.ursulin%40linux.intel.com patch subject: [PATCH 6/6] drm/i915: Implement fdinfo memory stats printing config: i386-randconfig-062-20230927 (https://download.01.org/0day-ci/archive/20230927/202309271528.TmGx2jEq-lkp@intel.com/config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230927/202309271528.TmGx2jEq-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202309271528.TmGx2jEq-lkp@intel.com/ sparse warnings: (new ones prefixed by >>) >> drivers/gpu/drm/i915/i915_drm_client.c:92:9: sparse: sparse: incompatible types in comparison expression (different address spaces): >> drivers/gpu/drm/i915/i915_drm_client.c:92:9: sparse: struct list_head [noderef] __rcu * >> drivers/gpu/drm/i915/i915_drm_client.c:92:9: sparse: struct list_head * >> drivers/gpu/drm/i915/i915_drm_client.c:92:9: sparse: sparse: incompatible types in comparison expression (different address spaces): >> drivers/gpu/drm/i915/i915_drm_client.c:92:9: sparse: struct list_head [noderef] __rcu * >> drivers/gpu/drm/i915/i915_drm_client.c:92:9: sparse: struct list_head * vim +92 drivers/gpu/drm/i915/i915_drm_client.c 72 73 static void show_meminfo(struct drm_printer *p, struct drm_file *file) 74 { 75 struct drm_memory_stats stats[INTEL_REGION_UNKNOWN] = {}; 76 struct drm_i915_file_private *fpriv = file->driver_priv; 77 struct i915_drm_client *client = fpriv->client; 78 struct drm_i915_private *i915 = fpriv->i915; 79 struct drm_i915_gem_object *obj; 80 struct intel_memory_region *mr; 81 struct list_head *pos; 82 unsigned int id; 83 84 /* Public objects. */ 85 spin_lock(&file->table_lock); 86 idr_for_each_entry(&file->object_idr, obj, id) 87 obj_meminfo(obj, stats); 88 spin_unlock(&file->table_lock); 89 90 /* Internal objects. */ 91 rcu_read_lock(); > 92 list_for_each_rcu(pos, &client->objects_list) { 93 obj = i915_gem_object_get_rcu(list_entry(pos, typeof(*obj), 94 client_link)); 95 if (!obj) 96 continue; 97 obj_meminfo(obj, stats); 98 i915_gem_object_put(obj); 99 } 100 rcu_read_unlock(); 101 102 for_each_memory_region(mr, i915, id) 103 drm_print_memory_stats(p, 104 &stats[id], 105 DRM_GEM_OBJECT_RESIDENT | 106 DRM_GEM_OBJECT_PURGEABLE, 107 mr->uabi_name); 108 } 109
On 27/09/2023 07:54, Andi Shyti wrote: > Hi Tvrtko, > >> Use the newly added drm_print_memory_stats helper to show memory >> utilisation of our objects in drm/driver specific fdinfo output. >> >> To collect the stats we walk the per memory regions object lists >> and accumulate object size into the respective drm_memory_stats >> categories. >> >> v2: >> * Only account against the active region. >> * Use DMA_RESV_USAGE_BOOKKEEP when testing for active. (Tejas) >> >> v3: >> * Update commit text. (Aravind) >> * Update to use memory regions uabi names. >> >> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> >> Cc: Aravind Iddamsetty <aravind.iddamsetty@intel.com> >> Cc: Rob Clark <robdclark@gmail.com> >> Cc: Andi Shyti <andi.shyti@linux.intel.com> >> Cc: Tejas Upadhyay <tejas.upadhyay@intel.com> >> Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> # v1 >> Reviewed-by: Aravind Iddamsetty <aravind.iddamsetty@intel.com> # v2 > > Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> Thanks guys, just the IGTs remaining now. I've just sent a respin of one patch in that series which will hopefully fix things up. * https://patchwork.freedesktop.org/series/124118/ First two patches is what we need to merge the kernel side, while the rest are intel_gpu_top fixes followed by per client memory support. Regards, Tvrtko
On 27/09/2023 14:23, Tvrtko Ursulin wrote: > > On 27/09/2023 07:54, Andi Shyti wrote: >> Hi Tvrtko, >> >>> Use the newly added drm_print_memory_stats helper to show memory >>> utilisation of our objects in drm/driver specific fdinfo output. >>> >>> To collect the stats we walk the per memory regions object lists >>> and accumulate object size into the respective drm_memory_stats >>> categories. >>> >>> v2: >>> * Only account against the active region. >>> * Use DMA_RESV_USAGE_BOOKKEEP when testing for active. (Tejas) >>> >>> v3: >>> * Update commit text. (Aravind) >>> * Update to use memory regions uabi names. >>> >>> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> >>> Cc: Aravind Iddamsetty <aravind.iddamsetty@intel.com> >>> Cc: Rob Clark <robdclark@gmail.com> >>> Cc: Andi Shyti <andi.shyti@linux.intel.com> >>> Cc: Tejas Upadhyay <tejas.upadhyay@intel.com> >>> Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> # v1 >>> Reviewed-by: Aravind Iddamsetty <aravind.iddamsetty@intel.com> # v2 >> >> Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> > > Thanks guys, just the IGTs remaining now. I've just sent a respin of one > patch in that series which will hopefully fix things up. Actually no, I forgot that decided I will respin the i915 series with yet one more patch. Stay tuned please. Regards, Tvrtko > * https://patchwork.freedesktop.org/series/124118/ > > First two patches is what we need to merge the kernel side, while the > rest are intel_gpu_top fixes followed by per client memory support. > > Regards, > > Tvrtko >
diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c index a61356012df8..7efffdaa508d 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.c +++ b/drivers/gpu/drm/i915/i915_drm_client.c @@ -45,6 +45,68 @@ void __i915_drm_client_free(struct kref *kref) } #ifdef CONFIG_PROC_FS +static void +obj_meminfo(struct drm_i915_gem_object *obj, + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN]) +{ + const enum intel_region_id id = obj->mm.region ? + obj->mm.region->id : INTEL_REGION_SMEM; + const u64 sz = obj->base.size; + + if (obj->base.handle_count > 1) + stats[id].shared += sz; + else + stats[id].private += sz; + + if (i915_gem_object_has_pages(obj)) { + stats[id].resident += sz; + + if (!dma_resv_test_signaled(obj->base.resv, + DMA_RESV_USAGE_BOOKKEEP)) + stats[id].active += sz; + else if (i915_gem_object_is_shrinkable(obj) && + obj->mm.madv == I915_MADV_DONTNEED) + stats[id].purgeable += sz; + } +} + +static void show_meminfo(struct drm_printer *p, struct drm_file *file) +{ + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN] = {}; + struct drm_i915_file_private *fpriv = file->driver_priv; + struct i915_drm_client *client = fpriv->client; + struct drm_i915_private *i915 = fpriv->i915; + struct drm_i915_gem_object *obj; + struct intel_memory_region *mr; + struct list_head *pos; + unsigned int id; + + /* Public objects. */ + spin_lock(&file->table_lock); + idr_for_each_entry(&file->object_idr, obj, id) + obj_meminfo(obj, stats); + spin_unlock(&file->table_lock); + + /* Internal objects. */ + rcu_read_lock(); + list_for_each_rcu(pos, &client->objects_list) { + obj = i915_gem_object_get_rcu(list_entry(pos, typeof(*obj), + client_link)); + if (!obj) + continue; + obj_meminfo(obj, stats); + i915_gem_object_put(obj); + } + rcu_read_unlock(); + + for_each_memory_region(mr, i915, id) + drm_print_memory_stats(p, + &stats[id], + DRM_GEM_OBJECT_RESIDENT | + DRM_GEM_OBJECT_PURGEABLE, + mr->uabi_name); +} + static const char * const uabi_class_names[] = { [I915_ENGINE_CLASS_RENDER] = "render", [I915_ENGINE_CLASS_COPY] = "copy", @@ -106,6 +168,8 @@ void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file) * ****************************************************************** */ + show_meminfo(p, file); + if (GRAPHICS_VER(i915) < 8) return;