From: Igor Mammedov <imammedo@redhat.com>
To: Babu Moger <babu.moger@amd.com>
Cc: ehabkost@redhat.com, mst@redhat.com, armbru@redhat.com,
qemu-devel@nongnu.org, pbonzini@redhat.com, rth@twiddle.net
Subject: Re: [PATCH v3 03/18] hw/i386: Consolidate topology functions
Date: Tue, 28 Jan 2020 16:46:07 +0100 [thread overview]
Message-ID: <20200128164607.7611ad5f@redhat.com> (raw)
In-Reply-To: <157541983500.46157.10867081966222391072.stgit@naples-babu.amd.com>
On Tue, 03 Dec 2019 18:37:15 -0600
Babu Moger <babu.moger@amd.com> wrote:
> Now that we have all the parameters in X86CPUTopoInfo, we can just pass the
> structure to calculate the offsets and width.
>
> Signed-off-by: Babu Moger <babu.moger@amd.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
> ---
> include/hw/i386/topology.h | 64 ++++++++++++++------------------------------
> target/i386/cpu.c | 23 ++++++++--------
> 2 files changed, 32 insertions(+), 55 deletions(-)
>
> diff --git a/include/hw/i386/topology.h b/include/hw/i386/topology.h
> index cf1935d548..ba52d49079 100644
> --- a/include/hw/i386/topology.h
> +++ b/include/hw/i386/topology.h
> @@ -69,56 +69,42 @@ static unsigned apicid_bitwidth_for_count(unsigned count)
>
> /* Bit width of the SMT_ID (thread ID) field on the APIC ID
> */
> -static inline unsigned apicid_smt_width(unsigned nr_dies,
> - unsigned nr_cores,
> - unsigned nr_threads)
> +static inline unsigned apicid_smt_width(X86CPUTopoInfo *topo_info)
> {
> - return apicid_bitwidth_for_count(nr_threads);
> + return apicid_bitwidth_for_count(topo_info->threads_per_core);
> }
>
> /* Bit width of the Core_ID field
> */
> -static inline unsigned apicid_core_width(unsigned nr_dies,
> - unsigned nr_cores,
> - unsigned nr_threads)
> +static inline unsigned apicid_core_width(X86CPUTopoInfo *topo_info)
> {
> - return apicid_bitwidth_for_count(nr_cores);
> + return apicid_bitwidth_for_count(topo_info->cores_per_die);
> }
>
> /* Bit width of the Die_ID field */
> -static inline unsigned apicid_die_width(unsigned nr_dies,
> - unsigned nr_cores,
> - unsigned nr_threads)
> +static inline unsigned apicid_die_width(X86CPUTopoInfo *topo_info)
> {
> - return apicid_bitwidth_for_count(nr_dies);
> + return apicid_bitwidth_for_count(topo_info->dies_per_pkg);
> }
>
> /* Bit offset of the Core_ID field
> */
> -static inline unsigned apicid_core_offset(unsigned nr_dies,
> - unsigned nr_cores,
> - unsigned nr_threads)
> +static inline unsigned apicid_core_offset(X86CPUTopoInfo *topo_info)
> {
> - return apicid_smt_width(nr_dies, nr_cores, nr_threads);
> + return apicid_smt_width(topo_info);
> }
>
> /* Bit offset of the Die_ID field */
> -static inline unsigned apicid_die_offset(unsigned nr_dies,
> - unsigned nr_cores,
> - unsigned nr_threads)
> +static inline unsigned apicid_die_offset(X86CPUTopoInfo *topo_info)
> {
> - return apicid_core_offset(nr_dies, nr_cores, nr_threads) +
> - apicid_core_width(nr_dies, nr_cores, nr_threads);
> + return apicid_core_offset(topo_info) + apicid_core_width(topo_info);
> }
>
> /* Bit offset of the Pkg_ID (socket ID) field
> */
> -static inline unsigned apicid_pkg_offset(unsigned nr_dies,
> - unsigned nr_cores,
> - unsigned nr_threads)
> +static inline unsigned apicid_pkg_offset(X86CPUTopoInfo *topo_info)
> {
> - return apicid_die_offset(nr_dies, nr_cores, nr_threads) +
> - apicid_die_width(nr_dies, nr_cores, nr_threads);
> + return apicid_die_offset(topo_info) + apicid_die_width(topo_info);
> }
>
> /* Make APIC ID for the CPU based on Pkg_ID, Core_ID, SMT_ID
> @@ -128,13 +114,9 @@ static inline unsigned apicid_pkg_offset(unsigned nr_dies,
> static inline apic_id_t apicid_from_topo_ids(X86CPUTopoInfo *topo_info,
> const X86CPUTopoIDs *topo_ids)
> {
> - unsigned nr_dies = topo_info->dies_per_pkg;
> - unsigned nr_cores = topo_info->cores_per_die;
> - unsigned nr_threads = topo_info->threads_per_core;
> -
> - return (topo_ids->pkg_id << apicid_pkg_offset(nr_dies, nr_cores, nr_threads)) |
> - (topo_ids->die_id << apicid_die_offset(nr_dies, nr_cores, nr_threads)) |
> - (topo_ids->core_id << apicid_core_offset(nr_dies, nr_cores, nr_threads)) |
> + return (topo_ids->pkg_id << apicid_pkg_offset(topo_info)) |
> + (topo_ids->die_id << apicid_die_offset(topo_info)) |
> + (topo_ids->core_id << apicid_core_offset(topo_info)) |
> topo_ids->smt_id;
> }
>
> @@ -162,19 +144,15 @@ static inline void x86_topo_ids_from_apicid(apic_id_t apicid,
> X86CPUTopoInfo *topo_info,
> X86CPUTopoIDs *topo_ids)
> {
> - unsigned nr_dies = topo_info->dies_per_pkg;
> - unsigned nr_cores = topo_info->cores_per_die;
> - unsigned nr_threads = topo_info->threads_per_core;
> -
> topo_ids->smt_id = apicid &
> - ~(0xFFFFFFFFUL << apicid_smt_width(nr_dies, nr_cores, nr_threads));
> + ~(0xFFFFFFFFUL << apicid_smt_width(topo_info));
> topo_ids->core_id =
> - (apicid >> apicid_core_offset(nr_dies, nr_cores, nr_threads)) &
> - ~(0xFFFFFFFFUL << apicid_core_width(nr_dies, nr_cores, nr_threads));
> + (apicid >> apicid_core_offset(topo_info)) &
> + ~(0xFFFFFFFFUL << apicid_core_width(topo_info));
> topo_ids->die_id =
> - (apicid >> apicid_die_offset(nr_dies, nr_cores, nr_threads)) &
> - ~(0xFFFFFFFFUL << apicid_die_width(nr_dies, nr_cores, nr_threads));
> - topo_ids->pkg_id = apicid >> apicid_pkg_offset(nr_dies, nr_cores, nr_threads);
> + (apicid >> apicid_die_offset(topo_info)) &
> + ~(0xFFFFFFFFUL << apicid_die_width(topo_info));
> + topo_ids->pkg_id = apicid >> apicid_pkg_offset(topo_info);
> }
>
> /* Make APIC ID for the CPU 'cpu_index'
> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> index 07cf562d89..bc9b491557 100644
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c
> @@ -4551,6 +4551,11 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
> uint32_t die_offset;
> uint32_t limit;
> uint32_t signature[3];
> + X86CPUTopoInfo topo_info;
> +
> + topo_info.dies_per_pkg = env->nr_dies;
> + topo_info.cores_per_die = cs->nr_cores;
> + topo_info.threads_per_core = cs->nr_threads;
>
> /* Calculate & apply limits for different index ranges */
> if (index >= 0xC0000000) {
> @@ -4637,8 +4642,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
> eax, ebx, ecx, edx);
> break;
> case 3: /* L3 cache info */
> - die_offset = apicid_die_offset(env->nr_dies,
> - cs->nr_cores, cs->nr_threads);
> + die_offset = apicid_die_offset(&topo_info);
> if (cpu->enable_l3_cache) {
> encode_cache_cpuid4(env->cache_info_cpuid4.l3_cache,
> (1 << die_offset), cs->nr_cores,
> @@ -4729,14 +4733,12 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
>
> switch (count) {
> case 0:
> - *eax = apicid_core_offset(env->nr_dies,
> - cs->nr_cores, cs->nr_threads);
> + *eax = apicid_core_offset(&topo_info);
> *ebx = cs->nr_threads;
> *ecx |= CPUID_TOPOLOGY_LEVEL_SMT;
> break;
> case 1:
> - *eax = apicid_pkg_offset(env->nr_dies,
> - cs->nr_cores, cs->nr_threads);
> + *eax = apicid_pkg_offset(&topo_info);
> *ebx = cs->nr_cores * cs->nr_threads;
> *ecx |= CPUID_TOPOLOGY_LEVEL_CORE;
> break;
> @@ -4760,20 +4762,17 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
> *edx = cpu->apic_id;
> switch (count) {
> case 0:
> - *eax = apicid_core_offset(env->nr_dies, cs->nr_cores,
> - cs->nr_threads);
> + *eax = apicid_core_offset(&topo_info);
> *ebx = cs->nr_threads;
> *ecx |= CPUID_TOPOLOGY_LEVEL_SMT;
> break;
> case 1:
> - *eax = apicid_die_offset(env->nr_dies, cs->nr_cores,
> - cs->nr_threads);
> + *eax = apicid_die_offset(&topo_info);
> *ebx = cs->nr_cores * cs->nr_threads;
> *ecx |= CPUID_TOPOLOGY_LEVEL_CORE;
> break;
> case 2:
> - *eax = apicid_pkg_offset(env->nr_dies, cs->nr_cores,
> - cs->nr_threads);
> + *eax = apicid_pkg_offset(&topo_info);
> *ebx = env->nr_dies * cs->nr_cores * cs->nr_threads;
> *ecx |= CPUID_TOPOLOGY_LEVEL_DIE;
> break;
>
next prev parent reply other threads:[~2020-01-28 15:47 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-04 0:36 [PATCH v3 00/18] APIC ID fixes for AMD EPYC CPU models Babu Moger
2019-12-04 0:37 ` [PATCH v3 01/18] hw/i386: Rename X86CPUTopoInfo structure to X86CPUTopoIDs Babu Moger
2020-02-03 15:08 ` Igor Mammedov
2020-02-03 18:25 ` Babu Moger
2019-12-04 0:37 ` [PATCH v3 02/18] hw/i386: Introduce X86CPUTopoInfo to contain topology info Babu Moger
2020-01-28 15:44 ` Igor Mammedov
2019-12-04 0:37 ` [PATCH v3 03/18] hw/i386: Consolidate topology functions Babu Moger
2020-01-28 15:46 ` Igor Mammedov [this message]
2019-12-04 0:37 ` [PATCH v3 04/18] hw/i386: Introduce initialize_topo_info to initialize X86CPUTopoInfo Babu Moger
2020-01-28 15:49 ` Igor Mammedov
2020-01-28 16:42 ` Babu Moger
2019-12-04 0:37 ` [PATCH v3 05/18] machine: Add SMP Sockets in CpuTopology Babu Moger
2019-12-04 0:37 ` [PATCH v3 06/18] hw/core: Add core complex id in X86CPU topology Babu Moger
2020-01-28 16:27 ` Igor Mammedov
2020-01-28 16:44 ` Babu Moger
2020-01-28 16:31 ` Eric Blake
2020-01-28 16:44 ` Babu Moger
2019-12-04 0:37 ` [PATCH v3 07/18] machine: Add a new function init_apicid_fn in MachineClass Babu Moger
2020-01-28 16:29 ` Igor Mammedov
2020-01-28 19:45 ` Babu Moger
2020-01-28 20:12 ` Eduardo Habkost
2020-01-29 9:14 ` Igor Mammedov
2020-01-29 16:17 ` Babu Moger
2020-02-03 15:17 ` Igor Mammedov
2020-02-03 21:49 ` Babu Moger
2020-02-04 7:38 ` Igor Mammedov
2020-01-29 16:32 ` Babu Moger
2020-01-29 16:51 ` Eduardo Habkost
2020-01-29 17:05 ` Babu Moger
2019-12-04 0:37 ` [PATCH v3 08/18] hw/i386: Update structures for nodes_per_pkg Babu Moger
2019-12-04 0:37 ` [PATCH v3 09/18] i386: Add CPUX86Family type in CPUX86State Babu Moger
2019-12-04 0:38 ` [PATCH v3 10/18] hw/386: Add EPYC mode topology decoding functions Babu Moger
2019-12-04 0:38 ` [PATCH v3 11/18] i386: Cleanup and use the EPYC mode topology functions Babu Moger
2019-12-04 0:38 ` [PATCH v3 12/18] numa: Split the numa initialization Babu Moger
2019-12-04 0:38 ` [PATCH v3 13/18] hw/i386: Introduce apicid_from_cpu_idx in PCMachineState Babu Moger
2019-12-04 0:38 ` [PATCH v3 14/18] hw/i386: Introduce topo_ids_from_apicid handler PCMachineState Babu Moger
2019-12-04 0:38 ` [PATCH v3 15/18] hw/i386: Introduce apic_id_from_topo_ids handler in PCMachineState Babu Moger
2019-12-04 0:38 ` [PATCH v3 16/18] hw/i386: Introduce EPYC mode function handlers Babu Moger
2020-01-28 20:04 ` Eduardo Habkost
2020-01-28 21:48 ` Babu Moger
2020-01-29 16:41 ` Eduardo Habkost
2019-12-04 0:38 ` [PATCH v3 17/18] i386: Fix pkg_id offset for epyc mode Babu Moger
2019-12-04 0:39 ` [PATCH v3 18/18] tests: Update the Unit tests Babu Moger
2020-02-03 14:59 ` [PATCH v3 00/18] APIC ID fixes for AMD EPYC CPU models Igor Mammedov
2020-02-03 19:31 ` Babu Moger
2020-02-04 8:02 ` Igor Mammedov
2020-02-04 19:08 ` Babu Moger
2020-02-05 9:38 ` Igor Mammedov
2020-02-05 16:10 ` Babu Moger
2020-02-05 16:56 ` Igor Mammedov
2020-02-05 19:07 ` Babu Moger
2020-02-06 13:08 ` Igor Mammedov
2020-02-06 15:32 ` Babu Moger
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=20200128164607.7611ad5f@redhat.com \
--to=imammedo@redhat.com \
--cc=armbru@redhat.com \
--cc=babu.moger@amd.com \
--cc=ehabkost@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/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;
as well as URLs for NNTP newsgroup(s).