mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mario Limonciello <mario.limonciello@amd.com>
To: Rui Huang <ray.huang@amd.com>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	Viresh Kumar <viresh.kumar@linaro.org>
Cc: "open list:AMD PSTATE DRIVER" <linux-pm@vger.kernel.org>,
	Perry Yuan <Perry.Yuan@amd.com>,
	open list <linux-kernel@vger.kernel.org>,
	"Mario Limonciello" <mario.limonciello@amd.com>
Subject: [PATCH v3 4/6] cpufreq: amd-pstate: Allow replacing acpi-cpufreq when loaded
Date: Thu, 14 Apr 2022 11:47:59 -0500	[thread overview]
Message-ID: <20220414164801.1051-5-mario.limonciello@amd.com> (raw)
In-Reply-To: <20220414164801.1051-1-mario.limonciello@amd.com>

`amd-pstate` can be compiled as a module.  This however can be a
deficiency because `acpi-cpufreq` will be loaded earlier when compiled
into the kernel meaning `amd-pstate` doesn't get a chance.
`acpi-cpufreq` is also unable to be unloaded in this circumstance.

To better improve the usability of `amd-pstate` when compiled as a module,
add an optional module parameter that will force it to replace other
cpufreq drivers at startup.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
v2->v3:
 * Rebase on earlier patches
 * Use IS_REACHABLE
 * Only add replace parameter if acpu-cpufreq is enabled
 * Only show info message once
v1->v2:
 * Update to changes from v1.
 * Verify the driver being matched is acpi-cpufreq.
 * Show a message letting users know they can use amd-pstate.

 drivers/cpufreq/amd-pstate.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index d323f3e3888c..8ae65a2072d6 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -63,6 +63,13 @@ module_param(shared_mem, bool, 0444);
 MODULE_PARM_DESC(shared_mem,
 		 "enable amd-pstate on processors with shared memory solution (false = disabled (default), true = enabled)");
 
+#if defined(CONFIG_X86_ACPI_CPUFREQ) || defined(CONFIG_X86_ACPI_CPUFREQ_MODULE)
+static bool replace = false;
+module_param(replace, bool, 0444);
+MODULE_PARM_DESC(replace,
+		  "replace acpi-cpufreq driver upon init if necessary");
+#endif
+
 static struct cpufreq_driver amd_pstate_driver;
 
 /**
@@ -643,6 +650,7 @@ static struct cpufreq_driver amd_pstate_driver = {
 
 static int __init amd_pstate_init(void)
 {
+	const char *current_driver;
 	int ret;
 
 	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
@@ -666,9 +674,19 @@ static int __init amd_pstate_init(void)
 		return -ENODEV;
 	}
 
-	/* don't keep reloading if cpufreq_driver exists */
-	if (cpufreq_get_current_driver())
+	current_driver = cpufreq_get_current_driver();
+	if (current_driver) {
+#if IS_REACHABLE(CONFIG_X86_ACPI_CPUFREQ)
+		if (replace && strcmp(current_driver, "acpi-cpufreq") == 0) {
+			acpi_cpufreq_exit();
+		} else {
+			pr_info_once("A processor on this system supports amd-pstate, you can enable it with amd_pstate.replace=1\n");
+			return -EEXIST;
+		}
+#else
 		return -EEXIST;
+#endif
+	}
 
 	/* enable amd pstate feature */
 	ret = amd_pstate_enable(true);
-- 
2.34.1


  parent reply	other threads:[~2022-04-14 17:04 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-14 16:47 [PATCH v3 0/6] Improve usability for amd-pstate Mario Limonciello
2022-04-14 16:47 ` [PATCH v3 1/6] cpufreq: Export acpu_cpufreq_exit for other drivers to call Mario Limonciello
2022-04-14 16:47 ` [PATCH v3 2/6] cpufreq: amd-pstate: Only show shared memory solution message once Mario Limonciello
2022-04-27 13:46   ` Huang Rui
2022-04-14 16:47 ` [PATCH v3 3/6] cpufreq: amd-pstate: Move cpufreq driver check later Mario Limonciello
2022-04-27 14:45   ` Huang Rui
2022-04-14 16:47 ` Mario Limonciello [this message]
2022-04-14 17:32   ` [PATCH v3 4/6] cpufreq: amd-pstate: Allow replacing acpi-cpufreq when loaded Nathan Fontenot
2022-04-14 17:58     ` Limonciello, Mario
2022-04-21 18:38       ` Rafael J. Wysocki
2022-04-28  7:15         ` Huang Rui
2022-04-29  2:36           ` Nathan Fontenot
2022-04-29  6:26             ` Huang Rui
2022-04-14 16:48 ` [PATCH v3 5/6] cpufreq: amd-pstate: Add a module device table Mario Limonciello
2022-04-14 16:48 ` [PATCH v3 6/6] cpufreq: amd-pstate: Default to replace acpi-cpufreq Mario Limonciello

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=20220414164801.1051-5-mario.limonciello@amd.com \
    --to=mario.limonciello@amd.com \
    --cc=Perry.Yuan@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=ray.huang@amd.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

all inboxes | Powered by JetHome®