diff mbox series

[4/8] x86/amd: Move amd_get_highest_perf() out of amd-pstate

Message ID 20240826211358.2694603-5-superm1@kernel.org
State New
Headers show
Series Adjustments for preferred core detection | expand

Commit Message

Mario Limonciello Aug. 26, 2024, 9:13 p.m. UTC
From: Mario Limonciello <mario.limonciello@amd.com>

amd_get_highest_perf() is a helper used to get the highest perf
value on AMD systems.  It's used in amd-pstate as part of preferred
core handling, but applicable for acpi-cpufreq as well.

Move it out to cppc handling code.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
 arch/x86/kernel/acpi/cppc.c  | 30 ++++++++++++++++++++++++++++++
 drivers/cpufreq/amd-pstate.c | 34 ++--------------------------------
 include/acpi/cppc_acpi.h     |  2 ++
 3 files changed, 34 insertions(+), 32 deletions(-)

Comments

Yuan, Perry Aug. 27, 2024, 6:46 a.m. UTC | #1
[AMD Official Use Only - AMD Internal Distribution Only]

> -----Original Message-----
> From: Mario Limonciello <superm1@kernel.org>
> Sent: Tuesday, August 27, 2024 5:14 AM
> To: Borislav Petkov <bp@alien8.de>; Shenoy, Gautham Ranjal
> <gautham.shenoy@amd.com>; Yuan, Perry <Perry.Yuan@amd.com>
> Cc: maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT) <x86@kernel.org>;
> Rafael J . Wysocki <rafael@kernel.org>; open list:X86 ARCHITECTURE (32-BIT
> AND 64-BIT) <linux-kernel@vger.kernel.org>; open list:ACPI <linux-
> acpi@vger.kernel.org>; open list:CPU FREQUENCY SCALING FRAMEWORK
> <linux-pm@vger.kernel.org>; Limonciello, Mario
> <Mario.Limonciello@amd.com>
> Subject: [PATCH 4/8] x86/amd: Move amd_get_highest_perf() out of amd-
> pstate
>
> From: Mario Limonciello <mario.limonciello@amd.com>
>
> amd_get_highest_perf() is a helper used to get the highest perf value on AMD
> systems.  It's used in amd-pstate as part of preferred core handling, but
> applicable for acpi-cpufreq as well.
>
> Move it out to cppc handling code.
>
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
>  arch/x86/kernel/acpi/cppc.c  | 30 ++++++++++++++++++++++++++++++
> drivers/cpufreq/amd-pstate.c | 34 ++--------------------------------
>  include/acpi/cppc_acpi.h     |  2 ++
>  3 files changed, 34 insertions(+), 32 deletions(-)
>
> diff --git a/arch/x86/kernel/acpi/cppc.c b/arch/x86/kernel/acpi/cppc.c index
> e94507110ca24..5a6c01a1b0d95 100644
> --- a/arch/x86/kernel/acpi/cppc.c
> +++ b/arch/x86/kernel/acpi/cppc.c
> @@ -119,6 +119,36 @@ void init_freq_invariance_cppc(void)
>       mutex_unlock(&freq_invariance_lock);
>  }
>
> +/*
> + * Get the highest performance register value.
> + * @cpu: CPU from which to get highest performance.
> + * @highest_perf: Return address for highest performance value.
> + *
> + * Return: 0 for success, negative error code otherwise.
> + */
> +int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf) {
> +     u64 val;
> +     int ret;
> +
> +     if (cpu_feature_enabled(X86_FEATURE_CPPC)) {
> +             ret = rdmsrl_safe_on_cpu(cpu, MSR_AMD_CPPC_CAP1, &val);
> +             if (ret)
> +                     goto out;
> +
> +             val = AMD_CPPC_HIGHEST_PERF(val);
> +     } else {
> +             ret = cppc_get_highest_perf(cpu, &val);
> +             if (ret)
> +                     goto out;
> +     }
> +
> +     WRITE_ONCE(*highest_perf, (u32)val);
> +out:
> +     return ret;
> +}
> +EXPORT_SYMBOL_GPL(amd_get_highest_perf);
> +
>  /**
>   * amd_get_boost_ratio_numerator: Get the numerator to use for boost ratio
> calculation
>   * @cpu: CPU to get numerator for.
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 89bda7a2bb8d1..f470b5700db58 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -803,36 +803,6 @@ static void
> amd_pstste_sched_prefcore_workfn(struct work_struct *work)  }  static
> DECLARE_WORK(sched_prefcore_work,
> amd_pstste_sched_prefcore_workfn);
>
> -/*
> - * Get the highest performance register value.
> - * @cpu: CPU from which to get highest performance.
> - * @highest_perf: Return address.
> - *
> - * Return: 0 for success, -EIO otherwise.
> - */
> -static int amd_pstate_get_highest_perf(int cpu, u32 *highest_perf) -{
> -     int ret;
> -
> -     if (cpu_feature_enabled(X86_FEATURE_CPPC)) {
> -             u64 cap1;
> -
> -             ret = rdmsrl_safe_on_cpu(cpu, MSR_AMD_CPPC_CAP1,
> &cap1);
> -             if (ret)
> -                     return ret;
> -             WRITE_ONCE(*highest_perf,
> AMD_CPPC_HIGHEST_PERF(cap1));
> -     } else {
> -             u64 cppc_highest_perf;
> -
> -             ret = cppc_get_highest_perf(cpu, &cppc_highest_perf);
> -             if (ret)
> -                     return ret;
> -             WRITE_ONCE(*highest_perf, cppc_highest_perf);
> -     }
> -
> -     return (ret);
> -}
> -
>  #define CPPC_MAX_PERF        U8_MAX
>
>  static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata) @@ -
> 840,7 +810,7 @@ static void amd_pstate_init_prefcore(struct amd_cpudata
> *cpudata)
>       int ret, prio;
>       u32 highest_perf;
>
> -     ret = amd_pstate_get_highest_perf(cpudata->cpu, &highest_perf);
> +     ret = amd_get_highest_perf(cpudata->cpu, &highest_perf);
>       if (ret)
>               return;
>
> @@ -879,7 +849,7 @@ static void amd_pstate_update_limits(unsigned int
> cpu)
>       if ((!amd_pstate_prefcore) || (!cpudata->hw_prefcore))
>               goto free_cpufreq_put;
>
> -     ret = amd_pstate_get_highest_perf(cpu, &cur_high);
> +     ret = amd_get_highest_perf(cpu, &cur_high);
>       if (ret)
>               goto free_cpufreq_put;
>
> diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h index
> f25a881cd46dd..2246ce0630362 100644
> --- a/include/acpi/cppc_acpi.h
> +++ b/include/acpi/cppc_acpi.h
> @@ -137,8 +137,10 @@ struct cppc_cpudata {  };
>
>  #ifdef CONFIG_CPU_SUP_AMD
> +extern int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf);
>  extern int amd_get_boost_ratio_numerator(unsigned int cpu, u64
> *numerator);  #else /* !CONFIG_CPU_SUP_AMD */
> +static inline int amd_get_highest_perf(unsigned int cpu, u32
> +*highest_perf) { return -ENODEV; }
>  static inline int amd_get_boost_ratio_numerator(unsigned int cpu, u64
> *numerator) { return -ENODEV; }  #endif /* !CONFIG_CPU_SUP_AMD */
>
> --
> 2.43.0
>

LGTM, thank you.

Reviewed-by: Perry Yuan <perry.yuan@amd.com>


Best Regards.

Perry.
diff mbox series

Patch

diff --git a/arch/x86/kernel/acpi/cppc.c b/arch/x86/kernel/acpi/cppc.c
index e94507110ca24..5a6c01a1b0d95 100644
--- a/arch/x86/kernel/acpi/cppc.c
+++ b/arch/x86/kernel/acpi/cppc.c
@@ -119,6 +119,36 @@  void init_freq_invariance_cppc(void)
 	mutex_unlock(&freq_invariance_lock);
 }
 
+/*
+ * Get the highest performance register value.
+ * @cpu: CPU from which to get highest performance.
+ * @highest_perf: Return address for highest performance value.
+ *
+ * Return: 0 for success, negative error code otherwise.
+ */
+int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf)
+{
+	u64 val;
+	int ret;
+
+	if (cpu_feature_enabled(X86_FEATURE_CPPC)) {
+		ret = rdmsrl_safe_on_cpu(cpu, MSR_AMD_CPPC_CAP1, &val);
+		if (ret)
+			goto out;
+
+		val = AMD_CPPC_HIGHEST_PERF(val);
+	} else {
+		ret = cppc_get_highest_perf(cpu, &val);
+		if (ret)
+			goto out;
+	}
+
+	WRITE_ONCE(*highest_perf, (u32)val);
+out:
+	return ret;
+}
+EXPORT_SYMBOL_GPL(amd_get_highest_perf);
+
 /**
  * amd_get_boost_ratio_numerator: Get the numerator to use for boost ratio calculation
  * @cpu: CPU to get numerator for.
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 89bda7a2bb8d1..f470b5700db58 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -803,36 +803,6 @@  static void amd_pstste_sched_prefcore_workfn(struct work_struct *work)
 }
 static DECLARE_WORK(sched_prefcore_work, amd_pstste_sched_prefcore_workfn);
 
-/*
- * Get the highest performance register value.
- * @cpu: CPU from which to get highest performance.
- * @highest_perf: Return address.
- *
- * Return: 0 for success, -EIO otherwise.
- */
-static int amd_pstate_get_highest_perf(int cpu, u32 *highest_perf)
-{
-	int ret;
-
-	if (cpu_feature_enabled(X86_FEATURE_CPPC)) {
-		u64 cap1;
-
-		ret = rdmsrl_safe_on_cpu(cpu, MSR_AMD_CPPC_CAP1, &cap1);
-		if (ret)
-			return ret;
-		WRITE_ONCE(*highest_perf, AMD_CPPC_HIGHEST_PERF(cap1));
-	} else {
-		u64 cppc_highest_perf;
-
-		ret = cppc_get_highest_perf(cpu, &cppc_highest_perf);
-		if (ret)
-			return ret;
-		WRITE_ONCE(*highest_perf, cppc_highest_perf);
-	}
-
-	return (ret);
-}
-
 #define CPPC_MAX_PERF	U8_MAX
 
 static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata)
@@ -840,7 +810,7 @@  static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata)
 	int ret, prio;
 	u32 highest_perf;
 
-	ret = amd_pstate_get_highest_perf(cpudata->cpu, &highest_perf);
+	ret = amd_get_highest_perf(cpudata->cpu, &highest_perf);
 	if (ret)
 		return;
 
@@ -879,7 +849,7 @@  static void amd_pstate_update_limits(unsigned int cpu)
 	if ((!amd_pstate_prefcore) || (!cpudata->hw_prefcore))
 		goto free_cpufreq_put;
 
-	ret = amd_pstate_get_highest_perf(cpu, &cur_high);
+	ret = amd_get_highest_perf(cpu, &cur_high);
 	if (ret)
 		goto free_cpufreq_put;
 
diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h
index f25a881cd46dd..2246ce0630362 100644
--- a/include/acpi/cppc_acpi.h
+++ b/include/acpi/cppc_acpi.h
@@ -137,8 +137,10 @@  struct cppc_cpudata {
 };
 
 #ifdef CONFIG_CPU_SUP_AMD
+extern int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf);
 extern int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator);
 #else /* !CONFIG_CPU_SUP_AMD */
+static inline int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf) { return -ENODEV; }
 static inline int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator) { return -ENODEV; }
 #endif /* !CONFIG_CPU_SUP_AMD */