Skip to contentSkip to conversation

accel/ivpu: Add memory statistics support

PATCH In review Karol Wachowski 3 participants 6 messages Nov 6, 2025 – Nov 8, 2025

Subsystems (2)
lore
Share & tools
lore

Karol Wachowski

author maintainer
#0 lore raw

cover accel/ivpu: Add memory statistics support

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(-)
Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH 1/2 accel/ivpu: Add fdinfo support for memory statistics

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.

---
 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(+)
drivers/accel/ivpu/ivpu_drv.c +6 -0
index b305effcf003..ce7dbd473059 100644
@@ -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,
drivers/accel/ivpu/ivpu_gem.c +12 -0
index 03d39615ad37..a460cef4e0a0 100644
@@ -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,
 };
 
drivers/accel/ivpu/ivpu_gem.h +5 -0
index 2dcd7eba9cb7..0c3350f22b55 100644
@@ -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)
Signature · 1 line
2.43.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] accel/ivpu: Add fdinfo support for memory statistics

Quoted 6 lines · 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.

Have not used the fdinfo interface so I might be missing something subtle, but this looks sane to me. Seems rather elegant.

#3 lore raw

Re: [PATCH 1/2] accel/ivpu: Add fdinfo support for memory statistics

In reply to Karol Wachowski
kernel test robot noticed the following build warnings:

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/[email protected]/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/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

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

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author maintainer
#4 lore raw

PATCH 2/2 accel/ivpu: Count only resident buffers in memory utilization

In reply to 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")
---
 drivers/accel/ivpu/ivpu_sysfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/accel/ivpu/ivpu_sysfs.c +2 -1
index 268ab7744a8b..d250a10caca9 100644
@@ -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);
Signature · 1 line
2.43.0
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] accel/ivpu: Count only resident buffers in memory utilization

Quoted 11 lines · 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")