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

ACPI: cpufreq: Use platform devices to load ACPI PPC and PCC drivers

The acpi-cpufreq and pcc-cpufreq drivers are loaded through per-CPU
module aliases. This can result in many unnecessary load requests during
boot if another frequency module, such as intel_pstate, is already
active. For instance, on a typical Intel system, one can observe that
udev makes 2x#CPUs attempts to insert acpi_cpufreq and 1x#CPUs attempts
for pcc_cpufreq. All these tries then fail if another frequency module
is already registered.

In the worst case, without the recent fix in commit 0254127ab977e
("module: Don't wait for GOING modules"), these module loads occupied
all udev workers and had their initialization attempts ran sequentially.
Resolving all these loads then on some larger machines took too long,
prevented other hardware from getting its drivers initialized and
resulted in a failed boot. Discussion over these duplicate module
requests ended up with a conclusion that only one load attempt should be
ideally made.

Both acpi-cpufreq and pcc-cpufreq drivers use platform firmware controls
which are defined by ACPI. It is possible to treat these interfaces as
platform devices.

The patch extends the ACPI parsing logic to check the ACPI namespace if
the PPC or PCC interface is present and creates a virtual platform
device for each if it is available. The acpi-cpufreq and pcc-cpufreq
drivers are then updated to map to these devices.

This allows to try loading acpi-cpufreq and pcc-cpufreq only once during
boot and only if a given interface is available in the firmware.

Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
[ rjw: whitespace and error message log level adjustments, subject edits ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Petr Pavlu and committed by
Rafael J. Wysocki
691a6371 4dea4177

+86 -29
+40 -2
drivers/acpi/acpi_processor.c
··· 15 15 #include <linux/kernel.h> 16 16 #include <linux/module.h> 17 17 #include <linux/pci.h> 18 + #include <linux/platform_device.h> 18 19 19 20 #include <acpi/processor.h> 20 21 ··· 149 148 return result; 150 149 } 151 150 151 + /* Create a platform device to represent a CPU frequency control mechanism. */ 152 + static void cpufreq_add_device(const char *name) 153 + { 154 + struct platform_device *pdev; 155 + 156 + pdev = platform_device_register_simple(name, PLATFORM_DEVID_NONE, NULL, 0); 157 + if (IS_ERR(pdev)) 158 + pr_info("%s device creation failed: %ld\n", name, PTR_ERR(pdev)); 159 + } 160 + 161 + #ifdef CONFIG_X86 162 + /* Check presence of Processor Clocking Control by searching for \_SB.PCCH. */ 163 + static void __init acpi_pcc_cpufreq_init(void) 164 + { 165 + acpi_status status; 166 + acpi_handle handle; 167 + 168 + status = acpi_get_handle(NULL, "\\_SB", &handle); 169 + if (ACPI_FAILURE(status)) 170 + return; 171 + 172 + if (acpi_has_method(handle, "PCCH")) 173 + cpufreq_add_device("pcc-cpufreq"); 174 + } 175 + #else 176 + static void __init acpi_pcc_cpufreq_init(void) {} 177 + #endif /* CONFIG_X86 */ 178 + 152 179 /* Initialization */ 153 180 #ifdef CONFIG_ACPI_HOTPLUG_CPU 154 181 int __weak acpi_map_cpu(acpi_handle handle, ··· 309 280 dev_dbg(&device->dev, "Failed to get CPU physical ID.\n"); 310 281 311 282 pr->id = acpi_map_cpuid(pr->phys_id, pr->acpi_id); 312 - if (!cpu0_initialized && !acpi_has_cpu_in_madt()) { 283 + if (!cpu0_initialized) { 313 284 cpu0_initialized = 1; 314 285 /* 315 286 * Handle UP system running SMP kernel, with no CPU 316 287 * entry in MADT 317 288 */ 318 - if (invalid_logical_cpuid(pr->id) && (num_online_cpus() == 1)) 289 + if (!acpi_has_cpu_in_madt() && invalid_logical_cpuid(pr->id) && 290 + (num_online_cpus() == 1)) 319 291 pr->id = 0; 292 + /* 293 + * Check availability of Processor Performance Control by 294 + * looking at the presence of the _PCT object under the first 295 + * processor definition. 296 + */ 297 + if (acpi_has_method(pr->handle, "_PCT")) 298 + cpufreq_add_device("acpi-cpufreq"); 320 299 } 321 300 322 301 /* ··· 723 686 acpi_processor_check_duplicates(); 724 687 acpi_scan_add_handler_with_hotplug(&processor_handler, "processor"); 725 688 acpi_scan_add_handler(&processor_container_handler); 689 + acpi_pcc_cpufreq_init(); 726 690 } 727 691 728 692 #ifdef CONFIG_ACPI_PROCESSOR_CSTATE
+22 -17
drivers/cpufreq/acpi-cpufreq.c
··· 965 965 acpi_cpufreq_driver.boost_enabled = boost_state(0); 966 966 } 967 967 968 - static int __init acpi_cpufreq_init(void) 968 + static int __init acpi_cpufreq_probe(struct platform_device *pdev) 969 969 { 970 970 int ret; 971 971 ··· 1010 1010 return ret; 1011 1011 } 1012 1012 1013 - static void __exit acpi_cpufreq_exit(void) 1013 + static int acpi_cpufreq_remove(struct platform_device *pdev) 1014 1014 { 1015 1015 pr_debug("%s\n", __func__); 1016 1016 1017 1017 cpufreq_unregister_driver(&acpi_cpufreq_driver); 1018 1018 1019 1019 free_acpi_perf_data(); 1020 + 1021 + return 0; 1022 + } 1023 + 1024 + static struct platform_driver acpi_cpufreq_platdrv = { 1025 + .driver = { 1026 + .name = "acpi-cpufreq", 1027 + }, 1028 + .remove = acpi_cpufreq_remove, 1029 + }; 1030 + 1031 + static int __init acpi_cpufreq_init(void) 1032 + { 1033 + return platform_driver_probe(&acpi_cpufreq_platdrv, acpi_cpufreq_probe); 1034 + } 1035 + 1036 + static void __exit acpi_cpufreq_exit(void) 1037 + { 1038 + platform_driver_unregister(&acpi_cpufreq_platdrv); 1020 1039 } 1021 1040 1022 1041 module_param(acpi_pstate_strict, uint, 0644); ··· 1046 1027 late_initcall(acpi_cpufreq_init); 1047 1028 module_exit(acpi_cpufreq_exit); 1048 1029 1049 - static const struct x86_cpu_id __maybe_unused acpi_cpufreq_ids[] = { 1050 - X86_MATCH_FEATURE(X86_FEATURE_ACPI, NULL), 1051 - X86_MATCH_FEATURE(X86_FEATURE_HW_PSTATE, NULL), 1052 - {} 1053 - }; 1054 - MODULE_DEVICE_TABLE(x86cpu, acpi_cpufreq_ids); 1055 - 1056 - static const struct acpi_device_id __maybe_unused processor_device_ids[] = { 1057 - {ACPI_PROCESSOR_OBJECT_HID, }, 1058 - {ACPI_PROCESSOR_DEVICE_HID, }, 1059 - {}, 1060 - }; 1061 - MODULE_DEVICE_TABLE(acpi, processor_device_ids); 1062 - 1063 - MODULE_ALIAS("acpi"); 1030 + MODULE_ALIAS("platform:acpi-cpufreq");
+24 -10
drivers/cpufreq/pcc-cpufreq.c
··· 384 384 return ret; 385 385 } 386 386 387 - static int __init pcc_cpufreq_probe(void) 387 + static int __init pcc_cpufreq_evaluate(void) 388 388 { 389 389 acpi_status status; 390 390 struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; ··· 576 576 .name = "pcc-cpufreq", 577 577 }; 578 578 579 - static int __init pcc_cpufreq_init(void) 579 + static int __init pcc_cpufreq_probe(struct platform_device *pdev) 580 580 { 581 581 int ret; 582 582 ··· 587 587 if (acpi_disabled) 588 588 return -ENODEV; 589 589 590 - ret = pcc_cpufreq_probe(); 590 + ret = pcc_cpufreq_evaluate(); 591 591 if (ret) { 592 - pr_debug("pcc_cpufreq_init: PCCH evaluation failed\n"); 592 + pr_debug("pcc_cpufreq_probe: PCCH evaluation failed\n"); 593 593 return ret; 594 594 } 595 595 ··· 607 607 return ret; 608 608 } 609 609 610 - static void __exit pcc_cpufreq_exit(void) 610 + static int pcc_cpufreq_remove(struct platform_device *pdev) 611 611 { 612 612 cpufreq_unregister_driver(&pcc_cpufreq_driver); 613 613 614 614 pcc_clear_mapping(); 615 615 616 616 free_percpu(pcc_cpu_info); 617 + 618 + return 0; 617 619 } 618 620 619 - static const struct acpi_device_id __maybe_unused processor_device_ids[] = { 620 - {ACPI_PROCESSOR_OBJECT_HID, }, 621 - {ACPI_PROCESSOR_DEVICE_HID, }, 622 - {}, 621 + static struct platform_driver pcc_cpufreq_platdrv = { 622 + .driver = { 623 + .name = "pcc-cpufreq", 624 + }, 625 + .remove = pcc_cpufreq_remove, 623 626 }; 624 - MODULE_DEVICE_TABLE(acpi, processor_device_ids); 627 + 628 + static int __init pcc_cpufreq_init(void) 629 + { 630 + return platform_driver_probe(&pcc_cpufreq_platdrv, pcc_cpufreq_probe); 631 + } 632 + 633 + static void __exit pcc_cpufreq_exit(void) 634 + { 635 + platform_driver_unregister(&pcc_cpufreq_platdrv); 636 + } 637 + 638 + MODULE_ALIAS("platform:pcc-cpufreq"); 625 639 626 640 MODULE_AUTHOR("Matthew Garrett, Naga Chumbalkar"); 627 641 MODULE_VERSION(PCC_VERSION);