* [Qemu-devel] X86 CPU topology broken in qemu ?
[not found] <CAGZKiBpbqMALiRdNRqd0WN6iqNWpnkOcsvVb8AzJAGocuWBrTw@mail.gmail.com>
@ 2011-08-17 5:25 ` Bharata B Rao
2011-08-19 9:51 ` Bharata B Rao
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Bharata B Rao @ 2011-08-17 5:25 UTC (permalink / raw)
To: qemu-devel
Hi,
I see that x86 CPU topology inside VM is not showing up as specified.
With some debugging, I found out that the root cause for this: qemu is
not enumerating the apic ids correctly for vcpus. I made the below
hackish change to get it working. Has anybody else seen this problem
? This patch is on qemu-kvm-0.14.1. Using 2.6.39 for guest.
***************************
Fix apic id enumeration
apic id returned to guest kernel in ebx for cpuid(function=1) depends on
CPUX86State->cpuid_apic_id which gets populated after the cpuid information
is cached in the host kernel.
Fix this by setting cpuid_apic_id before cpuid information is passed to
the host kernel.
Signed-off-by: Bharata B Rao <bharata.rao@gmail.com>
---
hw/pc.c | 4 +---
target-i386/kvm.c | 3 +++
2 files changed, 4 insertions(+), 3 deletions(-)
Index: qemu-kvm-0.14.1/hw/pc.c
===================================================================
--- qemu-kvm-0.14.1.orig/hw/pc.c
+++ qemu-kvm-0.14.1/hw/pc.c
@@ -930,10 +930,8 @@ CPUState *pc_new_cpu(const char *cpu_mod
fprintf(stderr, "Unable to find x86 CPU definition\n");
exit(1);
}
- if ((env->cpuid_features & CPUID_APIC) || smp_cpus > 1) {
- env->cpuid_apic_id = env->cpu_index;
+ if ((env->cpuid_features & CPUID_APIC) || smp_cpus > 1)
env->apic_state = apic_init(env, env->cpuid_apic_id);
- }
qemu_register_reset(pc_cpu_reset, env);
pc_cpu_reset(env);
return env;
Index: qemu-kvm-0.14.1/target-i386/kvm.c
===================================================================
--- qemu-kvm-0.14.1.orig/target-i386/kvm.c
+++ qemu-kvm-0.14.1/target-i386/kvm.c
@@ -340,6 +340,9 @@ int kvm_arch_init_vcpu(CPUState *env)
cpuid_i = 0;
+ if (env->cpuid_features & CPUID_APIC)
+ env->cpuid_apic_id = env->cpu_index;
+
#ifdef CONFIG_KVM_PARA
/* Paravirtualization CPUIDs */
memcpy(signature, "KVMKVMKVM\0\0\0", 12);
**************************
This is how various fields look like before and after this change with
qemu command line option of "-smp ,sockets=1,cores=4,threads=2"
Before
------
root@sqzy:~# grep "core id" /proc/cpuinfo
core id : 0
core id : 0
core id : 0
core id : 0
core id : 0
core id : 0
core id : 0
core id : 0
After
-----
root@sqzy:~# grep "core id" /proc/cpuinfo
core id : 0
core id : 0
core id : 1
core id : 1
core id : 2
core id : 2
core id : 3
core id : 3
Before
------
root@sqzy:~# grep "cpu cores" /proc/cpuinfo
cpu cores : 1
cpu cores : 1
cpu cores : 1
cpu cores : 1
cpu cores : 1
cpu cores : 1
cpu cores : 1
cpu cores : 1
After
-----
root@sqzy:~# grep "cpu cores" /proc/cpuinfo
cpu cores : 4
cpu cores : 4
cpu cores : 4
cpu cores : 4
cpu cores : 4
cpu cores : 4
cpu cores : 4
cpu cores : 4
Before
------
root@sqzy:~# grep apicid /proc/cpuinfo
apicid : 0
initial apicid : 0
apicid : 0
initial apicid : 0
apicid : 0
initial apicid : 0
apicid : 0
initial apicid : 0
apicid : 0
initial apicid : 0
apicid : 0
initial apicid : 0
apicid : 0
initial apicid : 0
apicid : 0
initial apicid : 0
After
-----
root@sqzy:~# grep apicid /proc/cpuinfo
apicid : 0
initial apicid : 0
apicid : 1
initial apicid : 1
apicid : 2
initial apicid : 2
apicid : 3
initial apicid : 3
apicid : 4
initial apicid : 4
apicid : 5
initial apicid : 5
apicid : 6
initial apicid : 6
apicid : 7
initial apicid : 7
Before
------
root@sqzy:/sys/devices/system/cpu# cat cpu*/topology/core_siblings_list
0-7
0-7
0-7
0-7
0-7
0-7
0-7
0-7
root@sqzy:/sys/devices/system/cpu# cat cpu*/topology/thread_siblings_list
0-7
0-7
0-7
0-7
0-7
0-7
0-7
0-7
After
-----
root@sqzy:/sys/devices/system/cpu# cat cpu*/topology/core_siblings_list
0-7
0-7
0-7
0-7
0-7
0-7
0-7
0-7
root@sqzy:/sys/devices/system/cpu# cat cpu*/topology/thread_siblings_list
0-1
0-1
2-3
2-3
4-5
4-5
6-7
6-7
Regards,
Bharata.
--
http://bharata.sulekha.com/blog/posts.htm, http://raobharata.wordpress.com/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] X86 CPU topology broken in qemu ?
2011-08-17 5:25 ` [Qemu-devel] X86 CPU topology broken in qemu ? Bharata B Rao
@ 2011-08-19 9:51 ` Bharata B Rao
2011-08-25 10:01 ` Avi Kivity
2011-08-25 10:47 ` Jan Kiszka
2 siblings, 0 replies; 6+ messages in thread
From: Bharata B Rao @ 2011-08-19 9:51 UTC (permalink / raw)
To: qemu-devel; +Cc: Avi Kivity
On Wed, Aug 17, 2011 at 10:55 AM, Bharata B Rao <bharata.rao@gmail.com> wrote:
> Hi,
>
> I see that x86 CPU topology inside VM is not showing up as specified.
> With some debugging, I found out that the root cause for this: qemu is
> not enumerating the apic ids correctly for vcpus. I made the below
> hackish change to get it working. Has anybody else seen this problem
> ? This patch is on qemu-kvm-0.14.1. Using 2.6.39 for guest.
>
> ***************************
> Fix apic id enumeration
>
> apic id returned to guest kernel in ebx for cpuid(function=1) depends on
> CPUX86State->cpuid_apic_id which gets populated after the cpuid information
> is cached in the host kernel.
>
> Fix this by setting cpuid_apic_id before cpuid information is passed to
> the host kernel.
Going by the lack of response I assume not many people are using - smp
option with sockets, cores and threads specified explicitly ?
Or is it that I hit a corner case and not using the -smp option
correctly enough ?
Regards,
Bharata.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] X86 CPU topology broken in qemu ?
2011-08-17 5:25 ` [Qemu-devel] X86 CPU topology broken in qemu ? Bharata B Rao
2011-08-19 9:51 ` Bharata B Rao
@ 2011-08-25 10:01 ` Avi Kivity
2011-08-30 5:42 ` Bharata B Rao
2011-08-25 10:47 ` Jan Kiszka
2 siblings, 1 reply; 6+ messages in thread
From: Avi Kivity @ 2011-08-25 10:01 UTC (permalink / raw)
To: Bharata B Rao; +Cc: qemu-devel
> Hi,
>
> I see that x86 CPU topology inside VM is not showing up as specified.
> With some debugging, I found out that the root cause for this: qemu is
> not enumerating the apic ids correctly for vcpus. I made the below
> hackish change to get it working. Has anybody else seen this problem
> ? This patch is on qemu-kvm-0.14.1. Using 2.6.39 for guest.
>
> ***************************
> Fix apic id enumeration
>
> apic id returned to guest kernel in ebx for cpuid(function=1) depends
> on
> CPUX86State->cpuid_apic_id which gets populated after the cpuid
> information
> is cached in the host kernel.
>
> Fix this by setting cpuid_apic_id before cpuid information is passed
> to
> the host kernel.
>
> Index: qemu-kvm-0.14.1/hw/pc.c
> ===================================================================
> --- qemu-kvm-0.14.1.orig/hw/pc.c
> +++ qemu-kvm-0.14.1/hw/pc.c
Please post a patch against qemu.git master branch.
>
> + if (env->cpuid_features & CPUID_APIC)
> + env->cpuid_apic_id = env->cpu_index;
> +
qemu coding style requires braces even around single statements in if () blocks.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] X86 CPU topology broken in qemu ?
2011-08-17 5:25 ` [Qemu-devel] X86 CPU topology broken in qemu ? Bharata B Rao
2011-08-19 9:51 ` Bharata B Rao
2011-08-25 10:01 ` Avi Kivity
@ 2011-08-25 10:47 ` Jan Kiszka
2011-08-30 5:43 ` Bharata B Rao
2 siblings, 1 reply; 6+ messages in thread
From: Jan Kiszka @ 2011-08-25 10:47 UTC (permalink / raw)
To: Bharata B Rao; +Cc: qemu-devel
On 2011-08-17 07:25, Bharata B Rao wrote:
> Hi,
>
> I see that x86 CPU topology inside VM is not showing up as specified.
> With some debugging, I found out that the root cause for this: qemu is
> not enumerating the apic ids correctly for vcpus. I made the below
> hackish change to get it working. Has anybody else seen this problem
> ? This patch is on qemu-kvm-0.14.1. Using 2.6.39 for guest.
>
> ***************************
> Fix apic id enumeration
>
> apic id returned to guest kernel in ebx for cpuid(function=1) depends on
> CPUX86State->cpuid_apic_id which gets populated after the cpuid information
> is cached in the host kernel.
>
> Fix this by setting cpuid_apic_id before cpuid information is passed to
> the host kernel.
>
> Signed-off-by: Bharata B Rao <bharata.rao@gmail.com>
> ---
> hw/pc.c | 4 +---
> target-i386/kvm.c | 3 +++
> 2 files changed, 4 insertions(+), 3 deletions(-)
>
> Index: qemu-kvm-0.14.1/hw/pc.c
> ===================================================================
> --- qemu-kvm-0.14.1.orig/hw/pc.c
> +++ qemu-kvm-0.14.1/hw/pc.c
> @@ -930,10 +930,8 @@ CPUState *pc_new_cpu(const char *cpu_mod
> fprintf(stderr, "Unable to find x86 CPU definition\n");
> exit(1);
> }
> - if ((env->cpuid_features & CPUID_APIC) || smp_cpus > 1) {
> - env->cpuid_apic_id = env->cpu_index;
> + if ((env->cpuid_features & CPUID_APIC) || smp_cpus > 1)
> env->apic_state = apic_init(env, env->cpuid_apic_id);
> - }
> qemu_register_reset(pc_cpu_reset, env);
> pc_cpu_reset(env);
> return env;
> Index: qemu-kvm-0.14.1/target-i386/kvm.c
> ===================================================================
> --- qemu-kvm-0.14.1.orig/target-i386/kvm.c
> +++ qemu-kvm-0.14.1/target-i386/kvm.c
> @@ -340,6 +340,9 @@ int kvm_arch_init_vcpu(CPUState *env)
>
> cpuid_i = 0;
>
> + if (env->cpuid_features & CPUID_APIC)
> + env->cpuid_apic_id = env->cpu_index;
> +
Moving it only here will break TCG mode. Make sure to test both. I guess
it's best to move cpuid_apic_id initialization into cpu_x86_init. And
you need to take care of the external APIC case (i486) as well.
Jan
--
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] X86 CPU topology broken in qemu ?
2011-08-25 10:01 ` Avi Kivity
@ 2011-08-30 5:42 ` Bharata B Rao
0 siblings, 0 replies; 6+ messages in thread
From: Bharata B Rao @ 2011-08-30 5:42 UTC (permalink / raw)
To: Avi Kivity; +Cc: qemu-devel
On Thu, Aug 25, 2011 at 3:31 PM, Avi Kivity <avi@redhat.com> wrote:
>> Hi,
>>
>> I see that x86 CPU topology inside VM is not showing up as specified.
>> With some debugging, I found out that the root cause for this: qemu is
>> not enumerating the apic ids correctly for vcpus. I made the below
>> hackish change to get it working. Has anybody else seen this problem
>> ? This patch is on qemu-kvm-0.14.1. Using 2.6.39 for guest.
>>
>
>> Index: qemu-kvm-0.14.1/hw/pc.c
>> ===================================================================
>> --- qemu-kvm-0.14.1.orig/hw/pc.c
>> +++ qemu-kvm-0.14.1/hw/pc.c
>
> Please post a patch against qemu.git master branch.
Sure I will rebase. The previous version was just a quick and hackish
change, I just wanted pass by the list.
>
>>
>> + if (env->cpuid_features & CPUID_APIC)
>> + env->cpuid_apic_id = env->cpu_index;
>> +
>
> qemu coding style requires braces even around single statements in if () blocks.
Sure.
Thanks,
Bharata.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] X86 CPU topology broken in qemu ?
2011-08-25 10:47 ` Jan Kiszka
@ 2011-08-30 5:43 ` Bharata B Rao
0 siblings, 0 replies; 6+ messages in thread
From: Bharata B Rao @ 2011-08-30 5:43 UTC (permalink / raw)
To: Jan Kiszka; +Cc: qemu-devel
On Thu, Aug 25, 2011 at 4:17 PM, Jan Kiszka <jan.kiszka@siemens.com> wrote:
> On 2011-08-17 07:25, Bharata B Rao wrote:
>> Index: qemu-kvm-0.14.1/target-i386/kvm.c
>> ===================================================================
>> --- qemu-kvm-0.14.1.orig/target-i386/kvm.c
>> +++ qemu-kvm-0.14.1/target-i386/kvm.c
>> @@ -340,6 +340,9 @@ int kvm_arch_init_vcpu(CPUState *env)
>>
>> cpuid_i = 0;
>>
>> + if (env->cpuid_features & CPUID_APIC)
>> + env->cpuid_apic_id = env->cpu_index;
>> +
>
> Moving it only here will break TCG mode. Make sure to test both. I guess
> it's best to move cpuid_apic_id initialization into cpu_x86_init. And
> you need to take care of the external APIC case (i486) as well.
Thanks for the review. The patch was just a quick fix. Let me work on
a proper fix that addresses your comments.
Regards,
Bharata.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-08-30 5:43 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <CAGZKiBpbqMALiRdNRqd0WN6iqNWpnkOcsvVb8AzJAGocuWBrTw@mail.gmail.com>
2011-08-17 5:25 ` [Qemu-devel] X86 CPU topology broken in qemu ? Bharata B Rao
2011-08-19 9:51 ` Bharata B Rao
2011-08-25 10:01 ` Avi Kivity
2011-08-30 5:42 ` Bharata B Rao
2011-08-25 10:47 ` Jan Kiszka
2011-08-30 5:43 ` Bharata B Rao
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).