Skip to contentSkip to conversation

cpu: Register QOM links at /machine/cpus/<index>

PATCH Andreas Färber 4 participants 6 messages Apr 30, 2015 – May 5, 2015

lore
Share & tools
lore
#0 lore raw

First I did not participate in that discussion, second nack to that self pointer. Please hold off on this until I'm back. Andreas

Quoted 72 lines · Eduardo Habkost

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.

---
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.

Reference to previous discussion:

Date: Thu, 23 Apr 2015 10:17:36 -0300
From: Eduardo Habkost <[email protected]>
Subject: Re: [Qemu-devel] cpu modelling and hotplug (was: [PATCH RFC 0/4] target-i386: PC socket/core/thread modeling, part 1)
Message-ID: <[email protected]>
---
exec.c | 16 ++++++++++++++++
include/qom/cpu.h | 3 +++

2 files changed, 19 insertions(+)
exec.c +16 -0
index ae37b98..8bdfa65 100644
@@ -519,6 +519,20 @@ 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 *cobj = OBJECT(cpu);
+    Object *cpu_container = container_get(OBJECT(current_machine), "/cpus");
+    char *path = g_strdup_printf("%d", cpu->cpu_index);
+
+    cpu->self = cobj;
+    object_property_add_link(cpu_container, path, TYPE_CPU, &cpu->self, NULL,
+                             OBJ_PROP_LINK_UNREF_ON_RELEASE, &error_abort);
+    g_free(path);
+#endif
+}
+
 void cpu_exec_init(CPUArchState *env)
 {
    CPUState *cpu = ENV_GET_CPU(env);
@@ -558,6 +572,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)
include/qom/cpu.h +3 -0
index 39f0f19..c253420 100644
@@ -246,6 +246,9 @@ struct CPUState {
    DeviceState parent_obj;
    /*< public >*/
 
+    /* Needed for the /machine/cpus/<index> link */
+    Object *self;
+
    int nr_cores;
    int nr_threads;
    int numa_node;
Signature · 1 line
2.1.0
#1 lore raw
Quoted 3 lines · Andreas Färber

Review

Quoted 3 lines
(quoted diff) +3 -0
+    cpu->self = cobj;
+    object_property_add_link(cpu_container, path, TYPE_CPU, &cpu->self, NULL,
+                             OBJ_PROP_LINK_UNREF_ON_RELEASE, &error_abort);

Doesn't this leak the CPU object?

I have a patch to add "." and ".." properties. You can use them to add an alias to an object.

Paolo

#2 lore raw
Quoted 12 lines · Paolo Bonzini
Quoted 3 lines · Andreas Färber

Review

Quoted 3 lines
(quoted diff) +3 -0
+    cpu->self = cobj;
+    object_property_add_link(cpu_container, path, TYPE_CPU, &cpu->self, NULL,
+                             OBJ_PROP_LINK_UNREF_ON_RELEASE, &error_abort);

Doesn't this leak the CPU object?

I have a patch to add "." and ".." properties. You can use them to add an alias to an object.

Curious, are we ultimately going for full canonical path navigation by string? Going the other way, I still have application of setting a property of a child object from reference to a parent that might fit in:

http://lists.gnu.org/archive/html/qemu-devel/2014-05/msg03281.html

Regards,
Peter

Quoted 2 lines

Paolo

#3 lore raw
In reply to Paolo Bonzini
Quoted 8 lines · Paolo Bonzini
Quoted 3 lines · Andreas Färber

Review

Quoted 3 lines
(quoted diff) +3 -0
+    cpu->self = cobj;
+    object_property_add_link(cpu_container, path, TYPE_CPU, &cpu->self, NULL,
+                             OBJ_PROP_LINK_UNREF_ON_RELEASE, &error_abort);

Doesn't this leak the CPU object?

I am not sure I follow. CPUs can't be destroyed today because there's no code to remove them from the global cpus list. The day we implement cpu_exec_uninit(), it should undo everything done by cpu_exec_init() including removing the link above and removing the CPU from the global cpus list.

Quoted 3 lines

I have a patch to add "." and ".." properties. You can use them to add an alias to an object.

What's the difference between a link and an alias to an object?

Signature · 1 line
Eduardo
#4 lore raw
Quoted 4 lines · Eduardo Habkost
Quoted 2 lines

I have a patch to add "." and ".." properties. You can use them to add an alias to an object.

What's the difference between a link and an alias to an object?

A (read-only) link adds a reference to the target, an alias doesn't.

Paolo

#5 lore raw
In reply to Andreas Färber
Quoted 2 lines · Andreas Färber

First I did not participate in that discussion, second nack to that self pointer. Please hold off on this until I'm back. Andreas

I suggested it 3 times before. The message mentioned in the patch has pointers to the other 2 discussions.

I wasn't happy with the self pointer, either. I will try to implement a object_property_add_readonly_link() function that doesn't need Object** as argument.

Signature · 1 line
Eduardo