thermal: processor_thermal: Power floor status
Subsystems (3)
v2 cover thermal: processor_thermal: Power floor status
Support power floor notifications for Meteor Lake processors.
The first three changes is to prepare for power floor status and others add support for power floor.
v2
- Use common define for offset
- Fix potential race during clearing of interrupt with workload hint
- Address comment for v1 for
thermal: int340x: processor_thermal: Support power floor notifications
Srinivas Pandruvada (7):
thermal: int340x: processor_thermal: Move interrupt status MMIO offset
to common header
thermal: int340x: processor_thermal: Common function to clear SOC
interrupt
thermal: int340x: processor_thermal: Set feature mask before
proc_thermal_add
thermal: int340x: processor_thermal: Support power floor notifications
thermal: int340x: processor_thermal: Handle power floor interrupts
thermal: int340x: processor_thermal: Enable power floor support selftests/thermel/intel: Add test to read power floor status
.../driver-api/thermal/intel_dptf.rst | 8 ++ .../thermal/intel/int340x_thermal/Makefile | 1 + .../processor_thermal_device.c | 68 +++++++++- .../processor_thermal_device.h | 11 ++ .../processor_thermal_device_pci.c | 43 ++++-- .../processor_thermal_power_floor.c | 126 ++++++++++++++++++ .../processor_thermal_wt_hint.c | 3 - tools/testing/selftests/Makefile | 1 + .../thermal/intel/power_floor/Makefile | 12 ++ .../intel/power_floor/power_floor_test.c | 108 +++++++++++++++ 10 files changed, 365 insertions(+), 16 deletions(-) create mode 100644 drivers/thermal/intel/int340x_thermal/processor_thermal_power_floor.c create mode 100644 tools/testing/selftests/thermal/intel/power_floor/Makefile create mode 100644 tools/testing/selftests/thermal/intel/power_floor/power_floor_test.c
Signature · 1 line
2.40.1
PATCH v2 1/7 thermal: int340x: processor_thermal: Move interrupt status MMIO offset to common header
Move define SOC_WT_RES_INT_STATUS_OFFSET to processor_thermal_device.h. This way it can be reused in other modules.
---
v2:
- New patch in the series
.../thermal/intel/int340x_thermal/processor_thermal_device.h | 2 ++ .../thermal/intel/int340x_thermal/processor_thermal_wt_hint.c | 1 - 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/thermal/intel/int340x_thermal/processor_thermal_device.h +2 -0
@@ -91,6 +91,8 @@ void proc_thermal_wt_req_remove(struct pci_dev *pdev);#define MBOX_DATA_BIT_AC_DC 30#define MBOX_DATA_BIT_VALID 31 +#define SOC_WT_RES_INT_STATUS_OFFSET 0x5B18 +int processor_thermal_send_mbox_read_cmd (struct pci_dev *pdev,u16 id,u64 *resp);int processor_thermal_send_mbox_write_cmd (struct pci_dev *pdev,u16 id,u32 data); int processor_thermal_mbox_interrupt_config(struct pci_dev *pdev, bool enable, int enable_bit,
drivers/thermal/intel/int340x_thermal/processor_thermal_wt_hint.c +0 -1
@@ -32,7 +32,6 @@#include <linux/pci.h> #include "processor_thermal_device.h" -#define SOC_WT_RES_INT_STATUS_OFFSET 0x5B18#define SOC_WT GENMASK_ULL(47, 40)#define SOC_WT_PREDICTION_INT_ENABLE_BIT 23
Signature · 1 line
2.40.1
PATCH v2 2/7 thermal: int340x: processor_thermal: Common function to clear SOC interrupt
In reply to Srinivas PandruvadaThe SOC interrupt status register contains multiple interrupt sources (workload hint interrupt and power floor interrupt). This is not possible to clear individual interrupt source with read-modify-write, as it may clear the new interrupt from the firmware after read operation. This is also not possible to set the interrupt status bit to 1 for the other interrupt source, which is not part of clearing.
Hence create a common function, which does clear all status bits at once. Call this function after processing all interrupt sources.
---
v2:
- New patch in the series
.../int340x_thermal/processor_thermal_device.h | 1 + .../int340x_thermal/processor_thermal_device_pci.c | 13 +++++++++++++ .../int340x_thermal/processor_thermal_wt_hint.c | 2 -- 3 files changed, 14 insertions(+), 2 deletions(-)
drivers/thermal/intel/int340x_thermal/processor_thermal_device.h +1 -0
@@ -92,6 +92,7 @@ void proc_thermal_wt_req_remove(struct pci_dev *pdev);#define MBOX_DATA_BIT_VALID 31#define SOC_WT_RES_INT_STATUS_OFFSET 0x5B18 +#define SOC_WT_RES_INT_STATUS_MASK GENMASK_ULL(3, 2)int processor_thermal_send_mbox_read_cmd (struct pci_dev *pdev,u16 id,u64 *resp);int processor_thermal_send_mbox_write_cmd (struct pci_dev *pdev,u16 id,u32 data);
drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c +13 -0
@@ -122,11 +122,24 @@ static void pkg_thermal_schedule_work(struct delayed_work *work)schedule_delayed_work (work, ms); } +static void proc_thermal_clear_soc_int_status (struct proc_thermal_device *proc_priv) +{ +u64 status; + +if (!(proc_priv->mmio_feature_mask &PROC_THERMAL_FEATURE_WT_HINT )) +return ; + + status =readq (proc_priv->mmio_base +SOC_WT_RES_INT_STATUS_OFFSET ); +writeq (status & ~SOC_WT_RES_INT_STATUS_MASK , + proc_priv->mmio_base +SOC_WT_RES_INT_STATUS_OFFSET ); +} +static irqreturn_t proc_thermal_irq_thread_handler (int irq,void *devid) {struct proc_thermal_pci *pci_info = devid;proc_thermal_wt_intr_callback (pci_info->pdev, pci_info->proc_priv); +proc_thermal_clear_soc_int_status (pci_info->proc_priv);return IRQ_HANDLED ; }
drivers/thermal/intel/int340x_thermal/processor_thermal_wt_hint.c +0 -2
@@ -215,8 +215,6 @@ void proc_thermal_wt_intr_callback(struct pci_dev *pdev, struct proc_thermal_devif (!(status &SOC_WT_PREDICTION_INT_ACTIVE ))return ; -writeq (status & ~SOC_WT_PREDICTION_INT_ACTIVE , - proc_priv->mmio_base +SOC_WT_RES_INT_STATUS_OFFSET );sysfs_notify (&pdev->dev.kobj,"workload_hint" ,"workload_type_index" ); }EXPORT_SYMBOL_NS_GPL (proc_thermal_wt_intr_callback,INT340X_THERMAL );
Signature · 1 line
2.40.1
PATCH v2 3/7 thermal: int340x: processor_thermal: Set feature mask before proc_thermal_add
In reply to Srinivas PandruvadaThe function proc_thermal_add() adds sysfs entries for power limits. The feature mask of available features is not present by this time. If feature mask is available, then this can be used to selectively create attributes.
Feature mask is set during call to proc_thermal_mmio_add(). Change the order of calls so that proc_thermal_mmio_add() is called before proc_thermal_add().
There is no functional impact with this change.
---
v2:
No change
.../processor_thermal_device_pci.c | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c +10 -11
@@ -266,19 +266,19 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev, const struct pci_device_INIT_DELAYED_WORK (&pci_info->work, proc_thermal_threshold_work_fn); - ret =proc_thermal_add (&pdev->dev, proc_priv); -if (ret) { -dev_err (&pdev->dev,"error: proc_thermal_add, will continue\n" ); - pci_info->no_legacy =1 ; - } - proc_priv->priv_data = pci_info; pci_info->proc_priv = proc_priv;pci_set_drvdata (pdev, proc_priv); ret =proc_thermal_mmio_add (pdev, proc_priv, id->driver_data);if (ret) - goto err_ret_thermal; +return ret; + + ret =proc_thermal_add (&pdev->dev, proc_priv); +if (ret) { +dev_err (&pdev->dev,"error: proc_thermal_add, will continue\n" ); + pci_info->no_legacy =1 ; + } psv_trip.temperature =get_trip_temp (pci_info);
@@ -288,7 +288,7 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev, const struct pci_device_ &tzone_params, 0, 0);if (IS_ERR (pci_info->tzone)) { ret =PTR_ERR (pci_info->tzone); - goto err_ret_mmio; + goto err_del_legacy; }if (use_msi && (pdev->msi_enabled || pdev->msix_enabled)) {
@@ -325,11 +325,10 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev, const struct pci_device_pci_free_irq_vectors (pdev); err_ret_tzone:thermal_zone_device_unregister (pci_info->tzone); -err_ret_mmio: -proc_thermal_mmio_remove (pdev, proc_priv); -err_ret_thermal: +err_del_legacy:if (!pci_info->no_legacy)proc_thermal_remove (proc_priv); +proc_thermal_mmio_remove (pdev, proc_priv);pci_disable_device (pdev);return ret;
Signature · 1 line
2.40.1
PATCH v2 4/7 thermal: int340x: processor_thermal: Support power floor notifications
In reply to Srinivas PandruvadaWhen the hardware reduces the power to the minimum possible, the power floor is notified via an interrupt. This can happen when user space requests a power limit via powercap RAPL interface, which forces the system to enter to the lowest power. This power floor indication can be used as a hint to resort to other methods of reducing power than via RAPL power limit.
Before power floor status can be read or get notifications from the firmware, it needs to be configured via a mailbox command. Actual power floor status is read via bit 39 of MMIO offset 0x5B18 of the processor thermal PCI device.
To show the current power floor status and get notification on a sysfs attribute, add additional attributes to /sys/bus/pci/devices/0000\:00\:04.0/power_limits/
power_floor_enable : This attribute is present when a SoC supports power floor notification. This attribute allows to enable/disable power floor notifications.
power_floor_status : This attribute is present when a SoC supports power floor notification. When enabled this shows the current status of power floor.
The power floor implementation provides interfaces, which are called from the sysfs callbacks to enable/disable and read power floor status. Also provides two additional interface to check if the current processor thermal device interrupt is for power floor status and send notification to user space.
---
v2:
- Use kernel doc as suggested by Rafael
- Code changes as suggested by Rafael
- Use common offset from header file
- Removed clearing of interrupt
.../driver-api/thermal/intel_dptf.rst | 8 ++ .../thermal/intel/int340x_thermal/Makefile | 1 + .../processor_thermal_device.c | 68 +++++++++- .../processor_thermal_device.h | 8 ++ .../processor_thermal_power_floor.c | 126 ++++++++++++++++++ 5 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 drivers/thermal/intel/int340x_thermal/processor_thermal_power_floor.c
Documentation/driver-api/thermal/intel_dptf.rst +8 -0
@@ -164,6 +164,14 @@ ABI. ``power_limit_1_tmax_us`` (RO) Maximum powercap sysfs constraint_1_time_window_us for Intel RAPL +``power_floor_status`` (RO) + When set to 1, hardware is not able to satisfy the requested power limit + via Intel RAPL. + +``power_floor_enable`` (RW) + When set to 1, enable reading and notification of power floor status. + Notifications are issued for changes in the power_floor_status attribute. + :file:`/sys/bus/pci/devices/0000\:00\:04.0/` ``tcc_offset_degree_celsius`` (RW)
drivers/thermal/intel/int340x_thermal/Makefile +1 -0
@@ -12,5 +12,6 @@ obj-$(CONFIG_INT340X_THERMAL) += processor_thermal_rfim.o obj-$(CONFIG_INT340X_THERMAL) += processor_thermal_mbox.o obj-$(CONFIG_INT340X_THERMAL) += processor_thermal_wt_req.o obj-$(CONFIG_INT340X_THERMAL) += processor_thermal_wt_hint.o +obj-$(CONFIG_INT340X_THERMAL) += processor_thermal_power_floor.o obj-$(CONFIG_INT3406_THERMAL) += int3406_thermal.o obj-$(CONFIG_ACPI_THERMAL_REL) += acpi_thermal_rel.o
drivers/thermal/intel/int340x_thermal/processor_thermal_device.c +67 -1
97 lines not on this page · raw message
drivers/thermal/intel/int340x_thermal/processor_thermal_device.h +8 -0
@@ -63,6 +63,7 @@ struct rapl_mmio_regs {#define PROC_THERMAL_FEATURE_WT_REQ 0x08#define PROC_THERMAL_FEATURE_DLVR 0x10#define PROC_THERMAL_FEATURE_WT_HINT 0x20 +#define PROC_THERMAL_FEATURE_POWER_FLOOR 0x40#if IS_ENABLED (CONFIG_PROC_THERMAL_MMIO_RAPL )int proc_thermal_rapl_add (struct pci_dev *pdev,struct proc_thermal_device *proc_priv);
@@ -94,6 +95,13 @@ void proc_thermal_wt_req_remove(struct pci_dev *pdev);#define SOC_WT_RES_INT_STATUS_OFFSET 0x5B18#define SOC_WT_RES_INT_STATUS_MASK GENMASK_ULL(3, 2) +int proc_thermal_read_power_floor_status (struct proc_thermal_device *proc_priv); +int proc_thermal_power_floor_set_state (struct proc_thermal_device *proc_priv,bool enable); +bool proc_thermal_power_floor_get_state (struct proc_thermal_device *proc_priv); +void proc_thermal_power_floor_intr_callback (struct pci_dev *pdev, +struct proc_thermal_device *proc_priv); +bool proc_thermal_check_power_floor_intr (struct proc_thermal_device *proc_priv); +int processor_thermal_send_mbox_read_cmd (struct pci_dev *pdev,u16 id,u64 *resp);int processor_thermal_send_mbox_write_cmd (struct pci_dev *pdev,u16 id,u32 data); int processor_thermal_mbox_interrupt_config(struct pci_dev *pdev, bool enable, int enable_bit,
drivers/thermal/intel/int340x_thermal/processor_thermal_power_floor.c new file +126 -0
126 lines not on this page · raw message
Signature · 1 line
2.40.1
PATCH v2 5/7 thermal: int340x: processor_thermal: Handle power floor interrupts
In reply to Srinivas PandruvadaOn thermal device interrupt, if the interrupt is generated for passing power floor status, call the callback to pass notification to the user space.
First call proc_thermal_check_power_floor_intr() to check interrupt, if this callback returns true, wake the IRQ thread to call proc_thermal_power_floor_intr_callback() to notify user space.
---
v2:
- Use common interrupt clearing function to clear interrupt. Previously it was cleared in the callback function proc_thermal_power_floor_intr_callback().
.../intel/int340x_thermal/processor_thermal_device_pci.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c +8 -1
@@ -126,7 +126,8 @@ static void proc_thermal_clear_soc_int_status(struct proc_thermal_device *proc_p {u64 status; -if (!(proc_priv->mmio_feature_mask &PROC_THERMAL_FEATURE_WT_HINT )) +if (!(proc_priv->mmio_feature_mask & + (PROC_THERMAL_FEATURE_WT_HINT |PROC_THERMAL_FEATURE_POWER_FLOOR )))return ; status =readq (proc_priv->mmio_base +SOC_WT_RES_INT_STATUS_OFFSET );
@@ -139,6 +140,7 @@ static irqreturn_t proc_thermal_irq_thread_handler(int irq, void *devid)struct proc_thermal_pci *pci_info = devid;proc_thermal_wt_intr_callback (pci_info->pdev, pci_info->proc_priv); +proc_thermal_power_floor_intr_callback (pci_info->pdev, pci_info->proc_priv);proc_thermal_clear_soc_int_status (pci_info->proc_priv);return IRQ_HANDLED ;
@@ -158,6 +160,11 @@ static irqreturn_t proc_thermal_irq_handler(int irq, void *devid) ret =IRQ_WAKE_THREAD ; } +if (proc_priv->mmio_feature_mask &PROC_THERMAL_FEATURE_POWER_FLOOR ) { +if (proc_thermal_check_power_floor_intr (pci_info->proc_priv)) + ret =IRQ_WAKE_THREAD ; + } +/* * Since now there are two sources of interrupts: one from thermal threshold * and another from workload hint, add a check if there was really a threshold
Signature · 1 line
2.40.1
PATCH v2 6/7 thermal: int340x: processor_thermal: Enable power floor support
In reply to Srinivas PandruvadaEnable power floor feature support for Meteor Lake processors.
---
v2:
- No change
.../intel/int340x_thermal/processor_thermal_device_pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c +1 -1
@@ -409,7 +409,7 @@ static const struct pci_device_id proc_thermal_pci_ids[] = { PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_WT_REQ) }, {PCI_DEVICE_DATA (INTEL ,MTLP_THERMAL ,PROC_THERMAL_FEATURE_RAPL |PROC_THERMAL_FEATURE_FIVR |PROC_THERMAL_FEATURE_DVFS |PROC_THERMAL_FEATURE_DLVR | - PROC_THERMAL_FEATURE_WT_HINT) }, + PROC_THERMAL_FEATURE_WT_HINT | PROC_THERMAL_FEATURE_POWER_FLOOR) }, { PCI_DEVICE_DATA(INTEL, ARL_S_THERMAL, PROC_THERMAL_FEATURE_RAPL | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_DLVR | PROC_THERMAL_FEATURE_WT_HINT) }, { PCI_DEVICE_DATA(INTEL, RPL_THERMAL, PROC_THERMAL_FEATURE_RAPL |
Signature · 1 line
2.40.1
PATCH v2 7/7 selftests/thermel/intel: Add test to read power floor status
In reply to Srinivas PandruvadaSome SoCs have firmware support to notify, if the system can't lower power limit to a value requested from user space via RAPL constraints.
This test program waits for notification of power floor and prints. This program can be used to test this feature and also allows other user space programs to use as a reference.
---
v2:
- No change
tools/testing/selftests/Makefile | 1 + .../thermal/intel/power_floor/Makefile | 12 ++ .../intel/power_floor/power_floor_test.c | 108 ++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 tools/testing/selftests/thermal/intel/power_floor/Makefile create mode 100644 tools/testing/selftests/thermal/intel/power_floor/power_floor_test.c
tools/testing/selftests/Makefile +1 -0
@@ -86,6 +86,7 @@ TARGETS += syscall_user_dispatch TARGETS += sysctl TARGETS += tc-testing TARGETS += tdx +TARGETS += thermal/intel/power_floor TARGETS += thermal/intel/workload_hint TARGETS += timens ifneq (1, $(quicktest))
tools/testing/selftests/thermal/intel/power_floor/Makefile new file +12 -0
@@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0 +ifndef CROSS_COMPILE +uname_M := $(shell uname -m 2>/dev/null || echo not) +ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/) + +ifeq ($(ARCH),x86) +TEST_GEN_PROGS := power_floor_test + +include ../../../lib.mk + +endif +endif
tools/testing/selftests/thermal/intel/power_floor/power_floor_test.c new file +108 -0
108 lines not on this page · raw message
Signature · 1 line
2.40.1
Rafael J. Wysocki
maintainerQuoted 39 lines · Srinivas Pandruvada
Support power floor notifications for Meteor Lake processors.
The first three changes is to prepare for power floor status and others add support for power floor.
v2
- Use common define for offset
- Fix potential race during clearing of interrupt with workload hint
- Address comment for v1 for
thermal: int340x:processor_thermal: Support power floor notificationsSrinivas Pandruvada (7):
thermal: int340x:processor_thermal: Move interrupt status MMIO offset
to common header
thermal: int340x:processor_thermal: Common function to clear SOC
interrupt
thermal: int340x:processor_thermal: Set feature mask before
proc_thermal_add
thermal: int340x:processor_thermal: Support power floor notifications
thermal: int340x:processor_thermal: Handle power floor interrupts
thermal: int340x:processor_thermal: Enable power floor support selftests/thermel/intel: Add test to read power floor status.../driver-api/thermal/intel_dptf.rst | 8 ++ .../thermal/intel/int340x_thermal/Makefile | 1 + .../processor_thermal_device.c | 68 +++++++++- .../processor_thermal_device.h | 11 ++ .../processor_thermal_device_pci.c | 43 ++++-- .../processor_thermal_power_floor.c | 126 ++++++++++++++++++ .../processor_thermal_wt_hint.c | 3 - tools/testing/selftests/Makefile | 1 + .../thermal/intel/power_floor/Makefile | 12 ++ .../intel/power_floor/power_floor_test.c | 108 +++++++++++++++ 10 files changed, 365 insertions(+), 16 deletions(-) create mode 100644 drivers/thermal/intel/int340x_thermal/processor_thermal_power_floor.c create mode 100644 tools/testing/selftests/thermal/intel/power_floor/Makefile create mode 100644 tools/testing/selftests/thermal/intel/power_floor/power_floor_test.c
Quoted 1 line
--
Whole series queued up as 6.7 material.
I've edited a couple of changelogs to clarify them a bit and changed the documentation of the new sysfs attributes somewhat, so they don't talk about RAPL directly, because I think that the key point here is that if the power floor is signaled, the configuration of the system needs to be changed in order to reduce power below the current level.