From: Glauber Costa <glommer@redhat.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com
Subject: [Qemu-devel] [PATCH 2/4] Factor out common code in filling cpuid code
Date: Thu, 29 Jan 2009 12:19:27 -0500 [thread overview]
Message-ID: <1233249569-16686-3-git-send-email-glommer@redhat.com> (raw)
In-Reply-To: <1233249569-16686-2-git-send-email-glommer@redhat.com>
Use kvm_fill_cpuid to query qemu for cpuid data. There are two exactly equal
instances of this code, and the future introduction of kvm paravirt features
will make it three.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
target-i386/kvm.c | 46 +++++++++++++++++++++++-----------------------
1 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 729568c..64b24db 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -33,22 +33,19 @@
do { } while (0)
#endif
-int kvm_arch_init_vcpu(CPUState *env)
-{
- struct {
+typedef struct KVMCpuid {
struct kvm_cpuid2 cpuid;
struct kvm_cpuid_entry2 entries[100];
- } __attribute__((packed)) cpuid_data;
- uint32_t limit, i, cpuid_i;
- uint32_t eax, ebx, ecx, edx;
+} KVMCpuid;
- cpuid_i = 0;
-
- cpu_x86_cpuid(env, 0, &eax, &ebx, &ecx, &edx);
- limit = eax;
+static void kvm_fill_cpuid(CPUState *env, KVMCpuid *cpuid_data,
+ uint32_t start, uint32_t limit)
+{
+ int i;
+ uint32_t eax, ebx, ecx, edx;
- for (i = 0; i <= limit; i++) {
- struct kvm_cpuid_entry2 *c = &cpuid_data.entries[cpuid_i++];
+ for (i = start; i <= limit; i++) {
+ struct kvm_cpuid_entry2 *c = &cpuid_data->entries[cpuid_data->cpuid.nent++];
cpu_x86_cpuid(env, i, &eax, &ebx, &ecx, &edx);
c->function = i;
@@ -57,22 +54,25 @@ int kvm_arch_init_vcpu(CPUState *env)
c->ecx = ecx;
c->edx = edx;
}
+}
- cpu_x86_cpuid(env, 0x80000000, &eax, &ebx, &ecx, &edx);
+int kvm_arch_init_vcpu(CPUState *env)
+{
+ KVMCpuid cpuid_data;
+ uint32_t limit;
+ uint32_t eax, ebx, ecx, edx;
+
+ cpuid_data.cpuid.nent = 0;
+
+ cpu_x86_cpuid(env, 0, &eax, &ebx, &ecx, &edx);
limit = eax;
- for (i = 0x80000000; i <= limit; i++) {
- struct kvm_cpuid_entry2 *c = &cpuid_data.entries[cpuid_i++];
+ kvm_fill_cpuid(env, &cpuid_data, 0, limit);
- cpu_x86_cpuid(env, i, &eax, &ebx, &ecx, &edx);
- c->function = i;
- c->eax = eax;
- c->ebx = ebx;
- c->ecx = ecx;
- c->edx = edx;
- }
+ cpu_x86_cpuid(env, 0x80000000, &eax, &ebx, &ecx, &edx);
+ limit = eax;
- cpuid_data.cpuid.nent = cpuid_i;
+ kvm_fill_cpuid(env, &cpuid_data, 0x80000000, limit);
return kvm_vcpu_ioctl(env, KVM_SET_CPUID2, &cpuid_data);
}
--
1.5.6.5
next prev parent reply other threads:[~2009-01-29 17:19 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-29 17:19 [Qemu-devel] [PATCH 0/4] Improve cpuid x86 code Glauber Costa
2009-01-29 17:19 ` [Qemu-devel] [PATCH 1/4] convert cpuid registration to KVM_SET_CPUID2 Glauber Costa
2009-01-29 17:19 ` Glauber Costa [this message]
2009-01-29 17:19 ` [Qemu-devel] [PATCH 3/4] mask out forbidden cpuid features with kvm ioctl Glauber Costa
2009-01-29 17:19 ` [Qemu-devel] [PATCH 4/4] kvm pv features PART I Glauber Costa
2009-01-29 19:17 ` Glauber Costa
2009-01-29 20:50 ` [Qemu-devel] Re: [PATCH 3/4] mask out forbidden cpuid features with kvm ioctl Anthony Liguori
2009-01-30 12:37 ` Glauber Costa
2009-02-03 21:25 ` Avi Kivity
2009-02-04 6:26 ` Amit Shah
2009-02-03 21:27 ` Avi Kivity
2009-02-03 21:36 ` Anthony Liguori
2009-01-30 10:15 ` [Qemu-devel] [PATCH 0/4] Improve cpuid x86 code Amit Shah
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=1233249569-16686-3-git-send-email-glommer@redhat.com \
--to=glommer@redhat.com \
--cc=aliguori@us.ibm.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 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).