Linux Perf Users
 help / color / mirror / Atom feed
* [PATCH] arm64: hw_breakpoint: Reset the debug registers on all CPUs at once
@ 2026-12-04 18:30 Ayubjon Qosimov
  2026-12-04 18:44 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Ayubjon Qosimov @ 2026-12-04 18:30 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Mark Rutland
  Cc: linux-arm-kernel, linux-perf-users, nh-open-source, linux-kernel

arch_hw_breakpoint_init() runs after SMP bringup, so cpuhp_setup_state()
invokes hw_breakpoint_reset() on each online CPU in turn: it kicks that
CPU's hotplug thread and waits for it to finish before moving on to the
next one. The time grows linearly with the number of CPUs, and most of
it is spent where accesses to the debug registers trap to a hypervisor:
in a 96-vCPU KVM guest the initcall takes about 1.0 ms, around 10 us
per CPU.

This is on the boot path of a kernel started by kexec with Kexec
HandOver for a live update (Documentation/core-api/liveupdate.rst),
where the preserved workloads stay paused until the new kernel is up.

Reset the online CPUs with a single on_each_cpu() call instead, so that
they all run the reset at the same time, with interrupts disabled as in
the STARTING callback, and register the callback for CPUs that come up
later with cpuhp_setup_state_nocalls_cpuslocked(). With the hotplug
lock held across both, no CPU can come up in between and every online
CPU is past the STARTING states, so the same CPUs are reset as before.

In the 96-vCPU KVM guest on a Graviton4 host, arch_hw_breakpoint_init()
goes from about 1.0 ms to 0.085 ms (13 boots each).

Signed-off-by: Ayubjon Qosimov <ayubjon@amazon.de>
---
The same could be done for every STARTING state in the CPU hotplug core,
since STARTING callbacks cannot fail. I kept the change local to this
file, but can look at kernel/cpu.c instead if that is preferred.
---
 arch/arm64/kernel/hw_breakpoint.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
index 32b38967433e..7d54e2f35cf7 100644
--- a/arch/arm64/kernel/hw_breakpoint.c
+++ b/arch/arm64/kernel/hw_breakpoint.c
@@ -1003,6 +1003,11 @@ static int hw_breakpoint_reset(unsigned int cpu)
 	return 0;
 }
 
+static void __init hw_breakpoint_reset_ipi(void *unused)
+{
+	hw_breakpoint_reset(smp_processor_id());
+}
+
 /*
  * One-time initialisation.
  */
@@ -1019,10 +1024,17 @@ static int __init arch_hw_breakpoint_init(void)
 	/*
 	 * Reset the breakpoint resources. We assume that a halting
 	 * debugger will leave the world in a nice state for us.
+	 *
+	 * The online CPUs are reset here, the ones that come up later by the
+	 * hotplug callback. Holding the hotplug lock keeps a CPU from coming
+	 * up in between.
 	 */
-	ret = cpuhp_setup_state(CPUHP_AP_PERF_ARM_HW_BREAKPOINT_STARTING,
-			  "perf/arm64/hw_breakpoint:starting",
-			  hw_breakpoint_reset, NULL);
+	cpus_read_lock();
+	on_each_cpu(hw_breakpoint_reset_ipi, NULL, 1);
+	ret = cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_PERF_ARM_HW_BREAKPOINT_STARTING,
+						   "perf/arm64/hw_breakpoint:starting",
+						   hw_breakpoint_reset, NULL);
+	cpus_read_unlock();
 	if (ret)
 		pr_err("failed to register CPU hotplug notifier: %d\n", ret);
 

base-commit: f46be4da2cbb17574b5369517a9a1e1b414063b4
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] arm64: hw_breakpoint: Reset the debug registers on all CPUs at once
  2026-12-04 18:30 [PATCH] arm64: hw_breakpoint: Reset the debug registers on all CPUs at once Ayubjon Qosimov
@ 2026-12-04 18:44 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-04 18:44 UTC (permalink / raw)
  To: Ayubjon Qosimov; +Cc: linux-perf-users

> arch_hw_breakpoint_init() runs after SMP bringup, so cpuhp_setup_state()
> invokes hw_breakpoint_reset() on each online CPU in turn: it kicks that
> CPU's hotplug thread and waits for it to finish before moving on to the
> next one. The time grows linearly with the number of CPUs, and most of
> it is spent where accesses to the debug registers trap to a hypervisor:
> in a 96-vCPU KVM guest the initcall takes about 1.0 ms, around 10 us
> per CPU.
> 
> This is on the boot path of a kernel started by kexec with Kexec
> HandOver for a live update (Documentation/core-api/liveupdate.rst),
> where the preserved workloads stay paused until the new kernel is up.
> 
> Reset the online CPUs with a single on_each_cpu() call instead, so that
> they all run the reset at the same time, with interrupts disabled as in
> the STARTING callback, and register the callback for CPUs that come up
> later with cpuhp_setup_state_nocalls_cpuslocked(). With the hotplug
> lock held across both, no CPU can come up in between and every online
> CPU is past the STARTING states, so the same CPUs are reset as before.
> 
> In the 96-vCPU KVM guest on a Graviton4 host, arch_hw_breakpoint_init()
> goes from about 1.0 ms to 0.085 ms (13 boots each).
> 
> Signed-off-by: Ayubjon Qosimov <ayubjon@amazon.de>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204183014.79514-1-ayubjon@amazon.de?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-04 18:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 18:30 [PATCH] arm64: hw_breakpoint: Reset the debug registers on all CPUs at once Ayubjon Qosimov
2026-12-04 18:44 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox