From: Sean Christopherson <seanjc@google.com>
To: David Woodhouse <dwmw2@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H . Peter Anvin" <hpa@zytor.com>,
Paolo Bonzini <pbonzini@redhat.com>,
"Paul E . McKenney" <paulmck@kernel.org>,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
rcu@vger.kernel.org, mimoja@mimoja.de, hewenliang4@huawei.com,
hushiyuan@huawei.com, luolongjun@huawei.com,
hejingxian@huawei.com
Subject: Re: [PATCH v2 1/7] x86/apic/x2apic: Fix parallel handling of cluster_mask
Date: Tue, 14 Dec 2021 17:10:33 +0000 [thread overview]
Message-ID: <YbjQCf29BH7aTblP@google.com> (raw)
In-Reply-To: <20211214123250.88230-2-dwmw2@infradead.org>
On Tue, Dec 14, 2021, David Woodhouse wrote:
> -static int alloc_clustermask(unsigned int cpu, int node)
> +static int alloc_clustermask(unsigned int cpu, u32 cluster, int node)
> {
> + struct cluster_mask *cmsk = NULL;
> + unsigned int cpu_i;
> + u32 apicid;
> +
> if (per_cpu(cluster_masks, cpu))
> return 0;
> - /*
> - * If a hotplug spare mask exists, check whether it's on the right
> - * node. If not, free it and allocate a new one.
> +
> + /* For the hotplug case, don't always allocate a new one */
> + for_each_present_cpu(cpu_i) {
> + apicid = apic->cpu_present_to_apicid(cpu_i);
> + if (apicid != BAD_APICID && apicid >> 4 == cluster) {
> + cmsk = per_cpu(cluster_masks, cpu_i);
> + if (cmsk)
> + break;
> + }
> + }
> + if (!cmsk) {
> + cmsk = kzalloc_node(sizeof(*cmsk), GFP_KERNEL, node);
> + }
> + if (!cmsk)
> + return -ENOMEM;
This can be,
if (!cmsk) {
cmsk = kzalloc_node(sizeof(*cmsk), GFP_KERNEL, node);
if (!cmsk)
return -ENOMEM;
}
which IMO is more intuitive, and it also "fixes" the unnecessary braces in thew
initial check.
> +
> + cmsk->node = node;
> + cmsk->clusterid = cluster;
> +
> + per_cpu(cluster_masks, cpu) = cmsk;
> +
> + /*
> + * As an optimisation during boot, set the cluster_mask for *all*
> + * present CPUs at once, to prevent *each* of them having to iterate
> + * over the others to find the existing cluster_mask.
> */
> - if (cluster_hotplug_mask) {
> - if (cluster_hotplug_mask->node == node)
> - return 0;
> - kfree(cluster_hotplug_mask);
> + if (system_state < SYSTEM_RUNNING) {
This can be
if (system_state >= SYSTEM_RUNNING)
return 0;
to reduce indentation below.
> + for_each_present_cpu(cpu) {
Reusing @cpu here is all kinds of confusing.
> + u32 apicid = apic->cpu_present_to_apicid(cpu);
This shadows apicid. That's completely unnecessary.
> + if (apicid != BAD_APICID && apicid >> 4 == cluster) {
A helper for retrieving the cluster from a cpu would dedup at least three instances
of this pattern.
> + struct cluster_mask **cpu_cmsk = &per_cpu(cluster_masks, cpu);
> + if (*cpu_cmsk)
> + BUG_ON(*cpu_cmsk != cmsk);
> + else
> + *cpu_cmsk = cmsk;
The if statement is a little confusing because of the double pointer. BUG_ON()
won't return, maybe write it like so?
BUG_ON(*cpu_mask && *cpu_mask != cmsk);
*cpu_cmsk = cmsk;
> + }
> + }
> }
>
> - cluster_hotplug_mask = kzalloc_node(sizeof(*cluster_hotplug_mask),
> - GFP_KERNEL, node);
> - if (!cluster_hotplug_mask)
> - return -ENOMEM;
> - cluster_hotplug_mask->node = node;
> return 0;
> }
>
> static int x2apic_prepare_cpu(unsigned int cpu)
> {
> - if (alloc_clustermask(cpu, cpu_to_node(cpu)) < 0)
> + u32 phys_apicid = apic->cpu_present_to_apicid(cpu);
> + u32 cluster = phys_apicid >> 4;
> + u32 logical_apicid = (cluster << 16) | (1 << (phys_apicid & 0xf));
> +
> + x86_cpu_to_logical_apicid[cpu] = logical_apicid;
> +
> + if (alloc_clustermask(cpu, cluster, cpu_to_node(cpu)) < 0)
> return -ENOMEM;
> if (!zalloc_cpumask_var(&per_cpu(ipi_mask, cpu), GFP_KERNEL))
> return -ENOMEM;
> --
> 2.31.1
>
next prev parent reply other threads:[~2021-12-14 17:10 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-14 12:32 [PATCH v2 0/7] Parallel CPU bringup for x86_64 David Woodhouse
2021-12-14 12:32 ` [PATCH v2 1/7] x86/apic/x2apic: Fix parallel handling of cluster_mask David Woodhouse
2021-12-14 17:10 ` Sean Christopherson [this message]
2021-12-14 21:27 ` David Woodhouse
2021-12-14 12:32 ` [PATCH v2 2/7] cpu/hotplug: Move idle_thread_get() to <linux/smpboot.h> David Woodhouse
2021-12-14 12:32 ` [PATCH v2 3/7] cpu/hotplug: Add dynamic parallel bringup states before CPUHP_BRINGUP_CPU David Woodhouse
2021-12-14 14:24 ` Mark Rutland
2021-12-14 20:32 ` David Woodhouse
2021-12-15 11:10 ` Mark Rutland
2021-12-15 15:16 ` David Woodhouse
2021-12-14 12:32 ` [PATCH v2 4/7] x86/smpboot: Reference count on smpboot_setup_warm_reset_vector() David Woodhouse
2021-12-14 12:32 ` [PATCH v2 5/7] x86/smpboot: Split up native_cpu_up into separate phases and document them David Woodhouse
2021-12-14 12:32 ` [PATCH v2 6/7] x86/smpboot: Support parallel startup of secondary CPUs David Woodhouse
2021-12-14 12:32 ` [PATCH v2 7/7] x86/smpboot: Send INIT/SIPI/SIPI to secondary CPUs in parallel David Woodhouse
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=YbjQCf29BH7aTblP@google.com \
--to=seanjc@google.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=dwmw2@infradead.org \
--cc=hejingxian@huawei.com \
--cc=hewenliang4@huawei.com \
--cc=hpa@zytor.com \
--cc=hushiyuan@huawei.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luolongjun@huawei.com \
--cc=mimoja@mimoja.de \
--cc=mingo@redhat.com \
--cc=paulmck@kernel.org \
--cc=pbonzini@redhat.com \
--cc=rcu@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.