thermal: processor_thermal: Suport workload hint
Subsystems (3)
v3 cover thermal: processor_thermal: Suport workload hint
Add support for Meteor Lake workload hints. Before adding this support, some reorganization and clean up is required.
First four changes are for clean up and to reorganize code to add support for workload hint. The last patch adds a test program as part of self tests.
v3:
Changes in the commit log
Rename of files for using WT instead of WLT
Address comments from Rafael on v2
v2:
Changes in comments and commit log
Self test program is improved to disable workloadtype notification on exit
Srinivas Pandruvada (7):
thermal: int340x: processor_thermal: Move mailbox code to common
module
thermal: int340x: processor_thermal: Add interrupt configuration
thermal: int340x: processor_thermal: Use non MSI interrupts by default thermal/drivers/int340x: Remove PROC_THERMAL_FEATURE_WLT_REQ for
Meteor Lake
thermal: int340x: processor_thermal: Add workload type hint interface thermal/drivers/int340x: Support workload hint interrupts selftests/thermel/intel: Add test to read workload hint
.../driver-api/thermal/intel_dptf.rst | 51 ++++ .../thermal/intel/int340x_thermal/Makefile | 2 + .../processor_thermal_device.c | 17 +- .../processor_thermal_device.h | 21 +- .../processor_thermal_device_pci.c | 79 ++++-- .../processor_thermal_device_pci_legacy.c | 3 +- .../int340x_thermal/processor_thermal_mbox.c | 179 ++++--------- .../processor_thermal_wt_hint.c | 252 ++++++++++++++++++ .../processor_thermal_wt_req.c | 136 ++++++++++ tools/testing/selftests/Makefile | 1 + .../thermal/intel/workload_hint/Makefile | 12 + .../intel/workload_hint/workload_hint_test.c | 157 +++++++++++ 12 files changed, 752 insertions(+), 158 deletions(-) create mode 100644 drivers/thermal/intel/int340x_thermal/processor_thermal_wt_hint.c create mode 100644 drivers/thermal/intel/int340x_thermal/processor_thermal_wt_req.c create mode 100644 tools/testing/selftests/thermal/intel/workload_hint/Makefile create mode 100644 tools/testing/selftests/thermal/intel/workload_hint/workload_hint_test.c
Signature · 1 line
2.40.1
PATCH v3 1/7 thermal: int340x: processor_thermal: Move mailbox code to common module
The processor thermal mailbox is used for workload type request and also in the processor thermal RFIM module. So, move the workload type request code to its own module from the current processor thermal mailbox module.
processor_thermal_mailbox.c contains only mailbox read/write related source code. The source related to workload_types requests is moved to a module processor_thermal_wt_req.c.
In addition
-Rename PROC_THERMAL_FEATURE_MBOX to PROC_THERMAL_FEATURE_WT_REQ.
- proc_thermal_mbox_add(), which adds workload type sysfs attribute group is renamed to proc_thermal_wt_req_add(). -proc_thermal_mbox_remove() is renamed to proc_thermal_wt_req_remove().
While here, resolve check patch warnings for 100 columns for only modified lines.
No functional changes are expected.
---
v3:
Use WT|wt for workload files, api and defines for WLT|wlt
v2:
Removed extra blank line at the end of proc_thermal_wlt_req_remove()
.../thermal/intel/int340x_thermal/Makefile | 1 + .../processor_thermal_device.c | 8 +- .../processor_thermal_device.h | 12 +- .../processor_thermal_device_pci.c | 10 +- .../processor_thermal_device_pci_legacy.c | 3 +- .../int340x_thermal/processor_thermal_mbox.c | 130 ----------------- .../processor_thermal_wt_req.c | 136 ++++++++++++++++++ 7 files changed, 159 insertions(+), 141 deletions(-) create mode 100644 drivers/thermal/intel/int340x_thermal/processor_thermal_wt_req.c
drivers/thermal/intel/int340x_thermal/Makefile +1 -0
@@ -10,5 +10,6 @@ obj-$(CONFIG_INT340X_THERMAL) += processor_thermal_device_pci.o obj-$(CONFIG_PROC_THERMAL_MMIO_RAPL) += processor_thermal_rapl.o 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_INT3406_THERMAL) += int3406_thermal.o obj-$(CONFIG_ACPI_THERMAL_REL) += acpi_thermal_rel.o
drivers/thermal/intel/int340x_thermal/processor_thermal_device.c +4 -4
@@ -346,8 +346,8 @@ int proc_thermal_mmio_add(struct pci_dev *pdev, } } -if (feature_mask &PROC_THERMAL_FEATURE_MBOX ) { - ret =proc_thermal_mbox_add (pdev, proc_priv); +if (feature_mask &PROC_THERMAL_FEATURE_WT_REQ ) { + ret =proc_thermal_wt_req_add (pdev, proc_priv);if (ret) {dev_err (&pdev->dev,"failed to add MBOX interface\n" ); goto err_rem_rfim;
@@ -374,8 +374,8 @@ void proc_thermal_mmio_remove(struct pci_dev *pdev, struct proc_thermal_device * proc_priv->mmio_feature_mask & PROC_THERMAL_FEATURE_DVFS)proc_thermal_rfim_remove (pdev); -if (proc_priv->mmio_feature_mask &PROC_THERMAL_FEATURE_MBOX ) -proc_thermal_mbox_remove (pdev); +if (proc_priv->mmio_feature_mask &PROC_THERMAL_FEATURE_WT_REQ ) +proc_thermal_wt_req_remove (pdev); }EXPORT_SYMBOL_GPL (proc_thermal_mmio_remove);
drivers/thermal/intel/int340x_thermal/processor_thermal_device.h +9 -3
@@ -59,7 +59,7 @@ struct rapl_mmio_regs {#define PROC_THERMAL_FEATURE_RAPL 0x01#define PROC_THERMAL_FEATURE_FIVR 0x02#define PROC_THERMAL_FEATURE_DVFS 0x04 -#define PROC_THERMAL_FEATURE_MBOX 0x08 +#define PROC_THERMAL_FEATURE_WT_REQ 0x08#define PROC_THERMAL_FEATURE_DLVR 0x10#if IS_ENABLED (CONFIG_PROC_THERMAL_MMIO_RAPL )
@@ -80,8 +80,14 @@ static void __maybe_unused proc_thermal_rapl_remove(void)int proc_thermal_rfim_add (struct pci_dev *pdev,struct proc_thermal_device *proc_priv);void proc_thermal_rfim_remove (struct pci_dev *pdev); -int proc_thermal_mbox_add (struct pci_dev *pdev,struct proc_thermal_device *proc_priv); -void proc_thermal_mbox_remove (struct pci_dev *pdev); +int proc_thermal_wt_req_add (struct pci_dev *pdev,struct proc_thermal_device *proc_priv); +void proc_thermal_wt_req_remove (struct pci_dev *pdev); + +#define MBOX_CMD_WORKLOAD_TYPE_READ 0x0E +#define MBOX_CMD_WORKLOAD_TYPE_WRITE 0x0F + +#define MBOX_DATA_BIT_AC_DC 30 +#define MBOX_DATA_BIT_VALID 31int 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 +7 -3
@@ -350,9 +350,13 @@ static SIMPLE_DEV_PM_OPS(proc_thermal_pci_pm, proc_thermal_pci_suspend, proc_thermal_pci_resume);static const struct pci_device_id proc_thermal_pci_ids[] = { - {PCI_DEVICE_DATA (INTEL ,ADL_THERMAL ,PROC_THERMAL_FEATURE_RAPL |PROC_THERMAL_FEATURE_FIVR |PROC_THERMAL_FEATURE_DVFS |PROC_THERMAL_FEATURE_MBOX ) }, - {PCI_DEVICE_DATA (INTEL ,MTLP_THERMAL ,PROC_THERMAL_FEATURE_RAPL |PROC_THERMAL_FEATURE_FIVR |PROC_THERMAL_FEATURE_DVFS |PROC_THERMAL_FEATURE_MBOX |PROC_THERMAL_FEATURE_DLVR ) }, - {PCI_DEVICE_DATA (INTEL ,RPL_THERMAL ,PROC_THERMAL_FEATURE_RAPL |PROC_THERMAL_FEATURE_FIVR |PROC_THERMAL_FEATURE_DVFS |PROC_THERMAL_FEATURE_MBOX ) }, + {PCI_DEVICE_DATA (INTEL ,ADL_THERMAL ,PROC_THERMAL_FEATURE_RAPL | +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_WT_REQ | +PROC_THERMAL_FEATURE_DLVR ) }, + {PCI_DEVICE_DATA (INTEL ,RPL_THERMAL ,PROC_THERMAL_FEATURE_RAPL | +PROC_THERMAL_FEATURE_FIVR |PROC_THERMAL_FEATURE_DVFS |PROC_THERMAL_FEATURE_WT_REQ ) }, { }, };
drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci_legacy.c +2 -1
@@ -137,7 +137,8 @@ static const struct pci_device_id proc_thermal_pci_ids[] = { { PCI_DEVICE_DATA(INTEL, ICL_THERMAL, PROC_THERMAL_FEATURE_RAPL) }, { PCI_DEVICE_DATA(INTEL, JSL_THERMAL, 0) }, { PCI_DEVICE_DATA(INTEL, SKL_THERMAL, PROC_THERMAL_FEATURE_RAPL) }, - { PCI_DEVICE_DATA(INTEL, TGL_THERMAL, PROC_THERMAL_FEATURE_RAPL | PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_MBOX) }, + { PCI_DEVICE_DATA(INTEL, TGL_THERMAL, PROC_THERMAL_FEATURE_RAPL | + PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_WT_REQ) }, { }, };
drivers/thermal/intel/int340x_thermal/processor_thermal_mbox.c +0 -130
146 lines not on this page · raw message
drivers/thermal/intel/int340x_thermal/processor_thermal_wt_req.c new file +136 -0
136 lines not on this page · raw message
Signature · 1 line
2.40.1
PATCH v3 2/7 thermal: int340x: processor_thermal: Add interrupt configuration
In reply to Srinivas PandruvadaSome features like workload type prediction and power floor events require interrupt support to avoid polling. Here interrupts are enabled and disabled via sending mailbox commands. The mailbox command ID is 0x1E for read and 0x1F for write.
The interrupt configuration will require mutex protection as it involves read-modify-write operation. Since mutex are already used in the mailbox read/write functions: send_mbox_write_cmd() and send_mbox_read_cmd(), there will be double locking. But, this can be avoided by moving mutexes from mailbox read/write processing functions to the callers:
processor_thermal_send_mbox_[read|write]_cmd().
---
v3:
No change.
v2:
Added additional comment in the commit log for the interrupt bit
.../processor_thermal_device.h | 2 + .../int340x_thermal/processor_thermal_mbox.c | 85 ++++++++++++++----- 2 files changed, 68 insertions(+), 19 deletions(-)
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);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, +int time_window);int proc_thermal_add (struct device *dev,struct proc_thermal_device *priv);void proc_thermal_remove (struct proc_thermal_device *proc_priv);int proc_thermal_suspend (struct device *dev);
drivers/thermal/intel/int340x_thermal/processor_thermal_mbox.c +66 -19
129 lines not on this page · raw message
Signature · 1 line
2.40.1
PATCH v3 3/7 thermal: int340x: processor_thermal: Use non MSI interrupts by default
In reply to Srinivas PandruvadaThere are issues in using MSI interrupts for processor thermal device. The support is not consistent across generations. But the legacy PCI interrupts work on all current generations.
Hence always use legacy PCI interrupts by default, instead of MSI. Add a module param to use of MSI, so that MSI can be still used.
---
v3:
Address comments from Rafel for:
replace variable msi_enabled to use_msi
Add bus mastering for legacy PCI, even if it doesn't make any difference Use module param along with pci device msi enabled to use MSI
v2:
Changed msi_enabled to type bool
.../processor_thermal_device_pci.c | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-)
drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c +21 -9
@@ -15,6 +15,11 @@#define DRV_NAME "proc_thermal_pci" +static bool use_msi; +module_param (use_msi, bool,0644 ); +MODULE_PARM_DESC (use_msi, +"Use PCI MSI based interrupts for processor thermal device." ); +struct proc_thermal_pci {struct pci_dev *pdev;struct proc_thermal_device *proc_priv;
@@ -203,6 +208,7 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev, const struct pci_device_struct proc_thermal_device *proc_priv;struct proc_thermal_pci *pci_info;int irq_flag =0 , irq, ret; +bool msi_irq = false; proc_priv =devm_kzalloc (&pdev->dev,sizeof (*proc_priv),GFP_KERNEL );if (!proc_priv)
@@ -248,16 +254,21 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev, const struct pci_device_ goto err_ret_mmio; } -/* request and enable interrupt */ - ret =pci_alloc_irq_vectors (pdev,1 ,1 ,PCI_IRQ_ALL_TYPES ); -if (ret <0 ) { -dev_err (&pdev->dev,"Failed to allocate vectors!\n" ); - goto err_ret_tzone; - } -if (!pdev->msi_enabled && !pdev->msix_enabled) +if (use_msi && (pdev->msi_enabled || pdev->msix_enabled)) { +/* request and enable interrupt */ + ret =pci_alloc_irq_vectors (pdev,1 ,1 ,PCI_IRQ_ALL_TYPES ); +if (ret <0 ) { +dev_err (&pdev->dev,"Failed to allocate vectors!\n" ); + goto err_ret_tzone; + } + + irq =pci_irq_vector (pdev,0 ); + msi_irq = true; + }else { irq_flag =IRQF_SHARED ; + irq = pdev->irq; + } - irq =pci_irq_vector (pdev,0 ); ret =devm_request_threaded_irq (&pdev->dev, irq, proc_thermal_irq_handler,NULL , irq_flag,KBUILD_MODNAME , pci_info);
@@ -273,7 +284,8 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev, const struct pci_device_return 0 ; err_free_vectors: -pci_free_irq_vectors (pdev); +if (msi_irq) +pci_free_irq_vectors (pdev); err_ret_tzone:thermal_zone_device_unregister (pci_info->tzone); err_ret_mmio:
Signature · 1 line
2.40.1
PATCH v3 4/7 thermal/drivers/int340x: Remove PROC_THERMAL_FEATURE_WLT_REQ for Meteor Lake
In reply to Srinivas PandruvadaMeteor Lake processor supports firmware hints for predicting workload type. So, remove support for passing workload hints to the firmware.
---
v3:
No change
v2:
No change
.../intel/int340x_thermal/processor_thermal_device_pci.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c +1 -2
@@ -365,8 +365,7 @@ static const struct pci_device_id proc_thermal_pci_ids[] = { {PCI_DEVICE_DATA (INTEL ,ADL_THERMAL ,PROC_THERMAL_FEATURE_RAPL | 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_WT_REQ | - PROC_THERMAL_FEATURE_DLVR) }, + PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_DLVR) }, { PCI_DEVICE_DATA(INTEL, RPL_THERMAL, PROC_THERMAL_FEATURE_RAPL | PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_WT_REQ) }, { },
Signature · 1 line
2.40.1
PATCH v3 5/7 thermal: int340x: processor_thermal: Add workload type hint interface
In reply to Srinivas PandruvadaPrior to Meteor Lake processor generation, user space can pass workload type request to the firmware. Then firmware can optimize power based on workload type. User space also uses workload type request to implement its own heuristics.
The firmware in Meteor Lake processor generation is capable of predicting workload type without user space help.
To avoid duplicate processing, add a sysfs interface allowing user space to obtain the workload hint from the firmware instead of trying to predict the workload type by itself.
This workload hint is passed from the firmware via a MMIO offset 0x5B18 of processor thermal PCI device. Before workload hints can be produced by the firmware, it needs to be configured via a mailbox command.
This mailbox command turns ON the workload hint. Also allows to program a notification delay to rate control number of notifications.
This notification delay can be changed from user space vis sysfs.
Attribute group 'workload_hint' in sysfs is used for implementing the workload hints interface between user space and the kernel.
It contains the following attributes:
workload_type_enable: Enables/disables workload type hints from the firmware.
notification_delay_ms: Notification delay in milliseconds.
workload_type_index: The current workload type index predicted by the firmware (see the documentation changes below for supported index values and their meaning).
---
v3:
Updates based on Rafael's review for:
- commit description and header (most of the time copied as is from the suggestions)
- Documentation
clarify notification_delay_ms
Other comments copy as is from the suggestions
- Clarify MMIO offset and processor thermal device standard BDF
- Use WT|wt instead of WLT|wlt for file name, defines and function names
- Use *_OFFSET in defines instead of *_OFF for MMIO offsets
- Consistantcy on using notification delay as parameter for mailbox during disable
- Remove support for setting 0 notification delay
- Update the feature enable when notification delay is changed when the feature is already enabled. This will require additional mutex to check the enable status
Others:
- When workload hint feature is not enabled, return -ENODATA instead of default read value of 0
v2:
Update comments only
.../driver-api/thermal/intel_dptf.rst | 51 ++++ .../thermal/intel/int340x_thermal/Makefile | 1 + .../processor_thermal_device.c | 9 + .../processor_thermal_device.h | 7 + .../processor_thermal_device_pci.c | 3 +- .../processor_thermal_wt_hint.c | 253 ++++++++++++++++++ 6 files changed, 323 insertions(+), 1 deletion(-) create mode 100644 drivers/thermal/intel/int340x_thermal/processor_thermal_wt_hint.c
Documentation/driver-api/thermal/intel_dptf.rst +51 -0
@@ -315,3 +315,54 @@ DPTF Fan Control ---------------------------------------- Refer to Documentation/admin-guide/acpi/fan_performance_states.rst + +Workload Type Hints +---------------------------------------- + +The firmware in Meteor Lake processor generation is capable of predicting +workload type and passing hints regarding it to the OS. A special sysfs +interface is provided to allow user space to obtain workload type hints from +the firmware and control the rate at which they are provided. + +User space can poll attribute "workload_type_index" for the current hint or +can receive a notification whenever the value of this attribute is updated. + +file:`/sys/bus/pci/devices/0000:00:04.0/workload_hint/` +The segment 0, bus 0, device 4, function 0 is reserved for the processor thermal +device on all Intel client processors. So, the above path doesn't change +based on the processor generation. + +``workload_hint_enable`` (RW) + Enable firmware to send workload type hints to user space. + +``notification_delay_ms`` (RW) + Minimum delay in milliseconds before firmware will notify OS. This is for + the rate control of notifications. This delay is between changing the workload + type prediction in the firmware and notifying the OS about the change. + The default delay is 1024 ms. The delay of 0 is invalid. The delay is rounded + up to the nearest power of 2 to simplify firmware programming of the delay value. + The read of notification_delay_ms attribute shows the effective value used. + +``workload_type_index`` (RO) + Predicted workload type index. User space can get notification of change via + existing sysfs attribute change notification mechanism. + The supported index values and their meaning for the Meteor Lake processor + generation are as follows: + + 0 - Idle: System performs no tasks, power and idle residency are consistently + low for long periods of time. + + 1 – Battery Life: Power is relatively low, but the processor may still be + actively performing a task, such as video playback for a long period of + time. + + 2 – Sustained: Power level that is relatively high for a long period + of time, with very few to no periods of idleness, which will eventually + exhaust RAPL Power Limit 1 and 2. + + 3 – Bursty: Consumes a relatively constant average amount of power, but periods + of relative idleness are interrupted by bursts of activity. The bursts are + relatively short and the periods of relative idleness between them typically + prevent RAPL Power Limit 1 from being exhausted. + + 4 – Unknown: Can't classify.
drivers/thermal/intel/int340x_thermal/Makefile +1 -0
@@ -11,5 +11,6 @@ obj-$(CONFIG_PROC_THERMAL_MMIO_RAPL) += processor_thermal_rapl.o 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_INT3406_THERMAL) += int3406_thermal.o obj-$(CONFIG_ACPI_THERMAL_REL) += acpi_thermal_rel.o
drivers/thermal/intel/int340x_thermal/processor_thermal_device.c +9 -0
@@ -352,6 +352,12 @@ int proc_thermal_mmio_add(struct pci_dev *pdev,dev_err (&pdev->dev,"failed to add MBOX interface\n" ); goto err_rem_rfim; } + }else if (feature_mask &PROC_THERMAL_FEATURE_WT_HINT ) { + ret =proc_thermal_wt_hint_add (pdev, proc_priv); +if (ret) { +dev_err (&pdev->dev,"failed to add WT Hint\n" ); + goto err_rem_rfim; + } }return 0 ;
@@ -376,10 +382,13 @@ void proc_thermal_mmio_remove(struct pci_dev *pdev, struct proc_thermal_device *if (proc_priv->mmio_feature_mask &PROC_THERMAL_FEATURE_WT_REQ )proc_thermal_wt_req_remove (pdev); +else if (proc_priv->mmio_feature_mask &PROC_THERMAL_FEATURE_WT_HINT ) +proc_thermal_wt_hint_remove (pdev); }EXPORT_SYMBOL_GPL (proc_thermal_mmio_remove);MODULE_IMPORT_NS (INTEL_TCC ); +MODULE_IMPORT_NS (INT340X_THERMAL );MODULE_AUTHOR ("Srinivas Pandruvada <[email protected]>" );MODULE_DESCRIPTION ("Processor Thermal Reporting Device Driver" );MODULE_LICENSE ("GPL v2" );
drivers/thermal/intel/int340x_thermal/processor_thermal_device.h +7 -0
@@ -61,6 +61,7 @@ struct rapl_mmio_regs {#define PROC_THERMAL_FEATURE_DVFS 0x04#define PROC_THERMAL_FEATURE_WT_REQ 0x08#define PROC_THERMAL_FEATURE_DLVR 0x10 +#define PROC_THERMAL_FEATURE_WT_HINT 0x20#if IS_ENABLED (CONFIG_PROC_THERMAL_MMIO_RAPL )int proc_thermal_rapl_add (struct pci_dev *pdev,struct proc_thermal_device *proc_priv);
@@ -95,6 +96,12 @@ int processor_thermal_mbox_interrupt_config(struct pci_dev *pdev, bool enable, i int time_window);int proc_thermal_add (struct device *dev,struct proc_thermal_device *priv);void proc_thermal_remove (struct proc_thermal_device *proc_priv); + +int proc_thermal_wt_hint_add (struct pci_dev *pdev,struct proc_thermal_device *proc_priv); +void proc_thermal_wt_hint_remove (struct pci_dev *pdev); +void proc_thermal_wt_intr_callback (struct pci_dev *pdev,struct proc_thermal_device *proc_priv); +bool proc_thermal_check_wt_intr (struct proc_thermal_device *proc_priv); +int proc_thermal_suspend (struct device *dev);int proc_thermal_resume (struct device *dev); int proc_thermal_mmio_add(struct pci_dev *pdev,
drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c +2 -1
@@ -365,7 +365,8 @@ static const struct pci_device_id proc_thermal_pci_ids[] = { {PCI_DEVICE_DATA (INTEL ,ADL_THERMAL ,PROC_THERMAL_FEATURE_RAPL | 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_FIVR |PROC_THERMAL_FEATURE_DVFS |PROC_THERMAL_FEATURE_DLVR | + PROC_THERMAL_FEATURE_WT_HINT) }, { PCI_DEVICE_DATA(INTEL, RPL_THERMAL, PROC_THERMAL_FEATURE_RAPL | PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_WT_REQ) }, { },
drivers/thermal/intel/int340x_thermal/processor_thermal_wt_hint.c new file +253 -0
253 lines not on this page · raw message
Signature · 1 line
2.40.1
PATCH v3 6/7 thermal/drivers/int340x: Support workload hint interrupts
In reply to Srinivas PandruvadaOn thermal device interrupt, if the interrupt is generated for passing workload hint, call the callback to pass notification to the user space.
First call proc_thermal_check_wt_intr() to check interrupt, if this callback returns true, wake IRQ thread. Call proc_thermal_wt_intr_callback() to notify user space.
---
v3:
As suggested by Rafael:
- Undo the pkg_thermal_schedule_work() change to simlify
v2:
No change
.../processor_thermal_device_pci.c | 39 +++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-)
drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c +32 -7
@@ -122,20 +122,43 @@ static void pkg_thermal_schedule_work(struct delayed_work *work)schedule_delayed_work (work, ms); } +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); + +return IRQ_HANDLED ; +} +static irqreturn_t proc_thermal_irq_handler (int irq,void *devid) {struct proc_thermal_pci *pci_info = devid; +struct proc_thermal_device *proc_priv; +int ret =IRQ_HANDLED ;u32 status; -proc_thermal_mmio_read (pci_info,PROC_THERMAL_MMIO_INT_STATUS_0 , &status); + proc_priv = pci_info->proc_priv; -/* Disable enable interrupt flag */ -proc_thermal_mmio_write (pci_info,PROC_THERMAL_MMIO_INT_ENABLE_0 ,0 ); -pci_write_config_byte (pci_info->pdev,0xdc ,0x01 ); +if (proc_priv->mmio_feature_mask &PROC_THERMAL_FEATURE_WT_HINT ) { +if (proc_thermal_check_wt_intr (pci_info->proc_priv)) + ret =IRQ_WAKE_THREAD ; + } -pkg_thermal_schedule_work (&pci_info->work); +/* +* 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 +* interrupt before scheduling work function for thermal threshold. +*/ +proc_thermal_mmio_read (pci_info,PROC_THERMAL_MMIO_INT_STATUS_0 , &status); +if (status) { +/* Disable enable interrupt flag */ +proc_thermal_mmio_write (pci_info,PROC_THERMAL_MMIO_INT_ENABLE_0 ,0 ); +pci_write_config_byte (pci_info->pdev,0xdc ,0x01 ); +pkg_thermal_schedule_work (&pci_info->work); + } -return IRQ_HANDLED ; +return ret; }static int sys_get_curr_temp (struct thermal_zone_device *tzd,int *temp)
@@ -270,7 +293,7 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev, const struct pci_device_ } ret =devm_request_threaded_irq (&pdev->dev, irq, - proc_thermal_irq_handler,NULL , + proc_thermal_irq_handler, proc_thermal_irq_thread_handler, irq_flag,KBUILD_MODNAME , pci_info);if (ret) {dev_err (&pdev->dev,"Request IRQ %d failed\n" , pdev->irq);
@@ -384,6 +407,8 @@ static struct pci_driver proc_thermal_pci_driver = {module_pci_driver (proc_thermal_pci_driver); +MODULE_IMPORT_NS (INT340X_THERMAL ); +MODULE_AUTHOR ("Srinivas Pandruvada <[email protected]>" );MODULE_DESCRIPTION ("Processor Thermal Reporting Device Driver" );MODULE_LICENSE ("GPL v2" );
Signature · 1 line
2.40.1
PATCH v3 7/7 selftests/thermel/intel: Add test to read workload hint
In reply to Srinivas PandruvadaSome SoCs have in built firmware support to classify current running workload and pass to OS for making power management decisions.
This test program waits for notification of workload type change and prints. This program can be used to test this feature and also allows other user space programs to use as a reference.
---
v3:
No change
v2:
Add a signal handler for interrupting poll and exit Also moved inside intel/workload_type_hint foler Update Makefile
tools/testing/selftests/Makefile | 1 + .../thermal/intel/workload_hint/Makefile | 12 ++ .../intel/workload_hint/workload_hint_test.c | 157 ++++++++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 tools/testing/selftests/thermal/intel/workload_hint/Makefile create mode 100644 tools/testing/selftests/thermal/intel/workload_hint/workload_hint_test.c
tools/testing/selftests/Makefile +1 -0
@@ -85,6 +85,7 @@ TARGETS += syscall_user_dispatch TARGETS += sysctl TARGETS += tc-testing TARGETS += tdx +TARGETS += thermal/intel/workload_hint TARGETS += timens ifneq (1, $(quicktest)) TARGETS += timers
tools/testing/selftests/thermal/intel/workload_hint/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 := workload_hint_test + +include ../../../lib.mk + +endif +endif
tools/testing/selftests/thermal/intel/workload_hint/workload_hint_test.c new file +157 -0
157 lines not on this page · raw message
Signature · 1 line
2.40.1
Rafael J. Wysocki
maintainerQuoted 46 lines · Srinivas Pandruvada
Add support for Meteor Lake workload hints. Before adding this support, some reorganization and clean up is required.
First four changes are for clean up and to reorganize code to add support for workload hint. The last patch adds a test program as part of self tests.v3:
Changes in the commit log
Rename of files for using WT instead of WLT
Address comments from Rafael on v2v2:
Changes in comments and commit log
Self test program is improved to disable workloadtype notification on exitSrinivas Pandruvada (7):
thermal: int340x:processor_thermal: Move mailbox code to common
module
thermal: int340x:processor_thermal: Add interrupt configuration
thermal: int340x:processor_thermal: Use non MSI interrupts by default thermal/drivers/int340x: RemovePROC_THERMAL_FEATURE_WLT_REQfor
Meteor Lake
thermal: int340x:processor_thermal: Add workload type hint interface thermal/drivers/int340x: Support workload hint interrupts selftests/thermel/intel: Add test to read workload hint.../driver-api/thermal/intel_dptf.rst | 51 ++++ .../thermal/intel/int340x_thermal/Makefile | 2 + .../processor_thermal_device.c | 17 +- .../processor_thermal_device.h | 21 +- .../processor_thermal_device_pci.c | 79 ++++-- .../processor_thermal_device_pci_legacy.c | 3 +- .../int340x_thermal/processor_thermal_mbox.c | 179 ++++--------- .../processor_thermal_wt_hint.c | 252 ++++++++++++++++++ .../processor_thermal_wt_req.c | 136 ++++++++++ tools/testing/selftests/Makefile | 1 + .../thermal/intel/workload_hint/Makefile | 12 + .../intel/workload_hint/workload_hint_test.c | 157 +++++++++++ 12 files changed, 752 insertions(+), 158 deletions(-) create mode 100644 drivers/thermal/intel/int340x_thermal/processor_thermal_wt_hint.c create mode 100644 drivers/thermal/intel/int340x_thermal/processor_thermal_wt_req.c create mode 100644 tools/testing/selftests/thermal/intel/workload_hint/Makefile create mode 100644 tools/testing/selftests/thermal/intel/workload_hint/workload_hint_test.c
Quoted 1 line
--
There is a slight issue with the patch ordering in this series, because the interface to enable the interrupt should only be provided after implementing the interrupt handlers. I don't think that anyone will apply the series partially and try to enable the feature, though.
Also, I'm not actually sure if proc_thermal_wt_intr_callback() can run safely against the work item scheduled in proc_thermal_irq_handler() in case the workload hint one triggers along with a thermal threshold one. I think that the access to MMIO is cached, so what if they both try to update the same cache line at the same time? Or are they guaranteed to be different cache lines?
Anyway, tentatively applied as 6.7 material, but I've changed the second patch somewhat, because I couldn't convince myself that the implicit type conversions in processor_thermal_mbox_interrupt_config() would always do the right thing regardless of the numbers involved, so please check the result in my bleeding-edge branch.
Thanks!
Hi Rafael,
Quoted 4 lines · Rafael J. Wysocki
Quoted 2 lines · Srinivas Pandruvada
[...]
Quoted 7 lines
Quoted 1 line
--
There is a slight issue with the patch ordering in this series, because the interface to enable the interrupt should only be provided after implementing the interrupt handlers. I don't think that anyone will apply the series partially and try to enable the feature, though.
Thanks!
Quoted 8 lines
Also, I'm not actually sure if
proc_thermal_wt_intr_callback()can run
safely against the work item scheduled inproc_thermal_irq_handler()in case the workload hint one triggers along with a thermal threshold one. I think that the access to MMIO is cached, so what if they both try to update the same cache line at the same time? Or are they guaranteed to be different cache lines?
These two registers are 90 cache lines apart. Looking at all the registers on this bar for status offsets, they are several cache lines apart. Also this bar is non prefetchable, so continuous data can't be fetched ahead.
Quoted 9 lines
Anyway, tentatively applied as 6.7 material, but I've changed the second patch somewhat, because I couldn't convince myself that the implicit type conversions in
processor_thermal_mbox_interrupt_config()
would always do the right thing regardless of the numbers involved, so
please check the result in my bleeding-edge branch.
If I diff, there is only one change in processor_thermal_mbox.c. Tested that change and works fine.
Thanks,
Srinivas
Quoted 1 line
Thanks!
Rafael J. Wysocki
maintainerQuoted 28 lines · srinivas pandruvada
Hi Rafael,
Quoted 4 lines · Rafael J. Wysocki
Quoted 2 lines · Srinivas Pandruvada
[...]
Quoted 7 lines
Quoted 1 line
--
There is a slight issue with the patch ordering in this series, because the interface to enable the interrupt should only be provided after implementing the interrupt handlers. I don't think that anyone will apply the series partially and try to enable the feature, though.
Thanks!
Quoted 8 lines
Also, I'm not actually sure if
proc_thermal_wt_intr_callback()can run
safely against the work item scheduled inproc_thermal_irq_handler()in case the workload hint one triggers along with a thermal threshold one. I think that the access to MMIO is cached, so what if they both try to update the same cache line at the same time? Or are they guaranteed to be different cache lines?
Quoted 4 lines
These two registers are 90 cache lines apart. Looking at all the registers on this bar for status offsets, they are several cache lines apart. Also this bar is non prefetchable, so continuous data can't be fetched ahead.
OK
Quoted 11 lines
Quoted 9 lines
Anyway, tentatively applied as 6.7 material, but I've changed the second patch somewhat, because I couldn't convince myself that the implicit type conversions in
processor_thermal_mbox_interrupt_config()
would always do the right thing regardless of the numbers involved, so
please check the result in my bleeding-edge branch.If I diff, there is only one change in
processor_thermal_mbox.c. Tested that change and works fine.
Good, thanks!