* [Qemu-devel] [PATCH] target-i386: warns users when CPU threads>1 for AMD CPUs
@ 2014-10-21 15:00 Wei Huang
2014-10-21 15:37 ` Eduardo Habkost
2014-10-21 15:47 ` Paolo Bonzini
0 siblings, 2 replies; 3+ messages in thread
From: Wei Huang @ 2014-10-21 15:00 UTC (permalink / raw)
To: qemu-devel; +Cc: wei, pbonzini, afaerber, ehabkost
No AMD CPUs support hyperthreading. When users select threads>1 in
-smp option, QEMU fixes it by adjusting CPUID_0000_0001_EBX and
CPUID_8000_0008_ECX based on inputs (sockets, cores, threads);
so guest VM can boot correctly. However it is still better to gives
users a warning when such case happens.
Signed-off-by: Wei Huang <wei@redhat.com>
---
target-i386/cpu.c | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index e7bf9de..84cbbcd 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2696,6 +2696,10 @@ static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
}
#endif
+
+#define IS_AMD_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_AMD_1 && \
+ (env)->cpuid_vendor2 == CPUID_VENDOR_AMD_2 && \
+ (env)->cpuid_vendor3 == CPUID_VENDOR_AMD_3)
static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
{
CPUState *cs = CPU(dev);
@@ -2703,6 +2707,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
X86CPUClass *xcc = X86_CPU_GET_CLASS(dev);
CPUX86State *env = &cpu->env;
Error *local_err = NULL;
+ static bool ht_warned;
if (env->features[FEAT_7_0_EBX] && env->cpuid_level < 7) {
env->cpuid_level = 7;
@@ -2711,9 +2716,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
/* On AMD CPUs, some CPUID[8000_0001].EDX bits must match the bits on
* CPUID[1].EDX.
*/
- if (env->cpuid_vendor1 == CPUID_VENDOR_AMD_1 &&
- env->cpuid_vendor2 == CPUID_VENDOR_AMD_2 &&
- env->cpuid_vendor3 == CPUID_VENDOR_AMD_3) {
+ if (IS_AMD_CPU(env)) {
env->features[FEAT_8000_0001_EDX] &= ~CPUID_EXT2_AMD_ALIASES;
env->features[FEAT_8000_0001_EDX] |= (env->features[FEAT_1_EDX]
& CPUID_EXT2_AMD_ALIASES);
@@ -2742,6 +2745,20 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
mce_init(cpu);
qemu_init_vcpu(cs);
+ /* AMD CPU doesn't support hyperthreading. Even though QEMU fixes
+ * this issue by adjusting CPUID_0000_0001_EBX and CPUID_8000_0008_ECX
+ * based on inputs (sockets,cores,threads), it is still better to gives
+ * users a warning.
+ *
+ * NOTE: the following code has to follow qemu_init_vcpu(). Otherwise
+ * cs->nr_threads hasn't be populated yet and the checking is incorrect.
+ */
+ if (IS_AMD_CPU(env) && (cs->nr_threads > 1) && !ht_warned) {
+ error_report("AMD CPU doesn't support hyperthreading. Please configure"
+ " -smp options properly.");
+ ht_warned = true;
+ }
+
x86_cpu_apic_realize(cpu, &local_err);
if (local_err != NULL) {
goto out;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] target-i386: warns users when CPU threads>1 for AMD CPUs
2014-10-21 15:00 [Qemu-devel] [PATCH] target-i386: warns users when CPU threads>1 for AMD CPUs Wei Huang
@ 2014-10-21 15:37 ` Eduardo Habkost
2014-10-21 15:47 ` Paolo Bonzini
1 sibling, 0 replies; 3+ messages in thread
From: Eduardo Habkost @ 2014-10-21 15:37 UTC (permalink / raw)
To: Wei Huang; +Cc: pbonzini, qemu-devel, afaerber
On Tue, Oct 21, 2014 at 11:00:45AM -0400, Wei Huang wrote:
> No AMD CPUs support hyperthreading. When users select threads>1 in
> -smp option, QEMU fixes it by adjusting CPUID_0000_0001_EBX and
> CPUID_8000_0008_ECX based on inputs (sockets, cores, threads);
> so guest VM can boot correctly. However it is still better to gives
> users a warning when such case happens.
>
> Signed-off-by: Wei Huang <wei@redhat.com>
> ---
[...]
> @@ -2742,6 +2745,20 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
> mce_init(cpu);
> qemu_init_vcpu(cs);
>
> + /* AMD CPU doesn't support hyperthreading. Even though QEMU fixes
> + * this issue by adjusting CPUID_0000_0001_EBX and CPUID_8000_0008_ECX
> + * based on inputs (sockets,cores,threads), it is still better to gives
> + * users a warning.
> + *
> + * NOTE: the following code has to follow qemu_init_vcpu(). Otherwise
> + * cs->nr_threads hasn't be populated yet and the checking is incorrect.
> + */
> + if (IS_AMD_CPU(env) && (cs->nr_threads > 1) && !ht_warned) {
We set CmpLegacy for all non-Intel CPU vendors (and that's what makes
Linux guests ignore HT). So I believe we should warn if
!IS_INTEL_CPU(env) instead of just when it's AMD.
> + error_report("AMD CPU doesn't support hyperthreading. Please configure"
> + " -smp options properly.");
> + ht_warned = true;
> + }
> +
> x86_cpu_apic_realize(cpu, &local_err);
> if (local_err != NULL) {
> goto out;
> --
> 1.8.3.1
>
--
Eduardo
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] target-i386: warns users when CPU threads>1 for AMD CPUs
2014-10-21 15:00 [Qemu-devel] [PATCH] target-i386: warns users when CPU threads>1 for AMD CPUs Wei Huang
2014-10-21 15:37 ` Eduardo Habkost
@ 2014-10-21 15:47 ` Paolo Bonzini
1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2014-10-21 15:47 UTC (permalink / raw)
To: Wei Huang, qemu-devel; +Cc: afaerber, ehabkost
On 10/21/2014 05:00 PM, Wei Huang wrote:
> No AMD CPUs support hyperthreading. When users select threads>1 in
> -smp option, QEMU fixes it by adjusting CPUID_0000_0001_EBX and
> CPUID_8000_0008_ECX based on inputs (sockets, cores, threads);
> so guest VM can boot correctly. However it is still better to gives
> users a warning when such case happens.
>
> Signed-off-by: Wei Huang <wei@redhat.com>
Tweaked as suggested by Eduardo, and applied.
Paolo
> ---
> target-i386/cpu.c | 23 ++++++++++++++++++++---
> 1 file changed, 20 insertions(+), 3 deletions(-)
>
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index e7bf9de..84cbbcd 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -2696,6 +2696,10 @@ static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
> }
> #endif
>
> +
> +#define IS_AMD_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_AMD_1 && \
> + (env)->cpuid_vendor2 == CPUID_VENDOR_AMD_2 && \
> + (env)->cpuid_vendor3 == CPUID_VENDOR_AMD_3)
> static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
> {
> CPUState *cs = CPU(dev);
> @@ -2703,6 +2707,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
> X86CPUClass *xcc = X86_CPU_GET_CLASS(dev);
> CPUX86State *env = &cpu->env;
> Error *local_err = NULL;
> + static bool ht_warned;
>
> if (env->features[FEAT_7_0_EBX] && env->cpuid_level < 7) {
> env->cpuid_level = 7;
> @@ -2711,9 +2716,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
> /* On AMD CPUs, some CPUID[8000_0001].EDX bits must match the bits on
> * CPUID[1].EDX.
> */
> - if (env->cpuid_vendor1 == CPUID_VENDOR_AMD_1 &&
> - env->cpuid_vendor2 == CPUID_VENDOR_AMD_2 &&
> - env->cpuid_vendor3 == CPUID_VENDOR_AMD_3) {
> + if (IS_AMD_CPU(env)) {
> env->features[FEAT_8000_0001_EDX] &= ~CPUID_EXT2_AMD_ALIASES;
> env->features[FEAT_8000_0001_EDX] |= (env->features[FEAT_1_EDX]
> & CPUID_EXT2_AMD_ALIASES);
> @@ -2742,6 +2745,20 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
> mce_init(cpu);
> qemu_init_vcpu(cs);
>
> + /* AMD CPU doesn't support hyperthreading. Even though QEMU fixes
> + * this issue by adjusting CPUID_0000_0001_EBX and CPUID_8000_0008_ECX
> + * based on inputs (sockets,cores,threads), it is still better to gives
> + * users a warning.
> + *
> + * NOTE: the following code has to follow qemu_init_vcpu(). Otherwise
> + * cs->nr_threads hasn't be populated yet and the checking is incorrect.
> + */
> + if (IS_AMD_CPU(env) && (cs->nr_threads > 1) && !ht_warned) {
> + error_report("AMD CPU doesn't support hyperthreading. Please configure"
> + " -smp options properly.");
> + ht_warned = true;
> + }
> +
> x86_cpu_apic_realize(cpu, &local_err);
> if (local_err != NULL) {
> goto out;
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-10-21 15:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-21 15:00 [Qemu-devel] [PATCH] target-i386: warns users when CPU threads>1 for AMD CPUs Wei Huang
2014-10-21 15:37 ` Eduardo Habkost
2014-10-21 15:47 ` Paolo Bonzini
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.