[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC 7/9] target-i386: CPU subclass for -cpu "host"
From: |
Eduardo Habkost |
Subject: |
[Qemu-devel] [RFC 7/9] target-i386: CPU subclass for -cpu "host" |
Date: |
Fri, 28 Dec 2012 18:34:04 -0200 |
Note that we are initializing the CPU features inside instance_init (and
not storing any CPU feature information inside the class struct) because
kvm_cpu_fill_host() needs KVM to be initialized, and we can't guarantee
that KVM will be initialized when class_init is called.
Signed-off-by: Eduardo Habkost <address@hidden>
---
target-i386/cpu.c | 45 ++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 42 insertions(+), 3 deletions(-)
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index c824c08..2b6cc3b 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -330,6 +330,14 @@ typedef struct x86_def_t {
#define TCG_SVM_FEATURES 0
#define TCG_7_0_EBX_FEATURES (CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_SMAP)
+
+/* CPU class name definitions: */
+
+#define CPU_CLASS_NAME(name) (name "-" TYPE_X86_CPU)
+
+#define TYPE_X86_HOST_CPU CPU_CLASS_NAME("host")
+
+
/* maintains list of cpu model definitions
*/
static x86_def_t *x86_defs = {NULL};
@@ -1221,9 +1229,7 @@ static X86CPU *x86_cpu_create_from_name(const char *name,
Error **errp)
if (kvm_enabled() && name && strcmp(name, "host") == 0) {
#ifdef CONFIG_KVM
- cpu = X86_CPU(object_new(TYPE_X86_CPU));
- kvm_cpu_fill_host(x86_cpu_def);
- cpudef_2_x86_cpu(cpu, x86_cpu_def, &error);
+ cpu = X86_CPU(object_new(TYPE_X86_HOST_CPU));
#endif
} else {
x86_def_t *def;
@@ -2168,9 +2174,42 @@ static const TypeInfo x86_cpu_type_info = {
.class_init = x86_cpu_common_class_init,
};
+#ifdef CONFIG_KVM
+
+static void x86_host_cpu_initfn(Object *obj)
+{
+ X86CPU *cpu = X86_CPU(obj);
+ Error *err = NULL;
+ x86_def_t cpudef;
+
+ memset(&cpudef, 0, sizeof(cpudef));
+ kvm_cpu_fill_host(&cpudef);
+ cpudef_2_x86_cpu(cpu, &cpudef, &err);
+
+ if (err) {
+ error_report("unexpected cpu init error: %s", error_get_pretty(err));
+ exit(1);
+ }
+}
+
+static const TypeInfo x86_host_cpu_type_info = {
+ .name = TYPE_X86_HOST_CPU,
+ .parent = TYPE_X86_CPU,
+ .instance_size = sizeof(X86CPU),
+ .instance_init = x86_host_cpu_initfn,
+ .abstract = false,
+ .class_size = sizeof(X86CPUClass),
+};
+
+#endif /* CONFIG_KVM */
+
+
static void x86_cpu_register_types(void)
{
type_register_static(&x86_cpu_type_info);
+#ifdef CONFIG_KVM
+ type_register_static(&x86_host_cpu_type_info);
+#endif
}
type_init(x86_cpu_register_types)
--
1.7.11.7
- [Qemu-devel] [PATCH 0/9] x86 CPU subclasses, Eduardo Habkost, 2012/12/28
- [Qemu-devel] [PATCH 3/9] target-i386: Simplify cpu_x86_find_by_name() logic, Eduardo Habkost, 2012/12/28
- [Qemu-devel] [PATCH 1/9] target-i386: Move CPU object creation to cpu.c, Eduardo Habkost, 2012/12/28
- [Qemu-devel] [RFC 9/9] target-i386: Unify CPU object creation on x86_cpu_create_from_name(), Eduardo Habkost, 2012/12/28
- [Qemu-devel] [PATCH 2/9] target-i386: Make cpu_x86_create() get Error argument, Eduardo Habkost, 2012/12/28
- [Qemu-devel] [RFC 7/9] target-i386: CPU subclass for -cpu "host",
Eduardo Habkost <=
- [Qemu-devel] [RFC 4/9] target-i386: Set feature string parsing results directly on CPU object, Eduardo Habkost, 2012/12/28
- [Qemu-devel] [RFC 6/9] target-i386: Move CPU creation code to model name lookup function, Eduardo Habkost, 2012/12/28
- [Qemu-devel] [RFC 5/9] target-i386: Move kvm_features/hypervisor initialization to cpu_x86_find_by_name(), Eduardo Habkost, 2012/12/28
- [Qemu-devel] [RFC 8/9] target-i386: CPU subclasses for predefined CPU models, Eduardo Habkost, 2012/12/28