mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stanislav Spassov <stanspas@amazon.de>
To: <linux-kernel@vger.kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Peter Zijlstra <peterz@infradead.org>,
	David Woodhouse <dwmw@amazon.co.uk>,
	James Gowans <jgowans@amazon.com>,
	Stanislav Spassov <stanspas@amazon.de>
Subject: [PATCH] cpu: Reverse order of iteration in freeze_secondary_cpus
Date: Fri, 24 May 2024 16:04:49 +0000	[thread overview]
Message-ID: <20240524160449.48594-1-stanspas@amazon.de> (raw)

Whenever CPU hotplug state callbacks are registered (cpuhp_setup_state),
the startup callback is invoked on CPUs that have already reached the
provided state in order of ascending CPU id. For symmetry, we change
freeze_secondary_cpus to iterate through the CPUs in opposite order,
so that the teardown callback invocations happen in order of descending
CPU id.

One case where this is known to make a difference is the current
implementation of these callbacks in arch/x86/events/intel/uncore.c:

- uncore_event_cpu_online: designates the first CPU it is invoked for
  on each package as the uncore event collector for that package

- uncore_event_cpu_offline: if the CPU being offlined is the event
  collector for its package, transfers that responsibility over to
  the next (by ascending CPU id) one in the same package

Without reversing the order of teardowns in freeze_secondary_cpus, the
latter ends up doing the ownership transfer work on every single CPU.
That work involves a synchronize_rcu call (in perf_pmu_migrate_context),
ultimately unnecessarily degrading the performance of the CPU offlining.

Signed-off-by: Stanislav Spassov <stanspas@amazon.de>
---
 kernel/cpu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kernel/cpu.c b/kernel/cpu.c
index cc4a8068747c..aaa8b7d5f93e 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -1942,7 +1942,10 @@ int freeze_secondary_cpus(int primary)
 	cpumask_clear(frozen_cpus);
 
 	pr_info("Disabling non-boot CPUs ...\n");
-	for_each_online_cpu(cpu) {
+	for (cpu = nr_cpu_ids - 1; cpu >= 0; cpu--) {
+		if (!cpu_online(cpu))
+			continue;
+
 		if (cpu == primary)
 			continue;
 

base-commit: 266e95786452d97f42dcb9a881bba223584b9648
-- 
2.40.1




Amazon Web Services Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B
Sitz: Berlin
Ust-ID: DE 365 538 597


             reply	other threads:[~2024-05-24 16:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-24 16:04 Stanislav Spassov [this message]
2024-06-17 13:26 ` [tip: smp/core] cpu/hotplug: Reverse order of iteration in freeze_secondary_cpus() tip-bot2 for Stanislav Spassov

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=20240524160449.48594-1-stanspas@amazon.de \
    --to=stanspas@amazon.de \
    --cc=dwmw@amazon.co.uk \
    --cc=jgowans@amazon.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /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

all inboxes | Powered by JetHome®