Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ayubjon Qosimov <ayubjon@amazon.de>
To: Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>
Cc: <linux-arm-kernel@lists.infradead.org>,
	<linux-perf-users@vger.kernel.org>, <nh-open-source@amazon.com>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH] arm64: hw_breakpoint: Reset the debug registers on all CPUs at once
Date: Fri, 4 Dec 2026 18:30:14 +0000	[thread overview]
Message-ID: <20261204183014.79514-1-ayubjon@amazon.de> (raw)

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



                 reply	other threads:[~2026-12-04 18:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204183014.79514-1-ayubjon@amazon.de \
    --to=ayubjon@amazon.de \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=nh-open-source@amazon.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox