qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Bharata B Rao <bharata@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: ehabkost@redhat.com, aik@ozlabs.ru,
	Bharata B Rao <bharata@linux.vnet.ibm.com>,
	agraf@suse.de, armbru@redhat.com, pbonzini@redhat.com,
	imammedo@redhat.com, afaerber@suse.de,
	david@gibson.dropbear.id.au
Subject: [Qemu-devel] [RFC PATCH v0 7/8] qmp: Implement query cpu-packages
Date: Mon, 22 Feb 2016 10:31:24 +0530	[thread overview]
Message-ID: <1456117285-22273-8-git-send-email-bharata@linux.vnet.ibm.com> (raw)
In-Reply-To: <1456117285-22273-1-git-send-email-bharata@linux.vnet.ibm.com>

Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
---
 hw/cpu/package.c    | 19 +++++++++++++
 hw/ppc/spapr.c      | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/boards.h |  1 +
 qapi-schema.json    | 48 ++++++++++++++++++++++++++++++++
 4 files changed, 147 insertions(+)

diff --git a/hw/cpu/package.c b/hw/cpu/package.c
index 259dbfa..4ff20fa 100644
--- a/hw/cpu/package.c
+++ b/hw/cpu/package.c
@@ -7,7 +7,26 @@
  * See the COPYING file in the top-level directory.
  */
 #include "hw/cpu/package.h"
+#include "hw/boards.h"
 #include "qom/object_interfaces.h"
+#include "qmp-commands.h"
+#include "qapi/qmp/qerror.h"
+
+/*
+ * QMP: query cpu-pacakges
+ */
+CPUPackageInfoList *qmp_query_cpu_packages(Error **errp)
+{
+    MachineState *ms = MACHINE(qdev_get_machine());
+    MachineClass *mc = MACHINE_GET_CLASS(ms);
+
+    if (!mc->cpu_packages) {
+        error_setg(errp, QERR_UNSUPPORTED);
+        return NULL;
+    }
+
+    return mc->cpu_packages(ms);
+}
 
 Object *cpu_package_create_object(const char *typename, uint32_t index,
                                   Error **errp)
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 0bbbaf8..147b9d1 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -2441,6 +2441,84 @@ static unsigned spapr_cpu_index_to_socket_id(unsigned cpu_index)
     return cpu_index / smp_threads / smp_cores;
 }
 
+static int spapr_cpuinfo_list(Object *obj, void *opaque)
+{
+    MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine());
+    CPUInfoList ***prev = opaque;
+
+    if (object_dynamic_cast(obj, TYPE_CPU)) {
+        CPUInfoList *elem = g_new0(CPUInfoList, 1);
+        CPUInfo *s = g_new0(CPUInfo, 1);
+        CPUState *cpu = CPU(obj);
+        PowerPCCPU *pcpu = POWERPC_CPU(cpu);
+
+        s->arch_id = ppc_get_vcpu_dt_id(pcpu);
+        s->type = g_strdup(object_get_typename(obj));
+        s->thread = cpu->cpu_index;
+        s->has_thread = true;
+        s->core = cpu->cpu_index / smp_threads;
+        s->has_core = true;
+        if (mc->cpu_index_to_socket_id) {
+            s->socket = mc->cpu_index_to_socket_id(cpu->cpu_index);
+        } else {
+            s->socket = cpu->cpu_index / smp_threads / smp_cores;
+        }
+        s->has_socket = true;
+        s->node = cpu->numa_node;
+        s->has_node = true;
+        s->qom_path = object_get_canonical_path(obj);
+
+        elem->value = s;
+        elem->next = NULL;
+        **prev = elem;
+        *prev = &elem->next;
+    }
+    object_child_foreach(obj, spapr_cpuinfo_list, opaque);
+    return 0;
+}
+
+static int spapr_cpu_packageinfo_list(Object *obj, void *opaque)
+{
+    CPUPackageInfoList ***prev = opaque;
+
+    if (object_dynamic_cast(obj, TYPE_CPU_PACKAGE)) {
+        DeviceState *dev = DEVICE(obj);
+        CPUPackageInfoList *elem = g_new0(CPUPackageInfoList, 1);
+        CPUPackageInfo *s = g_new0(CPUPackageInfo, 1);
+        CPUInfoList *cpu_head = NULL;
+        CPUInfoList **cpu_prev = &cpu_head;
+
+        if (dev->id) {
+            s->has_id = true;
+            s->id = g_strdup(dev->id);
+        }
+        s->realized = object_property_get_bool(obj, "realized", NULL);
+        s->nr_cpus = smp_threads;
+        s->qom_path = object_get_canonical_path(obj);
+        s->type = g_strdup(TYPE_SPAPR_CPU_PACKAGE);
+        if (s->realized) {
+            spapr_cpuinfo_list(obj, &cpu_prev);
+        }
+        s->cpus = cpu_head;
+        elem->value = s;
+        elem->next = NULL;
+        **prev = elem;
+        *prev = &elem->next;
+    }
+
+    object_child_foreach(obj, spapr_cpu_packageinfo_list, opaque);
+    return 0;
+}
+
+static CPUPackageInfoList *spapr_cpu_packages(MachineState *machine)
+{
+    CPUPackageInfoList *head = NULL;
+    CPUPackageInfoList **prev = &head;
+
+    spapr_cpu_packageinfo_list(qdev_get_machine(), &prev);
+    return head;
+}
+
 static void spapr_machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -2467,6 +2545,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data)
     mc->has_dynamic_sysbus = true;
     mc->pci_allow_0_address = true;
     mc->get_hotplug_handler = spapr_get_hotpug_handler;
+    mc->cpu_packages = spapr_cpu_packages;
     hc->plug = spapr_machine_device_plug;
     hc->unplug = spapr_machine_device_unplug;
     mc->cpu_index_to_socket_id = spapr_cpu_index_to_socket_id;
diff --git a/include/hw/boards.h b/include/hw/boards.h
index cf95d10..66d8780 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -99,6 +99,7 @@ struct MachineClass {
     HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
                                            DeviceState *dev);
     unsigned (*cpu_index_to_socket_id)(unsigned cpu_index);
+    CPUPackageInfoList *(*cpu_packages)(MachineState *machine);
 };
 
 /**
diff --git a/qapi-schema.json b/qapi-schema.json
index 8d04897..5a0dd80 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4083,3 +4083,51 @@
 ##
 { 'enum': 'ReplayMode',
   'data': [ 'none', 'record', 'play' ] }
+
+##
+# @CPUThreadInfo:
+#
+# Information about CPU Threads
+#
+# Since: 2.6
+##
+
+{ 'struct': 'CPUInfo',
+  'data': { 'arch_id': 'int',
+            'type': 'str',
+            '*thread': 'int',
+            '*core': 'int',
+            '*socket' : 'int',
+            '*node' : 'int',
+            '*qom_path': 'str'
+          }
+}
+
+##
+# @CPUPackageInfo:
+#
+# Information about CPU Packages
+#
+# Since: 2.6
+##
+
+{ 'struct': 'CPUPackageInfo',
+  'data': { '*id': 'str',
+            'type': 'str',
+            'qom_path': 'str',
+            'realized': 'bool',
+            'nr_cpus': 'int',
+            'cpus' : ['CPUInfo']
+          }
+}
+
+##
+# @query-cpu-packages:
+#
+# Returns information for all CPU packages
+#
+# Returns: a list of @CPUPackageInfo
+#
+# Since: 2.6
+##
+{ 'command': 'query-cpu-packages', 'returns': ['CPUPackageInfo'] }
-- 
2.1.0

  parent reply	other threads:[~2016-02-22  5:02 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-22  5:01 [Qemu-devel] [RFC PATCH v0 0/8] cpu-package hotplug Bharata B Rao
2016-02-22  5:01 ` [Qemu-devel] [RFC PATCH v0 1/8] cpu: Store CPU typename in MachineState Bharata B Rao
2016-02-22  8:04   ` David Gibson
2016-02-22  5:01 ` [Qemu-devel] [RFC PATCH v0 2/8] cpu: Don't realize CPU from cpu_generic_init() Bharata B Rao
2016-02-22  5:01 ` [Qemu-devel] [RFC PATCH v0 3/8] cpu: CPU package abstract device Bharata B Rao
2016-02-22  5:01 ` [Qemu-devel] [RFC PATCH v0 4/8] spapr: Introduce CPU core device Bharata B Rao
2016-02-22  6:44   ` Andreas Färber
2016-02-22  7:47     ` David Gibson
2016-02-22 15:58       ` Andreas Färber
2016-02-22 23:24         ` David Gibson
2016-02-22  8:05     ` Bharata B Rao
2016-02-22 15:48       ` Andreas Färber
2016-02-22  5:01 ` [Qemu-devel] [RFC PATCH v0 5/8] spapr: Convert boot CPUs into CPU core device initialization Bharata B Rao
2016-02-22  5:01 ` [Qemu-devel] [RFC PATCH v0 6/8] spapr: CPU hotplug support Bharata B Rao
2016-02-22  5:01 ` Bharata B Rao [this message]
2016-02-22 16:49   ` [Qemu-devel] [RFC PATCH v0 7/8] qmp: Implement query cpu-packages Eric Blake
2016-02-23  8:37     ` Igor Mammedov
2016-02-22  5:01 ` [Qemu-devel] [RFC PATCH v0 8/8] hmp: Implement 'info cpu-slots' Bharata B Rao
2016-02-22  5:10 ` [Qemu-devel] [RFC PATCH v0 0/8] cpu-package hotplug Bharata B Rao
2016-02-22 15:32 ` Andreas Färber
2016-02-22 23:28   ` David Gibson
2016-02-23  6:11   ` Bharata B Rao

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=1456117285-22273-8-git-send-email-bharata@linux.vnet.ibm.com \
    --to=bharata@linux.vnet.ibm.com \
    --cc=afaerber@suse.de \
    --cc=agraf@suse.de \
    --cc=aik@ozlabs.ru \
    --cc=armbru@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=ehabkost@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=pbonzini@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).