Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ACPI: processor: Move arch_init_invariance_cppc() call later

arch_init_invariance_cppc() is called at the end of
acpi_cppc_processor_probe() in order to configure frequency invariance
based upon the values from _CPC.

This however doesn't work on AMD CPPC shared memory designs that have
AMD preferred cores enabled because _CPC needs to be analyzed from all
cores to judge if preferred cores are enabled.

This issue manifests to users as a warning since commit 21fb59ab4b97
("ACPI: CPPC: Adjust debug messages in amd_set_max_freq_ratio() to warn"):
```
Could not retrieve highest performance (-19)
```

However the warning isn't the cause of this, it was actually
commit 279f838a61f9 ("x86/amd: Detect preferred cores in
amd_get_boost_ratio_numerator()") which exposed the issue.

To fix this problem, change arch_init_invariance_cppc() into a new weak
symbol that is called at the end of acpi_processor_driver_init().
Each architecture that supports it can declare the symbol to override
the weak one.

Define it for x86, in arch/x86/kernel/acpi/cppc.c, and for all of the
architectures using the generic arch_topology.c code.

Fixes: 279f838a61f9 ("x86/amd: Detect preferred cores in amd_get_boost_ratio_numerator()")
Reported-by: Ivan Shapovalov <intelfx@intelfx.name>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=219431
Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Link: https://patch.msgid.link/20241104222855.3959267-1-superm1@kernel.org
[ rjw: Changelog edit ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Mario Limonciello and committed by
Rafael J. Wysocki
b79276dc 59b723cd

+22 -21
-4
arch/arm64/include/asm/topology.h
··· 26 26 #define arch_scale_freq_invariant topology_scale_freq_invariant 27 27 #define arch_scale_freq_ref topology_get_freq_ref 28 28 29 - #ifdef CONFIG_ACPI_CPPC_LIB 30 - #define arch_init_invariance_cppc topology_init_cpu_capacity_cppc 31 - #endif 32 - 33 29 /* Replace task scheduler's default cpu-invariant accounting */ 34 30 #define arch_scale_cpu_capacity topology_get_cpu_scale 35 31
-5
arch/x86/include/asm/topology.h
··· 305 305 extern void arch_scale_freq_tick(void); 306 306 #define arch_scale_freq_tick arch_scale_freq_tick 307 307 308 - #ifdef CONFIG_ACPI_CPPC_LIB 309 - void init_freq_invariance_cppc(void); 310 - #define arch_init_invariance_cppc init_freq_invariance_cppc 311 - #endif 312 - 313 308 #endif /* _ASM_X86_TOPOLOGY_H */
+6 -1
arch/x86/kernel/acpi/cppc.c
··· 110 110 111 111 static DEFINE_MUTEX(freq_invariance_lock); 112 112 113 - void init_freq_invariance_cppc(void) 113 + static inline void init_freq_invariance_cppc(void) 114 114 { 115 115 static bool init_done; 116 116 ··· 125 125 amd_set_max_freq_ratio(); 126 126 init_done = true; 127 127 mutex_unlock(&freq_invariance_lock); 128 + } 129 + 130 + void acpi_processor_init_invariance_cppc(void) 131 + { 132 + init_freq_invariance_cppc(); 128 133 } 129 134 130 135 /*
-6
drivers/acpi/cppc_acpi.c
··· 671 671 * ) 672 672 */ 673 673 674 - #ifndef arch_init_invariance_cppc 675 - static inline void arch_init_invariance_cppc(void) { } 676 - #endif 677 - 678 674 /** 679 675 * acpi_cppc_processor_probe - Search for per CPU _CPC objects. 680 676 * @pr: Ptr to acpi_processor containing this CPU's logical ID. ··· 900 904 kobject_put(&cpc_ptr->kobj); 901 905 goto out_free; 902 906 } 903 - 904 - arch_init_invariance_cppc(); 905 907 906 908 kfree(output.pointer); 907 909 return 0;
+9
drivers/acpi/processor_driver.c
··· 237 237 .notifier_call = acpi_processor_notifier, 238 238 }; 239 239 240 + void __weak acpi_processor_init_invariance_cppc(void) 241 + { } 242 + 240 243 /* 241 244 * We keep the driver loaded even when ACPI is not running. 242 245 * This is needed for the powernow-k8 driver, that works even without ··· 273 270 NULL, acpi_soft_cpu_dead); 274 271 275 272 acpi_processor_throttling_init(); 273 + 274 + /* 275 + * Frequency invariance calculations on AMD platforms can't be run until 276 + * after acpi_cppc_processor_probe() has been called for all online CPUs 277 + */ 278 + acpi_processor_init_invariance_cppc(); 276 279 return 0; 277 280 err: 278 281 driver_unregister(&acpi_processor_driver);
+5 -1
drivers/base/arch_topology.c
··· 366 366 #ifdef CONFIG_ACPI_CPPC_LIB 367 367 #include <acpi/cppc_acpi.h> 368 368 369 - void topology_init_cpu_capacity_cppc(void) 369 + static inline void topology_init_cpu_capacity_cppc(void) 370 370 { 371 371 u64 capacity, capacity_scale = 0; 372 372 struct cppc_perf_caps perf_caps; ··· 416 416 417 417 exit: 418 418 free_raw_capacity(); 419 + } 420 + void acpi_processor_init_invariance_cppc(void) 421 + { 422 + topology_init_cpu_capacity_cppc(); 419 423 } 420 424 #endif 421 425
+2
include/acpi/processor.h
··· 465 465 extern int acpi_processor_ffh_lpi_enter(struct acpi_lpi_state *lpi); 466 466 #endif 467 467 468 + void acpi_processor_init_invariance_cppc(void); 469 + 468 470 #endif
-4
include/linux/arch_topology.h
··· 11 11 void topology_normalize_cpu_scale(void); 12 12 int topology_update_cpu_topology(void); 13 13 14 - #ifdef CONFIG_ACPI_CPPC_LIB 15 - void topology_init_cpu_capacity_cppc(void); 16 - #endif 17 - 18 14 struct device_node; 19 15 bool topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu); 20 16