Skip to content

Commit 691a637

Browse files
petrpavlurafaeljw
authored andcommitted
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 0254127 ("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>
1 parent 4dea417 commit 691a637

3 files changed

Lines changed: 86 additions & 29 deletions

File tree

drivers/acpi/acpi_processor.c

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/kernel.h>
1616
#include <linux/module.h>
1717
#include <linux/pci.h>
18+
#include <linux/platform_device.h>
1819

1920
#include <acpi/processor.h>
2021

@@ -148,6 +149,34 @@ static int acpi_processor_errata(void)
148149
return result;
149150
}
150151

152+
/* Create a platform device to represent a CPU frequency control mechanism. */
153+
static void cpufreq_add_device(const char *name)
154+
{
155+
struct platform_device *pdev;
156+
157+
pdev = platform_device_register_simple(name, PLATFORM_DEVID_NONE, NULL, 0);
158+
if (IS_ERR(pdev))
159+
pr_info("%s device creation failed: %ld\n", name, PTR_ERR(pdev));
160+
}
161+
162+
#ifdef CONFIG_X86
163+
/* Check presence of Processor Clocking Control by searching for \_SB.PCCH. */
164+
static void __init acpi_pcc_cpufreq_init(void)
165+
{
166+
acpi_status status;
167+
acpi_handle handle;
168+
169+
status = acpi_get_handle(NULL, "\\_SB", &handle);
170+
if (ACPI_FAILURE(status))
171+
return;
172+
173+
if (acpi_has_method(handle, "PCCH"))
174+
cpufreq_add_device("pcc-cpufreq");
175+
}
176+
#else
177+
static void __init acpi_pcc_cpufreq_init(void) {}
178+
#endif /* CONFIG_X86 */
179+
151180
/* Initialization */
152181
#ifdef CONFIG_ACPI_HOTPLUG_CPU
153182
int __weak acpi_map_cpu(acpi_handle handle,
@@ -280,14 +309,22 @@ static int acpi_processor_get_info(struct acpi_device *device)
280309
dev_dbg(&device->dev, "Failed to get CPU physical ID.\n");
281310

282311
pr->id = acpi_map_cpuid(pr->phys_id, pr->acpi_id);
283-
if (!cpu0_initialized && !acpi_has_cpu_in_madt()) {
312+
if (!cpu0_initialized) {
284313
cpu0_initialized = 1;
285314
/*
286315
* Handle UP system running SMP kernel, with no CPU
287316
* entry in MADT
288317
*/
289-
if (invalid_logical_cpuid(pr->id) && (num_online_cpus() == 1))
318+
if (!acpi_has_cpu_in_madt() && invalid_logical_cpuid(pr->id) &&
319+
(num_online_cpus() == 1))
290320
pr->id = 0;
321+
/*
322+
* Check availability of Processor Performance Control by
323+
* looking at the presence of the _PCT object under the first
324+
* processor definition.
325+
*/
326+
if (acpi_has_method(pr->handle, "_PCT"))
327+
cpufreq_add_device("acpi-cpufreq");
291328
}
292329

293330
/*
@@ -686,6 +723,7 @@ void __init acpi_processor_init(void)
686723
acpi_processor_check_duplicates();
687724
acpi_scan_add_handler_with_hotplug(&processor_handler, "processor");
688725
acpi_scan_add_handler(&processor_container_handler);
726+
acpi_pcc_cpufreq_init();
689727
}
690728

691729
#ifdef CONFIG_ACPI_PROCESSOR_CSTATE

drivers/cpufreq/acpi-cpufreq.c

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ static void __init acpi_cpufreq_boost_init(void)
965965
acpi_cpufreq_driver.boost_enabled = boost_state(0);
966966
}
967967

968-
static int __init acpi_cpufreq_init(void)
968+
static int __init acpi_cpufreq_probe(struct platform_device *pdev)
969969
{
970970
int ret;
971971

@@ -1010,13 +1010,32 @@ static int __init acpi_cpufreq_init(void)
10101010
return ret;
10111011
}
10121012

1013-
static void __exit acpi_cpufreq_exit(void)
1013+
static int acpi_cpufreq_remove(struct platform_device *pdev)
10141014
{
10151015
pr_debug("%s\n", __func__);
10161016

10171017
cpufreq_unregister_driver(&acpi_cpufreq_driver);
10181018

10191019
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);
10201039
}
10211040

10221041
module_param(acpi_pstate_strict, uint, 0644);
@@ -1027,18 +1046,4 @@ MODULE_PARM_DESC(acpi_pstate_strict,
10271046
late_initcall(acpi_cpufreq_init);
10281047
module_exit(acpi_cpufreq_exit);
10291048

1030-
static const struct x86_cpu_id __maybe_unused acpi_cpufreq_ids[] = {
1031-
X86_MATCH_FEATURE(X86_FEATURE_ACPI, NULL),
1032-
X86_MATCH_FEATURE(X86_FEATURE_HW_PSTATE, NULL),
1033-
{}
1034-
};
1035-
MODULE_DEVICE_TABLE(x86cpu, acpi_cpufreq_ids);
1036-
1037-
static const struct acpi_device_id __maybe_unused processor_device_ids[] = {
1038-
{ACPI_PROCESSOR_OBJECT_HID, },
1039-
{ACPI_PROCESSOR_DEVICE_HID, },
1040-
{},
1041-
};
1042-
MODULE_DEVICE_TABLE(acpi, processor_device_ids);
1043-
1044-
MODULE_ALIAS("acpi");
1049+
MODULE_ALIAS("platform:acpi-cpufreq");

drivers/cpufreq/pcc-cpufreq.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ static int __init pcc_cpufreq_do_osc(acpi_handle *handle)
384384
return ret;
385385
}
386386

387-
static int __init pcc_cpufreq_probe(void)
387+
static int __init pcc_cpufreq_evaluate(void)
388388
{
389389
acpi_status status;
390390
struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
@@ -576,7 +576,7 @@ static struct cpufreq_driver pcc_cpufreq_driver = {
576576
.name = "pcc-cpufreq",
577577
};
578578

579-
static int __init pcc_cpufreq_init(void)
579+
static int __init pcc_cpufreq_probe(struct platform_device *pdev)
580580
{
581581
int ret;
582582

@@ -587,9 +587,9 @@ static int __init pcc_cpufreq_init(void)
587587
if (acpi_disabled)
588588
return -ENODEV;
589589

590-
ret = pcc_cpufreq_probe();
590+
ret = pcc_cpufreq_evaluate();
591591
if (ret) {
592-
pr_debug("pcc_cpufreq_init: PCCH evaluation failed\n");
592+
pr_debug("pcc_cpufreq_probe: PCCH evaluation failed\n");
593593
return ret;
594594
}
595595

@@ -607,21 +607,35 @@ static int __init pcc_cpufreq_init(void)
607607
return ret;
608608
}
609609

610-
static void __exit pcc_cpufreq_exit(void)
610+
static int pcc_cpufreq_remove(struct platform_device *pdev)
611611
{
612612
cpufreq_unregister_driver(&pcc_cpufreq_driver);
613613

614614
pcc_clear_mapping();
615615

616616
free_percpu(pcc_cpu_info);
617+
618+
return 0;
617619
}
618620

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,
623626
};
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");
625639

626640
MODULE_AUTHOR("Matthew Garrett, Naga Chumbalkar");
627641
MODULE_VERSION(PCC_VERSION);

0 commit comments

Comments
 (0)