[PATCH] leds: trigger: cpu: use cpuhp_setup_state_nocalls() for large CPU counts

Paul Sherman <[email protected]> Mon, 27 Jul 2026 15:16:06 -0700
Newsgroups org.kernel.vger.linux-leds,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
ledtrig_cpu_init() uses cpuhp_setup_state() which invokes the startup
callback on every already-online CPU at registration time. On systems
with large CPU counts this serializes callbacks across all online CPUs,
causing boot delays proportional to the number of CPUs.

On a 64-hart RISC-V system this caused ledtrig_cpu_init() to consume
~250 seconds at boot. The same pathology affects any system using
cpuhp_setup_state() where one CPU is slow to acknowledge.

Use cpuhp_setup_state_nocalls() instead, which skips callbacks for
already-online CPUs at registration time. The trigger operates correctly
for future hotplug events regardless.

Tested-on: Milk-V Pioneer (SG2042, 64-hart RISC-V)
Cc: Thierry Reding <[email protected]>
Signed-off-by: Paul Sherman <[email protected]>
---
 drivers/leds/trigger/ledtrig-cpu.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/leds/trigger/ledtrig-cpu.c b/drivers/leds/trigger/ledtrig-cpu.c
index 679323c2ccda0..ce75d5f54684c 100644
--- a/drivers/leds/trigger/ledtrig-cpu.c
+++ b/drivers/leds/trigger/ledtrig-cpu.c
@@ -163,7 +163,15 @@ static int __init ledtrig_cpu_init(void)
 
 	register_syscore(&ledtrig_cpu_syscore);
 
-	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "leds/trigger:starting",
+	/*
+	 * Use cpuhp_setup_state_nocalls() to avoid invoking ledtrig_online_cpu()
+	 * on every already-online CPU at registration time. On systems with large
+	 * CPU counts (e.g. 64-hart RISC-V) cpuhp_setup_state() would serialize
+	 * callbacks across all online CPUs, causing multi-hundred-second delays
+	 * during boot. The trigger operates correctly for future hotplug events
+	 * regardless.
+ 	 */
+	ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "leds/trigger:starting",
 				ledtrig_online_cpu, ledtrig_prepare_down_cpu);
 	if (ret < 0)
 		pr_err("CPU hotplug notifier for ledtrig-cpu could not be registered: %d\n",
-- 
2.53.0