Skip to contentSkip to conversation

cpufreq: amd-pstate: enable AMD Precision Boost mode switch

PATCH Superseded Perry Yuan 2 participants 3 messages Jul 7, 2022 – Jul 8, 2022

Subsystems (3)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Perry Yuan

author reviewer
#0 lore raw

PATCH 2/12 cpufreq: amd-pstate: enable AMD Precision Boost mode switch

Add support to switch AMD precision boost state to scale cpu max frequency that will help to improve the processor throughput.

when set boost state to be enabled, user will need to execute below commands, the CPU will reach absolute maximum performance level or the highest perf which CPU physical support. This performance level may not be sustainable for long durations, it will help to improve the IO workload tasks.

* turn on CPU boost state under root
echo 1 > /sys/devices/system/cpu/cpufreq/boost

If user set boost off,the CPU can reach to the maximum sustained performance level of the process, that level is the process can maintain continously working and definitely it can save some power compared to boost on mode.

* turn off CPU boost state under root
echo 0 > /sys/devices/system/cpu/cpufreq/boost

---
 arch/x86/include/asm/msr-index.h |  2 ++
 drivers/cpufreq/amd-pstate.c     | 22 +++++++++++++++++++---
 2 files changed, 21 insertions(+), 3 deletions(-)
arch/x86/include/asm/msr-index.h +2 -0
index 869508de8269..b952fd6d6916 100644
@@ -559,6 +559,8 @@
 #define AMD_CPPC_MIN_PERF(x)		(((x) & 0xff) << 8)
 #define AMD_CPPC_DES_PERF(x)		(((x) & 0xff) << 16)
 #define AMD_CPPC_ENERGY_PERF_PREF(x)	(((x) & 0xff) << 24)
+#define AMD_CPPC_PRECISION_BOOST_BIT	25
+#define AMD_CPPC_PRECISION_BOOST_ENABLED	BIT_ULL(AMD_CPPC_PRECISION_BOOST_BIT)
 
 /* AMD Performance Counter Global Status and Control MSRs */
 #define MSR_AMD64_PERF_CNTR_GLOBAL_STATUS	0xc0000300
drivers/cpufreq/amd-pstate.c +19 -3
index 9ac75c1cde9c..188e055e24a2 100644
@@ -122,6 +122,7 @@ struct amd_cpudata {
 
 	u64 freq;
 	bool	boost_supported;
+	u64 	cppc_hw_conf_cached;
 };
 
 static inline int pstate_enable(bool enable)
@@ -438,18 +439,27 @@ static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state)
 {
 	struct amd_cpudata *cpudata = policy->driver_data;
 	int ret;
+	u64 value;
 
 	if (!cpudata->boost_supported) {
 		pr_err("Boost mode is not supported by this processor or SBIOS\n");
 		return -EINVAL;
 	}
 
-	if (state)
+	ret = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_HW_CTL, &value);
+	if (ret)
+		return ret;
+
+	if (state) {
+		value |= AMD_CPPC_PRECISION_BOOST_ENABLED;
 		policy->cpuinfo.max_freq = cpudata->max_freq;
-	else
+	} else {
+		value &= ~AMD_CPPC_PRECISION_BOOST_ENABLED;
 		policy->cpuinfo.max_freq = cpudata->nominal_freq;
-
+	}
 	policy->max = policy->cpuinfo.max_freq;
+	WRITE_ONCE(cpudata->cppc_hw_conf_cached, value);
+	wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_HW_CTL, value);
 
 	ret = freq_qos_update_request(&cpudata->req[1],
 				      policy->cpuinfo.max_freq);
@@ -478,6 +488,7 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
 	int min_freq, max_freq, nominal_freq, lowest_nonlinear_freq, ret;
 	struct device *dev;
 	struct amd_cpudata *cpudata;
+	u64 value;
 
 	dev = get_cpu_device(policy->cpu);
 	if (!dev)
@@ -542,6 +553,11 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
 
 	policy->driver_data = cpudata;
 
+	ret = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_HW_CTL, &value);
+	if (ret)
+		return ret;
+	WRITE_ONCE(cpudata->cppc_hw_conf_cached, value);
+
 	amd_pstate_boost_init(cpudata);
 
 	return 0;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 43 lines · Perry Yuan

Add support to switch AMD precision boost state to scale cpu max frequency that will help to improve the processor throughput.

when set boost state to be enabled, user will need to execute below commands, the CPU will reach absolute maximum performance level or the highest perf which CPU physical support. This performance level may not be sustainable for long durations, it will help to improve the IO workload tasks.

* turn on CPU boost state under root
echo 1 > /sys/devices/system/cpu/cpufreq/boost

If user set boost off,the CPU can reach to the maximum sustained performance level of the process, that level is the process can maintain continously working and definitely it can save some power compared to boost on mode.

* turn off CPU boost state under root
echo 0 > /sys/devices/system/cpu/cpufreq/boost

---
 arch/x86/include/asm/msr-index.h |  2 ++
 drivers/cpufreq/amd-pstate.c     | 22 +++++++++++++++++++---
 2 files changed, 21 insertions(+), 3 deletions(-)
arch/x86/include/asm/msr-index.h +2 -0
index 869508de8269..b952fd6d6916 100644
@@ -559,6 +559,8 @@
 #define AMD_CPPC_MIN_PERF(x)		(((x) & 0xff) << 8)
 #define AMD_CPPC_DES_PERF(x)		(((x) & 0xff) << 16)
 #define AMD_CPPC_ENERGY_PERF_PREF(x)	(((x) & 0xff) << 24)
+#define AMD_CPPC_PRECISION_BOOST_BIT	25
+#define AMD_CPPC_PRECISION_BOOST_ENABLED	BIT_ULL(AMD_CPPC_PRECISION_BOOST_BIT)
 
 /* AMD Performance Counter Global Status and Control MSRs */
 #define MSR_AMD64_PERF_CNTR_GLOBAL_STATUS	0xc0000300
drivers/cpufreq/amd-pstate.c +0 -0
index 9ac75c1cde9c..188e055e24a2 100644

drivers/cpufreq/amd-pstate.c struct amd_cpudata { · line 125

Quoted 4 lines
drivers/cpufreq/amd-pstate.c +1 -0
@@ -122,6 +122,7 @@ struct amd_cpudata {
 
 	u64 freq;
 	bool	boost_supported;
+	u64 	cppc_hw_conf_cached;

The MSR value is cached but I don't see that the cached value is used anywhere. Perhaps I missed it in one of the other patches. Does this need to be cached?

-Nathan

Quoted 54 lines
drivers/cpufreq/amd-pstate.c +18 -3
 };
 
 static inline int pstate_enable(bool enable)
@@ -438,18 +439,27 @@ static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state)
 {
 	struct amd_cpudata *cpudata = policy->driver_data;
 	int ret;
+	u64 value;
 
 	if (!cpudata->boost_supported) {
 		pr_err("Boost mode is not supported by this processor or SBIOS\n");
 		return -EINVAL;
 	}
 
-	if (state)
+	ret = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_HW_CTL, &value);
+	if (ret)
+		return ret;
+
+	if (state) {
+		value |= AMD_CPPC_PRECISION_BOOST_ENABLED;
 		policy->cpuinfo.max_freq = cpudata->max_freq;
-	else
+	} else {
+		value &= ~AMD_CPPC_PRECISION_BOOST_ENABLED;
 		policy->cpuinfo.max_freq = cpudata->nominal_freq;
-
+	}
 	policy->max = policy->cpuinfo.max_freq;
+	WRITE_ONCE(cpudata->cppc_hw_conf_cached, value);
+	wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_HW_CTL, value);
 
 	ret = freq_qos_update_request(&cpudata->req[1],
 				      policy->cpuinfo.max_freq);
@@ -478,6 +488,7 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
 	int min_freq, max_freq, nominal_freq, lowest_nonlinear_freq, ret;
 	struct device *dev;
 	struct amd_cpudata *cpudata;
+	u64 value;
 
 	dev = get_cpu_device(policy->cpu);
 	if (!dev)
@@ -542,6 +553,11 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
 
 	policy->driver_data = cpudata;
 
+	ret = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_HW_CTL, &value);
+	if (ret)
+		return ret;
+	WRITE_ONCE(cpudata->cppc_hw_conf_cached, value);
+
 	amd_pstate_boost_init(cpudata);
 
 	return 0;
author reviewer
#2 lore raw

[AMD Official Use Only - General]

Hi Nathan:

Quoted 82 lines

-----Original Message-----
From: Fontenot, Nathan <[email protected]>
Sent: Friday, July 8, 2022 3:32 AM
To: Yuan, Perry <[email protected]>; [email protected]; [email protected]; Huang, Ray <[email protected]>; Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; Borislav Petkov <[email protected]>; Dave Hansen <[email protected]>; [email protected]; H. Peter Anvin <[email protected]>; Rafael J. Wysocki <[email protected]>; Peter Zijlstra <[email protected]>; Adrian Hunter <[email protected]>; Pawan Gupta <[email protected]>; Alexander Shishkin <[email protected]>; Tony Luck <[email protected]>; Stephane Eranian <[email protected]>; Ricardo Neri <ricardo.neri- [email protected]>; [email protected]; linux- [email protected]
Cc: Sharma, Deepak <[email protected]>; Limonciello, Mario <[email protected]>; Fontenot, Nathan <[email protected]>; Deucher, Alexander <[email protected]>; Su, Jinzhou (Joe) <[email protected]>; Huang, Shimmer <[email protected]>; Du, Xiaojian <[email protected]>; Meng, Li (Jassmine) <[email protected]>
Subject: Re: [PATCH 02/12] cpufreq: amd-pstate: enable AMD Precision Boost mode switch

Quoted 5 lines · Perry Yuan

Add support to switch AMD precision boost state to scale cpu max frequency that will help to improve the processor throughput.

when set boost state to be enabled, user will need to execute below commands, the CPU will reach absolute maximum performance level or

the

Quoted 2 lines

highest perf which CPU physical support. This performance level may not be sustainable for long durations, it will help to improve the IO

workload tasks.

Quoted 24 lines

* turn on CPU boost state under root
echo 1 > /sys/devices/system/cpu/cpufreq/boost

If user set boost off,the CPU can reach to the maximum sustained performance level of the process, that level is the process can maintain continously working and definitely it can save some power compared to boost on mode.

* turn off CPU boost state under root
echo 0 > /sys/devices/system/cpu/cpufreq/boost

---
 arch/x86/include/asm/msr-index.h |  2 ++
 drivers/cpufreq/amd-pstate.c     | 22 +++++++++++++++++++---
 2 files changed, 21 insertions(+), 3 deletions(-)
arch/x86/include/asm/msr-index.h +0 -0
index 869508de8269..b952fd6d6916 100644

arch/x86/include/asm/msr-index.h line 563

Quoted 5 lines
arch/x86/include/asm/msr-index.h +2 -0
@@ -559,6 +559,8 @@
 #define AMD_CPPC_MIN_PERF(x)		(((x) & 0xff) << 8)
 #define AMD_CPPC_DES_PERF(x)		(((x) & 0xff) << 16)
 #define AMD_CPPC_ENERGY_PERF_PREF(x)	(((x) & 0xff) << 24)
+#define AMD_CPPC_PRECISION_BOOST_BIT	25
+#define AMD_CPPC_PRECISION_BOOST_ENABLED

BIT_ULL(AMD_CPPC_PRECISION_BOOST_BIT)

Quoted 5 lines
arch/x86/include/asm/msr-index.h +0 -0
 /* AMD Performance Counter Global Status and Control MSRs */
 #define MSR_AMD64_PERF_CNTR_GLOBAL_STATUS	0xc0000300
(quoted diff) +0 -0

b/drivers/cpufreq/amd-pstate.c index 9ac75c1cde9c..188e055e24a2

100644

drivers/cpufreq/amd-pstate.c struct amd_cpudata { · line 125

Quoted 7 lines
drivers/cpufreq/amd-pstate.c +1 -0
@@ -122,6 +122,7 @@ struct amd_cpudata {
 
 	u64 freq;
 	bool	boost_supported;
+	u64 	cppc_hw_conf_cached;

The MSR value is cached but I don't see that the cached value is used anywhere. Perhaps I missed it in one of the other patches. Does this need to be cached?

Quoted 1 line

-Nathan

The bit value will be used in the coming CPPC EPP patches to check if the CPU precision boost bit is enabled. I early added this prefetching code as a preparing code.

Perry.

Quoted 60 lines

drivers/cpufreq/amd-pstate.c static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state)

Quoted 12 lines
drivers/cpufreq/amd-pstate.c +0 -0
 };
 
 static inline int pstate_enable(bool enable) @@ -438,18 +439,27 @@

static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state) {

drivers/cpufreq/amd-pstate.c +1 -0
 	struct amd_cpudata *cpudata = policy->driver_data;
 	int ret;
+	u64 value;
 
 	if (!cpudata->boost_supported) {
 		pr_err("Boost mode is not supported by this processor or

SBIOS\n");

drivers/cpufreq/amd-pstate.c static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state)

Quoted 5 lines
drivers/cpufreq/amd-pstate.c +1 -1
 		return -EINVAL;
 	}
 
-	if (state)
+	ret = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_HW_CTL,

&value);

drivers/cpufreq/amd-pstate.c static int amd_pstate_cpu_init(struct

Quoted 19 lines
drivers/cpufreq/amd-pstate.c +10 -2
+	if (ret)
+		return ret;
+
+	if (state) {
+		value |= AMD_CPPC_PRECISION_BOOST_ENABLED;
 		policy->cpuinfo.max_freq = cpudata->max_freq;
-	else
+	} else {
+		value &= ~AMD_CPPC_PRECISION_BOOST_ENABLED;
 		policy->cpuinfo.max_freq = cpudata->nominal_freq;
-
+	}
 	policy->max = policy->cpuinfo.max_freq;
+	WRITE_ONCE(cpudata->cppc_hw_conf_cached, value);
+	wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_HW_CTL, value);
 
 	ret = freq_qos_update_request(&cpudata->req[1],
 				      policy->cpuinfo.max_freq);
@@ -478,6 +488,7 @@ static int amd_pstate_cpu_init(struct

cpufreq_policy *policy)

drivers/cpufreq/amd-pstate.c static int amd_pstate_cpu_init(struct · line 557

Quoted 13 lines
drivers/cpufreq/amd-pstate.c +2 -0
 	int min_freq, max_freq, nominal_freq, lowest_nonlinear_freq, ret;
 	struct device *dev;
 	struct amd_cpudata *cpudata;
+	u64 value;
 
 	dev = get_cpu_device(policy->cpu);
 	if (!dev)
@@ -542,6 +553,11 @@ static int amd_pstate_cpu_init(struct
 cpufreq_policy *policy)
 
 	policy->driver_data = cpudata;
 
+	ret = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_HW_CTL,

&value);

Quoted 7 lines
drivers/cpufreq/amd-pstate.c +4 -0
+	if (ret)
+		return ret;
+	WRITE_ONCE(cpudata->cppc_hw_conf_cached, value);
+
 	amd_pstate_boost_init(cpudata);
 

return 0;