Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'thermal-5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm

Pull thermal control updates from Rafael Wysocki:
"As far as new functionality is concerned, there is a new thermal
driver for the Intel Hardware Feedback Interface (HFI) along with some
intel-speed-select utility changes to support it. There are also new
DT compatible strings for a couple of platforms, and thermal zones on
some platforms will be registered as HWmon sensors now.

Apart from the above, some drivers are updated (fixes mostly) and
there is a new piece of documentation for the Intel DPTF (Dynamic
Power and Thermal Framework) sysfs interface.

Specifics:

- Add a new thermal driver for the Intel Hardware Feedback Interface
(HFI) including the HFI initialization, HFI notification interrupt
handling and sending CPU capabilities change messages to user space
via the thermal netlink interface (Ricardo Neri, Srinivas
Pandruvada, Nathan Chancellor, Randy Dunlap).

- Extend the intel-speed-select utility to handle out-of-band CPU
configuration changes and add support for the CPU capabilities
change messages sent over the thermal netlink interface by the new
HFI thermal driver to it (Srinivas Pandruvada).

- Convert the DT bindings to yaml format for the Exynos platform and
fix and update the MAINTAINERS file for this driver (Krzysztof
Kozlowski).

- Register the thermal zones as HWmon sensors for the QCom's Tsens
driver and TI thermal platforms (Dmitry Baryshkov, Romain Naour).

- Add the msm8953 compatible documentation in the bindings (Luca
Weiss).

- Add the sm8150 platform support to the QCom LMh driver's DT binding
(Thara Gopinath).

- Check the command result from the IPC command to the BPMP in the
Tegra driver (Mikko Perttunen).

- Silence the error for normal configuration where the interrupt is
optionnal in the Broadcom thermal driver (Florian Fainelli).

- Remove remaining dead code from the TI thermal driver (Yue
Haibing).

- Don't use bitmap_weight() in end_power_clamp() in the powerclamp
driver (Yury Norov).

- Update the OS policy capabilities handshake in the int340x thermal
driver (Srinivas Pandruvada).

- Increase the policies bitmap size in int340x (Srinivas Pandruvada).

- Replace acpi_bus_get_device() with acpi_fetch_acpi_dev() in the
int340x thermal driver (Rafael Wysocki).

- Check for NULL after calling kmemdup() in int340x (Jiasheng Jiang).

- Add Intel Dynamic Power and Thermal Framework (DPTF) kernel
interface documentation (Srinivas Pandruvada).

- Fix bullet list warning in the thermal documentation (Randy
Dunlap)"

* tag 'thermal-5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (30 commits)
thermal: int340x: Update OS policy capability handshake
thermal: int340x: Increase bitmap size
Documentation: thermal: DPTF Documentation
MAINTAINERS: thermal: samsung: update Krzysztof Kozlowski's email
thermal/drivers/ti-soc-thermal: Remove unused function ti_thermal_get_temp()
thermal/drivers/brcmstb_thermal: Interrupt is optional
thermal: tegra-bpmp: Handle errors in BPMP response
drivers/thermal/ti-soc-thermal: Add hwmon support
dt-bindings: thermal: tsens: Add msm8953 compatible
dt-bindings: thermal: Add sm8150 compatible string for LMh
thermal/drivers/qcom/lmh: Add support for sm8150
thermal/drivers/tsens: register thermal zones as hwmon sensors
MAINTAINERS: thermal: samsung: Drop obsolete properties
dt-bindings: thermal: samsung: Convert to dtschema
tools/power/x86/intel-speed-select: v1.12 release
tools/power/x86/intel-speed-select: HFI support
tools/power/x86/intel-speed-select: OOB daemon mode
thermal: intel: hfi: INTEL_HFI_THERMAL depends on NET
thermal: netlink: Fix parameter type of thermal_genl_cpu_capability_event() stub
thermal: Replace acpi_bus_get_device()
...

+2022 -231
+1 -1
Documentation/ABI/testing/sysfs-class-thermal
··· 203 203 204 204 - for generic ACPI: should be "Fan", "Processor" or "LCD" 205 205 - for memory controller device on intel_menlow platform: 206 - should be "Memory controller". 206 + should be "Memory controller". 207 207 208 208 RO, Required 209 209
-106
Documentation/devicetree/bindings/thermal/exynos-thermal.txt
··· 1 - * Exynos Thermal Management Unit (TMU) 2 - 3 - ** Required properties: 4 - 5 - - compatible : One of the following: 6 - "samsung,exynos3250-tmu" 7 - "samsung,exynos4412-tmu" 8 - "samsung,exynos4210-tmu" 9 - "samsung,exynos5250-tmu" 10 - "samsung,exynos5260-tmu" 11 - "samsung,exynos5420-tmu" for TMU channel 0, 1 on Exynos5420 12 - "samsung,exynos5420-tmu-ext-triminfo" for TMU channels 2, 3 and 4 13 - Exynos5420 (Must pass triminfo base and triminfo clock) 14 - "samsung,exynos5433-tmu" 15 - "samsung,exynos7-tmu" 16 - - reg : Address range of the thermal registers. For soc's which has multiple 17 - instances of TMU and some registers are shared across all TMU's like 18 - interrupt related then 2 set of register has to supplied. First set 19 - belongs to register set of TMU instance and second set belongs to 20 - registers shared with the TMU instance. 21 - 22 - NOTE: On Exynos5420, the TRIMINFO register is misplaced for TMU 23 - channels 2, 3 and 4 24 - Use "samsung,exynos5420-tmu-ext-triminfo" in cases, there is a misplaced 25 - register, also provide clock to access that base. 26 - 27 - TRIMINFO at 0x1006c000 contains data for TMU channel 3 28 - TRIMINFO at 0x100a0000 contains data for TMU channel 4 29 - TRIMINFO at 0x10068000 contains data for TMU channel 2 30 - 31 - - interrupts : Should contain interrupt for thermal system 32 - - clocks : The main clocks for TMU device 33 - -- 1. operational clock for TMU channel 34 - -- 2. optional clock to access the shared registers of TMU channel 35 - -- 3. optional special clock for functional operation 36 - - clock-names : Thermal system clock name 37 - -- "tmu_apbif" operational clock for current TMU channel 38 - -- "tmu_triminfo_apbif" clock to access the shared triminfo register 39 - for current TMU channel 40 - -- "tmu_sclk" clock for functional operation of the current TMU 41 - channel 42 - 43 - The Exynos TMU supports generating interrupts when reaching given 44 - temperature thresholds. Number of supported thermal trip points depends 45 - on the SoC (only first trip points defined in DT will be configured): 46 - - most of SoC: 4 47 - - samsung,exynos5433-tmu: 8 48 - - samsung,exynos7-tmu: 8 49 - 50 - ** Optional properties: 51 - 52 - - vtmu-supply: This entry is optional and provides the regulator node supplying 53 - voltage to TMU. If needed this entry can be placed inside 54 - board/platform specific dts file. 55 - 56 - Example 1): 57 - 58 - tmu@100c0000 { 59 - compatible = "samsung,exynos4412-tmu"; 60 - interrupt-parent = <&combiner>; 61 - reg = <0x100C0000 0x100>; 62 - interrupts = <2 4>; 63 - clocks = <&clock 383>; 64 - clock-names = "tmu_apbif"; 65 - vtmu-supply = <&tmu_regulator_node>; 66 - #thermal-sensor-cells = <0>; 67 - }; 68 - 69 - Example 2): (In case of Exynos5420 "with misplaced TRIMINFO register") 70 - tmu_cpu2: tmu@10068000 { 71 - compatible = "samsung,exynos5420-tmu-ext-triminfo"; 72 - reg = <0x10068000 0x100>, <0x1006c000 0x4>; 73 - interrupts = <0 184 0>; 74 - clocks = <&clock 318>, <&clock 318>; 75 - clock-names = "tmu_apbif", "tmu_triminfo_apbif"; 76 - #thermal-sensor-cells = <0>; 77 - }; 78 - 79 - tmu_cpu3: tmu@1006c000 { 80 - compatible = "samsung,exynos5420-tmu-ext-triminfo"; 81 - reg = <0x1006c000 0x100>, <0x100a0000 0x4>; 82 - interrupts = <0 185 0>; 83 - clocks = <&clock 318>, <&clock 319>; 84 - clock-names = "tmu_apbif", "tmu_triminfo_apbif"; 85 - #thermal-sensor-cells = <0>; 86 - }; 87 - 88 - tmu_gpu: tmu@100a0000 { 89 - compatible = "samsung,exynos5420-tmu-ext-triminfo"; 90 - reg = <0x100a0000 0x100>, <0x10068000 0x4>; 91 - interrupts = <0 215 0>; 92 - clocks = <&clock 319>, <&clock 318>; 93 - clock-names = "tmu_apbif", "tmu_triminfo_apbif"; 94 - #thermal-sensor-cells = <0>; 95 - }; 96 - 97 - Note: For multi-instance tmu each instance should have an alias correctly 98 - numbered in "aliases" node. 99 - 100 - Example: 101 - 102 - aliases { 103 - tmuctrl0 = &tmuctrl_0; 104 - tmuctrl1 = &tmuctrl_1; 105 - tmuctrl2 = &tmuctrl_2; 106 - };
+1
Documentation/devicetree/bindings/thermal/qcom-lmh.yaml
··· 19 19 compatible: 20 20 enum: 21 21 - qcom,sdm845-lmh 22 + - qcom,sm8150-lmh 22 23 23 24 reg: 24 25 items:
+1
Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
··· 43 43 - description: v2 of TSENS 44 44 items: 45 45 - enum: 46 + - qcom,msm8953-tsens 46 47 - qcom,msm8996-tsens 47 48 - qcom,msm8998-tsens 48 49 - qcom,sc7180-tsens
+184
Documentation/devicetree/bindings/thermal/samsung,exynos-thermal.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/thermal/samsung,exynos-thermal.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Samsung Exynos SoC Thermal Management Unit (TMU) 8 + 9 + maintainers: 10 + - Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com> 11 + 12 + description: | 13 + For multi-instance tmu each instance should have an alias correctly numbered 14 + in "aliases" node. 15 + 16 + properties: 17 + compatible: 18 + enum: 19 + - samsung,exynos3250-tmu 20 + - samsung,exynos4412-tmu 21 + - samsung,exynos4210-tmu 22 + - samsung,exynos5250-tmu 23 + - samsung,exynos5260-tmu 24 + # For TMU channel 0, 1 on Exynos5420: 25 + - samsung,exynos5420-tmu 26 + # For TMU channels 2, 3 and 4 of Exynos5420: 27 + - samsung,exynos5420-tmu-ext-triminfo 28 + - samsung,exynos5433-tmu 29 + - samsung,exynos7-tmu 30 + 31 + clocks: 32 + minItems: 1 33 + maxItems: 3 34 + 35 + clock-names: 36 + minItems: 1 37 + maxItems: 3 38 + 39 + interrupts: 40 + description: | 41 + The Exynos TMU supports generating interrupts when reaching given 42 + temperature thresholds. Number of supported thermal trip points depends 43 + on the SoC (only first trip points defined in DT will be configured):: 44 + - most of SoC: 4 45 + - samsung,exynos5433-tmu: 8 46 + - samsung,exynos7-tmu: 8 47 + maxItems: 1 48 + 49 + reg: 50 + items: 51 + - description: TMU instance registers. 52 + - description: | 53 + Shared TMU registers. 54 + 55 + Note:: On Exynos5420, the TRIMINFO register is misplaced for TMU 56 + channels 2, 3 and 4 Use "samsung,exynos5420-tmu-ext-triminfo" in 57 + cases, there is a misplaced register, also provide clock to access 58 + that base. 59 + TRIMINFO at 0x1006c000 contains data for TMU channel 3 60 + TRIMINFO at 0x100a0000 contains data for TMU channel 4 61 + TRIMINFO at 0x10068000 contains data for TMU channel 2 62 + minItems: 1 63 + 64 + '#thermal-sensor-cells': true 65 + 66 + vtmu-supply: 67 + description: The regulator node supplying voltage to TMU. 68 + 69 + required: 70 + - compatible 71 + - clocks 72 + - clock-names 73 + - interrupts 74 + - reg 75 + 76 + allOf: 77 + - $ref: /schemas/thermal/thermal-sensor.yaml 78 + - if: 79 + properties: 80 + compatible: 81 + contains: 82 + const: samsung,exynos5420-tmu-ext-triminfo 83 + then: 84 + properties: 85 + clocks: 86 + items: 87 + - description: 88 + Operational clock for TMU channel. 89 + - description: 90 + Optional clock to access the shared registers (e.g. TRIMINFO) of TMU 91 + channel. 92 + clock-names: 93 + items: 94 + - const: tmu_apbif 95 + - const: tmu_triminfo_apbif 96 + reg: 97 + minItems: 2 98 + maxItems: 2 99 + - if: 100 + properties: 101 + compatible: 102 + contains: 103 + enum: 104 + - samsung,exynos5433-tmu 105 + - samsung,exynos7-tmu 106 + then: 107 + properties: 108 + clocks: 109 + items: 110 + - description: 111 + Operational clock for TMU channel. 112 + - description: 113 + Optional special clock for functional operation of TMU channel. 114 + clock-names: 115 + items: 116 + - const: tmu_apbif 117 + - const: tmu_sclk 118 + reg: 119 + minItems: 1 120 + maxItems: 1 121 + 122 + - if: 123 + properties: 124 + compatible: 125 + contains: 126 + enum: 127 + - samsung,exynos3250-tmu 128 + - samsung,exynos4412-tmu 129 + - samsung,exynos4210-tmu 130 + - samsung,exynos5250-tmu 131 + - samsung,exynos5260-tmu 132 + - samsung,exynos5420-tmu 133 + then: 134 + properties: 135 + clocks: 136 + minItems: 1 137 + maxItems: 1 138 + reg: 139 + minItems: 1 140 + maxItems: 1 141 + 142 + additionalProperties: false 143 + 144 + examples: 145 + - | 146 + #include <dt-bindings/clock/exynos4.h> 147 + 148 + tmu@100c0000 { 149 + compatible = "samsung,exynos4412-tmu"; 150 + reg = <0x100C0000 0x100>; 151 + interrupt-parent = <&combiner>; 152 + interrupts = <2 4>; 153 + #thermal-sensor-cells = <0>; 154 + clocks = <&clock CLK_TMU_APBIF>; 155 + clock-names = "tmu_apbif"; 156 + vtmu-supply = <&ldo10_reg>; 157 + }; 158 + 159 + - | 160 + #include <dt-bindings/interrupt-controller/arm-gic.h> 161 + 162 + tmu@10068000 { 163 + compatible = "samsung,exynos5420-tmu-ext-triminfo"; 164 + reg = <0x10068000 0x100>, <0x1006c000 0x4>; 165 + interrupts = <GIC_SPI 184 IRQ_TYPE_LEVEL_HIGH>; 166 + #thermal-sensor-cells = <0>; 167 + clocks = <&clock 318>, <&clock 318>; /* CLK_TMU */ 168 + clock-names = "tmu_apbif", "tmu_triminfo_apbif"; 169 + vtmu-supply = <&ldo7_reg>; 170 + }; 171 + 172 + - | 173 + #include <dt-bindings/interrupt-controller/arm-gic.h> 174 + 175 + tmu@10060000 { 176 + compatible = "samsung,exynos5433-tmu"; 177 + reg = <0x10060000 0x200>; 178 + interrupts = <GIC_SPI 95 IRQ_TYPE_LEVEL_HIGH>; 179 + #thermal-sensor-cells = <0>; 180 + clocks = <&cmu_peris 3>, /* CLK_PCLK_TMU0_APBIF */ 181 + <&cmu_peris 35>; /* CLK_SCLK_TMU0 */ 182 + clock-names = "tmu_apbif", "tmu_sclk"; 183 + vtmu-supply = <&ldo3_reg>; 184 + };
+1
Documentation/driver-api/thermal/index.rst
··· 17 17 intel_powerclamp 18 18 nouveau_thermal 19 19 x86_pkg_temperature_thermal 20 + intel_dptf
+272
Documentation/driver-api/thermal/intel_dptf.rst
··· 1 + .. SPDX-License-Identifier: GPL-2.0 2 + 3 + =============================================================== 4 + Intel(R) Dynamic Platform and Thermal Framework Sysfs Interface 5 + =============================================================== 6 + 7 + :Copyright: |copy| 2022 Intel Corporation 8 + 9 + :Author: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> 10 + 11 + Introduction 12 + ------------ 13 + 14 + Intel(R) Dynamic Platform and Thermal Framework (DPTF) is a platform 15 + level hardware/software solution for power and thermal management. 16 + 17 + As a container for multiple power/thermal technologies, DPTF provides 18 + a coordinated approach for different policies to effect the hardware 19 + state of a system. 20 + 21 + Since it is a platform level framework, this has several components. 22 + Some parts of the technology is implemented in the firmware and uses 23 + ACPI and PCI devices to expose various features for monitoring and 24 + control. Linux has a set of kernel drivers exposing hardware interface 25 + to user space. This allows user space thermal solutions like 26 + "Linux Thermal Daemon" to read platform specific thermal and power 27 + tables to deliver adequate performance while keeping the system under 28 + thermal limits. 29 + 30 + DPTF ACPI Drivers interface 31 + ---------------------------- 32 + 33 + :file:`/sys/bus/platform/devices/<N>/uuids`, where <N> 34 + =INT3400|INTC1040|INTC1041|INTC10A0 35 + 36 + ``available_uuids`` (RO) 37 + A set of UUIDs strings presenting available policies 38 + which should be notified to the firmware when the 39 + user space can support those policies. 40 + 41 + UUID strings: 42 + 43 + "42A441D6-AE6A-462b-A84B-4A8CE79027D3" : Passive 1 44 + 45 + "3A95C389-E4B8-4629-A526-C52C88626BAE" : Active 46 + 47 + "97C68AE7-15FA-499c-B8C9-5DA81D606E0A" : Critical 48 + 49 + "63BE270F-1C11-48FD-A6F7-3AF253FF3E2D" : Adaptive performance 50 + 51 + "5349962F-71E6-431D-9AE8-0A635B710AEE" : Emergency call 52 + 53 + "9E04115A-AE87-4D1C-9500-0F3E340BFE75" : Passive 2 54 + 55 + "F5A35014-C209-46A4-993A-EB56DE7530A1" : Power Boss 56 + 57 + "6ED722A7-9240-48A5-B479-31EEF723D7CF" : Virtual Sensor 58 + 59 + "16CAF1B7-DD38-40ED-B1C1-1B8A1913D531" : Cooling mode 60 + 61 + "BE84BABF-C4D4-403D-B495-3128FD44dAC1" : HDC 62 + 63 + ``current_uuid`` (RW) 64 + User space can write strings from available UUIDs, one at a 65 + time. 66 + 67 + :file:`/sys/bus/platform/devices/<N>/`, where <N> 68 + =INT3400|INTC1040|INTC1041|INTC10A0 69 + 70 + ``imok`` (WO) 71 + User space daemon write 1 to respond to firmware event 72 + for sending keep alive notification. User space receives 73 + THERMAL_EVENT_KEEP_ALIVE kobject uevent notification when 74 + firmware calls for user space to respond with imok ACPI 75 + method. 76 + 77 + ``odvp*`` (RO) 78 + Firmware thermal status variable values. Thermal tables 79 + calls for different processing based on these variable 80 + values. 81 + 82 + ``data_vault`` (RO) 83 + Binary thermal table. Refer to 84 + https:/github.com/intel/thermal_daemon for decoding 85 + thermal table. 86 + 87 + 88 + ACPI Thermal Relationship table interface 89 + ------------------------------------------ 90 + 91 + :file:`/dev/acpi_thermal_rel` 92 + 93 + This device provides IOCTL interface to read standard ACPI 94 + thermal relationship tables via ACPI methods _TRT and _ART. 95 + These IOCTLs are defined in 96 + drivers/thermal/intel/int340x_thermal/acpi_thermal_rel.h 97 + 98 + IOCTLs: 99 + 100 + ACPI_THERMAL_GET_TRT_LEN: Get length of TRT table 101 + 102 + ACPI_THERMAL_GET_ART_LEN: Get length of ART table 103 + 104 + ACPI_THERMAL_GET_TRT_COUNT: Number of records in TRT table 105 + 106 + ACPI_THERMAL_GET_ART_COUNT: Number of records in ART table 107 + 108 + ACPI_THERMAL_GET_TRT: Read binary TRT table, length to read is 109 + provided via argument to ioctl(). 110 + 111 + ACPI_THERMAL_GET_ART: Read binary ART table, length to read is 112 + provided via argument to ioctl(). 113 + 114 + DPTF ACPI Sensor drivers 115 + ------------------------- 116 + 117 + DPTF Sensor drivers are presented as standard thermal sysfs thermal_zone. 118 + 119 + 120 + DPTF ACPI Cooling drivers 121 + -------------------------- 122 + 123 + DPTF cooling drivers are presented as standard thermal sysfs cooling_device. 124 + 125 + 126 + DPTF Processor thermal PCI Driver interface 127 + -------------------------------------------- 128 + 129 + :file:`/sys/bus/pci/devices/0000\:00\:04.0/power_limits/` 130 + 131 + Refer to Documentation/power/powercap/powercap.rst for powercap 132 + ABI. 133 + 134 + ``power_limit_0_max_uw`` (RO) 135 + Maximum powercap sysfs constraint_0_power_limit_uw for Intel RAPL 136 + 137 + ``power_limit_0_step_uw`` (RO) 138 + Power limit increment/decrements for Intel RAPL constraint 0 power limit 139 + 140 + ``power_limit_0_min_uw`` (RO) 141 + Minimum powercap sysfs constraint_0_power_limit_uw for Intel RAPL 142 + 143 + ``power_limit_0_tmin_us`` (RO) 144 + Minimum powercap sysfs constraint_0_time_window_us for Intel RAPL 145 + 146 + ``power_limit_0_tmax_us`` (RO) 147 + Maximum powercap sysfs constraint_0_time_window_us for Intel RAPL 148 + 149 + ``power_limit_1_max_uw`` (RO) 150 + Maximum powercap sysfs constraint_1_power_limit_uw for Intel RAPL 151 + 152 + ``power_limit_1_step_uw`` (RO) 153 + Power limit increment/decrements for Intel RAPL constraint 1 power limit 154 + 155 + ``power_limit_1_min_uw`` (RO) 156 + Minimum powercap sysfs constraint_1_power_limit_uw for Intel RAPL 157 + 158 + ``power_limit_1_tmin_us`` (RO) 159 + Minimum powercap sysfs constraint_1_time_window_us for Intel RAPL 160 + 161 + ``power_limit_1_tmax_us`` (RO) 162 + Maximum powercap sysfs constraint_1_time_window_us for Intel RAPL 163 + 164 + :file:`/sys/bus/pci/devices/0000\:00\:04.0/` 165 + 166 + ``tcc_offset_degree_celsius`` (RW) 167 + TCC offset from the critical temperature where hardware will throttle 168 + CPU. 169 + 170 + :file:`/sys/bus/pci/devices/0000\:00\:04.0/workload_request` 171 + 172 + ``workload_available_types`` (RO) 173 + Available workload types. User space can specify one of the workload type 174 + it is currently executing via workload_type. For example: idle, bursty, 175 + sustained etc. 176 + 177 + ``workload_type`` (RW) 178 + User space can specify any one of the available workload type using 179 + this interface. 180 + 181 + DPTF Processor thermal RFIM interface 182 + -------------------------------------------- 183 + 184 + RFIM interface allows adjustment of FIVR (Fully Integrated Voltage Regulator) 185 + and DDR (Double Data Rate)frequencies to avoid RF interference with WiFi and 5G. 186 + 187 + Switching voltage regulators (VR) generate radiated EMI or RFI at the 188 + fundamental frequency and its harmonics. Some harmonics may interfere 189 + with very sensitive wireless receivers such as Wi-Fi and cellular that 190 + are integrated into host systems like notebook PCs. One of mitigation 191 + methods is requesting SOC integrated VR (IVR) switching frequency to a 192 + small % and shift away the switching noise harmonic interference from 193 + radio channels. OEM or ODMs can use the driver to control SOC IVR 194 + operation within the range where it does not impact IVR performance. 195 + 196 + DRAM devices of DDR IO interface and their power plane can generate EMI 197 + at the data rates. Similar to IVR control mechanism, Intel offers a 198 + mechanism by which DDR data rates can be changed if several conditions 199 + are met: there is strong RFI interference because of DDR; CPU power 200 + management has no other restriction in changing DDR data rates; 201 + PC ODMs enable this feature (real time DDR RFI Mitigation referred to as 202 + DDR-RFIM) for Wi-Fi from BIOS. 203 + 204 + 205 + FIVR attributes 206 + 207 + :file:`/sys/bus/pci/devices/0000\:00\:04.0/fivr/` 208 + 209 + ``vco_ref_code_lo`` (RW) 210 + The VCO reference code is an 11-bit field and controls the FIVR 211 + switching frequency. This is the 3-bit LSB field. 212 + 213 + ``vco_ref_code_hi`` (RW) 214 + The VCO reference code is an 11-bit field and controls the FIVR 215 + switching frequency. This is the 8-bit MSB field. 216 + 217 + ``spread_spectrum_pct`` (RW) 218 + Set the FIVR spread spectrum clocking percentage 219 + 220 + ``spread_spectrum_clk_enable`` (RW) 221 + Enable/disable of the FIVR spread spectrum clocking feature 222 + 223 + ``rfi_vco_ref_code`` (RW) 224 + This field is a read only status register which reflects the 225 + current FIVR switching frequency 226 + 227 + ``fivr_fffc_rev`` (RW) 228 + This field indicated the revision of the FIVR HW. 229 + 230 + 231 + DVFS attributes 232 + 233 + :file:`/sys/bus/pci/devices/0000\:00\:04.0/dvfs/` 234 + 235 + ``rfi_restriction_run_busy`` (RW) 236 + Request the restriction of specific DDR data rate and set this 237 + value 1. Self reset to 0 after operation. 238 + 239 + ``rfi_restriction_err_code`` (RW) 240 + 0 :Request is accepted, 1:Feature disabled, 241 + 2: the request restricts more points than it is allowed 242 + 243 + ``rfi_restriction_data_rate_Delta`` (RW) 244 + Restricted DDR data rate for RFI protection: Lower Limit 245 + 246 + ``rfi_restriction_data_rate_Base`` (RW) 247 + Restricted DDR data rate for RFI protection: Upper Limit 248 + 249 + ``ddr_data_rate_point_0`` (RO) 250 + DDR data rate selection 1st point 251 + 252 + ``ddr_data_rate_point_1`` (RO) 253 + DDR data rate selection 2nd point 254 + 255 + ``ddr_data_rate_point_2`` (RO) 256 + DDR data rate selection 3rd point 257 + 258 + ``ddr_data_rate_point_3`` (RO) 259 + DDR data rate selection 4th point 260 + 261 + ``rfi_disable (RW)`` 262 + Disable DDR rate change feature 263 + 264 + DPTF Power supply and Battery Interface 265 + ---------------------------------------- 266 + 267 + Refer to Documentation/ABI/testing/sysfs-platform-dptf 268 + 269 + DPTF Fan Control 270 + ---------------------------------------- 271 + 272 + Refer to Documentation/admin-guide/acpi/fan_performance_states.rst
+1
Documentation/x86/index.rst
··· 21 21 tlb 22 22 mtrr 23 23 pat 24 + intel-hfi 24 25 intel-iommu 25 26 intel_txt 26 27 amd-memory-encryption
+72
Documentation/x86/intel-hfi.rst
··· 1 + .. SPDX-License-Identifier: GPL-2.0 2 + 3 + ============================================================ 4 + Hardware-Feedback Interface for scheduling on Intel Hardware 5 + ============================================================ 6 + 7 + Overview 8 + -------- 9 + 10 + Intel has described the Hardware Feedback Interface (HFI) in the Intel 64 and 11 + IA-32 Architectures Software Developer's Manual (Intel SDM) Volume 3 Section 12 + 14.6 [1]_. 13 + 14 + The HFI gives the operating system a performance and energy efficiency 15 + capability data for each CPU in the system. Linux can use the information from 16 + the HFI to influence task placement decisions. 17 + 18 + The Hardware Feedback Interface 19 + ------------------------------- 20 + 21 + The Hardware Feedback Interface provides to the operating system information 22 + about the performance and energy efficiency of each CPU in the system. Each 23 + capability is given as a unit-less quantity in the range [0-255]. Higher values 24 + indicate higher capability. Energy efficiency and performance are reported in 25 + separate capabilities. Even though on some systems these two metrics may be 26 + related, they are specified as independent capabilities in the Intel SDM. 27 + 28 + These capabilities may change at runtime as a result of changes in the 29 + operating conditions of the system or the action of external factors. The rate 30 + at which these capabilities are updated is specific to each processor model. On 31 + some models, capabilities are set at boot time and never change. On others, 32 + capabilities may change every tens of milliseconds. For instance, a remote 33 + mechanism may be used to lower Thermal Design Power. Such change can be 34 + reflected in the HFI. Likewise, if the system needs to be throttled due to 35 + excessive heat, the HFI may reflect reduced performance on specific CPUs. 36 + 37 + The kernel or a userspace policy daemon can use these capabilities to modify 38 + task placement decisions. For instance, if either the performance or energy 39 + capabilities of a given logical processor becomes zero, it is an indication that 40 + the hardware recommends to the operating system to not schedule any tasks on 41 + that processor for performance or energy efficiency reasons, respectively. 42 + 43 + Implementation details for Linux 44 + -------------------------------- 45 + 46 + The infrastructure to handle thermal event interrupts has two parts. In the 47 + Local Vector Table of a CPU's local APIC, there exists a register for the 48 + Thermal Monitor Register. This register controls how interrupts are delivered 49 + to a CPU when the thermal monitor generates and interrupt. Further details 50 + can be found in the Intel SDM Vol. 3 Section 10.5 [1]_. 51 + 52 + The thermal monitor may generate interrupts per CPU or per package. The HFI 53 + generates package-level interrupts. This monitor is configured and initialized 54 + via a set of machine-specific registers. Specifically, the HFI interrupt and 55 + status are controlled via designated bits in the IA32_PACKAGE_THERM_INTERRUPT 56 + and IA32_PACKAGE_THERM_STATUS registers, respectively. There exists one HFI 57 + table per package. Further details can be found in the Intel SDM Vol. 3 58 + Section 14.9 [1]_. 59 + 60 + The hardware issues an HFI interrupt after updating the HFI table and is ready 61 + for the operating system to consume it. CPUs receive such interrupt via the 62 + thermal entry in the Local APIC's Local Vector Table. 63 + 64 + When servicing such interrupt, the HFI driver parses the updated table and 65 + relays the update to userspace using the thermal notification framework. Given 66 + that there may be many HFI updates every second, the updates relayed to 67 + userspace are throttled at a rate of CONFIG_HZ jiffies. 68 + 69 + References 70 + ---------- 71 + 72 + .. [1] https://www.intel.com/sdm
+4 -3
MAINTAINERS
··· 17143 17143 F: drivers/net/ethernet/samsung/sxgbe/ 17144 17144 17145 17145 SAMSUNG THERMAL DRIVER 17146 - M: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> 17146 + M: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> 17147 + M: Krzysztof Kozlowski <krzk@kernel.org> 17147 17148 L: linux-pm@vger.kernel.org 17148 17149 L: linux-samsung-soc@vger.kernel.org 17149 - S: Supported 17150 - T: git https://github.com/lmajewski/linux-samsung-thermal.git 17150 + S: Maintained 17151 + F: Documentation/devicetree/bindings/thermal/samsung,exynos-thermal.yaml 17151 17152 F: drivers/thermal/samsung/ 17152 17153 17153 17154 SAMSUNG USB2 PHY DRIVER
+1
arch/x86/include/asm/cpufeatures.h
··· 327 327 #define X86_FEATURE_HWP_ACT_WINDOW (14*32+ 9) /* HWP Activity Window */ 328 328 #define X86_FEATURE_HWP_EPP (14*32+10) /* HWP Energy Perf. Preference */ 329 329 #define X86_FEATURE_HWP_PKG_REQ (14*32+11) /* HWP Package Level Request */ 330 + #define X86_FEATURE_HFI (14*32+19) /* Hardware Feedback Interface */ 330 331 331 332 /* AMD SVM Feature Identification, CPUID level 0x8000000a (EDX), word 15 */ 332 333 #define X86_FEATURE_NPT (15*32+ 0) /* Nested Page Table support */
+6
arch/x86/include/asm/msr-index.h
··· 705 705 706 706 #define PACKAGE_THERM_STATUS_PROCHOT (1 << 0) 707 707 #define PACKAGE_THERM_STATUS_POWER_LIMIT (1 << 10) 708 + #define PACKAGE_THERM_STATUS_HFI_UPDATED (1 << 26) 708 709 709 710 #define MSR_IA32_PACKAGE_THERM_INTERRUPT 0x000001b2 710 711 711 712 #define PACKAGE_THERM_INT_HIGH_ENABLE (1 << 0) 712 713 #define PACKAGE_THERM_INT_LOW_ENABLE (1 << 1) 713 714 #define PACKAGE_THERM_INT_PLN_ENABLE (1 << 24) 715 + #define PACKAGE_THERM_INT_HFI_ENABLE (1 << 25) 714 716 715 717 /* Thermal Thresholds Support */ 716 718 #define THERM_INT_THRESHOLD0_ENABLE (1 << 15) ··· 960 958 #define MSR_VM_CR 0xc0010114 961 959 #define MSR_VM_IGNNE 0xc0010115 962 960 #define MSR_VM_HSAVE_PA 0xc0010117 961 + 962 + /* Hardware Feedback Interface */ 963 + #define MSR_IA32_HW_FEEDBACK_PTR 0x17d0 964 + #define MSR_IA32_HW_FEEDBACK_CONFIG 0x17d1 963 965 964 966 #endif /* _ASM_X86_MSR_INDEX_H */
+1 -1
drivers/thermal/broadcom/brcmstb_thermal.c
··· 351 351 352 352 priv->thermal = thermal; 353 353 354 - irq = platform_get_irq(pdev, 0); 354 + irq = platform_get_irq_optional(pdev, 0); 355 355 if (irq >= 0) { 356 356 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 357 357 brcmstb_tmon_irq_thread,
+14
drivers/thermal/intel/Kconfig
··· 99 99 Intel Menlow platform. 100 100 101 101 If unsure, say N. 102 + 103 + config INTEL_HFI_THERMAL 104 + bool "Intel Hardware Feedback Interface" 105 + depends on NET 106 + depends on CPU_SUP_INTEL 107 + depends on X86_THERMAL_VECTOR 108 + select THERMAL_NETLINK 109 + help 110 + Select this option to enable the Hardware Feedback Interface. If 111 + selected, hardware provides guidance to the operating system on 112 + the performance and energy efficiency capabilities of each CPU. 113 + These capabilities may change as a result of changes in the operating 114 + conditions of the system such power and thermal limits. If selected, 115 + the kernel relays updates in CPUs' capabilities to userspace.
+1
drivers/thermal/intel/Makefile
··· 13 13 obj-$(CONFIG_INTEL_TCC_COOLING) += intel_tcc_cooling.o 14 14 obj-$(CONFIG_X86_THERMAL_VECTOR) += therm_throt.o 15 15 obj-$(CONFIG_INTEL_MENLOW) += intel_menlow.o 16 + obj-$(CONFIG_INTEL_HFI_THERMAL) += intel_hfi.o
+7 -16
drivers/thermal/intel/int340x_thermal/acpi_thermal_rel.c
··· 72 72 int i; 73 73 int nr_bad_entries = 0; 74 74 struct trt *trts; 75 - struct acpi_device *adev; 76 75 union acpi_object *p; 77 76 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 78 77 struct acpi_buffer element = { 0, NULL }; ··· 111 112 if (!create_dev) 112 113 continue; 113 114 114 - result = acpi_bus_get_device(trt->source, &adev); 115 - if (result) 115 + if (!acpi_fetch_acpi_dev(trt->source)) 116 116 pr_warn("Failed to get source ACPI device\n"); 117 117 118 - result = acpi_bus_get_device(trt->target, &adev); 119 - if (result) 118 + if (!acpi_fetch_acpi_dev(trt->target)) 120 119 pr_warn("Failed to get target ACPI device\n"); 121 120 } 122 121 ··· 146 149 int i; 147 150 int nr_bad_entries = 0; 148 151 struct art *arts; 149 - struct acpi_device *adev; 150 152 union acpi_object *p; 151 153 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 152 154 struct acpi_buffer element = { 0, NULL }; ··· 187 191 if (!create_dev) 188 192 continue; 189 193 190 - if (art->source) { 191 - result = acpi_bus_get_device(art->source, &adev); 192 - if (result) 193 - pr_warn("Failed to get source ACPI device\n"); 194 - } 195 - if (art->target) { 196 - result = acpi_bus_get_device(art->target, &adev); 197 - if (result) 198 - pr_warn("Failed to get target ACPI device\n"); 199 - } 194 + if (!acpi_fetch_acpi_dev(art->source)) 195 + pr_warn("Failed to get source ACPI device\n"); 196 + 197 + if (!acpi_fetch_acpi_dev(art->target)) 198 + pr_warn("Failed to get target ACPI device\n"); 200 199 } 201 200 202 201 *artp = arts;
+103 -50
drivers/thermal/intel/int340x_thermal/int3400_thermal.c
··· 17 17 #define INT3400_KEEP_ALIVE 0xA0 18 18 19 19 enum int3400_thermal_uuid { 20 + INT3400_THERMAL_ACTIVE = 0, 20 21 INT3400_THERMAL_PASSIVE_1, 21 - INT3400_THERMAL_ACTIVE, 22 22 INT3400_THERMAL_CRITICAL, 23 23 INT3400_THERMAL_ADAPTIVE_PERFORMANCE, 24 24 INT3400_THERMAL_EMERGENCY_CALL_MODE, ··· 31 31 }; 32 32 33 33 static char *int3400_thermal_uuids[INT3400_THERMAL_MAXIMUM_UUID] = { 34 - "42A441D6-AE6A-462b-A84B-4A8CE79027D3", 35 34 "3A95C389-E4B8-4629-A526-C52C88626BAE", 35 + "42A441D6-AE6A-462b-A84B-4A8CE79027D3", 36 36 "97C68AE7-15FA-499c-B8C9-5DA81D606E0A", 37 37 "63BE270F-1C11-48FD-A6F7-3AF253FF3E2D", 38 38 "5349962F-71E6-431D-9AE8-0A635B710AEE", ··· 53 53 struct art *arts; 54 54 int trt_count; 55 55 struct trt *trts; 56 - u8 uuid_bitmap; 56 + u32 uuid_bitmap; 57 57 int rel_misc_dev_res; 58 58 int current_uuid_index; 59 59 char *data_vault; 60 60 int odvp_count; 61 61 int *odvp; 62 + u32 os_uuid_mask; 62 63 struct odvp_attr *odvp_attrs; 63 64 }; 64 65 ··· 143 142 struct device_attribute *devattr, char *buf) 144 143 { 145 144 struct int3400_thermal_priv *priv = dev_get_drvdata(dev); 145 + int i, length = 0; 146 146 147 - if (priv->current_uuid_index == -1) 148 - return sprintf(buf, "INVALID\n"); 147 + if (priv->current_uuid_index > 0) 148 + return sprintf(buf, "%s\n", 149 + int3400_thermal_uuids[priv->current_uuid_index]); 149 150 150 - return sprintf(buf, "%s\n", 151 - int3400_thermal_uuids[priv->current_uuid_index]); 151 + for (i = 0; i <= INT3400_THERMAL_CRITICAL; i++) { 152 + if (priv->os_uuid_mask & BIT(i)) 153 + length += scnprintf(&buf[length], 154 + PAGE_SIZE - length, 155 + "%s\n", 156 + int3400_thermal_uuids[i]); 157 + } 158 + 159 + if (length) 160 + return length; 161 + 162 + return sprintf(buf, "INVALID\n"); 163 + } 164 + 165 + static int int3400_thermal_run_osc(acpi_handle handle, char *uuid_str, int *enable) 166 + { 167 + u32 ret, buf[2]; 168 + acpi_status status; 169 + int result = 0; 170 + struct acpi_osc_context context = { 171 + .uuid_str = NULL, 172 + .rev = 1, 173 + .cap.length = 8, 174 + }; 175 + 176 + context.uuid_str = uuid_str; 177 + 178 + buf[OSC_QUERY_DWORD] = 0; 179 + buf[OSC_SUPPORT_DWORD] = *enable; 180 + 181 + context.cap.pointer = buf; 182 + 183 + status = acpi_run_osc(handle, &context); 184 + if (ACPI_SUCCESS(status)) { 185 + ret = *((u32 *)(context.ret.pointer + 4)); 186 + if (ret != *enable) 187 + result = -EPERM; 188 + } else 189 + result = -EPERM; 190 + 191 + kfree(context.ret.pointer); 192 + 193 + return result; 152 194 } 153 195 154 196 static ssize_t current_uuid_store(struct device *dev, ··· 208 164 * If we have a list of supported UUIDs, make sure 209 165 * this one is supported. 210 166 */ 211 - if (priv->uuid_bitmap && 212 - !(priv->uuid_bitmap & (1 << i))) 167 + if (priv->uuid_bitmap & BIT(i)) { 168 + priv->current_uuid_index = i; 169 + return count; 170 + } 171 + 172 + /* 173 + * There is support of only 3 policies via the new 174 + * _OSC to inform OS capability: 175 + * INT3400_THERMAL_ACTIVE 176 + * INT3400_THERMAL_PASSIVE_1 177 + * INT3400_THERMAL_CRITICAL 178 + */ 179 + 180 + if (i > INT3400_THERMAL_CRITICAL) 213 181 return -EINVAL; 214 182 215 - priv->current_uuid_index = i; 216 - return count; 183 + priv->os_uuid_mask |= BIT(i); 184 + 185 + break; 217 186 } 218 187 } 219 188 220 - return -EINVAL; 189 + if (priv->os_uuid_mask) { 190 + int cap, ret; 191 + 192 + /* 193 + * Capability bits: 194 + * Bit 0: set to 1 to indicate DPTF is active 195 + * Bi1 1: set to 1 to active cooling is supported by user space daemon 196 + * Bit 2: set to 1 to passive cooling is supported by user space daemon 197 + * Bit 3: set to 1 to critical trip is handled by user space daemon 198 + */ 199 + cap = ((priv->os_uuid_mask << 1) | 0x01); 200 + ret = int3400_thermal_run_osc(priv->adev->handle, 201 + "b23ba85d-c8b7-3542-88de-8de2ffcfd698", 202 + &cap); 203 + if (ret) 204 + return ret; 205 + } 206 + 207 + return count; 221 208 } 222 209 223 210 static DEVICE_ATTR_RW(current_uuid); ··· 308 233 309 234 end: 310 235 kfree(buf.pointer); 311 - return result; 312 - } 313 - 314 - static int int3400_thermal_run_osc(acpi_handle handle, 315 - enum int3400_thermal_uuid uuid, bool enable) 316 - { 317 - u32 ret, buf[2]; 318 - acpi_status status; 319 - int result = 0; 320 - struct acpi_osc_context context = { 321 - .uuid_str = NULL, 322 - .rev = 1, 323 - .cap.length = 8, 324 - }; 325 - 326 - if (uuid < 0 || uuid >= INT3400_THERMAL_MAXIMUM_UUID) 327 - return -EINVAL; 328 - 329 - context.uuid_str = int3400_thermal_uuids[uuid]; 330 - 331 - buf[OSC_QUERY_DWORD] = 0; 332 - buf[OSC_SUPPORT_DWORD] = enable; 333 - 334 - context.cap.pointer = buf; 335 - 336 - status = acpi_run_osc(handle, &context); 337 - if (ACPI_SUCCESS(status)) { 338 - ret = *((u32 *)(context.ret.pointer + 4)); 339 - if (ret != enable) 340 - result = -EPERM; 341 - } else 342 - result = -EPERM; 343 - 344 - kfree(context.ret.pointer); 345 - 346 236 return result; 347 237 } 348 238 ··· 466 426 if (!priv) 467 427 return -EINVAL; 468 428 469 - if (mode != thermal->mode) 429 + if (mode != thermal->mode) { 430 + int enabled; 431 + 432 + if (priv->current_uuid_index < 0 || 433 + priv->current_uuid_index >= INT3400_THERMAL_MAXIMUM_UUID) 434 + return -EINVAL; 435 + 436 + enabled = (mode == THERMAL_DEVICE_ENABLED); 470 437 result = int3400_thermal_run_osc(priv->adev->handle, 471 - priv->current_uuid_index, 472 - mode == THERMAL_DEVICE_ENABLED); 438 + int3400_thermal_uuids[priv->current_uuid_index], 439 + &enabled); 440 + } 473 441 474 442 475 443 evaluate_odvp(priv); ··· 516 468 priv->data_vault = kmemdup(obj->package.elements[0].buffer.pointer, 517 469 obj->package.elements[0].buffer.length, 518 470 GFP_KERNEL); 471 + if (!priv->data_vault) { 472 + kfree(buffer.pointer); 473 + return; 474 + } 475 + 519 476 bin_attr_data_vault.private = priv->data_vault; 520 477 bin_attr_data_vault.size = obj->package.elements[0].buffer.length; 521 478 kfree(buffer.pointer);
+569
drivers/thermal/intel/intel_hfi.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Hardware Feedback Interface Driver 4 + * 5 + * Copyright (c) 2021, Intel Corporation. 6 + * 7 + * Authors: Aubrey Li <aubrey.li@linux.intel.com> 8 + * Ricardo Neri <ricardo.neri-calderon@linux.intel.com> 9 + * 10 + * 11 + * The Hardware Feedback Interface provides a performance and energy efficiency 12 + * capability information for each CPU in the system. Depending on the processor 13 + * model, hardware may periodically update these capabilities as a result of 14 + * changes in the operating conditions (e.g., power limits or thermal 15 + * constraints). On other processor models, there is a single HFI update 16 + * at boot. 17 + * 18 + * This file provides functionality to process HFI updates and relay these 19 + * updates to userspace. 20 + */ 21 + 22 + #define pr_fmt(fmt) "intel-hfi: " fmt 23 + 24 + #include <linux/bitops.h> 25 + #include <linux/cpufeature.h> 26 + #include <linux/cpumask.h> 27 + #include <linux/gfp.h> 28 + #include <linux/io.h> 29 + #include <linux/kernel.h> 30 + #include <linux/math.h> 31 + #include <linux/mutex.h> 32 + #include <linux/percpu-defs.h> 33 + #include <linux/printk.h> 34 + #include <linux/processor.h> 35 + #include <linux/slab.h> 36 + #include <linux/spinlock.h> 37 + #include <linux/string.h> 38 + #include <linux/topology.h> 39 + #include <linux/workqueue.h> 40 + 41 + #include <asm/msr.h> 42 + 43 + #include "../thermal_core.h" 44 + #include "intel_hfi.h" 45 + 46 + #define THERM_STATUS_CLEAR_PKG_MASK (BIT(1) | BIT(3) | BIT(5) | BIT(7) | \ 47 + BIT(9) | BIT(11) | BIT(26)) 48 + 49 + /* Hardware Feedback Interface MSR configuration bits */ 50 + #define HW_FEEDBACK_PTR_VALID_BIT BIT(0) 51 + #define HW_FEEDBACK_CONFIG_HFI_ENABLE_BIT BIT(0) 52 + 53 + /* CPUID detection and enumeration definitions for HFI */ 54 + 55 + #define CPUID_HFI_LEAF 6 56 + 57 + union hfi_capabilities { 58 + struct { 59 + u8 performance:1; 60 + u8 energy_efficiency:1; 61 + u8 __reserved:6; 62 + } split; 63 + u8 bits; 64 + }; 65 + 66 + union cpuid6_edx { 67 + struct { 68 + union hfi_capabilities capabilities; 69 + u32 table_pages:4; 70 + u32 __reserved:4; 71 + s32 index:16; 72 + } split; 73 + u32 full; 74 + }; 75 + 76 + /** 77 + * struct hfi_cpu_data - HFI capabilities per CPU 78 + * @perf_cap: Performance capability 79 + * @ee_cap: Energy efficiency capability 80 + * 81 + * Capabilities of a logical processor in the HFI table. These capabilities are 82 + * unitless. 83 + */ 84 + struct hfi_cpu_data { 85 + u8 perf_cap; 86 + u8 ee_cap; 87 + } __packed; 88 + 89 + /** 90 + * struct hfi_hdr - Header of the HFI table 91 + * @perf_updated: Hardware updated performance capabilities 92 + * @ee_updated: Hardware updated energy efficiency capabilities 93 + * 94 + * Properties of the data in an HFI table. 95 + */ 96 + struct hfi_hdr { 97 + u8 perf_updated; 98 + u8 ee_updated; 99 + } __packed; 100 + 101 + /** 102 + * struct hfi_instance - Representation of an HFI instance (i.e., a table) 103 + * @local_table: Base of the local copy of the HFI table 104 + * @timestamp: Timestamp of the last update of the local table. 105 + * Located at the base of the local table. 106 + * @hdr: Base address of the header of the local table 107 + * @data: Base address of the data of the local table 108 + * @cpus: CPUs represented in this HFI table instance 109 + * @hw_table: Pointer to the HFI table of this instance 110 + * @update_work: Delayed work to process HFI updates 111 + * @table_lock: Lock to protect acceses to the table of this instance 112 + * @event_lock: Lock to process HFI interrupts 113 + * 114 + * A set of parameters to parse and navigate a specific HFI table. 115 + */ 116 + struct hfi_instance { 117 + union { 118 + void *local_table; 119 + u64 *timestamp; 120 + }; 121 + void *hdr; 122 + void *data; 123 + cpumask_var_t cpus; 124 + void *hw_table; 125 + struct delayed_work update_work; 126 + raw_spinlock_t table_lock; 127 + raw_spinlock_t event_lock; 128 + }; 129 + 130 + /** 131 + * struct hfi_features - Supported HFI features 132 + * @nr_table_pages: Size of the HFI table in 4KB pages 133 + * @cpu_stride: Stride size to locate the capability data of a logical 134 + * processor within the table (i.e., row stride) 135 + * @hdr_size: Size of the table header 136 + * 137 + * Parameters and supported features that are common to all HFI instances 138 + */ 139 + struct hfi_features { 140 + unsigned int nr_table_pages; 141 + unsigned int cpu_stride; 142 + unsigned int hdr_size; 143 + }; 144 + 145 + /** 146 + * struct hfi_cpu_info - Per-CPU attributes to consume HFI data 147 + * @index: Row of this CPU in its HFI table 148 + * @hfi_instance: Attributes of the HFI table to which this CPU belongs 149 + * 150 + * Parameters to link a logical processor to an HFI table and a row within it. 151 + */ 152 + struct hfi_cpu_info { 153 + s16 index; 154 + struct hfi_instance *hfi_instance; 155 + }; 156 + 157 + static DEFINE_PER_CPU(struct hfi_cpu_info, hfi_cpu_info) = { .index = -1 }; 158 + 159 + static int max_hfi_instances; 160 + static struct hfi_instance *hfi_instances; 161 + 162 + static struct hfi_features hfi_features; 163 + static DEFINE_MUTEX(hfi_instance_lock); 164 + 165 + static struct workqueue_struct *hfi_updates_wq; 166 + #define HFI_UPDATE_INTERVAL HZ 167 + #define HFI_MAX_THERM_NOTIFY_COUNT 16 168 + 169 + static void get_hfi_caps(struct hfi_instance *hfi_instance, 170 + struct thermal_genl_cpu_caps *cpu_caps) 171 + { 172 + int cpu, i = 0; 173 + 174 + raw_spin_lock_irq(&hfi_instance->table_lock); 175 + for_each_cpu(cpu, hfi_instance->cpus) { 176 + struct hfi_cpu_data *caps; 177 + s16 index; 178 + 179 + index = per_cpu(hfi_cpu_info, cpu).index; 180 + caps = hfi_instance->data + index * hfi_features.cpu_stride; 181 + cpu_caps[i].cpu = cpu; 182 + 183 + /* 184 + * Scale performance and energy efficiency to 185 + * the [0, 1023] interval that thermal netlink uses. 186 + */ 187 + cpu_caps[i].performance = caps->perf_cap << 2; 188 + cpu_caps[i].efficiency = caps->ee_cap << 2; 189 + 190 + ++i; 191 + } 192 + raw_spin_unlock_irq(&hfi_instance->table_lock); 193 + } 194 + 195 + /* 196 + * Call update_capabilities() when there are changes in the HFI table. 197 + */ 198 + static void update_capabilities(struct hfi_instance *hfi_instance) 199 + { 200 + struct thermal_genl_cpu_caps *cpu_caps; 201 + int i = 0, cpu_count; 202 + 203 + /* CPUs may come online/offline while processing an HFI update. */ 204 + mutex_lock(&hfi_instance_lock); 205 + 206 + cpu_count = cpumask_weight(hfi_instance->cpus); 207 + 208 + /* No CPUs to report in this hfi_instance. */ 209 + if (!cpu_count) 210 + goto out; 211 + 212 + cpu_caps = kcalloc(cpu_count, sizeof(*cpu_caps), GFP_KERNEL); 213 + if (!cpu_caps) 214 + goto out; 215 + 216 + get_hfi_caps(hfi_instance, cpu_caps); 217 + 218 + if (cpu_count < HFI_MAX_THERM_NOTIFY_COUNT) 219 + goto last_cmd; 220 + 221 + /* Process complete chunks of HFI_MAX_THERM_NOTIFY_COUNT capabilities. */ 222 + for (i = 0; 223 + (i + HFI_MAX_THERM_NOTIFY_COUNT) <= cpu_count; 224 + i += HFI_MAX_THERM_NOTIFY_COUNT) 225 + thermal_genl_cpu_capability_event(HFI_MAX_THERM_NOTIFY_COUNT, 226 + &cpu_caps[i]); 227 + 228 + cpu_count = cpu_count - i; 229 + 230 + last_cmd: 231 + /* Process the remaining capabilities if any. */ 232 + if (cpu_count) 233 + thermal_genl_cpu_capability_event(cpu_count, &cpu_caps[i]); 234 + 235 + kfree(cpu_caps); 236 + out: 237 + mutex_unlock(&hfi_instance_lock); 238 + } 239 + 240 + static void hfi_update_work_fn(struct work_struct *work) 241 + { 242 + struct hfi_instance *hfi_instance; 243 + 244 + hfi_instance = container_of(to_delayed_work(work), struct hfi_instance, 245 + update_work); 246 + if (!hfi_instance) 247 + return; 248 + 249 + update_capabilities(hfi_instance); 250 + } 251 + 252 + void intel_hfi_process_event(__u64 pkg_therm_status_msr_val) 253 + { 254 + struct hfi_instance *hfi_instance; 255 + int cpu = smp_processor_id(); 256 + struct hfi_cpu_info *info; 257 + u64 new_timestamp; 258 + 259 + if (!pkg_therm_status_msr_val) 260 + return; 261 + 262 + info = &per_cpu(hfi_cpu_info, cpu); 263 + if (!info) 264 + return; 265 + 266 + /* 267 + * A CPU is linked to its HFI instance before the thermal vector in the 268 + * local APIC is unmasked. Hence, info->hfi_instance cannot be NULL 269 + * when receiving an HFI event. 270 + */ 271 + hfi_instance = info->hfi_instance; 272 + if (unlikely(!hfi_instance)) { 273 + pr_debug("Received event on CPU %d but instance was null", cpu); 274 + return; 275 + } 276 + 277 + /* 278 + * On most systems, all CPUs in the package receive a package-level 279 + * thermal interrupt when there is an HFI update. It is sufficient to 280 + * let a single CPU to acknowledge the update and queue work to 281 + * process it. The remaining CPUs can resume their work. 282 + */ 283 + if (!raw_spin_trylock(&hfi_instance->event_lock)) 284 + return; 285 + 286 + /* Skip duplicated updates. */ 287 + new_timestamp = *(u64 *)hfi_instance->hw_table; 288 + if (*hfi_instance->timestamp == new_timestamp) { 289 + raw_spin_unlock(&hfi_instance->event_lock); 290 + return; 291 + } 292 + 293 + raw_spin_lock(&hfi_instance->table_lock); 294 + 295 + /* 296 + * Copy the updated table into our local copy. This includes the new 297 + * timestamp. 298 + */ 299 + memcpy(hfi_instance->local_table, hfi_instance->hw_table, 300 + hfi_features.nr_table_pages << PAGE_SHIFT); 301 + 302 + raw_spin_unlock(&hfi_instance->table_lock); 303 + raw_spin_unlock(&hfi_instance->event_lock); 304 + 305 + /* 306 + * Let hardware know that we are done reading the HFI table and it is 307 + * free to update it again. 308 + */ 309 + pkg_therm_status_msr_val &= THERM_STATUS_CLEAR_PKG_MASK & 310 + ~PACKAGE_THERM_STATUS_HFI_UPDATED; 311 + wrmsrl(MSR_IA32_PACKAGE_THERM_STATUS, pkg_therm_status_msr_val); 312 + 313 + queue_delayed_work(hfi_updates_wq, &hfi_instance->update_work, 314 + HFI_UPDATE_INTERVAL); 315 + } 316 + 317 + static void init_hfi_cpu_index(struct hfi_cpu_info *info) 318 + { 319 + union cpuid6_edx edx; 320 + 321 + /* Do not re-read @cpu's index if it has already been initialized. */ 322 + if (info->index > -1) 323 + return; 324 + 325 + edx.full = cpuid_edx(CPUID_HFI_LEAF); 326 + info->index = edx.split.index; 327 + } 328 + 329 + /* 330 + * The format of the HFI table depends on the number of capabilities that the 331 + * hardware supports. Keep a data structure to navigate the table. 332 + */ 333 + static void init_hfi_instance(struct hfi_instance *hfi_instance) 334 + { 335 + /* The HFI header is below the time-stamp. */ 336 + hfi_instance->hdr = hfi_instance->local_table + 337 + sizeof(*hfi_instance->timestamp); 338 + 339 + /* The HFI data starts below the header. */ 340 + hfi_instance->data = hfi_instance->hdr + hfi_features.hdr_size; 341 + } 342 + 343 + /** 344 + * intel_hfi_online() - Enable HFI on @cpu 345 + * @cpu: CPU in which the HFI will be enabled 346 + * 347 + * Enable the HFI to be used in @cpu. The HFI is enabled at the die/package 348 + * level. The first CPU in the die/package to come online does the full HFI 349 + * initialization. Subsequent CPUs will just link themselves to the HFI 350 + * instance of their die/package. 351 + * 352 + * This function is called before enabling the thermal vector in the local APIC 353 + * in order to ensure that @cpu has an associated HFI instance when it receives 354 + * an HFI event. 355 + */ 356 + void intel_hfi_online(unsigned int cpu) 357 + { 358 + struct hfi_instance *hfi_instance; 359 + struct hfi_cpu_info *info; 360 + phys_addr_t hw_table_pa; 361 + u64 msr_val; 362 + u16 die_id; 363 + 364 + /* Nothing to do if hfi_instances are missing. */ 365 + if (!hfi_instances) 366 + return; 367 + 368 + /* 369 + * Link @cpu to the HFI instance of its package/die. It does not 370 + * matter whether the instance has been initialized. 371 + */ 372 + info = &per_cpu(hfi_cpu_info, cpu); 373 + die_id = topology_logical_die_id(cpu); 374 + hfi_instance = info->hfi_instance; 375 + if (!hfi_instance) { 376 + if (die_id < 0 || die_id >= max_hfi_instances) 377 + return; 378 + 379 + hfi_instance = &hfi_instances[die_id]; 380 + info->hfi_instance = hfi_instance; 381 + } 382 + 383 + init_hfi_cpu_index(info); 384 + 385 + /* 386 + * Now check if the HFI instance of the package/die of @cpu has been 387 + * initialized (by checking its header). In such case, all we have to 388 + * do is to add @cpu to this instance's cpumask. 389 + */ 390 + mutex_lock(&hfi_instance_lock); 391 + if (hfi_instance->hdr) { 392 + cpumask_set_cpu(cpu, hfi_instance->cpus); 393 + goto unlock; 394 + } 395 + 396 + /* 397 + * Hardware is programmed with the physical address of the first page 398 + * frame of the table. Hence, the allocated memory must be page-aligned. 399 + */ 400 + hfi_instance->hw_table = alloc_pages_exact(hfi_features.nr_table_pages, 401 + GFP_KERNEL | __GFP_ZERO); 402 + if (!hfi_instance->hw_table) 403 + goto unlock; 404 + 405 + hw_table_pa = virt_to_phys(hfi_instance->hw_table); 406 + 407 + /* 408 + * Allocate memory to keep a local copy of the table that 409 + * hardware generates. 410 + */ 411 + hfi_instance->local_table = kzalloc(hfi_features.nr_table_pages << PAGE_SHIFT, 412 + GFP_KERNEL); 413 + if (!hfi_instance->local_table) 414 + goto free_hw_table; 415 + 416 + /* 417 + * Program the address of the feedback table of this die/package. On 418 + * some processors, hardware remembers the old address of the HFI table 419 + * even after having been reprogrammed and re-enabled. Thus, do not free 420 + * the pages allocated for the table or reprogram the hardware with a 421 + * new base address. Namely, program the hardware only once. 422 + */ 423 + msr_val = hw_table_pa | HW_FEEDBACK_PTR_VALID_BIT; 424 + wrmsrl(MSR_IA32_HW_FEEDBACK_PTR, msr_val); 425 + 426 + init_hfi_instance(hfi_instance); 427 + 428 + INIT_DELAYED_WORK(&hfi_instance->update_work, hfi_update_work_fn); 429 + raw_spin_lock_init(&hfi_instance->table_lock); 430 + raw_spin_lock_init(&hfi_instance->event_lock); 431 + 432 + cpumask_set_cpu(cpu, hfi_instance->cpus); 433 + 434 + /* 435 + * Enable the hardware feedback interface and never disable it. See 436 + * comment on programming the address of the table. 437 + */ 438 + rdmsrl(MSR_IA32_HW_FEEDBACK_CONFIG, msr_val); 439 + msr_val |= HW_FEEDBACK_CONFIG_HFI_ENABLE_BIT; 440 + wrmsrl(MSR_IA32_HW_FEEDBACK_CONFIG, msr_val); 441 + 442 + unlock: 443 + mutex_unlock(&hfi_instance_lock); 444 + return; 445 + 446 + free_hw_table: 447 + free_pages_exact(hfi_instance->hw_table, hfi_features.nr_table_pages); 448 + goto unlock; 449 + } 450 + 451 + /** 452 + * intel_hfi_offline() - Disable HFI on @cpu 453 + * @cpu: CPU in which the HFI will be disabled 454 + * 455 + * Remove @cpu from those covered by its HFI instance. 456 + * 457 + * On some processors, hardware remembers previous programming settings even 458 + * after being reprogrammed. Thus, keep HFI enabled even if all CPUs in the 459 + * die/package of @cpu are offline. See note in intel_hfi_online(). 460 + */ 461 + void intel_hfi_offline(unsigned int cpu) 462 + { 463 + struct hfi_cpu_info *info = &per_cpu(hfi_cpu_info, cpu); 464 + struct hfi_instance *hfi_instance; 465 + 466 + /* 467 + * Check if @cpu as an associated, initialized (i.e., with a non-NULL 468 + * header). Also, HFI instances are only initialized if X86_FEATURE_HFI 469 + * is present. 470 + */ 471 + hfi_instance = info->hfi_instance; 472 + if (!hfi_instance) 473 + return; 474 + 475 + if (!hfi_instance->hdr) 476 + return; 477 + 478 + mutex_lock(&hfi_instance_lock); 479 + cpumask_clear_cpu(cpu, hfi_instance->cpus); 480 + mutex_unlock(&hfi_instance_lock); 481 + } 482 + 483 + static __init int hfi_parse_features(void) 484 + { 485 + unsigned int nr_capabilities; 486 + union cpuid6_edx edx; 487 + 488 + if (!boot_cpu_has(X86_FEATURE_HFI)) 489 + return -ENODEV; 490 + 491 + /* 492 + * If we are here we know that CPUID_HFI_LEAF exists. Parse the 493 + * supported capabilities and the size of the HFI table. 494 + */ 495 + edx.full = cpuid_edx(CPUID_HFI_LEAF); 496 + 497 + if (!edx.split.capabilities.split.performance) { 498 + pr_debug("Performance reporting not supported! Not using HFI\n"); 499 + return -ENODEV; 500 + } 501 + 502 + /* 503 + * The number of supported capabilities determines the number of 504 + * columns in the HFI table. Exclude the reserved bits. 505 + */ 506 + edx.split.capabilities.split.__reserved = 0; 507 + nr_capabilities = hweight8(edx.split.capabilities.bits); 508 + 509 + /* The number of 4KB pages required by the table */ 510 + hfi_features.nr_table_pages = edx.split.table_pages + 1; 511 + 512 + /* 513 + * The header contains change indications for each supported feature. 514 + * The size of the table header is rounded up to be a multiple of 8 515 + * bytes. 516 + */ 517 + hfi_features.hdr_size = DIV_ROUND_UP(nr_capabilities, 8) * 8; 518 + 519 + /* 520 + * Data of each logical processor is also rounded up to be a multiple 521 + * of 8 bytes. 522 + */ 523 + hfi_features.cpu_stride = DIV_ROUND_UP(nr_capabilities, 8) * 8; 524 + 525 + return 0; 526 + } 527 + 528 + void __init intel_hfi_init(void) 529 + { 530 + struct hfi_instance *hfi_instance; 531 + int i, j; 532 + 533 + if (hfi_parse_features()) 534 + return; 535 + 536 + /* There is one HFI instance per die/package. */ 537 + max_hfi_instances = topology_max_packages() * 538 + topology_max_die_per_package(); 539 + 540 + /* 541 + * This allocation may fail. CPU hotplug callbacks must check 542 + * for a null pointer. 543 + */ 544 + hfi_instances = kcalloc(max_hfi_instances, sizeof(*hfi_instances), 545 + GFP_KERNEL); 546 + if (!hfi_instances) 547 + return; 548 + 549 + for (i = 0; i < max_hfi_instances; i++) { 550 + hfi_instance = &hfi_instances[i]; 551 + if (!zalloc_cpumask_var(&hfi_instance->cpus, GFP_KERNEL)) 552 + goto err_nomem; 553 + } 554 + 555 + hfi_updates_wq = create_singlethread_workqueue("hfi-updates"); 556 + if (!hfi_updates_wq) 557 + goto err_nomem; 558 + 559 + return; 560 + 561 + err_nomem: 562 + for (j = 0; j < i; ++j) { 563 + hfi_instance = &hfi_instances[j]; 564 + free_cpumask_var(hfi_instance->cpus); 565 + } 566 + 567 + kfree(hfi_instances); 568 + hfi_instances = NULL; 569 + }
+17
drivers/thermal/intel/intel_hfi.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _INTEL_HFI_H 3 + #define _INTEL_HFI_H 4 + 5 + #if defined(CONFIG_INTEL_HFI_THERMAL) 6 + void __init intel_hfi_init(void); 7 + void intel_hfi_online(unsigned int cpu); 8 + void intel_hfi_offline(unsigned int cpu); 9 + void intel_hfi_process_event(__u64 pkg_therm_status_msr_val); 10 + #else 11 + static inline void intel_hfi_init(void) { } 12 + static inline void intel_hfi_online(unsigned int cpu) { } 13 + static inline void intel_hfi_offline(unsigned int cpu) { } 14 + static inline void intel_hfi_process_event(__u64 pkg_therm_status_msr_val) { } 15 + #endif /* CONFIG_INTEL_HFI_THERMAL */ 16 + 17 + #endif /* _INTEL_HFI_H */
+3 -6
drivers/thermal/intel/intel_powerclamp.c
··· 556 556 * stop faster. 557 557 */ 558 558 clamping = false; 559 - if (bitmap_weight(cpu_clamping_mask, num_possible_cpus())) { 560 - for_each_set_bit(i, cpu_clamping_mask, num_possible_cpus()) { 561 - pr_debug("clamping worker for cpu %d alive, destroy\n", 562 - i); 563 - stop_power_clamp_worker(i); 564 - } 559 + for_each_set_bit(i, cpu_clamping_mask, num_possible_cpus()) { 560 + pr_debug("clamping worker for cpu %d alive, destroy\n", i); 561 + stop_power_clamp_worker(i); 565 562 } 566 563 } 567 564
+22
drivers/thermal/intel/therm_throt.c
··· 32 32 #include <asm/irq.h> 33 33 #include <asm/msr.h> 34 34 35 + #include "intel_hfi.h" 35 36 #include "thermal_interrupt.h" 36 37 37 38 /* How long to wait between reporting thermal events */ ··· 476 475 INIT_DELAYED_WORK(&state->package_throttle.therm_work, throttle_active_work); 477 476 INIT_DELAYED_WORK(&state->core_throttle.therm_work, throttle_active_work); 478 477 478 + /* 479 + * The first CPU coming online will enable the HFI. Usually this causes 480 + * hardware to issue an HFI thermal interrupt. Such interrupt will reach 481 + * the CPU once we enable the thermal vector in the local APIC. 482 + */ 483 + intel_hfi_online(cpu); 484 + 479 485 /* Unmask the thermal vector after the above workqueues are initialized. */ 480 486 l = apic_read(APIC_LVTTHMR); 481 487 apic_write(APIC_LVTTHMR, l & ~APIC_LVT_MASKED); ··· 500 492 l = apic_read(APIC_LVTTHMR); 501 493 apic_write(APIC_LVTTHMR, l | APIC_LVT_MASKED); 502 494 495 + intel_hfi_offline(cpu); 496 + 503 497 cancel_delayed_work_sync(&state->package_throttle.therm_work); 504 498 cancel_delayed_work_sync(&state->core_throttle.therm_work); 505 499 ··· 518 508 519 509 if (!atomic_read(&therm_throt_en)) 520 510 return 0; 511 + 512 + intel_hfi_init(); 521 513 522 514 ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/therm:online", 523 515 thermal_throttle_online, ··· 620 608 PACKAGE_THERM_STATUS_POWER_LIMIT, 621 609 POWER_LIMIT_EVENT, 622 610 PACKAGE_LEVEL); 611 + 612 + if (this_cpu_has(X86_FEATURE_HFI)) 613 + intel_hfi_process_event(msr_val & 614 + PACKAGE_THERM_STATUS_HFI_UPDATED); 623 615 } 624 616 } 625 617 ··· 733 717 wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, 734 718 l | (PACKAGE_THERM_INT_LOW_ENABLE 735 719 | PACKAGE_THERM_INT_HIGH_ENABLE), h); 720 + 721 + if (cpu_has(c, X86_FEATURE_HFI)) { 722 + rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h); 723 + wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, 724 + l | PACKAGE_THERM_INT_HFI_ENABLE, h); 725 + } 736 726 } 737 727 738 728 rdmsr(MSR_IA32_MISC_ENABLE, l, h);
+31 -23
drivers/thermal/qcom/lmh.c
··· 28 28 29 29 #define LMH_REG_DCVS_INTR_CLR 0x8 30 30 31 + #define LMH_ENABLE_ALGOS 1 32 + 31 33 struct lmh_hw_data { 32 34 void __iomem *base; 33 35 struct irq_domain *domain; ··· 92 90 struct device_node *cpu_node; 93 91 struct lmh_hw_data *lmh_data; 94 92 int temp_low, temp_high, temp_arm, cpu_id, ret; 93 + unsigned int enable_alg; 95 94 u32 node_id; 96 95 97 96 lmh_data = devm_kzalloc(dev, sizeof(*lmh_data), GFP_KERNEL); ··· 144 141 if (!qcom_scm_lmh_dcvsh_available()) 145 142 return -EINVAL; 146 143 147 - ret = qcom_scm_lmh_dcvsh(LMH_SUB_FN_CRNT, LMH_ALGO_MODE_ENABLE, 1, 148 - LMH_NODE_DCVS, node_id, 0); 149 - if (ret) 150 - dev_err(dev, "Error %d enabling current subfunction\n", ret); 144 + enable_alg = (uintptr_t)of_device_get_match_data(dev); 151 145 152 - ret = qcom_scm_lmh_dcvsh(LMH_SUB_FN_REL, LMH_ALGO_MODE_ENABLE, 1, 153 - LMH_NODE_DCVS, node_id, 0); 154 - if (ret) 155 - dev_err(dev, "Error %d enabling reliability subfunction\n", ret); 146 + if (enable_alg) { 147 + ret = qcom_scm_lmh_dcvsh(LMH_SUB_FN_CRNT, LMH_ALGO_MODE_ENABLE, 1, 148 + LMH_NODE_DCVS, node_id, 0); 149 + if (ret) 150 + dev_err(dev, "Error %d enabling current subfunction\n", ret); 156 151 157 - ret = qcom_scm_lmh_dcvsh(LMH_SUB_FN_BCL, LMH_ALGO_MODE_ENABLE, 1, 158 - LMH_NODE_DCVS, node_id, 0); 159 - if (ret) 160 - dev_err(dev, "Error %d enabling BCL subfunction\n", ret); 152 + ret = qcom_scm_lmh_dcvsh(LMH_SUB_FN_REL, LMH_ALGO_MODE_ENABLE, 1, 153 + LMH_NODE_DCVS, node_id, 0); 154 + if (ret) 155 + dev_err(dev, "Error %d enabling reliability subfunction\n", ret); 161 156 162 - ret = qcom_scm_lmh_dcvsh(LMH_SUB_FN_THERMAL, LMH_ALGO_MODE_ENABLE, 1, 163 - LMH_NODE_DCVS, node_id, 0); 164 - if (ret) { 165 - dev_err(dev, "Error %d enabling thermal subfunction\n", ret); 166 - return ret; 167 - } 157 + ret = qcom_scm_lmh_dcvsh(LMH_SUB_FN_BCL, LMH_ALGO_MODE_ENABLE, 1, 158 + LMH_NODE_DCVS, node_id, 0); 159 + if (ret) 160 + dev_err(dev, "Error %d enabling BCL subfunction\n", ret); 168 161 169 - ret = qcom_scm_lmh_profile_change(0x1); 170 - if (ret) { 171 - dev_err(dev, "Error %d changing profile\n", ret); 172 - return ret; 162 + ret = qcom_scm_lmh_dcvsh(LMH_SUB_FN_THERMAL, LMH_ALGO_MODE_ENABLE, 1, 163 + LMH_NODE_DCVS, node_id, 0); 164 + if (ret) { 165 + dev_err(dev, "Error %d enabling thermal subfunction\n", ret); 166 + return ret; 167 + } 168 + 169 + ret = qcom_scm_lmh_profile_change(0x1); 170 + if (ret) { 171 + dev_err(dev, "Error %d changing profile\n", ret); 172 + return ret; 173 + } 173 174 } 174 175 175 176 /* Set default thermal trips */ ··· 220 213 } 221 214 222 215 static const struct of_device_id lmh_table[] = { 223 - { .compatible = "qcom,sdm845-lmh", }, 216 + { .compatible = "qcom,sdm845-lmh", .data = (void *)LMH_ENABLE_ALGOS}, 217 + { .compatible = "qcom,sm8150-lmh", }, 224 218 {} 225 219 }; 226 220 MODULE_DEVICE_TABLE(of, lmh_table);
+5
drivers/thermal/qcom/tsens.c
··· 18 18 #include <linux/regmap.h> 19 19 #include <linux/slab.h> 20 20 #include <linux/thermal.h> 21 + #include "../thermal_hwmon.h" 21 22 #include "tsens.h" 22 23 23 24 /** ··· 1061 1060 priv->sensor[i].tzd = tzd; 1062 1061 if (priv->ops->enable) 1063 1062 priv->ops->enable(priv, i); 1063 + 1064 + if (devm_thermal_add_hwmon_sysfs(tzd)) 1065 + dev_warn(priv->dev, 1066 + "Failed to add hwmon sysfs attributes\n"); 1064 1067 } 1065 1068 1066 1069 /* VER_0 require to set MIN and MAX THRESH
+12 -1
drivers/thermal/tegra/tegra-bpmp-thermal.c
··· 52 52 err = tegra_bpmp_transfer(zone->tegra->bpmp, &msg); 53 53 if (err) 54 54 return err; 55 + if (msg.rx.ret) 56 + return -EINVAL; 55 57 56 58 *out_temp = reply.get_temp.temp; 57 59 ··· 65 63 struct tegra_bpmp_thermal_zone *zone = data; 66 64 struct mrq_thermal_host_to_bpmp_request req; 67 65 struct tegra_bpmp_message msg; 66 + int err; 68 67 69 68 memset(&req, 0, sizeof(req)); 70 69 req.type = CMD_THERMAL_SET_TRIP; ··· 79 76 msg.tx.data = &req; 80 77 msg.tx.size = sizeof(req); 81 78 82 - return tegra_bpmp_transfer(zone->tegra->bpmp, &msg); 79 + err = tegra_bpmp_transfer(zone->tegra->bpmp, &msg); 80 + if (err) 81 + return err; 82 + if (msg.rx.ret) 83 + return -EINVAL; 84 + 85 + return 0; 83 86 } 84 87 85 88 static void tz_device_update_work_fn(struct work_struct *work) ··· 149 140 err = tegra_bpmp_transfer(bpmp, &msg); 150 141 if (err) 151 142 return err; 143 + if (msg.rx.ret) 144 + return -EINVAL; 152 145 153 146 *num_zones = reply.get_num_zones.num; 154 147
+53
drivers/thermal/thermal_netlink.c
··· 43 43 [THERMAL_GENL_ATTR_CDEV_MAX_STATE] = { .type = NLA_U32 }, 44 44 [THERMAL_GENL_ATTR_CDEV_NAME] = { .type = NLA_STRING, 45 45 .len = THERMAL_NAME_LENGTH }, 46 + /* CPU capabilities */ 47 + [THERMAL_GENL_ATTR_CPU_CAPABILITY] = { .type = NLA_NESTED }, 48 + [THERMAL_GENL_ATTR_CPU_CAPABILITY_ID] = { .type = NLA_U32 }, 49 + [THERMAL_GENL_ATTR_CPU_CAPABILITY_PERFORMANCE] = { .type = NLA_U32 }, 50 + [THERMAL_GENL_ATTR_CPU_CAPABILITY_EFFICIENCY] = { .type = NLA_U32 }, 46 51 }; 47 52 48 53 struct param { ··· 63 58 int temp; 64 59 int cdev_state; 65 60 int cdev_max_state; 61 + struct thermal_genl_cpu_caps *cpu_capabilities; 62 + int cpu_capabilities_count; 66 63 }; 67 64 68 65 typedef int (*cb_t)(struct param *); ··· 197 190 return 0; 198 191 } 199 192 193 + static int thermal_genl_event_cpu_capability_change(struct param *p) 194 + { 195 + struct thermal_genl_cpu_caps *cpu_cap = p->cpu_capabilities; 196 + struct sk_buff *msg = p->msg; 197 + struct nlattr *start_cap; 198 + int i; 199 + 200 + start_cap = nla_nest_start(msg, THERMAL_GENL_ATTR_CPU_CAPABILITY); 201 + if (!start_cap) 202 + return -EMSGSIZE; 203 + 204 + for (i = 0; i < p->cpu_capabilities_count; ++i) { 205 + if (nla_put_u32(msg, THERMAL_GENL_ATTR_CPU_CAPABILITY_ID, 206 + cpu_cap->cpu)) 207 + goto out_cancel_nest; 208 + 209 + if (nla_put_u32(msg, THERMAL_GENL_ATTR_CPU_CAPABILITY_PERFORMANCE, 210 + cpu_cap->performance)) 211 + goto out_cancel_nest; 212 + 213 + if (nla_put_u32(msg, THERMAL_GENL_ATTR_CPU_CAPABILITY_EFFICIENCY, 214 + cpu_cap->efficiency)) 215 + goto out_cancel_nest; 216 + 217 + ++cpu_cap; 218 + } 219 + 220 + nla_nest_end(msg, start_cap); 221 + 222 + return 0; 223 + out_cancel_nest: 224 + nla_nest_cancel(msg, start_cap); 225 + 226 + return -EMSGSIZE; 227 + } 228 + 200 229 int thermal_genl_event_tz_delete(struct param *p) 201 230 __attribute__((alias("thermal_genl_event_tz"))); 202 231 ··· 262 219 [THERMAL_GENL_EVENT_CDEV_DELETE] = thermal_genl_event_cdev_delete, 263 220 [THERMAL_GENL_EVENT_CDEV_STATE_UPDATE] = thermal_genl_event_cdev_state_update, 264 221 [THERMAL_GENL_EVENT_TZ_GOV_CHANGE] = thermal_genl_event_gov_change, 222 + [THERMAL_GENL_EVENT_CPU_CAPABILITY_CHANGE] = thermal_genl_event_cpu_capability_change, 265 223 }; 266 224 267 225 /* ··· 399 355 400 356 return thermal_genl_send_event(THERMAL_GENL_EVENT_TZ_GOV_CHANGE, &p); 401 357 } 358 + 359 + int thermal_genl_cpu_capability_event(int count, 360 + struct thermal_genl_cpu_caps *caps) 361 + { 362 + struct param p = { .cpu_capabilities_count = count, .cpu_capabilities = caps }; 363 + 364 + return thermal_genl_send_event(THERMAL_GENL_EVENT_CPU_CAPABILITY_CHANGE, &p); 365 + } 366 + EXPORT_SYMBOL_GPL(thermal_genl_cpu_capability_event); 402 367 403 368 /*************************** Command encoding ********************************/ 404 369
+14
drivers/thermal/thermal_netlink.h
··· 4 4 * Author: Daniel Lezcano <daniel.lezcano@linaro.org> 5 5 */ 6 6 7 + struct thermal_genl_cpu_caps { 8 + int cpu; 9 + int performance; 10 + int efficiency; 11 + }; 12 + 7 13 /* Netlink notification function */ 8 14 #ifdef CONFIG_THERMAL_NETLINK 9 15 int __init thermal_netlink_init(void); ··· 29 23 int thermal_notify_cdev_delete(int cdev_id); 30 24 int thermal_notify_tz_gov_change(int tz_id, const char *name); 31 25 int thermal_genl_sampling_temp(int id, int temp); 26 + int thermal_genl_cpu_capability_event(int count, 27 + struct thermal_genl_cpu_caps *caps); 32 28 #else 33 29 static inline int thermal_netlink_init(void) 34 30 { ··· 109 101 { 110 102 return 0; 111 103 } 104 + 105 + static inline int thermal_genl_cpu_capability_event(int count, struct thermal_genl_cpu_caps *caps) 106 + { 107 + return 0; 108 + } 109 + 112 110 #endif /* CONFIG_THERMAL_NETLINK */
+4 -8
drivers/thermal/ti-soc-thermal/ti-thermal-common.c
··· 21 21 22 22 #include "ti-thermal.h" 23 23 #include "ti-bandgap.h" 24 + #include "../thermal_hwmon.h" 24 25 25 26 /* common data structures */ 26 27 struct ti_thermal_data { ··· 107 106 return ret; 108 107 } 109 108 110 - static inline int ti_thermal_get_temp(struct thermal_zone_device *thermal, 111 - int *temp) 112 - { 113 - struct ti_thermal_data *data = thermal->devdata; 114 - 115 - return __ti_thermal_get_temp(data, temp); 116 - } 117 - 118 109 static int __ti_thermal_get_trend(void *p, int trip, enum thermal_trend *trend) 119 110 { 120 111 struct ti_thermal_data *data = p; ··· 181 188 182 189 ti_bandgap_set_sensor_data(bgp, id, data); 183 190 ti_bandgap_write_update_interval(bgp, data->sensor_id, interval); 191 + 192 + if (devm_thermal_add_hwmon_sysfs(data->ti_thermal)) 193 + dev_warn(bgp->dev, "failed to add hwmon sysfs attributes\n"); 184 194 185 195 return 0; 186 196 }
+5 -1
include/uapi/linux/thermal.h
··· 44 44 THERMAL_GENL_ATTR_CDEV_MAX_STATE, 45 45 THERMAL_GENL_ATTR_CDEV_NAME, 46 46 THERMAL_GENL_ATTR_GOV_NAME, 47 - 47 + THERMAL_GENL_ATTR_CPU_CAPABILITY, 48 + THERMAL_GENL_ATTR_CPU_CAPABILITY_ID, 49 + THERMAL_GENL_ATTR_CPU_CAPABILITY_PERFORMANCE, 50 + THERMAL_GENL_ATTR_CPU_CAPABILITY_EFFICIENCY, 48 51 __THERMAL_GENL_ATTR_MAX, 49 52 }; 50 53 #define THERMAL_GENL_ATTR_MAX (__THERMAL_GENL_ATTR_MAX - 1) ··· 74 71 THERMAL_GENL_EVENT_CDEV_DELETE, /* Cdev unbound */ 75 72 THERMAL_GENL_EVENT_CDEV_STATE_UPDATE, /* Cdev state updated */ 76 73 THERMAL_GENL_EVENT_TZ_GOV_CHANGE, /* Governor policy changed */ 74 + THERMAL_GENL_EVENT_CPU_CAPABILITY_CHANGE, /* CPU capability changed */ 77 75 __THERMAL_GENL_EVENT_MAX, 78 76 }; 79 77 #define THERMAL_GENL_EVENT_MAX (__THERMAL_GENL_EVENT_MAX - 1)
+1 -1
tools/power/x86/intel-speed-select/Build
··· 1 - intel-speed-select-y += isst-config.o isst-core.o isst-display.o 1 + intel-speed-select-y += isst-config.o isst-core.o isst-display.o isst-daemon.o hfi-events.o
+7 -3
tools/power/x86/intel-speed-select/Makefile
··· 13 13 # Do not use make's built-in rules 14 14 # (this improves performance and avoids hard-to-debug behaviour); 15 15 MAKEFLAGS += -r 16 - 17 - override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include 16 + override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include -I/usr/include/libnl3 17 + override LDFLAGS += -lnl-genl-3 -lnl-3 18 18 19 19 ALL_TARGETS := intel-speed-select 20 20 ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS)) ··· 31 31 mkdir -p $(OUTPUT)include/linux 2>&1 || true 32 32 ln -sf $(CURDIR)/../../../../include/uapi/linux/isst_if.h $@ 33 33 34 - prepare: $(OUTPUT)include/linux/isst_if.h 34 + $(OUTPUT)include/linux/thermal.h: ../../../../include/uapi/linux/thermal.h 35 + mkdir -p $(OUTPUT)include/linux 2>&1 || true 36 + ln -sf $(CURDIR)/../../../../include/uapi/linux/thermal.h $@ 37 + 38 + prepare: $(OUTPUT)include/linux/isst_if.h $(OUTPUT)include/linux/thermal.h 35 39 36 40 ISST_IN := $(OUTPUT)intel-speed-select-in.o 37 41
+309
tools/power/x86/intel-speed-select/hfi-events.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Intel Speed Select -- Read HFI events for OOB 4 + * Copyright (c) 2022 Intel Corporation. 5 + */ 6 + 7 + /* 8 + * This file incorporates work covered by the following copyright and 9 + * permission notice: 10 + 11 + * WPA Supplicant - driver interaction with Linux nl80211/cfg80211 12 + * Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi> 13 + * 14 + * This program is free software; you can redistribute it and/or modify 15 + * it under the terms of the GNU General Public License version 2 as 16 + * published by the Free Software Foundation. 17 + * 18 + * Alternatively, this software may be distributed under the terms of 19 + * BSD license. 20 + * 21 + * Requires 22 + * libnl-genl-3-dev 23 + * 24 + * For Fedora/CenOS 25 + * dnf install libnl3-devel 26 + * For Ubuntu 27 + * apt install libnl-3-dev libnl-genl-3-dev 28 + */ 29 + 30 + #include <stdio.h> 31 + #include <stdlib.h> 32 + #include <stdarg.h> 33 + #include <string.h> 34 + #include <unistd.h> 35 + #include <fcntl.h> 36 + #include <sys/file.h> 37 + #include <sys/types.h> 38 + #include <sys/stat.h> 39 + #include <errno.h> 40 + #include <getopt.h> 41 + #include <signal.h> 42 + #include <netlink/genl/genl.h> 43 + #include <netlink/genl/family.h> 44 + #include <netlink/genl/ctrl.h> 45 + 46 + #include <linux/thermal.h> 47 + #include "isst.h" 48 + 49 + struct hfi_event_data { 50 + struct nl_sock *nl_handle; 51 + struct nl_cb *nl_cb; 52 + }; 53 + 54 + struct hfi_event_data drv; 55 + 56 + static int ack_handler(struct nl_msg *msg, void *arg) 57 + { 58 + int *err = arg; 59 + *err = 0; 60 + return NL_STOP; 61 + } 62 + 63 + static int finish_handler(struct nl_msg *msg, void *arg) 64 + { 65 + int *ret = arg; 66 + *ret = 0; 67 + return NL_SKIP; 68 + } 69 + 70 + static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, 71 + void *arg) 72 + { 73 + int *ret = arg; 74 + *ret = err->error; 75 + return NL_SKIP; 76 + } 77 + 78 + static int seq_check_handler(struct nl_msg *msg, void *arg) 79 + { 80 + return NL_OK; 81 + } 82 + 83 + static int send_and_recv_msgs(struct hfi_event_data *drv, 84 + struct nl_msg *msg, 85 + int (*valid_handler)(struct nl_msg *, void *), 86 + void *valid_data) 87 + { 88 + struct nl_cb *cb; 89 + int err = -ENOMEM; 90 + 91 + cb = nl_cb_clone(drv->nl_cb); 92 + if (!cb) 93 + goto out; 94 + 95 + err = nl_send_auto_complete(drv->nl_handle, msg); 96 + if (err < 0) 97 + goto out; 98 + 99 + err = 1; 100 + 101 + nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); 102 + nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); 103 + nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); 104 + 105 + if (valid_handler) 106 + nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, 107 + valid_handler, valid_data); 108 + 109 + while (err > 0) 110 + nl_recvmsgs(drv->nl_handle, cb); 111 + out: 112 + nl_cb_put(cb); 113 + nlmsg_free(msg); 114 + return err; 115 + } 116 + 117 + struct family_data { 118 + const char *group; 119 + int id; 120 + }; 121 + 122 + static int family_handler(struct nl_msg *msg, void *arg) 123 + { 124 + struct family_data *res = arg; 125 + struct nlattr *tb[CTRL_ATTR_MAX + 1]; 126 + struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 127 + struct nlattr *mcgrp; 128 + int i; 129 + 130 + nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), 131 + genlmsg_attrlen(gnlh, 0), NULL); 132 + if (!tb[CTRL_ATTR_MCAST_GROUPS]) 133 + return NL_SKIP; 134 + 135 + nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { 136 + struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; 137 + nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), 138 + nla_len(mcgrp), NULL); 139 + if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || 140 + !tb2[CTRL_ATTR_MCAST_GRP_ID] || 141 + strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), 142 + res->group, 143 + nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) 144 + continue; 145 + res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); 146 + break; 147 + }; 148 + 149 + return 0; 150 + } 151 + 152 + static int nl_get_multicast_id(struct hfi_event_data *drv, 153 + const char *family, const char *group) 154 + { 155 + struct nl_msg *msg; 156 + int ret = -1; 157 + struct family_data res = { group, -ENOENT }; 158 + 159 + msg = nlmsg_alloc(); 160 + if (!msg) 161 + return -ENOMEM; 162 + genlmsg_put(msg, 0, 0, genl_ctrl_resolve(drv->nl_handle, "nlctrl"), 163 + 0, 0, CTRL_CMD_GETFAMILY, 0); 164 + NLA_PUT_STRING(msg, CTRL_ATTR_FAMILY_NAME, family); 165 + 166 + ret = send_and_recv_msgs(drv, msg, family_handler, &res); 167 + msg = NULL; 168 + if (ret == 0) 169 + ret = res.id; 170 + 171 + nla_put_failure: 172 + nlmsg_free(msg); 173 + return ret; 174 + } 175 + 176 + struct perf_cap { 177 + int cpu; 178 + int perf; 179 + int eff; 180 + }; 181 + 182 + static void process_hfi_event(struct perf_cap *perf_cap) 183 + { 184 + process_level_change(perf_cap->cpu); 185 + } 186 + 187 + static int handle_event(struct nl_msg *n, void *arg) 188 + { 189 + struct nlmsghdr *nlh = nlmsg_hdr(n); 190 + struct genlmsghdr *genlhdr = genlmsg_hdr(nlh); 191 + struct nlattr *attrs[THERMAL_GENL_ATTR_MAX + 1]; 192 + int ret; 193 + struct perf_cap perf_cap; 194 + 195 + ret = genlmsg_parse(nlh, 0, attrs, THERMAL_GENL_ATTR_MAX, NULL); 196 + 197 + debug_printf("Received event %d parse_rer:%d\n", genlhdr->cmd, ret); 198 + if (genlhdr->cmd == THERMAL_GENL_EVENT_CPU_CAPABILITY_CHANGE) { 199 + struct nlattr *cap; 200 + int j, index = 0; 201 + 202 + debug_printf("THERMAL_GENL_EVENT_CPU_CAPABILITY_CHANGE\n"); 203 + nla_for_each_nested(cap, attrs[THERMAL_GENL_ATTR_CPU_CAPABILITY], j) { 204 + switch (index) { 205 + case 0: 206 + perf_cap.cpu = nla_get_u32(cap); 207 + break; 208 + case 1: 209 + perf_cap.perf = nla_get_u32(cap); 210 + break; 211 + case 2: 212 + perf_cap.eff = nla_get_u32(cap); 213 + break; 214 + default: 215 + break; 216 + } 217 + ++index; 218 + if (index == 3) { 219 + index = 0; 220 + process_hfi_event(&perf_cap); 221 + } 222 + } 223 + } 224 + 225 + return 0; 226 + } 227 + 228 + static int _hfi_exit; 229 + 230 + static int check_hf_suport(void) 231 + { 232 + unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0; 233 + 234 + __cpuid(6, eax, ebx, ecx, edx); 235 + if (eax & BIT(19)) 236 + return 1; 237 + 238 + return 0; 239 + } 240 + 241 + int hfi_main(void) 242 + { 243 + struct nl_sock *sock; 244 + struct nl_cb *cb; 245 + int err = 0; 246 + int mcast_id; 247 + int no_block = 0; 248 + 249 + if (!check_hf_suport()) { 250 + fprintf(stderr, "CPU Doesn't support HFI\n"); 251 + return -1; 252 + } 253 + 254 + sock = nl_socket_alloc(); 255 + if (!sock) { 256 + fprintf(stderr, "nl_socket_alloc failed\n"); 257 + return -1; 258 + } 259 + 260 + if (genl_connect(sock)) { 261 + fprintf(stderr, "genl_connect(sk_event) failed\n"); 262 + goto free_sock; 263 + } 264 + 265 + drv.nl_handle = sock; 266 + drv.nl_cb = cb = nl_cb_alloc(NL_CB_DEFAULT); 267 + if (drv.nl_cb == NULL) { 268 + printf("Failed to allocate netlink callbacks"); 269 + goto free_sock; 270 + } 271 + 272 + mcast_id = nl_get_multicast_id(&drv, THERMAL_GENL_FAMILY_NAME, 273 + THERMAL_GENL_EVENT_GROUP_NAME); 274 + if (mcast_id < 0) { 275 + fprintf(stderr, "nl_get_multicast_id failed\n"); 276 + goto free_sock; 277 + } 278 + 279 + if (nl_socket_add_membership(sock, mcast_id)) { 280 + fprintf(stderr, "nl_socket_add_membership failed"); 281 + goto free_sock; 282 + } 283 + 284 + nl_cb_set(cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, seq_check_handler, 0); 285 + nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, handle_event, NULL); 286 + 287 + if (no_block) 288 + nl_socket_set_nonblocking(sock); 289 + 290 + debug_printf("hfi is initialized\n"); 291 + 292 + while (!_hfi_exit && !err) { 293 + err = nl_recvmsgs(sock, cb); 294 + debug_printf("nl_recv_message err:%d\n", err); 295 + } 296 + 297 + return 0; 298 + 299 + /* Netlink library doesn't have calls to dealloc cb or disconnect */ 300 + free_sock: 301 + nl_socket_free(sock); 302 + 303 + return -1; 304 + } 305 + 306 + void hfi_exit(void) 307 + { 308 + _hfi_exit = 1; 309 + }
+43 -11
tools/power/x86/intel-speed-select/isst-config.c
··· 15 15 int arg; 16 16 }; 17 17 18 - static const char *version_str = "v1.11"; 18 + static const char *version_str = "v1.12"; 19 + 19 20 static const int supported_api_ver = 1; 20 21 static struct isst_if_platform_info isst_platform_info; 21 22 static char *progname; ··· 369 368 return topo_max_cpus; 370 369 } 371 370 372 - static void set_cpu_online_offline(int cpu, int state) 371 + void set_cpu_online_offline(int cpu, int state) 373 372 { 374 373 char buffer[128]; 375 374 int fd, ret; ··· 410 409 unlink("/var/run/isst_cpu_topology.dat"); 411 410 } 412 411 413 - #define MAX_PACKAGE_COUNT 8 414 - #define MAX_DIE_PER_PACKAGE 2 415 - static void for_each_online_package_in_set(void (*callback)(int, void *, void *, 416 - void *, void *), 417 - void *arg1, void *arg2, void *arg3, 418 - void *arg4) 412 + void for_each_online_package_in_set(void (*callback)(int, void *, void *, 413 + void *, void *), 414 + void *arg1, void *arg2, void *arg3, 415 + void *arg4) 419 416 { 420 417 int max_packages[MAX_PACKAGE_COUNT * MAX_PACKAGE_COUNT]; 421 418 int pkg_index = 0, i; ··· 2802 2803 printf("\t[-p|--pause] : Delay between two mail box commands in milliseconds\n"); 2803 2804 printf("\t[-r|--retry] : Retry count for mail box commands on failure, default 3\n"); 2804 2805 printf("\t[-v|--version] : Print version\n"); 2805 - 2806 + printf("\t[-b|--oob : Start a daemon to process HFI events for perf profile change from Out of Band agent.\n"); 2807 + printf("\t[-n|--no-daemon : Don't run as daemon. By default --oob will turn on daemon mode\n"); 2808 + printf("\t[-w|--delay : Delay for reading config level state change in OOB poll mode.\n"); 2806 2809 printf("\nResult format\n"); 2807 2810 printf("\tResult display uses a common format for each command:\n"); 2808 2811 printf("\tResults are formatted in text/JSON with\n"); ··· 2838 2837 int opt, force_cpus_online = 0; 2839 2838 int option_index = 0; 2840 2839 int ret; 2840 + int oob_mode = 0; 2841 + int poll_interval = -1; 2842 + int no_daemon = 0; 2841 2843 2842 2844 static struct option long_options[] = { 2843 2845 { "all-cpus-online", no_argument, 0, 'a' }, ··· 2853 2849 { "out", required_argument, 0, 'o' }, 2854 2850 { "retry", required_argument, 0, 'r' }, 2855 2851 { "version", no_argument, 0, 'v' }, 2852 + { "oob", no_argument, 0, 'b' }, 2853 + { "no-daemon", no_argument, 0, 'n' }, 2854 + { "poll-interval", required_argument, 0, 'w' }, 2856 2855 { 0, 0, 0, 0 } 2857 2856 }; 2858 2857 ··· 2882 2875 } 2883 2876 2884 2877 progname = argv[0]; 2885 - while ((opt = getopt_long_only(argc, argv, "+c:df:hio:va", long_options, 2878 + while ((opt = getopt_long_only(argc, argv, "+c:df:hio:vabw:n", long_options, 2886 2879 &option_index)) != -1) { 2887 2880 switch (opt) { 2888 2881 case 'a': ··· 2927 2920 case 'v': 2928 2921 print_version(); 2929 2922 break; 2923 + case 'b': 2924 + oob_mode = 1; 2925 + break; 2926 + case 'n': 2927 + no_daemon = 1; 2928 + break; 2929 + case 'w': 2930 + ret = strtol(optarg, &ptr, 10); 2931 + if (!ret) { 2932 + fprintf(stderr, "Invalid poll interval count\n"); 2933 + exit(0); 2934 + } 2935 + poll_interval = ret; 2936 + break; 2930 2937 default: 2931 2938 usage(); 2932 2939 } 2933 2940 } 2934 2941 2935 - if (optind > (argc - 2)) { 2942 + if (optind > (argc - 2) && !oob_mode) { 2936 2943 usage(); 2937 2944 exit(0); 2938 2945 } ··· 2956 2935 store_cpu_topology(); 2957 2936 set_cpu_present_cpu_mask(); 2958 2937 set_cpu_target_cpu_mask(); 2938 + 2939 + if (oob_mode) { 2940 + create_cpu_map(); 2941 + if (debug_flag) 2942 + fprintf(stderr, "OOB mode is enabled in debug mode\n"); 2943 + 2944 + ret = isst_daemon(debug_flag, poll_interval, no_daemon); 2945 + if (ret) 2946 + fprintf(stderr, "OOB mode enable failed\n"); 2947 + goto out; 2948 + } 2959 2949 2960 2950 if (!is_clx_n_platform()) { 2961 2951 ret = isst_fill_platform_info();
+244
tools/power/x86/intel-speed-select/isst-daemon.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Intel Speed Select -- Allow speed select to daemonize 4 + * Copyright (c) 2022 Intel Corporation. 5 + */ 6 + 7 + #include <stdio.h> 8 + #include <stdlib.h> 9 + #include <stdarg.h> 10 + #include <string.h> 11 + #include <unistd.h> 12 + #include <fcntl.h> 13 + #include <sys/file.h> 14 + #include <sys/types.h> 15 + #include <sys/stat.h> 16 + #include <errno.h> 17 + #include <getopt.h> 18 + #include <signal.h> 19 + #include <time.h> 20 + 21 + #include "isst.h" 22 + 23 + static int per_package_levels_info[MAX_PACKAGE_COUNT][MAX_DIE_PER_PACKAGE]; 24 + static time_t per_package_levels_tm[MAX_PACKAGE_COUNT][MAX_DIE_PER_PACKAGE]; 25 + 26 + static void init_levels(void) 27 + { 28 + int i, j; 29 + 30 + for (i = 0; i < MAX_PACKAGE_COUNT; ++i) 31 + for (j = 0; j < MAX_DIE_PER_PACKAGE; ++j) 32 + per_package_levels_info[i][j] = -1; 33 + } 34 + 35 + void process_level_change(int cpu) 36 + { 37 + struct isst_pkg_ctdp_level_info ctdp_level; 38 + int pkg_id = get_physical_package_id(cpu); 39 + int die_id = get_physical_die_id(cpu); 40 + struct isst_pkg_ctdp pkg_dev; 41 + time_t tm; 42 + int ret; 43 + 44 + if (pkg_id >= MAX_PACKAGE_COUNT || die_id > MAX_DIE_PER_PACKAGE) { 45 + debug_printf("Invalid package/die info for cpu:%d\n", cpu); 46 + return; 47 + } 48 + 49 + tm = time(NULL); 50 + if (tm - per_package_levels_tm[pkg_id][die_id] < 2 ) 51 + return; 52 + 53 + per_package_levels_tm[pkg_id][die_id] = tm; 54 + 55 + ret = isst_get_ctdp_levels(cpu, &pkg_dev); 56 + if (ret) { 57 + debug_printf("Can't get tdp levels for cpu:%d\n", cpu); 58 + return; 59 + } 60 + 61 + debug_printf("Get Config level %d pkg:%d die:%d current_level:%d \n", cpu, 62 + pkg_id, die_id, pkg_dev.current_level); 63 + 64 + if (pkg_dev.locked) { 65 + debug_printf("config TDP s locked \n"); 66 + return; 67 + } 68 + 69 + if (per_package_levels_info[pkg_id][die_id] == pkg_dev.current_level) 70 + return; 71 + 72 + debug_printf("**Config level change for cpu:%d pkg:%d die:%d from %d to %d\n", 73 + cpu, pkg_id, die_id, per_package_levels_info[pkg_id][die_id], 74 + pkg_dev.current_level); 75 + 76 + per_package_levels_info[pkg_id][die_id] = pkg_dev.current_level; 77 + 78 + ctdp_level.core_cpumask_size = 79 + alloc_cpu_set(&ctdp_level.core_cpumask); 80 + ret = isst_get_coremask_info(cpu, pkg_dev.current_level, &ctdp_level); 81 + if (ret) { 82 + free_cpu_set(ctdp_level.core_cpumask); 83 + debug_printf("Can't get core_mask:%d\n", cpu); 84 + return; 85 + } 86 + 87 + if (ctdp_level.cpu_count) { 88 + int i, max_cpus = get_topo_max_cpus(); 89 + for (i = 0; i < max_cpus; ++i) { 90 + if (pkg_id != get_physical_package_id(i) || die_id != get_physical_die_id(i)) 91 + continue; 92 + if (CPU_ISSET_S(i, ctdp_level.core_cpumask_size, ctdp_level.core_cpumask)) { 93 + fprintf(stderr, "online cpu %d\n", i); 94 + set_cpu_online_offline(i, 1); 95 + } else { 96 + fprintf(stderr, "offline cpu %d\n", i); 97 + set_cpu_online_offline(i, 0); 98 + } 99 + } 100 + } 101 + 102 + free_cpu_set(ctdp_level.core_cpumask); 103 + } 104 + 105 + static void _poll_for_config_change(int cpu, void *arg1, void *arg2, 106 + void *arg3, void *arg4) 107 + { 108 + process_level_change(cpu); 109 + } 110 + 111 + static void poll_for_config_change(void) 112 + { 113 + for_each_online_package_in_set(_poll_for_config_change, NULL, NULL, 114 + NULL, NULL); 115 + } 116 + 117 + static int done = 0; 118 + static int pid_file_handle; 119 + 120 + static void signal_handler(int sig) 121 + { 122 + switch (sig) { 123 + case SIGINT: 124 + case SIGTERM: 125 + done = 1; 126 + hfi_exit(); 127 + exit(0); 128 + break; 129 + default: 130 + break; 131 + } 132 + } 133 + 134 + static void daemonize(char *rundir, char *pidfile) 135 + { 136 + int pid, sid, i; 137 + char str[10]; 138 + struct sigaction sig_actions; 139 + sigset_t sig_set; 140 + int ret; 141 + 142 + if (getppid() == 1) 143 + return; 144 + 145 + sigemptyset(&sig_set); 146 + sigaddset(&sig_set, SIGCHLD); 147 + sigaddset(&sig_set, SIGTSTP); 148 + sigaddset(&sig_set, SIGTTOU); 149 + sigaddset(&sig_set, SIGTTIN); 150 + sigprocmask(SIG_BLOCK, &sig_set, NULL); 151 + 152 + sig_actions.sa_handler = signal_handler; 153 + sigemptyset(&sig_actions.sa_mask); 154 + sig_actions.sa_flags = 0; 155 + 156 + sigaction(SIGHUP, &sig_actions, NULL); 157 + sigaction(SIGTERM, &sig_actions, NULL); 158 + sigaction(SIGINT, &sig_actions, NULL); 159 + 160 + pid = fork(); 161 + if (pid < 0) { 162 + /* Could not fork */ 163 + exit(EXIT_FAILURE); 164 + } 165 + if (pid > 0) 166 + exit(EXIT_SUCCESS); 167 + 168 + umask(027); 169 + 170 + sid = setsid(); 171 + if (sid < 0) 172 + exit(EXIT_FAILURE); 173 + 174 + /* close all descriptors */ 175 + for (i = getdtablesize(); i >= 0; --i) 176 + close(i); 177 + 178 + i = open("/dev/null", O_RDWR); 179 + ret = dup(i); 180 + if (ret == -1) 181 + exit(EXIT_FAILURE); 182 + 183 + ret = dup(i); 184 + if (ret == -1) 185 + exit(EXIT_FAILURE); 186 + 187 + ret = chdir(rundir); 188 + if (ret == -1) 189 + exit(EXIT_FAILURE); 190 + 191 + pid_file_handle = open(pidfile, O_RDWR | O_CREAT, 0600); 192 + if (pid_file_handle == -1) { 193 + /* Couldn't open lock file */ 194 + exit(1); 195 + } 196 + /* Try to lock file */ 197 + #ifdef LOCKF_SUPPORT 198 + if (lockf(pid_file_handle, F_TLOCK, 0) == -1) { 199 + #else 200 + if (flock(pid_file_handle, LOCK_EX|LOCK_NB) < 0) { 201 + #endif 202 + /* Couldn't get lock on lock file */ 203 + fprintf(stderr, "Couldn't get lock file %d\n", getpid()); 204 + exit(1); 205 + } 206 + snprintf(str, sizeof(str), "%d\n", getpid()); 207 + ret = write(pid_file_handle, str, strlen(str)); 208 + if (ret == -1) 209 + exit(EXIT_FAILURE); 210 + 211 + close(i); 212 + } 213 + 214 + int isst_daemon(int debug_mode, int poll_interval, int no_daemon) 215 + { 216 + int ret; 217 + 218 + if (!no_daemon && poll_interval < 0 && !debug_mode) { 219 + fprintf(stderr, "OOB mode is enabled and will run as daemon\n"); 220 + daemonize((char *) "/tmp/", 221 + (char *)"/tmp/hfi-events.pid"); 222 + } else { 223 + signal(SIGINT, signal_handler); 224 + } 225 + 226 + init_levels(); 227 + 228 + if (poll_interval < 0) { 229 + ret = hfi_main(); 230 + if (ret) { 231 + fprintf(stderr, "HFI initialization failed\n"); 232 + } 233 + fprintf(stderr, "Must specify poll-interval\n"); 234 + return ret; 235 + } 236 + 237 + debug_printf("Starting loop\n"); 238 + while (!done) { 239 + sleep(poll_interval); 240 + poll_for_config_change(); 241 + } 242 + 243 + return 0; 244 + }
+13
tools/power/x86/intel-speed-select/isst.h
··· 76 76 77 77 #define DISP_FREQ_MULTIPLIER 100 78 78 79 + #define MAX_PACKAGE_COUNT 8 80 + #define MAX_DIE_PER_PACKAGE 2 81 + 79 82 struct isst_clos_config { 80 83 int pkg_id; 81 84 int die_id; ··· 263 260 extern int is_spr_platform(void); 264 261 extern int is_icx_platform(void); 265 262 extern void isst_trl_display_information(int cpu, FILE *outf, unsigned long long trl); 263 + 264 + extern void set_cpu_online_offline(int cpu, int state); 265 + extern void for_each_online_package_in_set(void (*callback)(int, void *, void *, 266 + void *, void *), 267 + void *arg1, void *arg2, void *arg3, 268 + void *arg4); 269 + extern int isst_daemon(int debug_mode, int poll_interval, int no_daemon); 270 + extern void process_level_change(int cpu); 271 + extern int hfi_main(void); 272 + extern void hfi_exit(void); 266 273 #endif