Skip to contentSkip to conversation

acpi-cpufreq: Skip initialization if a cpufreq driver exists

PATCH Applied Kyle Meyer 3 participants 5 messages May 21, 2021 – Jun 7, 2021

Subsystems (2)
lore
Share & tools
lore

Kyle Meyer

author
#0 lore raw

PATCH 1/1 acpi-cpufreq: Skip initialization if a cpufreq driver exists

Revert part of commit 75c0758137c7a
("acpi-cpufreq: Fail initialization if driver cannot be registered").

acpi-cpufreq is mutually exclusive with intel_pstate, however, acpi-cpufreq is loaded multiple times during startup while intel_pstate is enabled. On systems using systemd the kernel triggers one uevent for each device as a result of systemd-udev-trigger.service. The service exists to retrigger all devices as uevents sent by the kernel before systemd-udevd is running are missed. The delay caused by systemd-udevd repeatedly loading the driver, getting a fail return, and unloading the driver twice per logical CPU has a significant impact on the startup time, and can cause some devices to be unavailable after reaching the root login prompt.

Load the driver once but skip initialization if a cpufreq driver exists by changing the return value of cpufreq_get_current_driver() from -EEXIST to 0.

---
 drivers/cpufreq/acpi-cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/acpi-cpufreq.c +1 -1
index 7e7450453714..e79a945369d1 100644
@@ -1003,7 +1003,7 @@ static int __init acpi_cpufreq_init(void)
 
 	/* don't keep reloading if cpufreq_driver exists */
 	if (cpufreq_get_current_driver())
-		return -EEXIST;
+		return 0;
 
 	pr_debug("%s\n", __func__);
 
Signature · 1 line
2.26.2
maintainer Applied
#1 lore raw
Quoted 28 lines · Kyle Meyer

Revert part of commit 75c0758137c7a
("acpi-cpufreq: Fail initialization if driver cannot be registered").

acpi-cpufreq is mutually exclusive with intel_pstate, however, acpi-cpufreq is loaded multiple times during startup while intel_pstate is enabled. On systems using systemd the kernel triggers one uevent for each device as a result of systemd-udev-trigger.service. The service exists to retrigger all devices as uevents sent by the kernel before systemd-udevd is running are missed. The delay caused by systemd-udevd repeatedly loading the driver, getting a fail return, and unloading the driver twice per logical CPU has a significant impact on the startup time, and can cause some devices to be unavailable after reaching the root login prompt.

Load the driver once but skip initialization if a cpufreq driver exists by changing the return value of cpufreq_get_current_driver() from -EEXIST to 0.

---
 drivers/cpufreq/acpi-cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/acpi-cpufreq.c +0 -0
index 7e7450453714..e79a945369d1 100644

drivers/cpufreq/acpi-cpufreq.c static int __init acpi_cpufreq_init(void)

Quoted 9 lines
drivers/cpufreq/acpi-cpufreq.c +1 -2
@@ -1003,7 +1003,7 @@ static int __init acpi_cpufreq_init(void)
 
        /* don't keep reloading if cpufreq_driver exists */
        if (cpufreq_get_current_driver())
-               return -EEXIST;
+               return 0;
 
        pr_debug("%s\n", __func__);
 
--

Applied as 5.14 material with some edits in the subject and changelog, thanks!

maintainer
#2 lore raw

Hi Rafael,

Quoted 13 lines · Rafael J. Wysocki
Quoted 11 lines · Kyle Meyer
drivers/cpufreq/acpi-cpufreq.c +1 -1
index 7e7450453714..e79a945369d1 100644
@@ -1003,7 +1003,7 @@ static int __init acpi_cpufreq_init(void)
 
        /* don't keep reloading if cpufreq_driver exists */
        if (cpufreq_get_current_driver())
-               return -EEXIST;
+               return 0;
 
Quoted 5 lines

drivers/cpufreq/acpi-cpufreq.c static int __init acpi_cpufreq_init(void)

Quoted 3 lines
drivers/cpufreq/acpi-cpufreq.c +0 -1
        pr_debug("%s\n", __func__);
 
--

Applied as 5.14 material with some edits in the subject and changelog, thanks!

I am not sure how this is supposed to work. If we return 0 from acpi_cpufreq_init(),
then the driver will never be used, since it's acpi_cpufreq_init() will never get
called again later.

cpufreq drivers don't follow the generic device/driver model where a driver gets probed again if a device appears and so this is broken.

Please revert this patch.

#3 lore raw
Quoted 23 lines · Viresh Kumar

Hi Rafael,

Quoted 13 lines · Rafael J. Wysocki
Quoted 11 lines · Kyle Meyer
drivers/cpufreq/acpi-cpufreq.c +1 -1
index 7e7450453714..e79a945369d1 100644
@@ -1003,7 +1003,7 @@ static int __init acpi_cpufreq_init(void)
 
        /* don't keep reloading if cpufreq_driver exists */
        if (cpufreq_get_current_driver())
-               return -EEXIST;
+               return 0;
 
Quoted 5 lines

drivers/cpufreq/acpi-cpufreq.c static int __init acpi_cpufreq_init(void)

Quoted 3 lines
drivers/cpufreq/acpi-cpufreq.c +0 -1
        pr_debug("%s\n", __func__);
 
--

Applied as 5.14 material with some edits in the subject and changelog, thanks!

Quoted 5 lines

I am not sure how this is supposed to work. If we return 0 from acpi_cpufreq_init(),
then the driver will never be used, since it's acpi_cpufreq_init() will never get
called again later.

Unless the module is unloaded and loaded again, that is.

Quoted 2 lines

cpufreq drivers don't follow the generic device/driver model where a driver gets probed again if a device appears and so this is broken.

It is broken anyway as per the changelog of this patch.

On systems with several hundred logical CPUs this really can be troublesome.

Quoted 1 line

Please revert this patch.

Well, you can argue that the problem at hand is outside the kernel and so it's not a kernel's business to address it.

After all, systemd-udevd could learn to avoid attempting to load the module again if it fails with -EEXIST, but I'm not sure how different that really would be from what this patch does, in practice.

maintainer
#4 lore raw
Quoted 8 lines · Rafael J. Wysocki
Quoted 5 lines · Viresh Kumar

I am not sure how this is supposed to work. If we return 0 from acpi_cpufreq_init(),
then the driver will never be used, since it's acpi_cpufreq_init() will never get
called again later.

Unless the module is unloaded and loaded again, that is.

Right.

Quoted 6 lines
Quoted 2 lines

cpufreq drivers don't follow the generic device/driver model where a driver gets probed again if a device appears and so this is broken.

It is broken anyway as per the changelog of this patch.

On systems with several hundred logical CPUs this really can be troublesome.

Hmm, I agree.

Quoted 4 lines
Quoted 1 line

Please revert this patch.

Well, you can argue that the problem at hand is outside the kernel and so it's not a kernel's business to address it.

Exactly, what we did here is add a band-aid to make a userspace tool happy, the kernel was doing the right thing earlier.

Quoted 2 lines

After all, systemd-udevd could learn to avoid attempting to load the module again if it fails with -EEXIST,

That is one way, right.

Quoted 2 lines

but I'm not sure how different
that really would be from what this patch does, in practice.

The very first difference is we won't be adding an incorrect hack in the kernel to solve this userspace problem. Else in order to make acpi-cpufreq driver work, after a user unloads intel-pstate, user would be required to unload the acpi-cpufreq and load it again, which will surely look confusing to the user. Why unload to load it again ?

Leaving a module inserted in an unusable state is not the right solution to fix a problem IMHO.

Signature · 1 line
viresh