All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Andreas Färber" <afaerber@suse.de>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Igor Mammedov" <imammedo@redhat.com>,
	kvm@vger.kernel.org, libvir-list@redhat.com,
	"Jiri Denemark" <jdenemar@redhat.com>
Subject: [uq/master PATCH 1/7] target-i386: Eliminate CONFIG_KVM #ifdefs
Date: Thu, 30 Jan 2014 17:48:53 -0200	[thread overview]
Message-ID: <1391111339-6958-2-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1391111339-6958-1-git-send-email-ehabkost@redhat.com>

The compiler is already able to eliminate the kvm_arch_get_supported_cpuid()
calls in kvm_cpu_fill_host() and filter_features_for_kvm(), so we can
eliminate the CONFIG_KVM #ifdefs there.

Also, kvm_cpu_fill_host() and host_cpuid() don't need to check
CONFIG_KVM, as they don't have any KVM-specific function calls.

Tested to build successfully with CONFIG_KVM disabled, using the
following CFLAGS combinations: "-DNDEBUG", "-DNDEBUG -O', "-DNDEBUG
-O0", "-DNDEBUG -O1", "-DNDEBUG -O2".

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v2:
 * Check for __i386__ on host_cpuid() so the code compiles properly
   on non-x86 hosts.
   Suggested-by: Paolo Bonzini <pbonzini@redhat.com>

Change v3:
 * Don't add assert(kvm_enabled()) line, which is not necessary to help
   the compiler (and wouldn't help it if using -DNDEBUG, anyway).
   Reported-by: Richard Henderson <rth@twiddle.net>
 * Commit message update
---
 target-i386/cpu.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 1f30efd..8425212 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -374,7 +374,6 @@ void disable_kvm_pv_eoi(void)
 void host_cpuid(uint32_t function, uint32_t count,
                 uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
 {
-#if defined(CONFIG_KVM)
     uint32_t vec[4];
 
 #ifdef __x86_64__
@@ -382,7 +381,7 @@ void host_cpuid(uint32_t function, uint32_t count,
                  : "=a"(vec[0]), "=b"(vec[1]),
                    "=c"(vec[2]), "=d"(vec[3])
                  : "0"(function), "c"(count) : "cc");
-#else
+#elif defined(__i386__)
     asm volatile("pusha \n\t"
                  "cpuid \n\t"
                  "mov %%eax, 0(%2) \n\t"
@@ -392,6 +391,8 @@ void host_cpuid(uint32_t function, uint32_t count,
                  "popa"
                  : : "a"(function), "c"(count), "S"(vec)
                  : "memory", "cc");
+#else
+    abort();
 #endif
 
     if (eax)
@@ -402,7 +403,6 @@ void host_cpuid(uint32_t function, uint32_t count,
         *ecx = vec[2];
     if (edx)
         *edx = vec[3];
-#endif
 }
 
 #define iswhite(c) ((c) && ((c) <= ' ' || '~' < (c)))
@@ -1119,7 +1119,6 @@ void x86_cpu_compat_set_features(const char *cpu_model, FeatureWord w,
     }
 }
 
-#ifdef CONFIG_KVM
 static int cpu_x86_fill_model_id(char *str)
 {
     uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
@@ -1134,7 +1133,6 @@ static int cpu_x86_fill_model_id(char *str)
     }
     return 0;
 }
-#endif
 
 /* Fill a x86_def_t struct with information about the host CPU, and
  * the CPU features supported by the host hardware + host kernel
@@ -1143,7 +1141,6 @@ static int cpu_x86_fill_model_id(char *str)
  */
 static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def)
 {
-#ifdef CONFIG_KVM
     KVMState *s = kvm_state;
     uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
 
@@ -1173,8 +1170,6 @@ static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def)
             kvm_arch_get_supported_cpuid(s, wi->cpuid_eax, wi->cpuid_ecx,
                                          wi->cpuid_reg);
     }
-
-#endif /* CONFIG_KVM */
 }
 
 static int unavailable_host_feature(FeatureWordInfo *f, uint32_t mask)
@@ -1817,7 +1812,6 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
     return cpu_list;
 }
 
-#ifdef CONFIG_KVM
 static void filter_features_for_kvm(X86CPU *cpu)
 {
     CPUX86State *env = &cpu->env;
@@ -1834,7 +1828,6 @@ static void filter_features_for_kvm(X86CPU *cpu)
         cpu->filtered_features[w] = requested_features & ~env->features[w];
     }
 }
-#endif
 
 static void cpu_x86_register(X86CPU *cpu, const char *name, Error **errp)
 {
@@ -2545,9 +2538,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
                        "Host's CPU doesn't support requested features");
             goto out;
         }
-#ifdef CONFIG_KVM
         filter_features_for_kvm(cpu);
-#endif
     }
 
 #ifndef CONFIG_USER_ONLY
-- 
1.8.4.2


WARNING: multiple messages have this Message-ID (diff)
From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: kvm@vger.kernel.org, libvir-list@redhat.com,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Jiri Denemark" <jdenemar@redhat.com>,
	"Andreas Färber" <afaerber@suse.de>
Subject: [Qemu-devel] [uq/master PATCH 1/7] target-i386: Eliminate CONFIG_KVM #ifdefs
Date: Thu, 30 Jan 2014 17:48:53 -0200	[thread overview]
Message-ID: <1391111339-6958-2-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1391111339-6958-1-git-send-email-ehabkost@redhat.com>

The compiler is already able to eliminate the kvm_arch_get_supported_cpuid()
calls in kvm_cpu_fill_host() and filter_features_for_kvm(), so we can
eliminate the CONFIG_KVM #ifdefs there.

Also, kvm_cpu_fill_host() and host_cpuid() don't need to check
CONFIG_KVM, as they don't have any KVM-specific function calls.

Tested to build successfully with CONFIG_KVM disabled, using the
following CFLAGS combinations: "-DNDEBUG", "-DNDEBUG -O', "-DNDEBUG
-O0", "-DNDEBUG -O1", "-DNDEBUG -O2".

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v2:
 * Check for __i386__ on host_cpuid() so the code compiles properly
   on non-x86 hosts.
   Suggested-by: Paolo Bonzini <pbonzini@redhat.com>

Change v3:
 * Don't add assert(kvm_enabled()) line, which is not necessary to help
   the compiler (and wouldn't help it if using -DNDEBUG, anyway).
   Reported-by: Richard Henderson <rth@twiddle.net>
 * Commit message update
---
 target-i386/cpu.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 1f30efd..8425212 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -374,7 +374,6 @@ void disable_kvm_pv_eoi(void)
 void host_cpuid(uint32_t function, uint32_t count,
                 uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
 {
-#if defined(CONFIG_KVM)
     uint32_t vec[4];
 
 #ifdef __x86_64__
@@ -382,7 +381,7 @@ void host_cpuid(uint32_t function, uint32_t count,
                  : "=a"(vec[0]), "=b"(vec[1]),
                    "=c"(vec[2]), "=d"(vec[3])
                  : "0"(function), "c"(count) : "cc");
-#else
+#elif defined(__i386__)
     asm volatile("pusha \n\t"
                  "cpuid \n\t"
                  "mov %%eax, 0(%2) \n\t"
@@ -392,6 +391,8 @@ void host_cpuid(uint32_t function, uint32_t count,
                  "popa"
                  : : "a"(function), "c"(count), "S"(vec)
                  : "memory", "cc");
+#else
+    abort();
 #endif
 
     if (eax)
@@ -402,7 +403,6 @@ void host_cpuid(uint32_t function, uint32_t count,
         *ecx = vec[2];
     if (edx)
         *edx = vec[3];
-#endif
 }
 
 #define iswhite(c) ((c) && ((c) <= ' ' || '~' < (c)))
@@ -1119,7 +1119,6 @@ void x86_cpu_compat_set_features(const char *cpu_model, FeatureWord w,
     }
 }
 
-#ifdef CONFIG_KVM
 static int cpu_x86_fill_model_id(char *str)
 {
     uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
@@ -1134,7 +1133,6 @@ static int cpu_x86_fill_model_id(char *str)
     }
     return 0;
 }
-#endif
 
 /* Fill a x86_def_t struct with information about the host CPU, and
  * the CPU features supported by the host hardware + host kernel
@@ -1143,7 +1141,6 @@ static int cpu_x86_fill_model_id(char *str)
  */
 static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def)
 {
-#ifdef CONFIG_KVM
     KVMState *s = kvm_state;
     uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
 
@@ -1173,8 +1170,6 @@ static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def)
             kvm_arch_get_supported_cpuid(s, wi->cpuid_eax, wi->cpuid_ecx,
                                          wi->cpuid_reg);
     }
-
-#endif /* CONFIG_KVM */
 }
 
 static int unavailable_host_feature(FeatureWordInfo *f, uint32_t mask)
@@ -1817,7 +1812,6 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
     return cpu_list;
 }
 
-#ifdef CONFIG_KVM
 static void filter_features_for_kvm(X86CPU *cpu)
 {
     CPUX86State *env = &cpu->env;
@@ -1834,7 +1828,6 @@ static void filter_features_for_kvm(X86CPU *cpu)
         cpu->filtered_features[w] = requested_features & ~env->features[w];
     }
 }
-#endif
 
 static void cpu_x86_register(X86CPU *cpu, const char *name, Error **errp)
 {
@@ -2545,9 +2538,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
                        "Host's CPU doesn't support requested features");
             goto out;
         }
-#ifdef CONFIG_KVM
         filter_features_for_kvm(cpu);
-#endif
     }
 
 #ifndef CONFIG_USER_ONLY
-- 
1.8.4.2

  reply	other threads:[~2014-01-30 19:49 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-30 19:48 [uq/master PATCH 0/7] x86 CPU subclasses, take 7 Eduardo Habkost
2014-01-30 19:48 ` [Qemu-devel] " Eduardo Habkost
2014-01-30 19:48 ` Eduardo Habkost [this message]
2014-01-30 19:48   ` [Qemu-devel] [uq/master PATCH 1/7] target-i386: Eliminate CONFIG_KVM #ifdefs Eduardo Habkost
2014-01-31 11:42   ` Paolo Bonzini
2014-01-31 11:42     ` [Qemu-devel] " Paolo Bonzini
2014-01-30 19:48 ` [uq/master PATCH 2/7] target-i386: Don't change x86_def_t struct on cpu_x86_register() Eduardo Habkost
2014-01-30 19:48   ` [Qemu-devel] " Eduardo Habkost
2014-01-31 11:42   ` Paolo Bonzini
2014-01-31 11:42     ` [Qemu-devel] " Paolo Bonzini
2014-01-30 19:48 ` [uq/master PATCH 3/7] target-i386: Move KVM default-vendor hack to instance_init Eduardo Habkost
2014-01-30 19:48   ` [Qemu-devel] " Eduardo Habkost
2014-01-31 11:42   ` Paolo Bonzini
2014-01-31 11:42     ` [Qemu-devel] " Paolo Bonzini
2014-01-30 19:48 ` [uq/master PATCH 4/7] target-i386: Rename cpu_x86_register() to x86_cpu_load_def() Eduardo Habkost
2014-01-30 19:48   ` [Qemu-devel] " Eduardo Habkost
2014-01-31 11:42   ` Paolo Bonzini
2014-01-31 11:42     ` [Qemu-devel] " Paolo Bonzini
2014-02-10  0:03     ` Andreas Färber
2014-01-30 19:48 ` [uq/master PATCH 5/7] target-i386: Call x86_cpu_load_def() earlier Eduardo Habkost
2014-01-30 19:48   ` [Qemu-devel] " Eduardo Habkost
2014-02-10  0:13   ` Andreas Färber
2014-02-10  0:13     ` [Qemu-devel] " Andreas Färber
2014-01-30 19:48 ` [uq/master PATCH 6/7] target-i386: Rename x86_def_t to X86CPUDefinition Eduardo Habkost
2014-01-30 19:48   ` [Qemu-devel] " Eduardo Habkost
2014-01-31 11:42   ` Paolo Bonzini
2014-01-31 11:42     ` [Qemu-devel] " Paolo Bonzini
2014-02-10  0:14     ` Andreas Färber
2014-01-30 19:48 ` [uq/master PATCH 7/7] target-i386: CPU model subclasses Eduardo Habkost
2014-01-30 19:48   ` [Qemu-devel] " Eduardo Habkost
2014-01-31 17:20   ` Eduardo Habkost
2014-01-31 17:20     ` Eduardo Habkost
2014-01-31 18:13   ` [uq/master PATCH 7/7 v8] " Eduardo Habkost
2014-01-31 18:13     ` [Qemu-devel] " Eduardo Habkost
2014-02-10  0:23     ` Andreas Färber
2014-02-10  0:23       ` Andreas Färber
2014-02-10  8:19       ` Eduardo Habkost
2014-02-10  8:19         ` Eduardo Habkost
2014-02-10  8:26         ` Eduardo Habkost
2014-02-10  8:26           ` Eduardo Habkost
2014-02-10 10:21           ` [qom-cpu PATCH 7/7 v9] " Eduardo Habkost
2014-02-10 10:21             ` [Qemu-devel] " Eduardo Habkost
2014-02-10 22:39             ` Andreas Färber
2014-02-10 22:39               ` [Qemu-devel] " Andreas Färber
2014-02-11  8:05               ` Eduardo Habkost
2014-02-11  8:05                 ` [Qemu-devel] " Eduardo Habkost
2014-02-11  8:07               ` Paolo Bonzini
2014-02-11  8:07                 ` [Qemu-devel] " Paolo Bonzini
2014-02-10  9:48       ` [Qemu-devel] [uq/master PATCH 7/7 v8] " Igor Mammedov
2014-02-10  9:48         ` Igor Mammedov
2014-01-30 21:47 ` [uq/master PATCH 0/7] x86 CPU subclasses, take 7 Paolo Bonzini
2014-01-30 21:47   ` [Qemu-devel] " Paolo Bonzini
2014-01-31 11:30   ` Andreas Färber
2014-01-31 11:30     ` [Qemu-devel] " Andreas Färber
2014-01-31 11:42     ` Paolo Bonzini
2014-01-31 11:42       ` [Qemu-devel] " Paolo Bonzini
2014-01-31 12:17       ` Eduardo Habkost
2014-01-31 12:17         ` [Qemu-devel] " Eduardo Habkost
2014-01-31 12:14     ` Eduardo Habkost
2014-01-31 12:14       ` [Qemu-devel] " Eduardo Habkost
2014-01-31 14:36     ` Igor Mammedov
2014-01-31 14:36       ` [Qemu-devel] " Igor Mammedov
2014-01-31 14:48 ` Igor Mammedov
2014-01-31 14:48   ` Igor Mammedov
2014-01-31 14:50   ` Paolo Bonzini
2014-01-31 14:50     ` Paolo Bonzini
2014-01-31 15:17     ` Eduardo Habkost
2014-01-31 15:17       ` Eduardo Habkost
2014-01-31 16:06       ` Igor Mammedov
2014-01-31 16:06         ` Igor Mammedov
2014-01-31 16:42         ` Eduardo Habkost
2014-01-31 16:42           ` Eduardo Habkost
2014-01-31 16:52           ` Paolo Bonzini
2014-01-31 16:52             ` Paolo Bonzini
2014-01-31 18:51             ` Eduardo Habkost
2014-01-31 18:51               ` Eduardo Habkost
2014-01-31 18:56               ` [libvirt] " Eric Blake
2014-01-31 18:56                 ` [Qemu-devel] [libvirt] " Eric Blake
2014-01-31 19:08                 ` [libvirt] [Qemu-devel] " Eduardo Habkost
2014-01-31 19:08                   ` [Qemu-devel] [libvirt] " Eduardo Habkost
2014-01-31 19:18                 ` Igor Mammedov
2014-01-31 19:18                   ` Igor Mammedov
2014-01-31 19:25                   ` Eduardo Habkost
2014-01-31 19:25                     ` Eduardo Habkost
2014-01-31 15:10   ` [Qemu-devel] " Eduardo Habkost
2014-01-31 15:10     ` Eduardo Habkost
2014-01-31 15:11     ` Paolo Bonzini
2014-01-31 15:11       ` Paolo Bonzini

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=1391111339-6958-2-git-send-email-ehabkost@redhat.com \
    --to=ehabkost@redhat.com \
    --cc=afaerber@suse.de \
    --cc=imammedo@redhat.com \
    --cc=jdenemar@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=libvir-list@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.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 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.