Skip to content

Commit 7bfc9fa

Browse files
m-falkowskijlawryno
authored andcommitted
accel/ivpu: Expose NPU memory utilization info in sysfs
Expose NPU memory utilization info in sysfs in bytes to show total memory used by NPU (FW + runtime). Signed-off-by: Maciej Falkowski <maciej.falkowski@linux.intel.com> Reviewed-by: Jacek Lawrynowicz <jacek.lawrynowicz@linux.intel.com> Signed-off-by: Jacek Lawrynowicz <jacek.lawrynowicz@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20250107173238.381120-5-maciej.falkowski@linux.intel.com
1 parent 5bbccad commit 7bfc9fa

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

drivers/accel/ivpu/ivpu_sysfs.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
#include <linux/err.h>
88

99
#include "ivpu_drv.h"
10+
#include "ivpu_gem.h"
1011
#include "ivpu_fw.h"
1112
#include "ivpu_hw.h"
1213
#include "ivpu_sysfs.h"
1314

14-
/*
15+
/**
16+
* DOC: npu_busy_time_us
17+
*
1518
* npu_busy_time_us is the time that the device spent executing jobs.
1619
* The time is counted when and only when there are jobs submitted to firmware.
1720
*
@@ -42,6 +45,30 @@ npu_busy_time_us_show(struct device *dev, struct device_attribute *attr, char *b
4245

4346
static DEVICE_ATTR_RO(npu_busy_time_us);
4447

48+
/**
49+
* DOC: npu_memory_utilization
50+
*
51+
* The npu_memory_utilization is used to report in bytes a current NPU memory utilization.
52+
*
53+
*/
54+
static ssize_t
55+
npu_memory_utilization_show(struct device *dev, struct device_attribute *attr, char *buf)
56+
{
57+
struct drm_device *drm = dev_get_drvdata(dev);
58+
struct ivpu_device *vdev = to_ivpu_device(drm);
59+
struct ivpu_bo *bo;
60+
u64 total_npu_memory = 0;
61+
62+
mutex_lock(&vdev->bo_list_lock);
63+
list_for_each_entry(bo, &vdev->bo_list, bo_list_node)
64+
total_npu_memory += bo->base.base.size;
65+
mutex_unlock(&vdev->bo_list_lock);
66+
67+
return sysfs_emit(buf, "%lld\n", total_npu_memory);
68+
}
69+
70+
static DEVICE_ATTR_RO(npu_memory_utilization);
71+
4572
/**
4673
* DOC: sched_mode
4774
*
@@ -65,6 +92,7 @@ static DEVICE_ATTR_RO(sched_mode);
6592

6693
static struct attribute *ivpu_dev_attrs[] = {
6794
&dev_attr_npu_busy_time_us.attr,
95+
&dev_attr_npu_memory_utilization.attr,
6896
&dev_attr_sched_mode.attr,
6997
NULL,
7098
};

0 commit comments

Comments
 (0)