Skip to content

Commit 1524c28

Browse files
akacprowjlawryno
authored andcommitted
accel/ivpu: Show NPU frequency in sysfs
Add sysfs files that show maximum and current frequency of the NPU's data processing unit. New sysfs entries: - npu_max_frequency_mhz - npu_current_frequency_mhz Signed-off-by: Andrzej Kacprowski <Andrzej.Kacprowski@intel.com> 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://lore.kernel.org/r/20250401155912.4049340-3-maciej.falkowski@linux.intel.com
1 parent 6c2b754 commit 1524c28

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

drivers/accel/ivpu/ivpu_hw.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ static inline u32 ivpu_hw_dpu_max_freq_get(struct ivpu_device *vdev)
8787
return ivpu_hw_btrs_dpu_max_freq_get(vdev);
8888
}
8989

90+
static inline u32 ivpu_hw_dpu_freq_get(struct ivpu_device *vdev)
91+
{
92+
return ivpu_hw_btrs_dpu_freq_get(vdev);
93+
}
94+
9095
static inline void ivpu_hw_irq_clear(struct ivpu_device *vdev)
9196
{
9297
ivpu_hw_ip_irq_clear(vdev);

drivers/accel/ivpu/ivpu_hw_btrs.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,14 @@ u32 ivpu_hw_btrs_dpu_max_freq_get(struct ivpu_device *vdev)
606606
return pll_ratio_to_dpu_freq(vdev, vdev->hw->pll.max_ratio);
607607
}
608608

609+
u32 ivpu_hw_btrs_dpu_freq_get(struct ivpu_device *vdev)
610+
{
611+
if (ivpu_hw_btrs_gen(vdev) == IVPU_HW_BTRS_MTL)
612+
return pll_ratio_to_dpu_freq_mtl(pll_config_get_mtl(vdev));
613+
else
614+
return pll_ratio_to_dpu_freq_lnl(pll_config_get_lnl(vdev));
615+
}
616+
609617
/* Handler for IRQs from Buttress core (irqB) */
610618
bool ivpu_hw_btrs_irq_handler_mtl(struct ivpu_device *vdev, int irq)
611619
{

drivers/accel/ivpu/ivpu_hw_btrs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ void ivpu_hw_btrs_profiling_freq_reg_set_lnl(struct ivpu_device *vdev);
3232
void ivpu_hw_btrs_ats_print_lnl(struct ivpu_device *vdev);
3333
void ivpu_hw_btrs_clock_relinquish_disable_lnl(struct ivpu_device *vdev);
3434
u32 ivpu_hw_btrs_dpu_max_freq_get(struct ivpu_device *vdev);
35+
u32 ivpu_hw_btrs_dpu_freq_get(struct ivpu_device *vdev);
3536
bool ivpu_hw_btrs_irq_handler_mtl(struct ivpu_device *vdev, int irq);
3637
bool ivpu_hw_btrs_irq_handler_lnl(struct ivpu_device *vdev, int irq);
3738
int ivpu_hw_btrs_dct_get_request(struct ivpu_device *vdev, bool *enable);

drivers/accel/ivpu/ivpu_sysfs.c

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22
/*
3-
* Copyright (C) 2024 Intel Corporation
3+
* Copyright (C) 2024-2025 Intel Corporation
44
*/
55

66
#include <linux/device.h>
77
#include <linux/err.h>
8+
#include <linux/pm_runtime.h>
9+
#include <linux/units.h>
810

911
#include "ivpu_drv.h"
1012
#include "ivpu_gem.h"
@@ -90,10 +92,55 @@ sched_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
9092

9193
static DEVICE_ATTR_RO(sched_mode);
9294

95+
/**
96+
* DOC: npu_max_frequency
97+
*
98+
* The npu_max_frequency shows maximum frequency in MHz of the NPU's data
99+
* processing unit
100+
*/
101+
static ssize_t
102+
npu_max_frequency_mhz_show(struct device *dev, struct device_attribute *attr, char *buf)
103+
{
104+
struct drm_device *drm = dev_get_drvdata(dev);
105+
struct ivpu_device *vdev = to_ivpu_device(drm);
106+
u32 freq = ivpu_hw_dpu_max_freq_get(vdev);
107+
108+
return sysfs_emit(buf, "%lu\n", freq / HZ_PER_MHZ);
109+
}
110+
111+
static DEVICE_ATTR_RO(npu_max_frequency_mhz);
112+
113+
/**
114+
* DOC: npu_current_frequency_mhz
115+
*
116+
* The npu_current_frequency_mhz shows current frequency in MHz of the NPU's
117+
* data processing unit
118+
*/
119+
static ssize_t
120+
npu_current_frequency_mhz_show(struct device *dev, struct device_attribute *attr, char *buf)
121+
{
122+
struct drm_device *drm = dev_get_drvdata(dev);
123+
struct ivpu_device *vdev = to_ivpu_device(drm);
124+
u32 freq = 0;
125+
126+
/* Read frequency only if device is active, otherwise frequency is 0 */
127+
if (pm_runtime_get_if_active(vdev->drm.dev) > 0) {
128+
freq = ivpu_hw_dpu_freq_get(vdev);
129+
130+
pm_runtime_put_autosuspend(vdev->drm.dev);
131+
}
132+
133+
return sysfs_emit(buf, "%lu\n", freq / HZ_PER_MHZ);
134+
}
135+
136+
static DEVICE_ATTR_RO(npu_current_frequency_mhz);
137+
93138
static struct attribute *ivpu_dev_attrs[] = {
94139
&dev_attr_npu_busy_time_us.attr,
95140
&dev_attr_npu_memory_utilization.attr,
96141
&dev_attr_sched_mode.attr,
142+
&dev_attr_npu_max_frequency_mhz.attr,
143+
&dev_attr_npu_current_frequency_mhz.attr,
97144
NULL,
98145
};
99146

0 commit comments

Comments
 (0)