1 From 3743d55b289c203d8f77b7cd47c24926b9d186ae Mon Sep 17 00:00:00 2001
2 From: Huang Rui <ray.huang@amd.com>
3 Date: Sun, 25 Apr 2021 15:34:51 +0800
4 Subject: x86, sched: Fix the AMD CPPC maximum performance value on certain AMD Ryzen generations
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 From: Huang Rui <ray.huang@amd.com>
11 commit 3743d55b289c203d8f77b7cd47c24926b9d186ae upstream.
13 Some AMD Ryzen generations has different calculation method on maximum
14 performance. 255 is not for all ASICs, some specific generations should use 166
15 as the maximum performance. Otherwise, it will report incorrect frequency value
20 CPU max MHz: 7228.3198
21 CPU min MHz: 2200.0000
23 [ mingo: Tidied up whitespace use. ]
24 [ Alexander Monakov <amonakov@ispras.ru>: fix 225 -> 255 typo. ]
26 Fixes: 41ea667227ba ("x86, sched: Calculate frequency invariance for AMD systems")
27 Fixes: 3c55e94c0ade ("cpufreq: ACPI: Extend frequency tables to cover boost frequencies")
28 Reported-by: Jason Bagavatsingham <jason.bagavatsingham@gmail.com>
29 Fixed-by: Alexander Monakov <amonakov@ispras.ru>
30 Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
31 Signed-off-by: Huang Rui <ray.huang@amd.com>
32 Signed-off-by: Ingo Molnar <mingo@kernel.org>
33 Tested-by: Jason Bagavatsingham <jason.bagavatsingham@gmail.com>
34 Cc: stable@vger.kernel.org
35 Link: https://lore.kernel.org/r/20210425073451.2557394-1-ray.huang@amd.com
36 Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=211791
37 Signed-off-by: Ingo Molnar <mingo@kernel.org>
38 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
40 arch/x86/include/asm/processor.h | 2 ++
41 arch/x86/kernel/cpu/amd.c | 16 ++++++++++++++++
42 arch/x86/kernel/smpboot.c | 2 +-
43 drivers/cpufreq/acpi-cpufreq.c | 6 +++++-
44 4 files changed, 24 insertions(+), 2 deletions(-)
46 --- a/arch/x86/include/asm/processor.h
47 +++ b/arch/x86/include/asm/processor.h
48 @@ -805,8 +805,10 @@ DECLARE_PER_CPU(u64, msr_misc_features_s
50 #ifdef CONFIG_CPU_SUP_AMD
51 extern u32 amd_get_nodes_per_socket(void);
52 +extern u32 amd_get_highest_perf(void);
54 static inline u32 amd_get_nodes_per_socket(void) { return 0; }
55 +static inline u32 amd_get_highest_perf(void) { return 0; }
58 static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
59 --- a/arch/x86/kernel/cpu/amd.c
60 +++ b/arch/x86/kernel/cpu/amd.c
61 @@ -1170,3 +1170,19 @@ void set_dr_addr_mask(unsigned long mask
66 +u32 amd_get_highest_perf(void)
68 + struct cpuinfo_x86 *c = &boot_cpu_data;
70 + if (c->x86 == 0x17 && ((c->x86_model >= 0x30 && c->x86_model < 0x40) ||
71 + (c->x86_model >= 0x70 && c->x86_model < 0x80)))
74 + if (c->x86 == 0x19 && ((c->x86_model >= 0x20 && c->x86_model < 0x30) ||
75 + (c->x86_model >= 0x40 && c->x86_model < 0x70)))
80 +EXPORT_SYMBOL_GPL(amd_get_highest_perf);
81 --- a/arch/x86/kernel/smpboot.c
82 +++ b/arch/x86/kernel/smpboot.c
83 @@ -2046,7 +2046,7 @@ static bool amd_set_max_freq_ratio(void)
87 - highest_perf = perf_caps.highest_perf;
88 + highest_perf = amd_get_highest_perf();
89 nominal_perf = perf_caps.nominal_perf;
91 if (!highest_perf || !nominal_perf) {
92 --- a/drivers/cpufreq/acpi-cpufreq.c
93 +++ b/drivers/cpufreq/acpi-cpufreq.c
94 @@ -646,7 +646,11 @@ static u64 get_max_boost_ratio(unsigned
98 - highest_perf = perf_caps.highest_perf;
99 + if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
100 + highest_perf = amd_get_highest_perf();
102 + highest_perf = perf_caps.highest_perf;
104 nominal_perf = perf_caps.nominal_perf;
106 if (!highest_perf || !nominal_perf) {