* [PATCH 0/2] accel/ivpu: Add memory statistics support @ 2025-11-06 10:10 Karol Wachowski 2025-11-06 10:10 ` [PATCH 1/2] accel/ivpu: Add fdinfo support for memory statistics Karol Wachowski 2025-11-06 10:10 ` [PATCH 2/2] accel/ivpu: Count only resident buffers in memory utilization Karol Wachowski 0 siblings, 2 replies; 6+ messages in thread From: Karol Wachowski @ 2025-11-06 10:10 UTC (permalink / raw) To: dri-devel Cc: oded.gabbay, jeff.hugo, maciej.falkowski, lizhi.hou, Karol Wachowski Add support for reporting memory usage statistics via fdinfo and correct the memory utilization calculation to count only resident buffers via sysfs. Karol Wachowski (2): accel/ivpu: Add fdinfo support for memory statistics accel/ivpu: Count only resident buffers in memory utilization drivers/accel/ivpu/ivpu_drv.c | 6 ++++++ drivers/accel/ivpu/ivpu_gem.c | 12 ++++++++++++ drivers/accel/ivpu/ivpu_gem.h | 5 +++++ drivers/accel/ivpu/ivpu_sysfs.c | 3 ++- 4 files changed, 25 insertions(+), 1 deletion(-) -- 2.43.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] accel/ivpu: Add fdinfo support for memory statistics 2025-11-06 10:10 [PATCH 0/2] accel/ivpu: Add memory statistics support Karol Wachowski @ 2025-11-06 10:10 ` Karol Wachowski 2025-11-07 16:12 ` Jeff Hugo 2025-11-08 6:05 ` kernel test robot 2025-11-06 10:10 ` [PATCH 2/2] accel/ivpu: Count only resident buffers in memory utilization Karol Wachowski 1 sibling, 2 replies; 6+ messages in thread From: Karol Wachowski @ 2025-11-06 10:10 UTC (permalink / raw) To: dri-devel Cc: oded.gabbay, jeff.hugo, maciej.falkowski, lizhi.hou, Karol Wachowski Implement DRM fdinfo interface to expose memory usage statistics for NPU device file descriptors. Exclude unpinned and imported buffers from resident memory calculations to provide accurate memory usage reporting. Signed-off-by: Karol Wachowski <karol.wachowski@linux.intel.com> --- drivers/accel/ivpu/ivpu_drv.c | 6 ++++++ drivers/accel/ivpu/ivpu_gem.c | 12 ++++++++++++ drivers/accel/ivpu/ivpu_gem.h | 5 +++++ 3 files changed, 23 insertions(+) diff --git a/drivers/accel/ivpu/ivpu_drv.c b/drivers/accel/ivpu/ivpu_drv.c index b305effcf003..ce7dbd473059 100644 --- a/drivers/accel/ivpu/ivpu_drv.c +++ b/drivers/accel/ivpu/ivpu_drv.c @@ -455,6 +455,9 @@ int ivpu_shutdown(struct ivpu_device *vdev) static const struct file_operations ivpu_fops = { .owner = THIS_MODULE, DRM_ACCEL_FOPS, +#if CONFIG_PROC_FS + .show_fdinfo = drm_show_fdinfo, +#endif }; static const struct drm_driver driver = { @@ -469,6 +472,9 @@ static const struct drm_driver driver = { .ioctls = ivpu_drm_ioctls, .num_ioctls = ARRAY_SIZE(ivpu_drm_ioctls), .fops = &ivpu_fops, +#if CONFIG_PROC_FS + .show_fdinfo = drm_show_memory_stats, +#endif .name = DRIVER_NAME, .desc = DRIVER_DESC, diff --git a/drivers/accel/ivpu/ivpu_gem.c b/drivers/accel/ivpu/ivpu_gem.c index 03d39615ad37..a460cef4e0a0 100644 --- a/drivers/accel/ivpu/ivpu_gem.c +++ b/drivers/accel/ivpu/ivpu_gem.c @@ -335,6 +335,17 @@ static void ivpu_gem_bo_free(struct drm_gem_object *obj) drm_gem_shmem_free(&bo->base); } +static enum drm_gem_object_status ivpu_gem_status(struct drm_gem_object *obj) +{ + struct ivpu_bo *bo = to_ivpu_bo(obj); + enum drm_gem_object_status status = 0; + + if (ivpu_bo_is_resident(bo)) + status |= DRM_GEM_OBJECT_RESIDENT; + + return status; +} + static const struct drm_gem_object_funcs ivpu_gem_funcs = { .free = ivpu_gem_bo_free, .open = ivpu_gem_bo_open, @@ -345,6 +356,7 @@ static const struct drm_gem_object_funcs ivpu_gem_funcs = { .vmap = drm_gem_shmem_object_vmap, .vunmap = drm_gem_shmem_object_vunmap, .mmap = drm_gem_shmem_object_mmap, + .status = ivpu_gem_status, .vm_ops = &drm_gem_shmem_vm_ops, }; diff --git a/drivers/accel/ivpu/ivpu_gem.h b/drivers/accel/ivpu/ivpu_gem.h index 2dcd7eba9cb7..0c3350f22b55 100644 --- a/drivers/accel/ivpu/ivpu_gem.h +++ b/drivers/accel/ivpu/ivpu_gem.h @@ -82,6 +82,11 @@ static inline bool ivpu_bo_is_read_only(struct ivpu_bo *bo) return bo->flags & DRM_IVPU_BO_READ_ONLY; } +static inline bool ivpu_bo_is_resident(struct ivpu_bo *bo) +{ + return !!bo->base.pages; +} + static inline void *ivpu_to_cpu_addr(struct ivpu_bo *bo, u32 vpu_addr) { if (vpu_addr < bo->vpu_addr) -- 2.43.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] accel/ivpu: Add fdinfo support for memory statistics 2025-11-06 10:10 ` [PATCH 1/2] accel/ivpu: Add fdinfo support for memory statistics Karol Wachowski @ 2025-11-07 16:12 ` Jeff Hugo 2025-11-08 6:05 ` kernel test robot 1 sibling, 0 replies; 6+ messages in thread From: Jeff Hugo @ 2025-11-07 16:12 UTC (permalink / raw) To: Karol Wachowski, dri-devel; +Cc: oded.gabbay, maciej.falkowski, lizhi.hou On 11/6/2025 3:10 AM, Karol Wachowski wrote: > Implement DRM fdinfo interface to expose memory usage statistics > for NPU device file descriptors. Exclude unpinned and imported > buffers from resident memory calculations to provide accurate > memory usage reporting. > > Signed-off-by: Karol Wachowski <karol.wachowski@linux.intel.com> Have not used the fdinfo interface so I might be missing something subtle, but this looks sane to me. Seems rather elegant. Reviewed-by: Jeff Hugo <jeff.hugo@oss.qualcomm.com> ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] accel/ivpu: Add fdinfo support for memory statistics 2025-11-06 10:10 ` [PATCH 1/2] accel/ivpu: Add fdinfo support for memory statistics Karol Wachowski 2025-11-07 16:12 ` Jeff Hugo @ 2025-11-08 6:05 ` kernel test robot 1 sibling, 0 replies; 6+ messages in thread From: kernel test robot @ 2025-11-08 6:05 UTC (permalink / raw) To: Karol Wachowski, dri-devel Cc: oe-kbuild-all, oded.gabbay, jeff.hugo, maciej.falkowski, lizhi.hou, Karol Wachowski Hi Karol, kernel test robot noticed the following build warnings: [auto build test WARNING on next-20251106] [cannot apply to drm-misc/drm-misc-next drm-tip/drm-tip linus/master v6.18-rc4 v6.18-rc3 v6.18-rc2 v6.18-rc4] [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/Karol-Wachowski/accel-ivpu-Add-fdinfo-support-for-memory-statistics/20251106-181300 base: next-20251106 patch link: https://lore.kernel.org/r/20251106101052.1050348-2-karol.wachowski%40linux.intel.com patch subject: [PATCH 1/2] accel/ivpu: Add fdinfo support for memory statistics config: x86_64-buildonly-randconfig-005-20251108 (https://download.01.org/0day-ci/archive/20251108/202511081303.INWfFdzI-lkp@intel.com/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251108/202511081303.INWfFdzI-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/202511081303.INWfFdzI-lkp@intel.com/ All warnings (new ones prefixed by >>): >> drivers/accel/ivpu/ivpu_drv.c:458:5: warning: "CONFIG_PROC_FS" is not defined, evaluates to 0 [-Wundef] 458 | #if CONFIG_PROC_FS | ^~~~~~~~~~~~~~ drivers/accel/ivpu/ivpu_drv.c:475:5: warning: "CONFIG_PROC_FS" is not defined, evaluates to 0 [-Wundef] 475 | #if CONFIG_PROC_FS | ^~~~~~~~~~~~~~ Kconfig warnings: (for reference only) WARNING: unmet direct dependencies detected for OF_GPIO Depends on [n]: GPIOLIB [=y] && OF [=n] && HAS_IOMEM [=y] Selected by [y]: - GPIO_TB10X [=y] && GPIOLIB [=y] && HAS_IOMEM [=y] && (ARC_PLAT_TB10X || COMPILE_TEST [=y]) WARNING: unmet direct dependencies detected for MFD_STMFX Depends on [n]: HAS_IOMEM [=y] && I2C [=y] && OF [=n] Selected by [y]: - PINCTRL_STMFX [=y] && PINCTRL [=y] && I2C [=y] && OF_GPIO [=y] && HAS_IOMEM [=y] WARNING: unmet direct dependencies detected for I2C_K1 Depends on [n]: I2C [=y] && HAS_IOMEM [=y] && (ARCH_SPACEMIT || COMPILE_TEST [=y]) && OF [=n] Selected by [y]: - MFD_SPACEMIT_P1 [=y] && HAS_IOMEM [=y] && (ARCH_SPACEMIT || COMPILE_TEST [=y]) && I2C [=y] vim +/CONFIG_PROC_FS +458 drivers/accel/ivpu/ivpu_drv.c 454 455 static const struct file_operations ivpu_fops = { 456 .owner = THIS_MODULE, 457 DRM_ACCEL_FOPS, > 458 #if CONFIG_PROC_FS 459 .show_fdinfo = drm_show_fdinfo, 460 #endif 461 }; 462 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2] accel/ivpu: Count only resident buffers in memory utilization 2025-11-06 10:10 [PATCH 0/2] accel/ivpu: Add memory statistics support Karol Wachowski 2025-11-06 10:10 ` [PATCH 1/2] accel/ivpu: Add fdinfo support for memory statistics Karol Wachowski @ 2025-11-06 10:10 ` Karol Wachowski 2025-11-07 16:13 ` Jeff Hugo 1 sibling, 1 reply; 6+ messages in thread From: Karol Wachowski @ 2025-11-06 10:10 UTC (permalink / raw) To: dri-devel Cc: oded.gabbay, jeff.hugo, maciej.falkowski, lizhi.hou, Karol Wachowski Do not count buffer objects that have no backing pages, including imported buffers where pages are set by VM faults triggered by userspace or pinned by other drivers. Instead, return information about actual memory used by the NPU. Counting imported buffers results in incorrect calculations when the same pages are counted multiple times, giving overly high results. Fixes: 7bfc9fa99580 ("accel/ivpu: Expose NPU memory utilization info in sysfs") Signed-off-by: Karol Wachowski <karol.wachowski@linux.intel.com> --- drivers/accel/ivpu/ivpu_sysfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/accel/ivpu/ivpu_sysfs.c b/drivers/accel/ivpu/ivpu_sysfs.c index 268ab7744a8b..d250a10caca9 100644 --- a/drivers/accel/ivpu/ivpu_sysfs.c +++ b/drivers/accel/ivpu/ivpu_sysfs.c @@ -63,7 +63,8 @@ npu_memory_utilization_show(struct device *dev, struct device_attribute *attr, c mutex_lock(&vdev->bo_list_lock); list_for_each_entry(bo, &vdev->bo_list, bo_list_node) - total_npu_memory += bo->base.base.size; + if (ivpu_bo_is_resident(bo)) + total_npu_memory += ivpu_bo_size(bo); mutex_unlock(&vdev->bo_list_lock); return sysfs_emit(buf, "%lld\n", total_npu_memory); -- 2.43.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] accel/ivpu: Count only resident buffers in memory utilization 2025-11-06 10:10 ` [PATCH 2/2] accel/ivpu: Count only resident buffers in memory utilization Karol Wachowski @ 2025-11-07 16:13 ` Jeff Hugo 0 siblings, 0 replies; 6+ messages in thread From: Jeff Hugo @ 2025-11-07 16:13 UTC (permalink / raw) To: Karol Wachowski, dri-devel; +Cc: oded.gabbay, maciej.falkowski, lizhi.hou On 11/6/2025 3:10 AM, Karol Wachowski wrote: > Do not count buffer objects that have no backing pages, including imported > buffers where pages are set by VM faults triggered by userspace or pinned > by other drivers. Instead, return information about actual memory used by > the NPU. > > Counting imported buffers results in incorrect calculations when > the same pages are counted multiple times, giving overly high > results. > > Fixes: 7bfc9fa99580 ("accel/ivpu: Expose NPU memory utilization info in sysfs") > Signed-off-by: Karol Wachowski <karol.wachowski@linux.intel.com> Reviewed-by: Jeff Hugo <jeff.hugo@oss.qualcomm.com> ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-11-08 6:06 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-11-06 10:10 [PATCH 0/2] accel/ivpu: Add memory statistics support Karol Wachowski 2025-11-06 10:10 ` [PATCH 1/2] accel/ivpu: Add fdinfo support for memory statistics Karol Wachowski 2025-11-07 16:12 ` Jeff Hugo 2025-11-08 6:05 ` kernel test robot 2025-11-06 10:10 ` [PATCH 2/2] accel/ivpu: Count only resident buffers in memory utilization Karol Wachowski 2025-11-07 16:13 ` Jeff Hugo
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox