Patchwork [13/19] Add a query-target command to QMP

login
register
mail settings
Submitter Daniel P. Berrange
Date June 7, 2010, 2:42 p.m.
Message ID <1275921752-29420-14-git-send-email-berrange@redhat.com>
Download mbox | patch
Permalink /patch/54877/
State New
Headers show

Comments

Daniel P. Berrange - June 7, 2010, 2:42 p.m.
Add a command to QMP to provide information about the QEMU binary
target being emulated.  This replaces the need to guess the architecture
and wordsize based on the 'qemu-system-XXXX' suffix. It also declares
what CPU execution engines are available in the binary (tcg, kvm, xen,
etc)

The data format looks like this

    {
        "arch": "i386",
        "wordsize": 32,
        "engines": [
            {
                "name": "tcg"
            },
            {
                "name": "kvm"
            },
            {
                "name": "xen"
            }
        ]
    }

There is no support for the legacy readline monitor

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 hw/boards.h |    1 +
 monitor.c   |   61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 0 deletions(-)
Paolo Bonzini - June 7, 2010, 3:43 p.m.
On 06/07/2010 04:42 PM, Daniel P. Berrange wrote:
> +#ifdef CONFIG_KVM
> +    qlist_append_obj(engines, qobject_from_jsonf("{ 'name': 'kvm' }"));
> +#endif
> +#ifdef CONFIG_XEN
> +    qlist_append_obj(engines, qobject_from_jsonf("{ 'name': 'xen' }"));
> +#endif

I suggest using kvm_available() and xen_available(), so that any 
cut-and-paste typos do not go undetected in the future.

Paolo

Patch

diff --git a/hw/boards.h b/hw/boards.h
index 2f6003d..d335da2 100644
--- a/hw/boards.h
+++ b/hw/boards.h
@@ -33,6 +33,7 @@  typedef struct QEMUMachine {
 
 int qemu_register_machine(QEMUMachine *m);
 void do_info_machines(Monitor *mon, QObject **data);
+void do_info_target(Monitor *mon, QObject **data);
 
 extern QEMUMachine *current_machine;
 
diff --git a/monitor.c b/monitor.c
index 2c4fb3f..d55b27b 100644
--- a/monitor.c
+++ b/monitor.c
@@ -978,6 +978,59 @@  static void do_info_cpu_stats(Monitor *mon)
 }
 #endif
 
+
+/**
+ * do_info_target()
+ *
+ * Provide basic information about the binary target.
+ * The QDict contains the keys
+ *
+ *  - 'arch': the name of the architecture
+ *  - 'wordsize': the wordsize of the architecture
+ *  - 'engines': a QList showing the modes of CPU execution (tcg, kvm, xen, etc)
+ *
+ * Each entry in the 'engines' QList is a QDict containing
+ * a single key
+ *
+ *  - 'name': name of the CPU execution engine
+ *
+ * Example:
+ *
+ * {
+ *   "arch": "i386",
+ *   "wordsize": 32,
+ *   "engines": [
+ *     {
+ *       "name": "tcg"
+ *     },
+ *     {
+ *       "name": "kvm"
+ *     },
+ *     {
+ *       "name": "xen"
+ *     }
+ *   ]
+ * }
+ * 
+ */
+void do_info_target(Monitor *mon, QObject **data)
+{
+    QList *engines = qlist_new();
+
+    qlist_append_obj(engines, qobject_from_jsonf("{ 'name': 'tcg' }"));
+#ifdef CONFIG_KVM
+    qlist_append_obj(engines, qobject_from_jsonf("{ 'name': 'kvm' }"));
+#endif
+#ifdef CONFIG_XEN
+    qlist_append_obj(engines, qobject_from_jsonf("{ 'name': 'xen' }"));
+#endif
+
+    /* XXX 'engines' isn't a very good name */
+    *data = qobject_from_jsonf("{ 'arch': %s, 'wordsize': %d, 'engines': %p }",
+			       TARGET_ARCH, TARGET_PHYS_ADDR_BITS, engines);
+}
+
+
 /**
  * do_quit(): Quit QEMU execution
  */
@@ -2475,6 +2528,14 @@  static const mon_cmd_t info_cmds[] = {
         .mhandler.info_new = do_info_cpu_types,
     },
     {
+        .name       = "target",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show the target arch capabilities",
+        .user_print = monitor_user_noop,
+        .mhandler.info_new = do_info_target,
+    },
+    {
         .name       = "commands",
         .args_type  = "",
         .params     = "",