-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BACKPORT: accel/ivpu: Share NPU busy time in sysfs
The driver tracks the time spent by NPU executing jobs and shares it through sysfs `npu_busy_time_us` file. It can be then used by user space applications to monitor device utilization. NPU is considered 'busy' starting with a first job submitted to firmware and ending when there is no more jobs pending/executing. Tracked-On: OAM-128674 Signed-off-by: Tomasz Rusinowicz <[email protected]> Signed-off-by: Jacek Lawrynowicz <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/drivers/accel/ivpu?id=0adff3b0ef12483a79dc8415b94547853d26d1f3 Signed-off-by: Zhao, Shirley <[email protected]>
- Loading branch information
1 parent
7735521
commit d8cf81e
Showing
6 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
/* | ||
* Copyright (C) 2024 Intel Corporation | ||
*/ | ||
|
||
#include <linux/device.h> | ||
#include <linux/err.h> | ||
|
||
#include "ivpu_hw.h" | ||
#include "ivpu_sysfs.h" | ||
|
||
/* | ||
* npu_busy_time_us is the time that the device spent executing jobs. | ||
* The time is counted when and only when there are jobs submitted to firmware. | ||
* | ||
* This time can be used to measure the utilization of NPU, either by calculating | ||
* npu_busy_time_us difference between two timepoints (i.e. measuring the time | ||
* that the NPU was active during some workload) or monitoring utilization percentage | ||
* by reading npu_busy_time_us periodically. | ||
* | ||
* When reading the value periodically, it shouldn't be read too often as it may have | ||
* an impact on job submission performance. Recommended period is 1 second. | ||
*/ | ||
static ssize_t | ||
npu_busy_time_us_show(struct device *dev, struct device_attribute *attr, char *buf) | ||
{ | ||
struct drm_device *drm = dev_get_drvdata(dev); | ||
struct ivpu_device *vdev = to_ivpu_device(drm); | ||
ktime_t total, now = 0; | ||
|
||
xa_lock(&vdev->submitted_jobs_xa); | ||
total = vdev->busy_time; | ||
if (!xa_empty(&vdev->submitted_jobs_xa)) | ||
now = ktime_sub(ktime_get(), vdev->busy_start_ts); | ||
xa_unlock(&vdev->submitted_jobs_xa); | ||
|
||
return sysfs_emit(buf, "%lld\n", ktime_to_us(ktime_add(total, now))); | ||
} | ||
|
||
static DEVICE_ATTR_RO(npu_busy_time_us); | ||
|
||
static struct attribute *ivpu_dev_attrs[] = { | ||
&dev_attr_npu_busy_time_us.attr, | ||
NULL, | ||
}; | ||
|
||
static struct attribute_group ivpu_dev_attr_group = { | ||
.attrs = ivpu_dev_attrs, | ||
}; | ||
|
||
void ivpu_sysfs_init(struct ivpu_device *vdev) | ||
{ | ||
int ret; | ||
|
||
ret = devm_device_add_group(vdev->drm.dev, &ivpu_dev_attr_group); | ||
if (ret) | ||
ivpu_warn(vdev, "Failed to add group to device, ret %d", ret); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-only */ | ||
/* | ||
* Copyright (C) 2024 Intel Corporation | ||
*/ | ||
|
||
#ifndef __IVPU_SYSFS_H__ | ||
#define __IVPU_SYSFS_H__ | ||
|
||
#include "ivpu_drv.h" | ||
|
||
void ivpu_sysfs_init(struct ivpu_device *vdev); | ||
|
||
#endif /* __IVPU_SYSFS_H__ */ |