From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Igor Mammedov" <imammedo@redhat.com>,
"Andreas Färber" <afaerber@suse.de>
Subject: [Qemu-devel] [RFC 6/9] target-i386: Move CPU creation code to model name lookup function
Date: Fri, 28 Dec 2012 18:34:03 -0200 [thread overview]
Message-ID: <1356726846-10637-7-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1356726846-10637-1-git-send-email-ehabkost@redhat.com>
While moving the code, rename the resulting function from
cpu_x86_find_by_name() to x86_cpu_create_from_name().
Note that this adds duplicate object_new() and cpudef_2_x86_cpu() calls.
This is because the "host" and predefined CPU classes will be converted
in separate steps. After both parts are converted to use subclasses, we
can unify the class lookup and object creation code for both cases.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
target-i386/cpu.c | 35 ++++++++++++++++++++++++-----------
1 file changed, 24 insertions(+), 11 deletions(-)
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index b3bd2f5..c824c08 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1211,12 +1211,19 @@ static void cpudef_2_x86_cpu(X86CPU *cpu, x86_def_t *def, Error **errp)
object_property_set_str(OBJECT(cpu), def->model_id, "model-id", errp);
}
-static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *name)
+static X86CPU *x86_cpu_create_from_name(const char *name, Error **errp)
{
+ Error *error = NULL;
+ X86CPU *cpu = NULL;
+ x86_def_t def1, *x86_cpu_def = &def1;
+
+ memset(&def1, 0, sizeof(def1));
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);
#endif
} else {
x86_def_t *def;
@@ -1228,9 +1235,11 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *name)
}
if (!def) {
- return -1;
+ error_setg(&error, "Unable to find CPU definition: %s", name);
+ goto out;
}
+ cpu = X86_CPU(object_new(TYPE_X86_CPU));
memcpy(x86_cpu_def, def, sizeof(*def));
/* sysenter isn't supported on compatibility mode on AMD, syscall
* isn't supported in compatibility mode on Intel.
@@ -1253,9 +1262,19 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *name)
&x86_cpu_def->kvm_features,
&x86_cpu_def->svm_features,
&x86_cpu_def->cpuid_7_0_ebx_features);
+
+ cpudef_2_x86_cpu(cpu, x86_cpu_def, &error);
}
- return 0;
+out:
+ if (error) {
+ error_propagate(errp, error);
+ if (cpu) {
+ object_delete(OBJECT(cpu));
+ }
+ return NULL;
+ }
+ return cpu;
}
/* Set features on X86CPU object based on a provide key,value list */
@@ -1502,14 +1521,11 @@ X86CPU *cpu_x86_create(const char *cpu_model, Error **errp)
{
X86CPU *cpu = NULL;
CPUX86State *env;
- x86_def_t def1, *def = &def1;
QDict *props = NULL;
Error *error = NULL;
char *name, *features;
gchar **model_pieces;
- memset(def, 0, sizeof(*def));
-
model_pieces = g_strsplit(cpu_model, ",", 2);
if (!model_pieces[0]) {
error_setg(&error, "Invalid/empty CPU model name");
@@ -1518,17 +1534,14 @@ X86CPU *cpu_x86_create(const char *cpu_model, Error **errp)
name = model_pieces[0];
features = model_pieces[1];
- if (cpu_x86_find_by_name(def, name) < 0) {
- error_setg(&error, "Unable to find CPU definition: %s", name);
+ cpu = x86_cpu_create_from_name(name, &error);
+ if (error) {
goto out;
}
- cpu = X86_CPU(object_new(TYPE_X86_CPU));
env = &cpu->env;
env->cpu_model_str = cpu_model;
- cpudef_2_x86_cpu(cpu, def, &error);
-
if (cpu_x86_parse_featurestr(cpu, features, &props) < 0) {
error_setg(&error, "Invalid cpu_model string format: %s", cpu_model);
goto out;
--
1.7.11.7
next prev parent reply other threads:[~2012-12-28 20:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-28 20:33 [Qemu-devel] [PATCH 0/9] x86 CPU subclasses Eduardo Habkost
2012-12-28 20:33 ` [Qemu-devel] [PATCH 1/9] target-i386: Move CPU object creation to cpu.c Eduardo Habkost
2012-12-28 20:33 ` [Qemu-devel] [PATCH 2/9] target-i386: Make cpu_x86_create() get Error argument Eduardo Habkost
2012-12-28 20:34 ` [Qemu-devel] [PATCH 3/9] target-i386: Simplify cpu_x86_find_by_name() logic Eduardo Habkost
2012-12-28 20:34 ` [Qemu-devel] [RFC 4/9] target-i386: Set feature string parsing results directly on CPU object Eduardo Habkost
2012-12-28 20:34 ` [Qemu-devel] [RFC 5/9] target-i386: Move kvm_features/hypervisor initialization to cpu_x86_find_by_name() Eduardo Habkost
2012-12-28 20:34 ` Eduardo Habkost [this message]
2012-12-28 20:34 ` [Qemu-devel] [RFC 7/9] target-i386: CPU subclass for -cpu "host" Eduardo Habkost
2013-01-02 19:00 ` Igor Mammedov
2013-01-02 20:07 ` Igor Mammedov
2013-01-02 20:20 ` Eduardo Habkost
2013-01-02 20:16 ` Eduardo Habkost
2012-12-28 20:34 ` [Qemu-devel] [RFC 8/9] target-i386: CPU subclasses for predefined CPU models Eduardo Habkost
2012-12-28 20:34 ` [Qemu-devel] [RFC 9/9] target-i386: Unify CPU object creation on x86_cpu_create_from_name() Eduardo Habkost
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=1356726846-10637-7-git-send-email-ehabkost@redhat.com \
--to=ehabkost@redhat.com \
--cc=afaerber@suse.de \
--cc=imammedo@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 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).