Skip to contentSkip to conversation

accel/ivpu: Add support for limiting NPU frequency

PATCH Superseded Andrzej Kacprowski 2 participants 2 messages Apr 8

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Andrzej Kacprowski

author maintainer
#0 lore raw

PATCH v2 1/1 accel/ivpu: Add support for limiting NPU frequency

Add configurable frequency limits to allow users to constrain the NPU operating frequency range for power and thermal management. This support requires firmware API version 3.34.0 or newer.

New sysfs interface:

The freq/ subdirectory contains the following attributes:

- hw_min_freq: Minimum frequency supported by hardware (read-only)
- hw_max_freq: Maximum frequency supported by hardware (read-only)
- hw_efficient_freq: Hardware's optimal operating frequency (read-only)
- current_freq: Current NPU frequency in MHz (read-only)
- set_min_freq: Configure minimum operating frequency (50XX+ devices)
- set_max_freq: Configure maximum operating frequency (50XX+ devices)

Legacy attributes npu_max_frequency_mhz and npu_current_frequency_mhz are maintained for backward compatibility.

Implementation details:

- Frequency configuration is communicated to firmware via JSM messages
- User-specified frequency values are clamped to hardware limits
- Power-efficient frequency (pn_ratio) is adjusted dynamically to stay within the configured range
- Frequency configuration is initialized during device boot
- The JSM API header is updated to version 3.34.0 to support the new VPU_JSM_MSG_FREQ_CONFIG firmware message

Added description for the sysfs attributes in the Documentation/ABI.

---
Changes in v2:
- Added sysfs attribute documentation in Documentation/ABI.
- Updated MAINTAINERS to include the new documentation files.

 Documentation/ABI/obsolete/sysfs-driver-ivpu |  30 +++
 Documentation/ABI/testing/sysfs-driver-ivpu  |  65 +++++++
 MAINTAINERS                                  |   2 +
 drivers/accel/ivpu/ivpu_drv.c                |   8 +-
 drivers/accel/ivpu/ivpu_hw.h                 |  16 +-
 drivers/accel/ivpu/ivpu_hw_btrs.c            | 112 ++++++++---
 drivers/accel/ivpu/ivpu_hw_btrs.h            |  10 +-
 drivers/accel/ivpu/ivpu_jsm_msg.c            |  18 +-
 drivers/accel/ivpu/ivpu_jsm_msg.h            |   4 +-
 drivers/accel/ivpu/ivpu_sysfs.c              | 186 ++++++++++++++++---
 drivers/accel/ivpu/vpu_jsm_api.h             |  34 +++-
 11 files changed, 420 insertions(+), 65 deletions(-)
 create mode 100644 Documentation/ABI/obsolete/sysfs-driver-ivpu
 create mode 100644 Documentation/ABI/testing/sysfs-driver-ivpu
Documentation/ABI/obsolete/sysfs-driver-ivpu new file +30 -0
new file mode 100644
index 000000000000..16f6a0b22406
@@ -0,0 +1,30 @@
+What:		/sys/bus/pci/drivers/intel_vpu/.../sched_mode
+Date:		October 2024
+KernelVersion:	6.12
+Contact:	[email protected]
+Description:	Current NPU scheduling mode. Returns one of the following strings:
+		- "HW" - Hardware Scheduler mode
+		- "OS" - Operating System Scheduler mode
+		Read-only.
+		Deprecated since the "OS" scheduling mode is not usable
+		and will be removed from future versions of the driver.
+		Will be removed in 2027
+
+What:		/sys/bus/pci/drivers/intel_vpu/.../npu_max_frequency_mhz
+Date:		April 2025
+KernelVersion:	6.15
+Contact:	[email protected]
+Description:	Legacy alias for /sys/bus/pci/drivers/intel_vpu/.../freq/hw_min_freq.
+		Shows maximum frequency in MHz of the NPU's data processing unit.
+		Read-only.
+		Will be removed in 2027
+
+What:		/sys/bus/pci/drivers/intel_vpu/.../npu_current_frequency_mhz
+Date:		April 2025
+KernelVersion:	6.15
+Contact:	[email protected]
+Description:	Legacy alias for /sys/bus/pci/drivers/intel_vpu/.../freq/current_freq.
+		Shows current frequency in MHz of the NPU's data processing unit.
+		The value is read only when the device is active; otherwise it returns 0.
+		Read-only.
+		Will be removed in 2027
Documentation/ABI/testing/sysfs-driver-ivpu new file +65 -0

65 lines not on this page · raw message

MAINTAINERS +2 -0
index ae8a01f30ff4..359456c4a96e 100644
@@ -7837,6 +7837,8 @@ M:	Karol Wachowski <[email protected]>
 L:	[email protected]
 S:	Supported
 T:	git https://gitlab.freedesktop.org/drm/misc/kernel.git
+F:	Documentation/ABI/obsolete/sysfs-driver-ivpu
+F:	Documentation/ABI/testing/sysfs-driver-ivpu
 F:	drivers/accel/ivpu/
 F:	include/uapi/drm/ivpu_accel.h
 
drivers/accel/ivpu/ivpu_drv.c +6 -2
index 2801378e3e19..e6d631108145 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (C) 2020-2025 Intel Corporation
+ * Copyright (C) 2020-2026 Intel Corporation
  */
 
 #include <linux/firmware.h>
@@ -234,7 +234,7 @@ static int ivpu_get_param_ioctl(struct drm_device *dev, void *data, struct drm_f
 		args->value = vdev->platform;
 		break;
 	case DRM_IVPU_PARAM_CORE_CLOCK_RATE:
-		args->value = ivpu_hw_dpu_max_freq_get(vdev);
+		args->value = ivpu_hw_btrs_pll_ratio_to_hz(vdev, vdev->hw->pll.max_ratio);
 		break;
 	case DRM_IVPU_PARAM_NUM_CONTEXTS:
 		args->value = file_priv->user_limits->max_ctx_count;
@@ -487,6 +487,10 @@ int ivpu_boot(struct ivpu_device *vdev)
 		ret = ivpu_hw_sched_init(vdev);
 		if (ret)
 			goto err_disable_ipc;
+
+		ret = ivpu_hw_btrs_cfg_freq_init(vdev);
+		if (ret)
+			goto err_disable_ipc;
 	}
 
 	return 0;
drivers/accel/ivpu/ivpu_hw.h +5 -11
index b6d0f0d0dccc..487a918e2fa9 100644
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 /*
- * Copyright (C) 2020-2025 Intel Corporation
+ * Copyright (C) 2020-2026 Intel Corporation
  */
 
 #ifndef __IVPU_HW_H__
@@ -28,6 +28,7 @@ struct ivpu_hw_info {
 		struct ivpu_addr_range dma;
 	} ranges;
 	struct {
+		/* Hardware min and max pll ratio */
 		u8 min_ratio;
 		u8 max_ratio;
 		/*
@@ -35,6 +36,9 @@ struct ivpu_hw_info {
 		 * performance to power ratio at this frequency.
 		 */
 		u8 pn_ratio;
+		/* Pll ratios configured via sysfs interface */
+		u8 cfg_min_ratio;
+		u8 cfg_max_ratio;
 		u32 profiling_freq;
 	} pll;
 	struct {
@@ -80,16 +84,6 @@ static inline u64 ivpu_hw_range_size(const struct ivpu_addr_range *range)
 	return range->end - range->start;
 }
 
-static inline u32 ivpu_hw_dpu_max_freq_get(struct ivpu_device *vdev)
-{
-	return ivpu_hw_btrs_dpu_max_freq_get(vdev);
-}
-
-static inline u32 ivpu_hw_dpu_freq_get(struct ivpu_device *vdev)
-{
-	return ivpu_hw_btrs_dpu_freq_get(vdev);
-}
-
 static inline void ivpu_hw_irq_clear(struct ivpu_device *vdev)
 {
 	ivpu_hw_ip_irq_clear(vdev);
drivers/accel/ivpu/ivpu_hw_btrs.c +89 -23

182 lines not on this page · raw message

drivers/accel/ivpu/ivpu_hw_btrs.h +7 -3
index c4c10e22f30f..d6343d734570 100644
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 /*
- * Copyright (C) 2020-2025 Intel Corporation
+ * Copyright (C) 2020-2026 Intel Corporation
  */
 
 #ifndef __IVPU_HW_BTRS_H__
@@ -31,8 +31,12 @@ int ivpu_hw_btrs_ip_reset(struct ivpu_device *vdev);
 void ivpu_hw_btrs_profiling_freq_reg_set_lnl(struct ivpu_device *vdev);
 void ivpu_hw_btrs_ats_print_lnl(struct ivpu_device *vdev);
 void ivpu_hw_btrs_clock_relinquish_disable_lnl(struct ivpu_device *vdev);
-u32 ivpu_hw_btrs_dpu_max_freq_get(struct ivpu_device *vdev);
-u32 ivpu_hw_btrs_dpu_freq_get(struct ivpu_device *vdev);
+u32 ivpu_hw_btrs_pll_ratio_to_mhz(struct ivpu_device *vdev, u8 pll_ratio);
+u32 ivpu_hw_btrs_pll_ratio_to_hz(struct ivpu_device *vdev, u8 pll_ratio);
+u32 ivpu_hw_btrs_current_freq_get(struct ivpu_device *vdev);
+int ivpu_hw_btrs_cfg_min_freq_set(struct ivpu_device *vdev, u32 freq_mhz);
+int ivpu_hw_btrs_cfg_max_freq_set(struct ivpu_device *vdev, u32 freq_mhz);
+int ivpu_hw_btrs_cfg_freq_init(struct ivpu_device *vdev);
 bool ivpu_hw_btrs_irq_handler_mtl(struct ivpu_device *vdev, int irq);
 bool ivpu_hw_btrs_irq_handler_lnl(struct ivpu_device *vdev, int irq);
 int ivpu_hw_btrs_dct_get_request(struct ivpu_device *vdev, bool *enable);
drivers/accel/ivpu/ivpu_jsm_msg.c +17 -1
index 07b1d6f615a9..17b42a76aef9 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (C) 2020-2024 Intel Corporation
+ * Copyright (C) 2020-2026 Intel Corporation
  */
 
 #include "ivpu_drv.h"
@@ -86,6 +86,9 @@ const char *ivpu_jsm_msg_type_to_str(enum vpu_ipc_msg_type type)
 	IVPU_CASE_TO_STR(VPU_JSM_MSG_DCT_ENABLE_DONE);
 	IVPU_CASE_TO_STR(VPU_JSM_MSG_DCT_DISABLE);
 	IVPU_CASE_TO_STR(VPU_JSM_MSG_DCT_DISABLE_DONE);
+	IVPU_CASE_TO_STR(VPU_JSM_MSG_FREQ_CONFIG);
+	IVPU_CASE_TO_STR(VPU_JSM_MSG_FREQ_CONFIG_RSP);
+	IVPU_CASE_TO_STR(VPU_JSM_MSG_RESERVED_111E);
 	}
 	#undef IVPU_CASE_TO_STR
 
@@ -571,3 +574,16 @@ int ivpu_jsm_state_dump_no_reply(struct ivpu_device *vdev)
 	return ivpu_ipc_send_and_wait(vdev, &req, VPU_IPC_CHAN_ASYNC_CMD,
 				      vdev->timeout.state_dump_msg);
 }
+
+int ivpu_jsm_msg_freq_config(struct ivpu_device *vdev, u16 min_ratio, u16 pn_ratio, u16 max_ratio)
+{
+	struct vpu_jsm_msg req = { .type = VPU_JSM_MSG_FREQ_CONFIG};
+	struct vpu_jsm_msg resp;
+
+	req.payload.freq_config.min_freq_pll_ratio = min_ratio;
+	req.payload.freq_config.pn_freq_pll_ratio = pn_ratio;
+	req.payload.freq_config.max_freq_pll_ratio = max_ratio;
+
+	return ivpu_ipc_send_receive_internal(vdev, &req, VPU_JSM_MSG_FREQ_CONFIG_RSP, &resp,
+					      VPU_IPC_CHAN_ASYNC_CMD, vdev->timeout.jsm);
+}
drivers/accel/ivpu/ivpu_jsm_msg.h +3 -1
index a74f5a0b0d93..ead7d07d300f 100644
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 /*
- * Copyright (C) 2020-2024 Intel Corporation
+ * Copyright (C) 2020-2026 Intel Corporation
  */
 
 #ifndef __IVPU_JSM_MSG_H__
@@ -45,5 +45,7 @@ int ivpu_jsm_dct_enable(struct ivpu_device *vdev, u32 active_us, u32 inactive_us
 int ivpu_jsm_dct_disable(struct ivpu_device *vdev);
 int ivpu_jsm_state_dump(struct ivpu_device *vdev);
 int ivpu_jsm_state_dump_no_reply(struct ivpu_device *vdev);
+int ivpu_jsm_msg_freq_config(struct ivpu_device *vdev, u16 min_ratio, u16 pn_ratio, u16 max_ratio);
+int ivpu_jsm_msg_freq_config(struct ivpu_device *vdev, u16 min_ratio, u16 pn_ratio, u16 max_ratio);
 
 #endif
drivers/accel/ivpu/ivpu_sysfs.c +163 -23

230 lines not on this page · raw message

drivers/accel/ivpu/vpu_jsm_api.h +33 -1
index bca6a44dc041..6d58d04cc0c4 100644
@@ -23,7 +23,7 @@
 /*
  * Minor version changes when API backward compatibility is preserved.
  */
-#define VPU_JSM_API_VER_MINOR 33
+#define VPU_JSM_API_VER_MINOR 34
 
 /*
  * API header changed (field names, documentation, formatting) but API itself has not been changed
@@ -604,6 +604,16 @@ enum vpu_ipc_msg_type {
 	 * This command has no payload
 	 */
 	VPU_JSM_MSG_DCT_DISABLE = 0x111d,
+	/**
+	 * Reserved command ID to ensure that the following command requests /
+	 * responses have the same lower byte value.
+	 */
+	VPU_JSM_MSG_RESERVED_111E = 0x111e,
+	/**
+	 * Control command: Configure VPU frequency scaling parameters.
+	 * @see vpu_ipc_msg_payload_freq_config
+	 */
+	VPU_JSM_MSG_FREQ_CONFIG = 0x111f,
 	/**
 	 * Dump VPU state. To be used for debug purposes only.
 	 * This command has no payload.
@@ -766,6 +776,11 @@ enum vpu_ipc_msg_type {
 	 * This command has no payload
 	 */
 	VPU_JSM_MSG_DCT_DISABLE_DONE = 0x221e,
+	/**
+	 * Response to control command: Configure VPU frequency scaling parameters.
+	 * @see vpu_ipc_msg_payload_freq_config
+	 */
+	VPU_JSM_MSG_FREQ_CONFIG_RSP = 0x221f,
 	/**
 	 * Response to state dump control command.
 	 * This command has no payload.
@@ -1650,6 +1665,22 @@ struct vpu_ipc_msg_payload_pwr_dct_control {
 	u32 dct_inactive_us;
 };
 
+/**
+ * Payload for @ref VPU_JSM_MSG_FREQ_CONFIG message.
+ *
+ * This payload allows the host to configure the VPU frequency scaling parameters.
+ */
+struct vpu_ipc_msg_payload_freq_config {
+	/** Minimum frequency PLL ratio */
+	u32 min_freq_pll_ratio;
+	/** Efficiency frequency PLL ratio */
+	u32 pn_freq_pll_ratio;
+	/** Maximum frequency PLL ratio */
+	u32 max_freq_pll_ratio;
+	/** Reserved for 64-bit alignment */
+	u32 reserved_0;
+};
+
 /*
  * Payloads union, used to define complete message format.
  */
@@ -1692,6 +1723,7 @@ union vpu_ipc_msg_payload {
 	struct vpu_ipc_msg_payload_hws_resume_engine hws_resume_engine;
 	struct vpu_ipc_msg_payload_pwr_d0i3_enter pwr_d0i3_enter;
 	struct vpu_ipc_msg_payload_pwr_dct_control pwr_dct_control;
+	struct vpu_ipc_msg_payload_freq_config freq_config;
 };
 
 /**
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 60 lines · Andrzej Kacprowski

Add configurable frequency limits to allow users to constrain the NPU operating frequency range for power and thermal management. This support requires firmware API version 3.34.0 or newer.

New sysfs interface:

The freq/ subdirectory contains the following attributes:

- hw_min_freq: Minimum frequency supported by hardware (read-only)
- hw_max_freq: Maximum frequency supported by hardware (read-only)
- hw_efficient_freq: Hardware's optimal operating frequency (read-only)
- current_freq: Current NPU frequency in MHz (read-only)
- set_min_freq: Configure minimum operating frequency (50XX+ devices)
- set_max_freq: Configure maximum operating frequency (50XX+ devices)

Legacy attributes npu_max_frequency_mhz and npu_current_frequency_mhz are maintained for backward compatibility.

Implementation details:

- Frequency configuration is communicated to firmware via JSM messages
- User-specified frequency values are clamped to hardware limits
- Power-efficient frequency (pn_ratio) is adjusted dynamically to stay within the configured range
- Frequency configuration is initialized during device boot
- The JSM API header is updated to version 3.34.0 to support the new VPU_JSM_MSG_FREQ_CONFIG firmware message

Added description for the sysfs attributes in the Documentation/ABI.

---
Changes in v2:
- Added sysfs attribute documentation in Documentation/ABI.
- Updated MAINTAINERS to include the new documentation files.

 Documentation/ABI/obsolete/sysfs-driver-ivpu |  30 +++
 Documentation/ABI/testing/sysfs-driver-ivpu  |  65 +++++++
 MAINTAINERS                                  |   2 +
 drivers/accel/ivpu/ivpu_drv.c                |   8 +-
 drivers/accel/ivpu/ivpu_hw.h                 |  16 +-
 drivers/accel/ivpu/ivpu_hw_btrs.c            | 112 ++++++++---
 drivers/accel/ivpu/ivpu_hw_btrs.h            |  10 +-
 drivers/accel/ivpu/ivpu_jsm_msg.c            |  18 +-
 drivers/accel/ivpu/ivpu_jsm_msg.h            |   4 +-
 drivers/accel/ivpu/ivpu_sysfs.c              | 186 ++++++++++++++++---
 drivers/accel/ivpu/vpu_jsm_api.h             |  34 +++-
 11 files changed, 420 insertions(+), 65 deletions(-)
 create mode 100644 Documentation/ABI/obsolete/sysfs-driver-ivpu
 create mode 100644 Documentation/ABI/testing/sysfs-driver-ivpu
Documentation/ABI/obsolete/sysfs-driver-ivpu new file +3 -0
new file mode 100644
index 000000000000..16f6a0b22406
@@ -0,0 +1,30 @@
+What:		/sys/bus/pci/drivers/intel_vpu/.../sched_mode
+Date:		October 2024
+KernelVersion:	6.12

Documentation/ABI/obsolete/sysfs-driver-ivpu line 13

Quoted 10 lines
Documentation/ABI/obsolete/sysfs-driver-ivpu new file +10 -0
+Contact:	[email protected]
+Description:	Current NPU scheduling mode. Returns one of the following strings:
+		- "HW" - Hardware Scheduler mode
+		- "OS" - Operating System Scheduler mode
+		Read-only.
+		Deprecated since the "OS" scheduling mode is not usable
+		and will be removed from future versions of the driver.
+		Will be removed in 2027
+
+What:		/sys/bus/pci/drivers/intel_vpu/.../npu_max_frequency_mhz

This says npu_max_frequency_mhz

Documentation/ABI/obsolete/sysfs-driver-ivpu line 17

Quoted 4 lines
Documentation/ABI/obsolete/sysfs-driver-ivpu new file +4 -0
+Date:		April 2025
+KernelVersion:	6.15
+Contact:	[email protected]
+Description:	Legacy alias for /sys/bus/pci/drivers/intel_vpu/.../freq/hw_min_freq.

But this is hw_min_freq - supposed to be hw_max_freq

Quoted 13 lines
Documentation/ABI/obsolete/sysfs-driver-ivpu new file +13 -0
+		Shows maximum frequency in MHz of the NPU's data processing unit.
+		Read-only.
+		Will be removed in 2027
+
+What:		/sys/bus/pci/drivers/intel_vpu/.../npu_current_frequency_mhz
+Date:		April 2025
+KernelVersion:	6.15
+Contact:	[email protected]
+Description:	Legacy alias for /sys/bus/pci/drivers/intel_vpu/.../freq/current_freq.
+		Shows current frequency in MHz of the NPU's data processing unit.
+		The value is read only when the device is active; otherwise it returns 0.
+		Read-only.
+		Will be removed in 2027

...

Quoted 13 lines
drivers/accel/ivpu/ivpu_jsm_msg.h +1 -1
index a74f5a0b0d93..ead7d07d300f 100644
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 /*
- * Copyright (C) 2020-2024 Intel Corporation
+ * Copyright (C) 2020-2026 Intel Corporation
  */
 
 #ifndef __IVPU_JSM_MSG_H__

drivers/accel/ivpu/ivpu_jsm_msg.h int ivpu_jsm_dct_enable(struct ivpu_device *vdev, u32 active_us, u32 inactive_us · line 49

Quoted 5 lines
drivers/accel/ivpu/ivpu_jsm_msg.h +2 -0
@@ -45,5 +45,7 @@ int ivpu_jsm_dct_enable(struct ivpu_device *vdev, u32 active_us, u32 inactive_us
 int ivpu_jsm_dct_disable(struct ivpu_device *vdev);
 int ivpu_jsm_state_dump(struct ivpu_device *vdev);
 int ivpu_jsm_state_dump_no_reply(struct ivpu_device *vdev);
+int ivpu_jsm_msg_freq_config(struct ivpu_device *vdev, u16 min_ratio, u16 pn_ratio, u16 max_ratio);
+int ivpu_jsm_msg_freq_config(struct ivpu_device *vdev, u16 min_ratio, u16 pn_ratio, u16 max_ratio);

This got added twice.

...

Karol