Skip to contentSkip to conversation

accel/ivpu: Add support for limiting NPU frequency

PATCH Superseded Andrzej Kacprowski 2 participants 5 messages Mar 30 – Apr 9

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Andrzej Kacprowski

author maintainer
#0 lore raw

PATCH 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

---
 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 +++++-
 8 files changed, 323 insertions(+), 65 deletions(-)
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
#1 lore raw
Quoted 6 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:

Quoted 8 lines

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)

I don't see Documentation/ABI changes in this patch, which are required for sysfs.

However, I wonder if this is the best way to move forward. At best, you appear to be implementing a completely custom version of hwmon. However, I wonder if hwmon/sysfs will be limiting as you support 3 generations of devices if I recall correctly, and that number is probably going to go up. With the different generations supporting different capabilities, I suspect the sysfs approach will eventually put you into a corner.

Your collegues over in the XE area have proposed a netlink mechanism, which is in -next currently (expected to go in the 7.1 merge window). We collaborated on that mechanism, and have plans to extend it for these kinds of "telemetry" items. I'm expecting we'll have some patches posted on list in a week, maybe 2 (finishing up some of the final details). Perhaps you would find that useful?

-Jeff

author maintainer
#2 lore raw
Quoted 9 lines · Jeff Hugo
Quoted 8 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:

Quoted 8 lines
Quoted 6 lines

- 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)

I don't see Documentation/ABI changes in this patch, which are required for sysfs.

Good point. I will add required documentation for all attributes exported by the ivpu driver. [PATCH V2] will follow.

Quoted 1 line

However, I wonder if this is the best way to move forward. At best, you appear to be implementing a completely custom version of hwmon. However, I wonder if hwmon/sysfs will be limiting as you support 3 generations of devices if I recall correctly, and that number is probably going to go up. With the different generations supporting different capabilities, I suspect the sysfs approach will eventually put you into a corner.

Hwmon supports a fixed set of sensor types (temperature, voltage, fan speed, etc...) but it does not support frequency, so its not suitable for the purpose. Frequency limiting is supported on 2 hardware generations (50XX and 60XX) without any delta. I'm not expecting any changes in this code for future hardware.

Quoted 2 lines

Your collegues over in the XE area have proposed a netlink mechanism, which is in -next currently (expected to go in the 7.1 merge window). We collaborated on that mechanism, and have plans to extend it for these kinds of "telemetry" items. I'm expecting we'll have some patches posted on list in a week, maybe 2 (finishing up some of the final details). Perhaps you would find that useful?

The DRM RAS over netlink seems to be tailored for reporting error counters.

The xe driver I was mimicking, still manages frequency limiting with sysfs, even thou it supported hwmon for discrete hw sensors, and now RAS over netlink as well for error counters.

- Andrzej

Quoted 2 lines

-Jeff

#3 lore raw
Quoted 16 lines · Andrzej Kacprowski
Quoted 15 lines · Jeff Hugo
Quoted 14 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)

Quoted 7 lines
Quoted 2 lines

I don't see Documentation/ABI changes in this patch, which are required for sysfs.

Good point. I will add required documentation for all attributes exported by the ivpu driver. [PATCH V2] will follow.

Quoted 1 line

However, I wonder if this is the best way to move forward. At best, you appear to be implementing a completely custom version of hwmon. However, I wonder if hwmon/sysfs will be limiting as you support 3 generations of devices if I recall correctly, and that number is probably going to go up. With the different generations supporting different capabilities, I suspect the sysfs approach will eventually put you into a corner.

Hwmon supports a fixed set of sensor types (temperature, voltage, fan speed, etc...) but it does not support frequency, so its not suitable for the purpose.

hwmon_device_register_with_info() allows you to extend the interface with the extra_groups parameter.

Quoted 11 lines

Frequency limiting is supported on 2 hardware generations (50XX and 60XX) without any delta. I'm not expecting any changes in this code for future hardware.

Quoted 2 lines

Your collegues over in the XE area have proposed a netlink mechanism, which is in -next currently (expected to go in the 7.1 merge window). We collaborated on that mechanism, and have plans to extend it for these kinds of "telemetry" items. I'm expecting we'll have some patches posted on list in a week, maybe 2 (finishing up some of the final details). Perhaps you would find that useful?

The DRM RAS over netlink seems to be tailored for reporting error counters.

The xe driver I was mimicking, still manages frequency limiting with sysfs, even thou it supported hwmon for discrete hw sensors, and now RAS over netlink as well for error counters.

- Andrzej

Quoted 2 lines

-Jeff

author maintainer
#4 lore raw
Quoted 19 lines · Jeff Hugo
Quoted 18 lines · Andrzej Kacprowski
Quoted 17 lines · Jeff Hugo
Quoted 6 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:

Quoted 8 lines

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)

I don't see Documentation/ABI changes in this patch, which are required for sysfs.

Quoted 7 lines
Quoted 5 lines

Good point. I will add required documentation for all attributes exported by the ivpu driver. [PATCH V2] will follow.

Quoted 1 line

However, I wonder if this is the best way to move forward. At best, you appear to be implementing a completely custom version of hwmon. However, I wonder if hwmon/sysfs will be limiting as you support 3 generations of devices if I recall correctly, and that number is probably going to go up. With the different generations supporting different capabilities, I suspect the sysfs approach will eventually put you into a corner.

Hwmon supports a fixed set of sensor types (temperature, voltage, fan speed, etc...) but it does not support frequency, so its not suitable for the purpose.

hwmon_device_register_with_info() allows you to extend the interface with the extra_groups parameter.

Indeed, looks like there is way to add custom attributes.
Still I haven't found any example where frequency would be managed though hwmon interface.

The intended purpose of the proposed ivpu feature is to allow system level power manager to limit NPU power usage and extend system battery life.

Hwmon does not seem to be a good match here - its main value is providing standardized sensors that can be accessed though common software like lm-sensors.

- Andrzej

Quoted 13 lines
Quoted 12 lines

Frequency limiting is supported on 2 hardware generations (50XX and 60XX) without any delta. I'm not expecting any changes in this code for future hardware.

Quoted 2 lines

Your collegues over in the XE area have proposed a netlink mechanism, which is in -next currently (expected to go in the 7.1 merge window). We collaborated on that mechanism, and have plans to extend it for these kinds of "telemetry" items. I'm expecting we'll have some patches posted on list in a week, maybe 2 (finishing up some of the final details). Perhaps you would find that useful?

The DRM RAS over netlink seems to be tailored for reporting error counters.

The xe driver I was mimicking, still manages frequency limiting with sysfs, even thou it supported hwmon for discrete hw sensors, and now RAS over netlink as well for error counters.

- Andrzej

Quoted 2 lines

-Jeff