1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2024 Intel Corporation
6 #include <linux/device.h>
12 #include "ivpu_sysfs.h"
15 * npu_busy_time_us is the time that the device spent executing jobs.
16 * The time is counted when and only when there are jobs submitted to firmware.
18 * This time can be used to measure the utilization of NPU, either by calculating
19 * npu_busy_time_us difference between two timepoints (i.e. measuring the time
20 * that the NPU was active during some workload) or monitoring utilization percentage
21 * by reading npu_busy_time_us periodically.
23 * When reading the value periodically, it shouldn't be read too often as it may have
24 * an impact on job submission performance. Recommended period is 1 second.
27 npu_busy_time_us_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
29 struct drm_device
*drm
= dev_get_drvdata(dev
);
30 struct ivpu_device
*vdev
= to_ivpu_device(drm
);
31 ktime_t total
, now
= 0;
33 xa_lock(&vdev
->submitted_jobs_xa
);
34 total
= vdev
->busy_time
;
35 if (!xa_empty(&vdev
->submitted_jobs_xa
))
36 now
= ktime_sub(ktime_get(), vdev
->busy_start_ts
);
37 xa_unlock(&vdev
->submitted_jobs_xa
);
39 return sysfs_emit(buf
, "%lld\n", ktime_to_us(ktime_add(total
, now
)));
42 static DEVICE_ATTR_RO(npu_busy_time_us
);
47 * The sched_mode is used to report current NPU scheduling mode.
49 * It returns following strings:
50 * - "HW" - Hardware Scheduler mode
51 * - "OS" - Operating System Scheduler mode
55 sched_mode_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
57 struct drm_device
*drm
= dev_get_drvdata(dev
);
58 struct ivpu_device
*vdev
= to_ivpu_device(drm
);
60 return sysfs_emit(buf
, "%s\n", vdev
->fw
->sched_mode
? "HW" : "OS");
63 static DEVICE_ATTR_RO(sched_mode
);
65 static struct attribute
*ivpu_dev_attrs
[] = {
66 &dev_attr_npu_busy_time_us
.attr
,
67 &dev_attr_sched_mode
.attr
,
71 static struct attribute_group ivpu_dev_attr_group
= {
72 .attrs
= ivpu_dev_attrs
,
75 void ivpu_sysfs_init(struct ivpu_device
*vdev
)
79 ret
= devm_device_add_group(vdev
->drm
.dev
, &ivpu_dev_attr_group
);
81 ivpu_warn(vdev
, "Failed to add group to device, ret %d", ret
);