diff mbox

[v2,2/2] cpu: Register QOM links at /machine/cpus[<index>]

Message ID 1430489347-13772-3-git-send-email-ehabkost@redhat.com
State New
Headers show

Commit Message

Eduardo Habkost May 1, 2015, 2:09 p.m. UTC
This will provide a predictable path for the CPU objects, and a more
powerful alternative for the query-cpus QMP command, as now every QOM
property on CPU objects can be easily queried.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v1 -> v2:
* Use object_property_add_const_link()
* Use "/machine/cpus[<index>]" instead of "/machine/cpus/<index>"
* Grab reference to object before adding link

Note that this doesn't replace any future topology enumeration
mechanisms we may choose to implement. It just replaces the existing
topology-unaware VCPU enumeration mechanism that is query-cpus.

References to previous discussions:

  Date: Thu, 23 Apr 2015 10:17:36 -0300
  From: Eduardo Habkost <ehabkost@redhat.com>
  Subject: Re: [Qemu-devel] cpu modelling and hotplug (was: [PATCH RFC 0/4] target-i386: PC socket/core/thread modeling, part 1)
  Message-ID: <20150423131736.GA17796@thinpad.lan.raisama.net>

  Date: Tue, 31 Mar 2015 10:16:23 -0300
  From: Eduardo Habkost <ehabkost@redhat.com>
  Subject: Re: [Qemu-devel] [PATCH v4 11/15] target-s390x: New QMP command query-cpu-model
  Message-ID: <20150331131623.GG7031@thinpad.lan.raisama.net>

  Date: Fri, 16 May 2014 12:16:41 -0300
  From: Eduardo Habkost <ehabkost@redhat.com>
  Subject: Re: [Qemu-devel] [RFC 0/5] Allow object-add on X86CPU subclasses, for CPU model probing
  Message-ID: <20140516151641.GY3302@otherpad.lan.raisama.net>
---
 exec.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
diff mbox

Patch

diff --git a/exec.c b/exec.c
index ae37b98..a68f0af 100644
--- a/exec.c
+++ b/exec.c
@@ -519,6 +519,19 @@  void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as)
 }
 #endif
 
+static void cpu_add_qom_link(CPUState *cpu)
+{
+#if !defined(CONFIG_USER_ONLY)
+    Object *obj = OBJECT(cpu);
+    char *path = g_strdup_printf("cpus[%d]", cpu->cpu_index);
+
+    object_ref(obj);
+    object_property_add_const_link(OBJECT(current_machine), path, TYPE_CPU,
+                                      obj, 0, &error_abort);
+    g_free(path);
+#endif
+}
+
 void cpu_exec_init(CPUArchState *env)
 {
     CPUState *cpu = ENV_GET_CPU(env);
@@ -558,6 +571,8 @@  void cpu_exec_init(CPUArchState *env)
     if (cc->vmsd != NULL) {
         vmstate_register(NULL, cpu_index, cc->vmsd, cpu);
     }
+
+    cpu_add_qom_link(cpu);
 }
 
 #if defined(CONFIG_USER_ONLY)