From: Xiaoyao Li <xiaoyao.li@intel.com>
To: Igor Mammedov <imammedo@redhat.com>
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Yanan Wang" <wangyanan55@huawei.com>,
"Zhao Liu" <zhao1.liu@intel.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Cameron Esfahani" <dirty@apple.com>,
"Roman Bolshakov" <rbolshakov@ddn.com>,
"Marcelo Tosatti" <mtosatti@redhat.com>,
qemu-devel@nongnu.org
Subject: Re: [RFC PATCH 3/4] i386: Track cores_per_module in CPUX86State
Date: Thu, 12 Dec 2024 11:30:27 +0800 [thread overview]
Message-ID: <6543614b-e6c0-4b74-a71e-c91fe360b2e0@intel.com> (raw)
In-Reply-To: <20241210174338.0fb05ecf@imammedo.users.ipa.redhat.com>
On 12/11/2024 12:43 AM, Igor Mammedov wrote:
> On Thu, 5 Dec 2024 09:57:15 -0500
> Xiaoyao Li <xiaoyao.li@intel.com> wrote:
>
>> x86 is the only user of CPUState::nr_cores.
>>
>> Define cores_per_module in CPUX86State, which can serve as the
>> substitute of CPUState::nr_cores. After x86 switches to use
>> CPUX86State::cores_per_module, CPUState::nr_cores will lose the only
>> user and QEMU can drop it.
>>
>> Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
>> ---
>> hw/i386/x86-common.c | 2 ++
>> target/i386/cpu.c | 2 +-
>> target/i386/cpu.h | 9 +++++++--
>> 3 files changed, 10 insertions(+), 3 deletions(-)
>>
>> diff --git a/hw/i386/x86-common.c b/hw/i386/x86-common.c
>> index dc031af66217..f7a20c1da30c 100644
>> --- a/hw/i386/x86-common.c
>> +++ b/hw/i386/x86-common.c
>> @@ -271,6 +271,8 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev,
>>
>> init_topo_info(&topo_info, x86ms);
>>
>> + env->nr_cores = ms->smp.cores;
> this doesn't look like the same as in qemu_init_vcpu(),
> which uses machine_topo_get_cores_per_socket()
> Can you clarify the change?
because env->nr_cores has a different meaning vs. cs->nr_cores.
As the below comments of nr_cores in the diff
+ /* Number of cores within one module. */
+ unsigned nr_cores;
it means the number of cores within one module. It uses the similar
convention as nr_dies and nr_modules in struct CPUArchState.
However, CPUState::nr_cores means the number of cores in the package.
yes, we can keep the same meaning of nr_cores as "number of cores in the
package" when define it struct CPUArchState. However, it leads to
inconsistency with nr_dies and nr_modules already there and confuses people.
>> +
>> if (ms->smp.modules > 1) {
>> env->nr_modules = ms->smp.modules;
>> set_bit(CPU_TOPOLOGY_LEVEL_MODULE, env->avail_cpu_topo);
>> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
>> index 3725dbbc4b3f..15b50c44ae79 100644
>> --- a/target/i386/cpu.c
>> +++ b/target/i386/cpu.c
>> @@ -6503,7 +6503,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
>>
>> topo_info.dies_per_pkg = env->nr_dies;
>> topo_info.modules_per_die = env->nr_modules;
>> - topo_info.cores_per_module = cs->nr_cores / env->nr_dies / env->nr_modules;
>> + topo_info.cores_per_module = env->nr_cores;
>> topo_info.threads_per_core = cs->nr_threads;
>>
>> cores_per_pkg = topo_info.cores_per_module * topo_info.modules_per_die *
>> diff --git a/target/i386/cpu.h b/target/i386/cpu.h
>> index 5795a497e567..c37a49a1a02b 100644
>> --- a/target/i386/cpu.h
>> +++ b/target/i386/cpu.h
>> @@ -2051,6 +2051,9 @@ typedef struct CPUArchState {
>> /* Number of modules within one die. */
>> unsigned nr_modules;
>>
>> + /* Number of cores within one module. */
>> + unsigned nr_cores;
>> +
>> /* Bitmap of available CPU topology levels for this CPU. */
>> DECLARE_BITMAP(avail_cpu_topo, CPU_TOPOLOGY_LEVEL__MAX);
>> } CPUX86State;
>> @@ -2393,10 +2396,12 @@ static inline void cpu_x86_load_seg_cache_sipi(X86CPU *cpu,
>> static inline uint64_t cpu_x86_get_msr_core_thread_count(X86CPU *cpu)
>> {
>> CPUState *cs = CPU(cpu);
>> + CPUX86State *env = &cpu->env;
>> uint64_t val;
>> + uint64_t cores_per_package = env->nr_cores * env->nr_modules * env->nr_dies;
>>
>> - val = cs->nr_threads * cs->nr_cores; /* thread count, bits 15..0 */
>> - val |= ((uint32_t)cs->nr_cores << 16); /* core count, bits 31..16 */
>> + val = cs->nr_threads * cores_per_package; /* thread count, bits 15..0 */
>> + val |= (cores_per_package << 16); /* core count, bits 31..16 */
>>
>> return val;
>> }
>
next prev parent reply other threads:[~2024-12-12 3:31 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-05 14:57 [RFC PATCH 0/4] cpu: Drop CPUState::nr_cores Xiaoyao Li
2024-12-05 14:57 ` [RFC PATCH 1/4] i386/topology: Update the comment of x86_apicid_from_topo_ids() Xiaoyao Li
2024-12-11 2:54 ` Zhao Liu
2024-12-12 3:58 ` Xiaoyao Li
2024-12-05 14:57 ` [RFC PATCH 2/4] i386: Extract a common fucntion to setup value of MSR_CORE_THREAD_COUNT Xiaoyao Li
2024-12-05 21:38 ` Philippe Mathieu-Daudé
2024-12-10 16:35 ` Igor Mammedov
2024-12-12 3:22 ` Xiaoyao Li
2024-12-05 14:57 ` [RFC PATCH 3/4] i386: Track cores_per_module in CPUX86State Xiaoyao Li
2024-12-10 16:43 ` Igor Mammedov
2024-12-11 2:50 ` Zhao Liu
2024-12-12 3:37 ` Xiaoyao Li
2024-12-12 3:30 ` Xiaoyao Li [this message]
2024-12-05 14:57 ` [RFC PATCH 4/4] cpu: Remove nr_cores from struct CPUState Xiaoyao Li
2024-12-11 2:56 ` Zhao Liu
2024-12-30 16:11 ` [RFC PATCH 0/4] cpu: Drop CPUState::nr_cores Igor Mammedov
2025-01-07 7:23 ` Xiaoyao Li
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=6543614b-e6c0-4b74-a71e-c91fe360b2e0@intel.com \
--to=xiaoyao.li@intel.com \
--cc=dirty@apple.com \
--cc=imammedo@redhat.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=rbolshakov@ddn.com \
--cc=richard.henderson@linaro.org \
--cc=wangyanan55@huawei.com \
--cc=zhao1.liu@intel.com \
/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.