All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: Eric Blake <eblake@redhat.com>,
	qemu-devel@nongnu.org, Markus Armbruster <armbru@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Marcel Apfelbaum <marcel@redhat.com>,
	Laine Stump <laine@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>,
	David Gibson <david@gibson.dropbear.id.au>,
	Bharata B Rao <bharata@linux.vnet.ibm.com>
Subject: [Qemu-devel] [RFC v4 07/13] qdev: Enumerate CPU slots on query-device-slots
Date: Mon, 14 Aug 2017 18:57:42 -0300	[thread overview]
Message-ID: <20170814215748.5158-8-ehabkost@redhat.com> (raw)
In-Reply-To: <20170814215748.5158-1-ehabkost@redhat.com>

Use machine_query_hotpluggable_cpus() to build the slot list for
CPU devices.

Example output: the following command line:

  $ qemu-system-x86_64 -machine q35,accel=kvm \
    -cpu Haswell -smp 2,maxcpus=4

will generate the following entries:

  {
    "available": false,
    "count": 1,
    "device": "/machine/unattached/device[0]",
    "device-types": [ "Haswell-x86_64-cpu" ],
    "hotpluggable": true,
    "opts": [
      { "option": "socket-id", "values": 0 },
      { "option": "thread-id", "values": 0 },
      { "option": "core-id", "values": 0 }
    ],
    "opts-complete": true
  }
  {
    "available": false,
    "count": 1,
    "device": "/machine/unattached/device[2]",
    "device-types": [ "Haswell-x86_64-cpu" ],
    "hotpluggable": true,
    "opts": [
      { "option": "socket-id", "values": 1 },
      { "option": "thread-id", "values": 0 },
      { "option": "core-id", "values": 0 }
    ],
    "opts-complete": true
  }
  {
    "available": true,
    "count": 2,
    "device-types": [ "Haswell-x86_64-cpu" ],
    "hotpluggable": true,
    "opts": [
      { "option": "socket-id", "values": [ [ 2, 3 ] ] },
      { "option": "thread-id", "values": 0 },
      { "option": "core-id", "values": 0 }
    ],
    "opts-complete": true
  }

Cc: Igor Mammedov <imammedo@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Cc: Bharata B Rao <bharata@linux.vnet.ibm.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 qdev-monitor.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/qdev-monitor.c b/qdev-monitor.c
index edc6e34..7ed41df 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -32,6 +32,8 @@
 #include "migration/misc.h"
 #include "qapi/qobject-output-visitor.h"
 #include "hw/boards.h"
+#include "hw/qdev-slotinfo.h"
+#include "qapi-visit.h"
 
 /*
  * Aliases were a bad idea from the start.  Let's keep them
@@ -668,11 +670,79 @@ static int enumerate_bus(Object *obj, void *opaque)
     return 0;
 }
 
+static void add_option(const char *key, QObject *obj, void *opaque)
+{
+    DeviceSlotInfo *slot = opaque;
+
+    qobject_incref(obj);
+    slot_add_opt(slot, key, obj);
+}
+
+/* Add all key/values in @d to as options to @slot */
+static void qdict_to_slot_props(QDict *d, DeviceSlotInfo *slot)
+{
+    qdict_iter(d, add_option, slot);
+}
+
+static QDict *cpu_instance_props_to_qdict(CpuInstanceProperties *src)
+{
+    QObject *qobj = NULL;
+    Visitor *v = qobject_output_visitor_new(&qobj);
+
+    visit_type_CpuInstanceProperties(v, "unused", &src, &error_abort);
+    visit_complete(v, &qobj);
+    visit_free(v);
+    return qobject_to_qdict(qobj);
+}
+
+static void enumerate_cpu_slots(SlotListState *s)
+{
+    DeviceSlotInfoList *r = NULL;
+    MachineState *ms = MACHINE(qdev_get_machine());
+    MachineClass *mc = MACHINE_GET_CLASS(ms);
+    HotpluggableCPUList *hcl;
+    HotpluggableCPUList *i;
+
+    if (!mc->has_hotpluggable_cpus) {
+        return;
+    }
+
+    hcl = machine_query_hotpluggable_cpus(ms);
+    for (i = hcl; i; i = i->next) {
+        DeviceSlotInfo *slot = g_new0(DeviceSlotInfo, 1);
+        HotpluggableCPU *hc = i->value;
+        QDict *props;
+
+        slot->device_types = g_new0(strList, 1);
+        slot->device_types->value = g_strdup(hc->type);
+        slot->available = !hc->has_qom_path;
+        if (hc->has_qom_path) {
+            slot->has_device = true;
+            slot->device = g_strdup(hc->qom_path);
+        }
+        slot->has_count = true;
+        slot->count = 1;
+        slot->opts_complete = true;
+        /*TODO: should 'hotpluggable' be always true? */
+        slot->hotpluggable = true;
+
+        props = cpu_instance_props_to_qdict(hc->props);
+        qdict_to_slot_props(props, slot);
+        QDECREF(props);
+
+        slot_list_add_slot(&r, slot);
+    }
+    qapi_free_HotpluggableCPUList(hcl);
+
+    append_slots(s, r);
+}
+
 DeviceSlotInfoList *qmp_query_device_slots(Error **errp)
 {
     SlotListState s = { .next = &s.result };
 
     object_child_foreach_recursive(qdev_get_machine(), enumerate_bus, &s);
+    enumerate_cpu_slots(&s);
 
     return slot_list_collapse(s.result);
 }
-- 
2.9.4

  parent reply	other threads:[~2017-08-14 21:59 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-14 21:57 [Qemu-devel] [RFC v4 00/13] qmp: query-device-slots command Eduardo Habkost
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 01/13] qmp: Define " Eduardo Habkost
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 02/13] qapi: qobject_compare() helper Eduardo Habkost
2017-08-15 16:16   ` Eric Blake
2017-08-15 17:59     ` Eduardo Habkost
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 03/13] qdev: Add BusClass::device_type field Eduardo Habkost
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 04/13] qdev: Slot info helpers Eduardo Habkost
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 05/13] query-device-slots: Collapse similar entries Eduardo Habkost
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 06/13] qdev core: generic enumerate_slots implementation Eduardo Habkost
2017-08-14 21:57 ` Eduardo Habkost [this message]
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 08/13] ide: " Eduardo Habkost
2017-08-16 21:46   ` John Snow
2017-08-17  4:54     ` Markus Armbruster
2017-08-17 18:40       ` John Snow
2017-08-18 16:57     ` Eduardo Habkost
2017-08-21 21:46       ` John Snow
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 09/13] pci: pci_bus_has_pcie_upstream_port() function Eduardo Habkost
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 10/13] pci: device-number & function properties Eduardo Habkost
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 11/13] pci: enumerate_slots implementation Eduardo Habkost
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 12/13] usb: " Eduardo Habkost
2017-08-21 11:44   ` Gerd Hoffmann
2017-08-23 17:17     ` Eduardo Habkost
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 13/13] tests: Experimental query-device-slots test code Eduardo Habkost
2017-08-14 22:37 ` [Qemu-devel] [libvirt] [RFC v4 00/13] qmp: query-device-slots command no-reply
2017-08-15 18:57 ` [Qemu-devel] " Eric Blake
2017-08-15 19:44   ` 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=20170814215748.5158-8-ehabkost@redhat.com \
    --to=ehabkost@redhat.com \
    --cc=armbru@redhat.com \
    --cc=bharata@linux.vnet.ibm.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=eblake@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=laine@redhat.com \
    --cc=marcel@redhat.com \
    --cc=mst@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.