diff mbox series

[1/2] acpi: processor: allow fixing up the frequency for a performance state

Message ID 20221221155203.11347-2-ptyadav@amazon.de
State New
Headers show
Series intel_pstate: fix turbo not being used after a processor is rebooted | expand

Commit Message

Pratyush Yadav Dec. 21, 2022, 3:52 p.m. UTC
In some cases the ACPI table can have an incorrect frequency populated
for a performance state. For example, in Intel platforms, the Turbo
frequency is just listed as +1 MHz above the max non-turbo frequency.
The frequency can actually go much higher based on various factors like
temperature, voltage, etc.

Allow drivers like intel_pstate to fix up performance state frequencies
with the actual maximum value. While at it, also update the QoS
constraints if needed to match the new frequency values.

Signed-off-by: Pratyush Yadav <ptyadav@amazon.de>
---
 drivers/acpi/processor_perflib.c | 40 ++++++++++++++++++++++++++++++++
 include/acpi/processor.h         |  2 ++
 2 files changed, 42 insertions(+)

Comments

Rafael J. Wysocki Dec. 22, 2022, 4:23 p.m. UTC | #1
On Wed, Dec 21, 2022 at 4:52 PM Pratyush Yadav <ptyadav@amazon.de> wrote:
>
> In some cases the ACPI table can have an incorrect frequency populated
> for a performance state. For example, in Intel platforms, the Turbo
> frequency is just listed as +1 MHz above the max non-turbo frequency.

Which is a known convention based on compatibility with some older OSes.

> The frequency can actually go much higher based on various factors like
> temperature, voltage, etc.

It can.

> Allow drivers like intel_pstate to fix up performance state frequencies
> with the actual maximum value.

Why do you want to do that?

> While at it, also update the QoS
> constraints if needed to match the new frequency values.
>
> Signed-off-by: Pratyush Yadav <ptyadav@amazon.de>
> ---
>  drivers/acpi/processor_perflib.c | 40 ++++++++++++++++++++++++++++++++
>  include/acpi/processor.h         |  2 ++
>  2 files changed, 42 insertions(+)
>
> diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
> index 970f04a958cd..4958aee4c024 100644
> --- a/drivers/acpi/processor_perflib.c
> +++ b/drivers/acpi/processor_perflib.c
> @@ -766,3 +766,43 @@ void acpi_processor_unregister_performance(unsigned int cpu)
>         mutex_unlock(&performance_mutex);
>  }
>  EXPORT_SYMBOL(acpi_processor_unregister_performance);
> +
> +int acpi_processor_fixup_perf_state(unsigned int cpu, unsigned int state,
> +                                   unsigned int frequency)
> +{
> +       struct acpi_processor *pr;
> +       int ret;
> +
> +       mutex_lock(&performance_mutex);
> +
> +       pr = per_cpu(processors, cpu);
> +       if (!pr) {
> +               mutex_unlock(&performance_mutex);
> +               return -ENODEV;
> +       }
> +
> +       if (!pr->performance) {
> +               mutex_unlock(&performance_mutex);
> +               return -EINVAL;
> +       }
> +
> +       if (state >= pr->performance->state_count) {
> +               mutex_unlock(&performance_mutex);
> +               return -EINVAL;
> +       }
> +
> +       pr->performance->states[state].core_frequency = frequency;
> +
> +       if (ignore_ppc != 1 && state == pr->performance_platform_limit &&
> +           freq_qos_request_active(&pr->perflib_req)) {
> +               ret = freq_qos_update_request(&pr->perflib_req,
> +                                             frequency * 1000);
> +               if (ret < 0)
> +                       pr_warn("Failed to update perflib freq constraint: CPU%d (%d)\n",
> +                               pr->id, ret);
> +       }
> +
> +       mutex_unlock(&performance_mutex);
> +       return 0;
> +}
> +EXPORT_SYMBOL(acpi_processor_fixup_perf_state);
> diff --git a/include/acpi/processor.h b/include/acpi/processor.h
> index 94181fe9780a..daff978cfa7d 100644
> --- a/include/acpi/processor.h
> +++ b/include/acpi/processor.h
> @@ -258,6 +258,8 @@ extern int acpi_processor_preregister_performance(struct
>  extern int acpi_processor_register_performance(struct acpi_processor_performance
>                                                *performance, unsigned int cpu);
>  extern void acpi_processor_unregister_performance(unsigned int cpu);
> +extern int acpi_processor_fixup_perf_state(unsigned int cpu, unsigned int state,
> +                                          unsigned int frequency);
>
>  int acpi_processor_pstate_control(void);
>  /* note: this locks both the calling module and the processor module
> --
> 2.38.1
>
Pratyush Yadav Dec. 22, 2022, 10:18 p.m. UTC | #2
On Thu, Dec 22 2022, Rafael J. Wysocki wrote:
> On Wed, Dec 21, 2022 at 4:52 PM Pratyush Yadav <ptyadav@amazon.de> wrote:
>>
>> In some cases the ACPI table can have an incorrect frequency populated
>> for a performance state. For example, in Intel platforms, the Turbo
>> frequency is just listed as +1 MHz above the max non-turbo frequency.
>
> Which is a known convention based on compatibility with some older OSes.

Interesting. I did not know that.

>
>> The frequency can actually go much higher based on various factors like
>> temperature, voltage, etc.
>
> It can.
>
>> Allow drivers like intel_pstate to fix up performance state frequencies
>> with the actual maximum value.
>
> Why do you want to do that?

To be able to use my processors at the full frequency they are capable
of. See [0] for more details.

[0] https://lore.kernel.org/linux-pm/mafs0k02jd8oh.fsf_-_@dev-dsk-ptyadav-1c-37607b33.eu-west-1.amazon.com/

>
[...]
diff mbox series

Patch

diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
index 970f04a958cd..4958aee4c024 100644
--- a/drivers/acpi/processor_perflib.c
+++ b/drivers/acpi/processor_perflib.c
@@ -766,3 +766,43 @@  void acpi_processor_unregister_performance(unsigned int cpu)
 	mutex_unlock(&performance_mutex);
 }
 EXPORT_SYMBOL(acpi_processor_unregister_performance);
+
+int acpi_processor_fixup_perf_state(unsigned int cpu, unsigned int state,
+				    unsigned int frequency)
+{
+	struct acpi_processor *pr;
+	int ret;
+
+	mutex_lock(&performance_mutex);
+
+	pr = per_cpu(processors, cpu);
+	if (!pr) {
+		mutex_unlock(&performance_mutex);
+		return -ENODEV;
+	}
+
+	if (!pr->performance) {
+		mutex_unlock(&performance_mutex);
+		return -EINVAL;
+	}
+
+	if (state >= pr->performance->state_count) {
+		mutex_unlock(&performance_mutex);
+		return -EINVAL;
+	}
+
+	pr->performance->states[state].core_frequency = frequency;
+
+	if (ignore_ppc != 1 && state == pr->performance_platform_limit &&
+	    freq_qos_request_active(&pr->perflib_req)) {
+		ret = freq_qos_update_request(&pr->perflib_req,
+					      frequency * 1000);
+		if (ret < 0)
+			pr_warn("Failed to update perflib freq constraint: CPU%d (%d)\n",
+				pr->id, ret);
+	}
+
+	mutex_unlock(&performance_mutex);
+	return 0;
+}
+EXPORT_SYMBOL(acpi_processor_fixup_perf_state);
diff --git a/include/acpi/processor.h b/include/acpi/processor.h
index 94181fe9780a..daff978cfa7d 100644
--- a/include/acpi/processor.h
+++ b/include/acpi/processor.h
@@ -258,6 +258,8 @@  extern int acpi_processor_preregister_performance(struct
 extern int acpi_processor_register_performance(struct acpi_processor_performance
 					       *performance, unsigned int cpu);
 extern void acpi_processor_unregister_performance(unsigned int cpu);
+extern int acpi_processor_fixup_perf_state(unsigned int cpu, unsigned int state,
+					   unsigned int frequency);
 
 int acpi_processor_pstate_control(void);
 /* note: this locks both the calling module and the processor module