aboutsummaryrefslogtreecommitdiff
path: root/qom
diff options
context:
space:
mode:
authorIgor Mammedov <imammedo@redhat.com>2017-09-13 18:04:53 +0200
committerEduardo Habkost <ehabkost@redhat.com>2017-09-19 09:09:32 -0300
commit3c72234c98004a01d79a24f78b07053cfebd0f22 (patch)
tree54232f14c31d8d8f83f9bb384ecf337ce1a19068 /qom
parent11ae6ed8affdd131e735bac39b21e7d3cde66f7b (diff)
downloadqemu-3c72234c98004a01d79a24f78b07053cfebd0f22.zip
qemu-3c72234c98004a01d79a24f78b07053cfebd0f22.tar.gz
qemu-3c72234c98004a01d79a24f78b07053cfebd0f22.tar.bz2
qom: cpus: split cpu_generic_init() on feature parsing and cpu creation parts
it would allow to reuse feature parsing part in various machines that have CPU features instead of re-implementing the same feature parsing each time. Signed-off-by: Igor Mammedov <imammedo@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-Id: <1505318697-77161-2-git-send-email-imammedo@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Diffstat (limited to 'qom')
-rw-r--r--qom/cpu.c46
1 files changed, 30 insertions, 16 deletions
diff --git a/qom/cpu.c b/qom/cpu.c
index dc5392d..483f26a 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -54,13 +54,26 @@ bool cpu_exists(int64_t id)
return !!cpu_by_arch_id(id);
}
-CPUState *cpu_generic_init(const char *typename, const char *cpu_model)
+CPUState *cpu_create(const char *typename)
+{
+ Error *err = NULL;
+ CPUState *cpu = CPU(object_new(typename));
+ object_property_set_bool(OBJECT(cpu), true, "realized", &err);
+ if (err != NULL) {
+ error_report_err(err);
+ object_unref(OBJECT(cpu));
+ return NULL;
+ }
+ return cpu;
+}
+
+const char *cpu_parse_cpu_model(const char *typename, const char *cpu_model)
{
- CPUState *cpu = NULL;
ObjectClass *oc;
CPUClass *cc;
Error *err = NULL;
gchar **model_pieces;
+ const char *cpu_type;
model_pieces = g_strsplit(cpu_model, ",", 2);
@@ -70,27 +83,28 @@ CPUState *cpu_generic_init(const char *typename, const char *cpu_model)
return NULL;
}
+ cpu_type = object_class_get_name(oc);
cc = CPU_CLASS(oc);
- /* TODO: all callers of cpu_generic_init() need to be converted to
- * call parse_features() only once, before calling cpu_generic_init().
- */
- cc->parse_features(object_class_get_name(oc), model_pieces[1], &err);
+ cc->parse_features(cpu_type, model_pieces[1], &err);
g_strfreev(model_pieces);
if (err != NULL) {
- goto out;
- }
-
- cpu = CPU(object_new(object_class_get_name(oc)));
- object_property_set_bool(OBJECT(cpu), true, "realized", &err);
-
-out:
- if (err != NULL) {
error_report_err(err);
- object_unref(OBJECT(cpu));
return NULL;
}
+ return cpu_type;
+}
- return cpu;
+CPUState *cpu_generic_init(const char *typename, const char *cpu_model)
+{
+ /* TODO: all callers of cpu_generic_init() need to be converted to
+ * call cpu_parse_features() only once, before calling cpu_generic_init().
+ */
+ const char *cpu_type = cpu_parse_cpu_model(typename, cpu_model);
+
+ if (cpu_type) {
+ return cpu_create(cpu_type);
+ }
+ return NULL;
}
bool cpu_paging_enabled(const CPUState *cpu)