public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Pratyush Yadav <ptyadav@amazon.de>
To: <linux-pm@vger.kernel.org>
Cc: Pratyush Yadav <ptyadav@amazon.de>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Len Brown <lenb@kernel.org>,
	Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	Robert Moore <robert.moore@intel.com>,
	<linux-acpi@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<devel@acpica.org>
Subject: [PATCH 1/2] acpi: processor: allow fixing up the frequency for a performance state
Date: Wed, 21 Dec 2022 16:52:02 +0100	[thread overview]
Message-ID: <20221221155203.11347-2-ptyadav@amazon.de> (raw)
In-Reply-To: <20221221155203.11347-1-ptyadav@amazon.de>

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(+)

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


  reply	other threads:[~2022-12-21 15:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-21 15:52 [PATCH 0/2] intel_pstate: fix turbo not being used after a processor is rebooted Pratyush Yadav
2022-12-21 15:52 ` Pratyush Yadav [this message]
2022-12-22 16:23   ` [PATCH 1/2] acpi: processor: allow fixing up the frequency for a performance state Rafael J. Wysocki
2022-12-22 22:18     ` Pratyush Yadav
2022-12-21 15:52 ` [PATCH 2/2] cpufreq: intel_pstate: use acpi perflib to update turbo frequency Pratyush Yadav
2022-12-21 21:34 ` [PATCH 0/2] intel_pstate: fix turbo not being used after a processor is rebooted srinivas pandruvada
2022-12-22 10:39   ` Pratyush Yadav
2022-12-23 18:10     ` srinivas pandruvada
2022-12-25  0:28       ` srinivas pandruvada
2022-12-27 15:38         ` Pratyush Yadav
2022-12-27 15:57           ` Rafael J. Wysocki
2022-12-27 16:40           ` srinivas pandruvada
2022-12-27 17:02             ` Rafael J. Wysocki
2022-12-27 17:13               ` Rafael J. Wysocki
2022-12-27 18:07               ` srinivas pandruvada
2022-12-27 18:47                 ` Rafael J. Wysocki
2022-12-27 18:49                   ` srinivas pandruvada
2022-12-27 18:54                     ` Rafael J. Wysocki
2022-12-27 16:15 ` Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221221155203.11347-2-ptyadav@amazon.de \
    --to=ptyadav@amazon.de \
    --cc=devel@acpica.org \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=robert.moore@intel.com \
    --cc=srinivas.pandruvada@linux.intel.com \
    --cc=viresh.kumar@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox