qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: qemu-devel@nongnu.org
Cc: Eduardo Habkost <ehabkost@redhat.com>,
	Andrew Jones <drjones@redhat.com>,
	Richard Henderson <rth@twiddle.net>
Subject: [Qemu-devel] [PATCH 1/6] qom: cpus: split cpu_generic_init() on feature parsing and cpu creation parts
Date: Mon,  4 Sep 2017 16:00:57 +0200	[thread overview]
Message-ID: <1504533662-198084-2-git-send-email-imammedo@redhat.com> (raw)
In-Reply-To: <1504533662-198084-1-git-send-email-imammedo@redhat.com>

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>
---
 include/qom/cpu.h | 21 +++++++++++++++++++++
 qom/cpu.c         | 46 ++++++++++++++++++++++++++++++----------------
 2 files changed, 51 insertions(+), 16 deletions(-)

diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index b7ac949..a92a7d2 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -633,6 +633,27 @@ void cpu_reset(CPUState *cpu);
 ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model);
 
 /**
+ * cpu_create:
+ * @typename: The CPU type.
+ *
+ * Instantiates a CPU and realizes the CPU.
+ *
+ * Returns: A #CPUState or %NULL if an error occurred.
+ */
+CPUState *cpu_create(const char *typename);
+
+/**
+ * cpu_parse_features:
+ * @typename: The CPU base type or CPU type.
+ * @cpu_model: The model string including optional parameters.
+ *
+ * processes optional parameters and registers them as global properties
+ *
+ * Returns: type of CPU to create or %NULL if an error occurred.
+ */
+const char *cpu_parse_features(const char *typename, const char *cpu_model);
+
+/**
  * cpu_generic_init:
  * @typename: The CPU base type.
  * @cpu_model: The model string including optional parameters.
diff --git a/qom/cpu.c b/qom/cpu.c
index deb8880..d715890 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -53,13 +53,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_features(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);
 
@@ -69,27 +82,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_features(typename, cpu_model);
+
+    if (cpu_type) {
+        return cpu_create(cpu_type);
+    }
+    return NULL;
 }
 
 bool cpu_paging_enabled(const CPUState *cpu)
-- 
2.7.4

  reply	other threads:[~2017-09-04 14:01 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-04 14:00 [Qemu-devel] [PATCH 0/6] generalize parsing of cpu_model (x86/arm) Igor Mammedov
2017-09-04 14:00 ` Igor Mammedov [this message]
2017-09-04 15:30   ` [Qemu-devel] [PATCH 1/6] qom: cpus: split cpu_generic_init() on feature parsing and cpu creation parts Philippe Mathieu-Daudé
2017-09-04 14:00 ` [Qemu-devel] [PATCH 2/6] cpu: make cpu_generic_init() abort QEMU on error Igor Mammedov
2017-09-04 15:15   ` Philippe Mathieu-Daudé
2017-09-11 14:30     ` Igor Mammedov
2017-09-05  5:41   ` Thomas Huth
2017-09-05 11:22     ` Eduardo Habkost
2017-09-11 14:51     ` Igor Mammedov
2017-09-05 20:19   ` Eduardo Habkost
2017-09-11 14:23     ` Igor Mammedov
2017-09-04 14:00 ` [Qemu-devel] [PATCH 3/6] cpu: rename cpu_parse_features() to cpu_parse_cpu_model() Igor Mammedov
2017-09-04 15:03   ` Philippe Mathieu-Daudé
2017-09-04 19:06     ` Igor Mammedov
2017-09-05  5:38       ` Thomas Huth
2017-09-11 15:07         ` Igor Mammedov
2017-09-04 14:01 ` [Qemu-devel] [PATCH 4/6] vl.c: convert cpu_model to cpu type and set of global properties before machine_init() Igor Mammedov
2017-09-04 14:01 ` [Qemu-devel] [PATCH 5/6] pc: use generic cpu_model parsing Igor Mammedov
2017-09-04 15:33   ` Philippe Mathieu-Daudé
2017-09-04 14:01 ` [Qemu-devel] [PATCH 6/6] arm: drop intermadiate cpu_model -> cpu type parsing and use cpu type directly Igor Mammedov
2017-09-05 21:31   ` Eduardo Habkost
2017-09-05 21:47     ` Alistair Francis
2017-09-05 22:12       ` Eduardo Habkost
2017-09-05 22:46         ` Alistair Francis
2017-09-06  0:16           ` Alistair Francis
2017-09-09 20:30           ` Eduardo Habkost
2017-09-09 22:41             ` Peter Maydell
2017-09-09 23:22               ` Eduardo Habkost
2017-09-12 10:22             ` Igor Mammedov
2017-09-12 12:01               ` Eduardo Habkost
2017-09-12 10:53         ` Igor Mammedov
2017-09-12 16:29           ` Alistair Francis
2017-09-12 11:02       ` Igor Mammedov
2017-09-12 12:04         ` Eduardo Habkost
2017-09-12 12:11     ` Igor Mammedov
2017-09-12 12:53       ` Eduardo Habkost
2017-09-12 14:06         ` Igor Mammedov

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=1504533662-198084-2-git-send-email-imammedo@redhat.com \
    --to=imammedo@redhat.com \
    --cc=drjones@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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).