mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] perf/core: Speed up kexec shutdown by avoiding unnecessary cross CPU calls
@ 2026-01-08 10:14 David Woodhouse
  2026-01-08 10:32 ` Peter Zijlstra
  2026-01-13 10:50 ` [tip: perf/core] " tip-bot2 for Jan H. Sch=C3=B6nherr
  0 siblings, 2 replies; 3+ messages in thread
From: David Woodhouse @ 2026-01-08 10:14 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, James Clark, linux-perf-users,
	linux-kernel
  Cc: Jan H. Schönherr

[-- Attachment #1: Type: text/plain, Size: 1393 bytes --]

From: Jan H. Schönherr <jschoenh@amazon.de>

There are typically a lot of PMUs registered, but in many cases only few
of them have an event registered (like the "cpu" PMU in the presence of
the watchdog). As the mutex is already held, it's safe to just check for
existing events before doing the cross CPU call.

This change saves tens of milliseconds from kexec time (perceived as
steal time during a hypervisor host update), with <2ms remaining for
this step in the shutdown. There might be additional potential for
parallelization or we could just disable performance monitoring during
the actual shutdown and be less graceful about it.

Signed-off-by: Jan H. Schönherr <jschoenh@amazon.de>
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
 kernel/events/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 413b88a4e00f..e36372b3c83f 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -14712,7 +14712,8 @@ static void perf_event_exit_cpu_context(int cpu)
 	ctx = &cpuctx->ctx;
 
 	mutex_lock(&ctx->mutex);
-	smp_call_function_single(cpu, __perf_event_exit_context, ctx, 1);
+	if (ctx->nr_events)
+		smp_call_function_single(cpu, __perf_event_exit_context, ctx, 1);
 	cpuctx->online = 0;
 	mutex_unlock(&ctx->mutex);
 	mutex_unlock(&pmus_lock);
-- 
2.43.0



[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5069 bytes --]

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

* Re: [PATCH] perf/core: Speed up kexec shutdown by avoiding unnecessary cross CPU calls
  2026-01-08 10:14 [PATCH] perf/core: Speed up kexec shutdown by avoiding unnecessary cross CPU calls David Woodhouse
@ 2026-01-08 10:32 ` Peter Zijlstra
  2026-01-13 10:50 ` [tip: perf/core] " tip-bot2 for Jan H. Sch=C3=B6nherr
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2026-01-08 10:32 UTC (permalink / raw)
  To: David Woodhouse
  Cc: Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers,
	Adrian Hunter, James Clark, linux-perf-users, linux-kernel,
	Jan H. Schönherr

On Thu, Jan 08, 2026 at 11:14:24AM +0100, David Woodhouse wrote:
> From: Jan H. Schönherr <jschoenh@amazon.de>
> 
> There are typically a lot of PMUs registered, but in many cases only few
> of them have an event registered (like the "cpu" PMU in the presence of
> the watchdog). As the mutex is already held, it's safe to just check for
> existing events before doing the cross CPU call.
> 
> This change saves tens of milliseconds from kexec time (perceived as
> steal time during a hypervisor host update), with <2ms remaining for
> this step in the shutdown. There might be additional potential for
> parallelization or we could just disable performance monitoring during
> the actual shutdown and be less graceful about it.
> 
> Signed-off-by: Jan H. Schönherr <jschoenh@amazon.de>
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---

Fair enough I suppose. Let me go queue this.

>  kernel/events/core.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 413b88a4e00f..e36372b3c83f 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -14712,7 +14712,8 @@ static void perf_event_exit_cpu_context(int cpu)
>  	ctx = &cpuctx->ctx;
>  
>  	mutex_lock(&ctx->mutex);
> -	smp_call_function_single(cpu, __perf_event_exit_context, ctx, 1);
> +	if (ctx->nr_events)
> +		smp_call_function_single(cpu, __perf_event_exit_context, ctx, 1);
>  	cpuctx->online = 0;
>  	mutex_unlock(&ctx->mutex);
>  	mutex_unlock(&pmus_lock);
> -- 
> 2.43.0
> 
> 



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

* [tip: perf/core] perf/core: Speed up kexec shutdown by avoiding unnecessary cross CPU calls
  2026-01-08 10:14 [PATCH] perf/core: Speed up kexec shutdown by avoiding unnecessary cross CPU calls David Woodhouse
  2026-01-08 10:32 ` Peter Zijlstra
@ 2026-01-13 10:50 ` tip-bot2 for Jan H. Sch=C3=B6nherr
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Jan H. Sch=C3=B6nherr @ 2026-01-13 10:50 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: jschoenh, David Woodhouse, Peter Zijlstra (Intel), x86, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     f4045e9dbb94825491b6da164f14f22b63de6a4e
Gitweb:        https://git.kernel.org/tip/f4045e9dbb94825491b6da164f14f22b63de6a4e
Author:        Jan H. Sch=C3=B6nherr <jschoenh@amazon.de>
AuthorDate:    Thu, 08 Jan 2026 11:14:24 +01:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Tue, 13 Jan 2026 11:45:36 +01:00

perf/core: Speed up kexec shutdown by avoiding unnecessary cross CPU calls

There are typically a lot of PMUs registered, but in many cases only few
of them have an event registered (like the "cpu" PMU in the presence of
the watchdog). As the mutex is already held, it's safe to just check for
existing events before doing the cross CPU call.

This change saves tens of milliseconds from kexec time (perceived as
steal time during a hypervisor host update), with <2ms remaining for
this step in the shutdown. There might be additional potential for
parallelization or we could just disable performance monitoring during
the actual shutdown and be less graceful about it.

Signed-off-by: Jan H. SchÃ=B6nherr <jschoenh@amazon.de>
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/0d0b7fe70e6dfa7979cb83b05317deb21187f74d.camel@infradead.org
---
 kernel/events/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 376fb07..101da5c 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -15066,7 +15066,8 @@ static void perf_event_exit_cpu_context(int cpu)
 	ctx = &cpuctx->ctx;
 
 	mutex_lock(&ctx->mutex);
-	smp_call_function_single(cpu, __perf_event_exit_context, ctx, 1);
+	if (ctx->nr_events)
+		smp_call_function_single(cpu, __perf_event_exit_context, ctx, 1);
 	cpuctx->online = 0;
 	mutex_unlock(&ctx->mutex);
 	mutex_unlock(&pmus_lock);

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

end of thread, other threads:[~2026-01-13 10:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-08 10:14 [PATCH] perf/core: Speed up kexec shutdown by avoiding unnecessary cross CPU calls David Woodhouse
2026-01-08 10:32 ` Peter Zijlstra
2026-01-13 10:50 ` [tip: perf/core] " tip-bot2 for Jan H. Sch=C3=B6nherr

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

all inboxes | Powered by JetHome®