From: Feng Tang <feng.tang@linux.alibaba.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Sudeep Holla <sudeep.holla@kernel.org>,
rafael@kernel.org, Danilo Krummrich <dakr@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
David Hildenbrand <david@kernel.org>,
linux-kernel@vger.kernel.org, driver-core@lists.linux.dev
Subject: Re: [PATCH RFC] arch_topology: Introduce nr_possible_packages
Date: Wed, 13 May 2026 09:35:30 +0800 [thread overview]
Message-ID: <agPVYkyVMcUye3cn@U-2FWC9VHC-2323.local> (raw)
In-Reply-To: <2026051214-supermom-brim-4608@gregkh>
Hi Greg,
Thanks for the review!
On Tue, May 12, 2026 at 05:51:25PM +0200, Greg Kroah-Hartman wrote:
> On Tue, May 12, 2026 at 11:05:05PM +0800, Feng Tang wrote:
> > In multi-sockets platform, kernel or driver code may need the number
> > of packages for chosing different code directions. Some architecture
> > already provide such kind of interface like x86, which is being used
> > in some architecture code and drivers.
> >
> > Add similar interface 'nr_possible_packages' for platforms which can
> > get package topology information by parsing ACPI tables in boot phase.
> >
> > Signed-off-by: Feng Tang <feng.tang@linux.alibaba.com>
> > ---
> > drivers/base/arch_topology.c | 21 +++++++++++++++++++++
> > include/linux/arch_topology.h | 5 +++++
> > 2 files changed, 26 insertions(+)
> >
> > diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
> > index 8c5e47c28d9a..796d8a7aceea 100644
> > --- a/drivers/base/arch_topology.c
> > +++ b/drivers/base/arch_topology.c
> > @@ -850,6 +850,16 @@ static bool __init acpi_cpu_is_threaded(int cpu)
> > return !!is_threaded;
> > }
> >
> > +unsigned int nr_possible_packages __ro_after_init = 1;
> > +EXPORT_SYMBOL(nr_possible_packages);
>
> EXPORT_SYMBOL_GPL() please?
Will change.
> And you don't have a user for this, so we can't verify how it actually
> works :(
Good point. Internally we have some PMU driver using this, but the HW is
not public and the drive hasn't been posted yet.
As for validation, we tested on production 1P platform, internal 2P
platform, and QEMU's multi-socket case.
I checked a production arm64 2P platform 'Kunpeng 920', and from the
output of "cat /sys/devices/system/cpu/cpu*/topology/physical_package_id",
the patch should work fine. I don't have root right of it yet, will try
to really run the patch on it.
> thanks,
>
> greg k-h
>
> > +/*
> > + * Assuming silicon has a sane package ID decoding method to not have
> > + * an ID bigger than 255 (1 byte).
>
> Is that a valid assumption? What about packages bigger than 255? Don't
> we have those today?
Myself have only touched 8P (16P) HW, which may limit my imagination :)
We can change it to 1024 or 2048, though I'm curious how the cross-socket
latency and coherency could be maintained for huge platforms.
>
> > + */
> > +#define MAX_PACKAGE_ID 255
> > +DECLARE_BITMAP(package_id_mask, MAX_PACKAGE_ID + 1);
> > +
> > /*
> > * Propagate the topology information of the processor_topology_node tree to the
> > * cpu_topology array.
> > @@ -912,6 +922,13 @@ __weak int __init parse_acpi_topology(void)
> > cpu_topology[cpu].cluster_id = topology_id;
> > topology_id = find_acpi_cpu_topology_package(cpu);
> > cpu_topology[cpu].package_id = topology_id;
> > +
> > +
> > + if (topology_id >= 0 && topology_id <= MAX_PACKAGE_ID)
> > + bitmap_set(package_id_mask, topology_id, 1);
> > + else
> > + pr_warn("ACPI: abnormal package ID: %d !\n",
> > + topology_id);
> > }
> >
> > /*
> > @@ -927,6 +944,10 @@ __weak int __init parse_acpi_topology(void)
> >
> > cpu_smt_set_num_threads(max_smt_thread_num, max_smt_thread_num);
> > xa_destroy(&hetero_cpu);
> > +
> > + /* Count the number of possible packages in system */
> > + nr_possible_packages = bitmap_weight(package_id_mask, MAX_PACKAGE_ID + 1);
> > + pr_info("ACPI: System has %u Package(s) detected\n", nr_possible_packages);
>
> Why "P" and not "p"?
:) will change.
>
> > return 0;
> > }
> >
> > diff --git a/include/linux/arch_topology.h b/include/linux/arch_topology.h
> > index ebd7f8935f96..dee076cc9c7a 100644
> > --- a/include/linux/arch_topology.h
> > +++ b/include/linux/arch_topology.h
> > @@ -111,4 +111,9 @@ static inline bool topology_core_has_smt(int cpu) { return false; }
> >
> > #endif /* CONFIG_GENERIC_ARCH_TOPOLOGY */
> >
> > +
> > +#if defined(CONFIG_ARM64) || defined(CONFIG_RISCV)
> > +extern unsigned int nr_possible_packages;
> > +#endif
>
> Why the ifdef?
Aha, initial version of patch doesn't have it, as I think many
architectures may need this.
It was added later as the 'parse_acpi_topology()' function is under
this 'ifdef'.
I can move the 'nr_possible_packages' for future expandability if
no objection.
Thanks,
Feng
> thanks,
>
> greg k-h
next prev parent reply other threads:[~2026-05-13 1:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 15:05 [PATCH RFC] arch_topology: Introduce nr_possible_packages Feng Tang
2026-05-12 15:51 ` Greg Kroah-Hartman
2026-05-13 1:35 ` Feng Tang [this message]
2026-05-13 9:46 ` Feng Tang
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=agPVYkyVMcUye3cn@U-2FWC9VHC-2323.local \
--to=feng.tang@linux.alibaba.com \
--cc=catalin.marinas@arm.com \
--cc=dakr@kernel.org \
--cc=david@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=sudeep.holla@kernel.org \
--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