thermal: intel: Allow processing of HWP interrupt
Subsystems (3)
Srinivas Pandruvada
maintainerPATCH 1/2 thermal: intel: Allow processing of HWP interrupt
Add a weak function to process HWP (Hardware P-states) notifications and move updating HWP_STATUS MSR to this function.
This allows HWP interrupts to be processed by the intel_pstate driver in HWP mode by overriding the implementation.
--- drivers/thermal/intel/therm_throt.c | 7 ++++++- drivers/thermal/intel/thermal_interrupt.h | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/thermal/intel/therm_throt.c +6 -1
@@ -569,13 +569,18 @@ static void notify_thresholds(__u64 msr_val)platform_thermal_notify (msr_val); } +void __weak notify_hwp_interrupt (void ) +{ +wrmsrl_safe (MSR_HWP_STATUS ,0 ); +} +/* Thermal transition interrupt handler */ void intel_thermal_interrupt (void ) {__u64 msr_val;if (static_cpu_has (X86_FEATURE_HWP )) -wrmsrl_safe (MSR_HWP_STATUS ,0 ); +notify_hwp_interrupt ();rdmsrl (MSR_IA32_THERM_STATUS , msr_val);
drivers/thermal/intel/thermal_interrupt.h +3 -0
@@ -12,4 +12,7 @@ extern int (*platform_thermal_notify)(__u64 msr_val);* callback has rate control */ extern bool (*platform_thermal_package_rate_control)(void ); +/* Handle HWP interrupt */ +extern void notify_hwp_interrupt (void ); +#endif /* _INTEL_THERMAL_INTERRUPT_H */
Signature · 1 line
2.31.1
Srinivas Pandruvada
maintainerPATCH 2/2 cpufreq: intel_pstate: Process HWP Guaranteed change notification
It is possible that HWP guaranteed ratio is changed in response to change in power and thermal limits. For example when Intel Speed Select performance profile is changed or there is change in TDP, hardware can send notifications. It is possible that the guaranteed ratio is increased. This creates an issue when turbo is disabled, as the old limits set in MSR_HWP_REQUEST are still lower and hardware will clip to older limits.
This change enables HWP interrupt and process HWP interrupts. When guaranteed is changed, calls cpufreq_update_policy() so that driver callbacks are called to update to new HWP limits. This callback is called from a delayed workqueue of 10ms to avoid frequent updates.
--- drivers/cpufreq/intel_pstate.c | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
drivers/cpufreq/intel_pstate.c +39 -0
@@ -32,6 +32,7 @@#include <asm/cpu_device_id.h> #include <asm/cpufeature.h> #include <asm/intel-family.h> +#include "../drivers/thermal/intel/thermal_interrupt.h" #define INTEL_PSTATE_SAMPLING_INTERVAL (10 * NSEC_PER_MSEC)
@@ -219,6 +220,7 @@ struct global_params {* @sched_flags: Store scheduler flags for possible cross CPU update * @hwp_boost_min: Last HWP boosted min performance * @suspended: Whether or not the driver has been suspended. +* @hwp_notify_work: workqueue for HWP notifications. * * This structure stores per CPU instance data for all CPUs. */
@@ -257,6 +259,7 @@ struct cpudata {unsigned int sched_flags;u32 hwp_boost_min;bool suspended; +struct delayed_work hwp_notify_work; };static struct cpudata **all_cpu_data;
@@ -1625,6 +1628,40 @@ static void intel_pstate_sysfs_hide_hwp_dynamic_boost(void)/************************** sysfs end ************************/ +static void intel_pstate_notify_work (struct work_struct *work) +{ +mutex_lock (&intel_pstate_driver_lock); +cpufreq_update_policy (smp_processor_id ()); +wrmsrl (MSR_HWP_STATUS ,0 ); +mutex_unlock (&intel_pstate_driver_lock); +} + +void notify_hwp_interrupt (void ) +{ +unsigned int this_cpu =smp_processor_id (); +struct cpudata *cpudata; +u64 value; + +if (!hwp_active || !boot_cpu_has (X86_FEATURE_HWP_NOTIFY )) +return ; + +rdmsrl (MSR_HWP_STATUS , value); +if (!(value &0x01 )) +return ; + + cpudata = all_cpu_data[this_cpu]; +schedule_delayed_work_on (this_cpu, &cpudata->hwp_notify_work,msecs_to_jiffies (10 )); +} + +static void intel_pstate_enable_hwp_interrupt (struct cpudata *cpudata) +{ +/* Enable HWP notification interrupt for guaranteed performance change */ +if (boot_cpu_has (X86_FEATURE_HWP_NOTIFY )) { +INIT_DELAYED_WORK (&cpudata->hwp_notify_work, intel_pstate_notify_work); +wrmsrl_on_cpu (cpudata->cpu,MSR_HWP_INTERRUPT ,0x01 ); + } +} +static void intel_pstate_hwp_enable (struct cpudata *cpudata) {/* First disable HWP notification interrupt as we don't process them */
@@ -1634,6 +1671,8 @@ static void intel_pstate_hwp_enable(struct cpudata *cpudata)wrmsrl_on_cpu (cpudata->cpu,MSR_PM_ENABLE ,0x1 );if (cpudata->epp_default == -EINVAL ) cpudata->epp_default =intel_pstate_get_epp (cpudata,0 ); + +intel_pstate_enable_hwp_interrupt (cpudata); }static int atom_get_min_pstate (void )
Signature · 1 line
2.31.1
Re: [PATCH 2/2] cpufreq: intel_pstate: Process HWP Guaranteed change notification
Quoted 8 lines · Srinivas Pandruvada
It is possible that HWP guaranteed ratio is changed in response to change in power and thermal limits. For example when Intel Speed Select performance profile is changed or there is change in TDP, hardware can send notifications. It is possible that the guaranteed ratio is increased. This creates an issue when turbo is disabled, as the old limits set in
MSR_HWP_REQUESTare still lower and hardware will clip to older limits.
Quoted 6 lines
This change enables HWP interrupt and process HWP interrupts. When guaranteed is changed, calls
cpufreq_update_policy()so that driver callbacks are called to update to new HWP limits. This callback is called from a delayed workqueue of 10ms to avoid frequent updates.Signed-off-by Srinivas Pandruvada <[email protected]>
Does this patch depend on 1/2 ?
Quoted 83 lines
--- drivers/cpufreq/intel_pstate.c | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)drivers/cpufreq/intel_pstate.c +39
-0@@ -32,6 +32,7 @@#include <asm/cpu_device_id.h> #include <asm/cpufeature.h> #include <asm/intel-family.h> +#include "../drivers/thermal/intel/thermal_interrupt.h" #define INTEL_PSTATE_SAMPLING_INTERVAL (10 * NSEC_PER_MSEC)@@ -219,6 +220,7 @@ struct global_params {* @sched_flags: Store scheduler flags for possible cross CPU update * @hwp_boost_min: Last HWP boosted min performance * @suspended: Whether or not the driver has been suspended. +* @hwp_notify_work: workqueue for HWP notifications. * * This structure stores per CPU instance data for all CPUs. */ @@ -257,6 +259,7 @@ struct cpudata {unsigned int sched_flags;u32 hwp_boost_min;bool suspended; +struct delayed_work hwp_notify_work; };static struct cpudata **all_cpu_data;@@ -1625,6 +1628,40 @@ static void intel_pstate_sysfs_hide_hwp_dynamic_boost(void)/************************** sysfs end ************************/ +static void intel_pstate_notify_work (struct work_struct *work) +{ +mutex_lock (&intel_pstate_driver_lock); +cpufreq_update_policy (smp_processor_id ()); +wrmsrl (MSR_HWP_STATUS ,0 ); +mutex_unlock (&intel_pstate_driver_lock); +} + +void notify_hwp_interrupt (void ) +{ +unsigned int this_cpu =smp_processor_id (); +struct cpudata *cpudata; +u64 value; + +if (!hwp_active || !boot_cpu_has (X86_FEATURE_HWP_NOTIFY )) +return ; + +rdmsrl (MSR_HWP_STATUS , value); +if (!(value &0x01 )) +return ; + + cpudata = all_cpu_data[this_cpu]; +schedule_delayed_work_on (this_cpu, &cpudata->hwp_notify_work,msecs_to_jiffies (10 )); +} + +static void intel_pstate_enable_hwp_interrupt (struct cpudata *cpudata) +{ +/* Enable HWP notification interrupt for guaranteed performance change */ +if (boot_cpu_has (X86_FEATURE_HWP_NOTIFY )) { +INIT_DELAYED_WORK (&cpudata->hwp_notify_work, intel_pstate_notify_work); +wrmsrl_on_cpu (cpudata->cpu,MSR_HWP_INTERRUPT ,0x01 ); + } +} +static void intel_pstate_hwp_enable (struct cpudata *cpudata) {/* First disable HWP notification interrupt as we don't process them */ @@ -1634,6 +1671,8 @@ static void intel_pstate_hwp_enable(struct cpudata *cpudata)wrmsrl_on_cpu (cpudata->cpu,MSR_PM_ENABLE ,0x1 );if (cpudata->epp_default == -EINVAL ) cpudata->epp_default =intel_pstate_get_epp (cpudata,0 ); + +intel_pstate_enable_hwp_interrupt (cpudata); }static int atom_get_min_pstate (void )
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Rafael J. Wysocki
maintainerRe: [PATCH 2/2] cpufreq: intel_pstate: Process HWP Guaranteed change notification
In reply to Srinivas PandruvadaQuoted 9 lines · Srinivas Pandruvada
It is possible that HWP guaranteed ratio is changed in response to change in power and thermal limits. For example when Intel Speed Select performance profile is changed or there is change in TDP, hardware can send notifications. It is possible that the guaranteed ratio is increased. This creates an issue when turbo is disabled, as the old limits set in
MSR_HWP_REQUESTare still lower and hardware will clip to older limits.
Quoted 6 lines
This change enables HWP interrupt and process HWP interrupts. When guaranteed is changed, calls
cpufreq_update_policy()so that driver callbacks are called to update to new HWP limits. This callback is called from a delayed workqueue of 10ms to avoid frequent updates.Signed-off-by Srinivas Pandruvada <[email protected]>
Applied along with the [1/2] as 5.15 material, thanks!
Quoted 85 lines
--- drivers/cpufreq/intel_pstate.c | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)drivers/cpufreq/intel_pstate.c +39
-1@@ -32,6 +32,7 @@#include <asm/cpu_device_id.h> #include <asm/cpufeature.h> #include <asm/intel-family.h> +#include "../drivers/thermal/intel/thermal_interrupt.h" #define INTEL_PSTATE_SAMPLING_INTERVAL (10 * NSEC_PER_MSEC)@@ -219,6 +220,7 @@ struct global_params {* @sched_flags: Store scheduler flags for possible cross CPU update * @hwp_boost_min: Last HWP boosted min performance * @suspended: Whether or not the driver has been suspended. +* @hwp_notify_work: workqueue for HWP notifications. * * This structure stores per CPU instance data for all CPUs. */ @@ -257,6 +259,7 @@ struct cpudata {unsigned int sched_flags;u32 hwp_boost_min;bool suspended; +struct delayed_work hwp_notify_work; };static struct cpudata **all_cpu_data;@@ -1625,6 +1628,40 @@ static void intel_pstate_sysfs_hide_hwp_dynamic_boost(void)/************************** sysfs end ************************/ +static void intel_pstate_notify_work (struct work_struct *work) +{ +mutex_lock (&intel_pstate_driver_lock); +cpufreq_update_policy (smp_processor_id ()); +wrmsrl (MSR_HWP_STATUS ,0 ); +mutex_unlock (&intel_pstate_driver_lock); +} + +void notify_hwp_interrupt (void ) +{ +unsigned int this_cpu =smp_processor_id (); +struct cpudata *cpudata; +u64 value; + +if (!hwp_active || !boot_cpu_has (X86_FEATURE_HWP_NOTIFY )) +return ; + +rdmsrl (MSR_HWP_STATUS , value); +if (!(value &0x01 )) +return ; + + cpudata = all_cpu_data[this_cpu]; +schedule_delayed_work_on (this_cpu, &cpudata->hwp_notify_work,msecs_to_jiffies (10 )); +} + +static void intel_pstate_enable_hwp_interrupt (struct cpudata *cpudata) +{ +/* Enable HWP notification interrupt for guaranteed performance change */ +if (boot_cpu_has (X86_FEATURE_HWP_NOTIFY )) { +INIT_DELAYED_WORK (&cpudata->hwp_notify_work, intel_pstate_notify_work); +wrmsrl_on_cpu (cpudata->cpu,MSR_HWP_INTERRUPT ,0x01 ); + } +} +static void intel_pstate_hwp_enable (struct cpudata *cpudata) {/* First disable HWP notification interrupt as we don't process them */ @@ -1634,6 +1671,8 @@ static void intel_pstate_hwp_enable(struct cpudata *cpudata)wrmsrl_on_cpu (cpudata->cpu,MSR_PM_ENABLE ,0x1 );if (cpudata->epp_default == -EINVAL ) cpudata->epp_default =intel_pstate_get_epp (cpudata,0 ); + +intel_pstate_enable_hwp_interrupt (cpudata); }static int atom_get_min_pstate (void ) --2.31.1
A message that is not in the archive (sent off-list or not yet received): [email protected]
Srinivas Pandruvada
maintainerRe: [PATCH 2/2] cpufreq: intel_pstate: Process HWP Guaranteed change notification
Hi Wang,
I think this is Lenovo system. The FW sends some interrupts prematurely before driver is ready,
There is a fix available but We have decided to revert the commit.
Please try the patch attached here.
https://bugzilla.kernel.org/show_bug.cgi?id=214329
Thanks,
Srinivas
Quoted 127 lines · Xi Ruoyao
Hi Srinivas,
Sorry for distrubing, but the mainline kernel panics on my system during
boot. By reverting this commit the problem seems fixed.I don't have kdump set up on the system, so I could only took a photo containing (a part of :( ) panic message. The system is a laptop with Core i7-1065G7. My kernel config is also attached.
Not sure if there is something wrong in this commit, or there is a firmware bug from the vendor of my laptop. In the latter case, can we have something in kernel config or cmdline to disable HWP as a workaround?
Quoted 110 lines · Srinivas Pandruvada
It is possible that HWP guaranteed ratio is changed in response to change in power and thermal limits. For example when Intel Speed Select
performance profile is changed or there is change in TDP, hardware can
send notifications. It is possible that the guaranteed ratio is increased. This creates an issue when turbo is disabled, as the old limits set inMSR_HWP_REQUESTare still lower and hardware will clip to older limits.This change enables HWP interrupt and process HWP interrupts. When guaranteed is changed, calls
cpufreq_update_policy()so that driver callbacks are called to update to new HWP limits. This callback is called from a delayed workqueue of 10ms to avoid frequent updates.Signed-off-by: Srinivas Pandruvada
<[email protected]>
---
drivers/cpufreq/intel_pstate.c | 39
++++++++++++++++++++++++++++++++++1 file changed, 39 insertions(+)drivers/cpufreq/intel_pstate.c +1
-0@@ -32,6 +32,7 @@ #include <asm/cpu_device_id.h> #include <asm/cpufeature.h> #include <asm/intel-family.h> +#include "../drivers/thermal/intel/thermal_interrupt.h"
#define INTEL_PSTATE_SAMPLING_INTERVAL (10 *NSEC_PER_MSEC)drivers/cpufreq/intel_pstate.c +0
-0@@ -219,6 +220,7 @@ struct global_params { * @sched_flags: Store scheduler flags for possible cross CPUupdate
* @hwp_boost_min: Last HWP boosted min performance
* @suspended: Whether or not the driver has been suspended.
+ * @hwp_notify_work: workqueue for HWP notifications.
*
* This structure stores per CPU instance data for all CPUs. */drivers/cpufreq/intel_pstate.c +1
-0@@ -257,6 +259,7 @@ struct cpudata { unsigned int sched_flags; u32 hwp_boost_min; bool suspended; + struct delayed_work hwp_notify_work; };
static struct cpudata **all_cpu_data;drivers/cpufreq/intel_pstate.c +0
-0@@ -1625,6 +1628,40 @@ static voidintel_pstate_sysfs_hide_hwp_dynamic_boost (void)
/************************** sysfs end ************************/drivers/cpufreq/intel_pstate.c +23
-0+static void intel_pstate_notify_work (struct work_struct *work) +{ + mutex_lock(&intel_pstate_driver_lock); + cpufreq_update_policy(smp_processor_id()); + wrmsrl(MSR_HWP_STATUS, 0); + mutex_unlock(&intel_pstate_driver_lock); +} + +void notify_hwp_interrupt (void ) +{ + unsigned int this_cpu = smp_processor_id(); + struct cpudata *cpudata; + u64 value; + + if (!hwp_active || !boot_cpu_has(X86_FEATURE_HWP_NOTIFY)) + return; + + rdmsrl(MSR_HWP_STATUS, value); + if (!(value & 0x01)) + return; + + cpudata = all_cpu_data[this_cpu]; + schedule_delayed_work_on(this_cpu, &cpudata->hwp_notify_work,
msecs_to_jiffies(10));drivers/cpufreq/intel_pstate.c +3
-0+} + +static void intel_pstate_enable_hwp_interrupt(struct cpudata*cpudata)
+{
+ /* Enable HWP notification interrupt for guaranteed performance change */
+ if (boot_cpu_has(X86_FEATURE_HWP_NOTIFY)) {
+ INIT_DELAYED_WORK(&cpudata->hwp_notify_work,intel_pstate_notify_work);
+ wrmsrl_on_cpu(cpudata->cpu,MSR_HWP_INTERRUPT,0x01); + }drivers/cpufreq/intel_pstate.c +2
-0+} +static void
intel_pstate_hwp_enable(struct cpudata *cpudata){
/* First disable HWP notification interrupt as we don't process them */drivers/cpufreq/intel_pstate.c +2
-0@@ -1634,6 +1671,8 @@ static void intel_pstate_hwp_enable(struct cpudata *cpudata) wrmsrl_on_cpu(cpudata->cpu, MSR_PM_ENABLE, 0x1); if (cpudata->epp_default == -EINVAL) cpudata->epp_default = intel_pstate_get_epp(cpudata,0 ); + + intel_pstate_enable_hwp_interrupt(cpudata); }
static intatom_get_min_pstate(void)
Re: [PATCH 2/2] cpufreq: intel_pstate: Process HWP Guaranteed change notification
Quoted 4 lines · Srinivas Pandruvada
Hi Wang,
I think this is Lenovo system. The FW sends some interrupts prematurely before driver is ready,
It's not Lenovo, but I think this kind of FW bugs exist in wild.
Quoted 4 lines
There is a fix available but We have decided to revert the commit.
Please try the patch attached here.
https://bugzilla.kernel.org/show_bug.cgi?id=214329
I can confirm it fixed the issue (at least on my machine :).
Thanks!
Signature · 2 lines
Xi Ruoyao <[email protected]> School of Aerospace Science and Technology, Xidian University
Quoted 10 lines · Srinivas Pandruvada
Add a weak function to process HWP (Hardware P-states) notifications and
move updatingHWP_STATUSMSR to this function.This allows HWP interrupts to be processed by the
intel_pstatedriver in
HWP mode by overriding the implementation.Signed-off-by: Srinivas Pandruvada <
[email protected]>
thanks,
rui
Quoted 44 lines
--- drivers/thermal/intel/therm_throt.c | 7 ++++++- drivers/thermal/intel/thermal_interrupt.h | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-)drivers/thermal/intel/therm_throt.c +6
-1@@ -569,13 +569,18 @@ static void notify_thresholds(__u64 msr_val)platform_thermal_notify (msr_val); } +void __weak notify_hwp_interrupt (void ) +{ +wrmsrl_safe (MSR_HWP_STATUS ,0 ); +} +/* Thermal transition interrupt handler */ void intel_thermal_interrupt (void ) {__u64 msr_val;if (static_cpu_has (X86_FEATURE_HWP )) -wrmsrl_safe (MSR_HWP_STATUS ,0 ); +notify_hwp_interrupt ();rdmsrl (MSR_IA32_THERM_STATUS , msr_val);drivers/thermal/intel/thermal_interrupt.h +3
-0@@ -12,4 +12,7 @@ extern int (*platform_thermal_notify)(__u64msr_val); * callback has rate control */ extern bool (*platform_thermal_package_rate_control)(void ); +/* Handle HWP interrupt */ +extern void notify_hwp_interrupt (void ); +#endif /*
_INTEL_THERMAL_INTERRUPT_H*/
[thermal: thermal/next] thermal/drivers/intel: Allow processing of HWP interrupt
In reply to Srinivas PandruvadaThe following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 5950fc44a57ace59f21dccfd792250019348a182 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//5950fc44a57ace59f21dccfd792250019348a182 Author: Srinivas Pandruvada <[email protected]> AuthorDate: Thu, 19 Aug 2021 19:40:05 -07:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 09 Sep 2021 16:33:20 +02:00
thermal/drivers/intel: Allow processing of HWP interrupt
Add a weak function to process HWP (Hardware P-states) notifications and move updating HWP_STATUS MSR to this function.
This allows HWP interrupts to be processed by the intel_pstate driver in HWP mode by overriding the implementation.
--- drivers/thermal/intel/therm_throt.c | 7 ++++++- drivers/thermal/intel/thermal_interrupt.h | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/thermal/intel/therm_throt.c +6 -1
@@ -569,13 +569,18 @@ static void notify_thresholds(__u64 msr_val)platform_thermal_notify (msr_val); } +void __weak notify_hwp_interrupt (void ) +{ +wrmsrl_safe (MSR_HWP_STATUS ,0 ); +} +/* Thermal transition interrupt handler */ void intel_thermal_interrupt (void ) {__u64 msr_val;if (static_cpu_has (X86_FEATURE_HWP )) -wrmsrl_safe (MSR_HWP_STATUS ,0 ); +notify_hwp_interrupt ();rdmsrl (MSR_IA32_THERM_STATUS , msr_val);
drivers/thermal/intel/thermal_interrupt.h +3 -0
@@ -12,4 +12,7 @@ extern int (*platform_thermal_notify)(__u64 msr_val);* callback has rate control */ extern bool (*platform_thermal_package_rate_control)(void ); +/* Handle HWP interrupt */ +extern void notify_hwp_interrupt (void ); +#endif /* _INTEL_THERMAL_INTERRUPT_H */