Skip to contentSkip to conversation

hostmem-ram: use whole path for region name with >= 3.1

PATCH In review Marc-André Lureau 5 participants 29 messages Sep 12, 2018 – Nov 1, 2018 Arm STM32

lore
Share & tools
lore
#0 lore raw

cover hostmem-ram: use whole path for region name with >= 3.1

Hi,

The migration code expects the RAM block name to match between the source and destination. However the backend type may change, so it is possible (so far) to migrate from a hostmem-file to a hostmem-memfd for example.

However, hostmem backends use inconsistent RAM naming, which can cause a name mismatch. hostmem-file and hostmem-memfd use the whole object path as memory name, while -ram use only the "component" (or basename) of the path.

This series adds global/compat property support for objects others than TYPE_DEVICE (only TYPE_USER_CREATABLE for now), and a new compat property "x-component-name" to hostmem-ram. Machines >= 3.1 will use the whole path for the -ram memory name (like -file and -memfd).

Marc-André Lureau (9):
qom/user-creatable: add a few helper macros
accel: register global_props like machine globals
qdev: move qdev_prop_register_global_list() to tests qom/globals: move qdev globals to qom
qom/globals: generalize object_property_set_globals() qom/object: set globals when initializing object
tests: add user-creatable test to test-qdev-global-props hw/i386: add pc-i440fx-3.1 & pc-q35-3.1
hostmem-ram: use whole path for memory region name with >= 3.1

 include/hw/compat.h                           |   6 +-
 include/hw/i386/pc.h                          |   5 +-
 include/hw/qdev-core.h                        |  20 ---
 include/hw/qdev-properties.h                  |  34 +---
 include/qom/globals.h                         |  32 ++++
 include/qom/object_interfaces.h               |   4 +
 accel/accel.c                                 |   9 +-
 backends/hostmem-ram.c                        |  47 +++++-
 hw/core/machine.c                             |   2 +-
 hw/core/qdev-properties.c                     |  97 -----------
 hw/core/qdev.c                                |   6 -
 hw/i386/pc_piix.c                             |  15 +-
 hw/i386/pc_q35.c                              |  13 +-
 qom/cpu.c                                     |   2 +-
 qom/globals.c                                 |  81 ++++++++++
 qom/object.c                                  |   6 +-
 qom/object_interfaces.c                       |   9 +-
 target/i386/cpu.c                             |   2 +-
 target/sparc/cpu.c                            |   2 +-
 ...dev-global-props.c => test-global-props.c} | 150 +++++++++++++++---
 vl.c                                          |   8 +-
 qom/Makefile.objs                             |   2 +-
 tests/Makefile.include                        |   4 +-
 23 files changed, 350 insertions(+), 206 deletions(-)
 create mode 100644 include/qom/globals.h
 create mode 100644 qom/globals.c
 rename tests/{test-qdev-global-props.c => test-global-props.c} (71%)
Signature · 1 line
2.19.0.rc1
#1 lore raw

PATCH 1/9 qom/user-creatable: add a few helper macros

Improve a bit code readability.

---
 include/qom/object_interfaces.h | 4 ++++
 qom/object.c                    | 4 ++--
 qom/object_interfaces.c         | 9 +++------
 3 files changed, 9 insertions(+), 8 deletions(-)
include/qom/object_interfaces.h +4 -0
index 4d513fb329..46b0861457 100644
@@ -9,9 +9,13 @@
 #define USER_CREATABLE_CLASS(klass) \
      OBJECT_CLASS_CHECK(UserCreatableClass, (klass), \
                         TYPE_USER_CREATABLE)
+#define IS_USER_CREATABLE_CLASS(klass) \
+    object_class_dynamic_cast(OBJECT_CLASS(oc), TYPE_USER_CREATABLE)
 #define USER_CREATABLE_GET_CLASS(obj) \
      OBJECT_GET_CLASS(UserCreatableClass, (obj), \
                       TYPE_USER_CREATABLE)
+#define IS_USER_CREATABLE(obj) \
+    object_dynamic_cast(OBJECT(obj), TYPE_USER_CREATABLE)
 #define USER_CREATABLE(obj) \
      INTERFACE_CHECK(UserCreatable, (obj), \
                      TYPE_USER_CREATABLE)
qom/object.c +2 -2
index 75d1d48944..0703e8e4ff 100644
@@ -424,7 +424,7 @@ void object_initialize_childv(Object *parentobj, const char *propname,
         goto out;
     }
 
-    if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
+    if (IS_USER_CREATABLE(obj)) {
         user_creatable_complete(obj, &local_err);
         if (local_err) {
             object_unparent(obj);
@@ -605,7 +605,7 @@ Object *object_new_with_propv(const char *typename,
         goto error;
     }
 
-    if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
+    if (IS_USER_CREATABLE(obj)) {
         user_creatable_complete(obj, &local_err);
         if (local_err) {
             object_unparent(obj);
qom/object_interfaces.c +3 -6
index 72b97a8bed..e3084bc04a 100644
@@ -10,18 +10,15 @@
 
 void user_creatable_complete(Object *obj, Error **errp)
 {
-
     UserCreatableClass *ucc;
-    UserCreatable *uc =
-        (UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE);
 
-    if (!uc) {
+    if (!IS_USER_CREATABLE(obj)) {
         return;
     }
 
-    ucc = USER_CREATABLE_GET_CLASS(uc);
+    ucc = USER_CREATABLE_GET_CLASS(obj);
     if (ucc->complete) {
-        ucc->complete(uc, errp);
+        ucc->complete(USER_CREATABLE(obj), errp);
     }
 }
 
Signature · 1 line
2.19.0.rc1
#2 lore raw

Re: [Qemu-devel] [PATCH 1/9] qom/user-creatable: add a few helper macros

Quoted 62 lines · On Wed, 12 Sep 2018 16:55:23 +0400 Marc-André Lureau…

Improve a bit code readability.

---
 include/qom/object_interfaces.h | 4 ++++
 qom/object.c                    | 4 ++--
 qom/object_interfaces.c         | 9 +++------
 3 files changed, 9 insertions(+), 8 deletions(-)
include/qom/object_interfaces.h +4 -0
index 4d513fb329..46b0861457 100644
@@ -9,9 +9,13 @@
 #define USER_CREATABLE_CLASS(klass) \
      OBJECT_CLASS_CHECK(UserCreatableClass, (klass), \
                         TYPE_USER_CREATABLE)
+#define IS_USER_CREATABLE_CLASS(klass) \
+    object_class_dynamic_cast(OBJECT_CLASS(oc), TYPE_USER_CREATABLE)
 #define USER_CREATABLE_GET_CLASS(obj) \
      OBJECT_GET_CLASS(UserCreatableClass, (obj), \
                       TYPE_USER_CREATABLE)
+#define IS_USER_CREATABLE(obj) \
+    object_dynamic_cast(OBJECT(obj), TYPE_USER_CREATABLE)
 #define USER_CREATABLE(obj) \
      INTERFACE_CHECK(UserCreatable, (obj), \
                      TYPE_USER_CREATABLE)
qom/object.c +2 -2
index 75d1d48944..0703e8e4ff 100644
@@ -424,7 +424,7 @@ void object_initialize_childv(Object *parentobj, const char *propname,
         goto out;
     }
 
-    if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
+    if (IS_USER_CREATABLE(obj)) {
         user_creatable_complete(obj, &local_err);
         if (local_err) {
             object_unparent(obj);
@@ -605,7 +605,7 @@ Object *object_new_with_propv(const char *typename,
         goto error;
     }
 
-    if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
+    if (IS_USER_CREATABLE(obj)) {
         user_creatable_complete(obj, &local_err);
         if (local_err) {
             object_unparent(obj);
qom/object_interfaces.c +0 -3
index 72b97a8bed..e3084bc04a 100644
@@ -10,18 +10,15 @@
 
 void user_creatable_complete(Object *obj, Error **errp)
 {
-
     UserCreatableClass *ucc;
-    UserCreatable *uc =
-        (UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE);
 

qom/object_interfaces.c line 21

Quoted 10 lines
qom/object_interfaces.c +3 -3
-    if (!uc) {
+    if (!IS_USER_CREATABLE(obj)) {
         return;
     }
 
-    ucc = USER_CREATABLE_GET_CLASS(uc);
+    ucc = USER_CREATABLE_GET_CLASS(obj);
     if (ucc->complete) {
-        ucc->complete(uc, errp);
+        ucc->complete(USER_CREATABLE(obj), errp);
                         ^^^

even though function becomes more concise,
this will call expensive dynamic cast 2nd time (IS_USER_CREATABLE was the 1st and discarded) so I'm not sure is a good idea to regress startup time for readability.

Quoted 3 lines
qom/object_interfaces.c +0 -0
     }
 }
 
#3 lore raw

Re: [Qemu-devel] [PATCH 1/9] qom/user-creatable: add a few helper macros

Quoted 76 lines · Igor Mammedov
Quoted 62 lines · On Wed, 12 Sep 2018 16:55:23 +0400 Marc-André Lureau…

Improve a bit code readability.

---
 include/qom/object_interfaces.h | 4 ++++
 qom/object.c                    | 4 ++--
 qom/object_interfaces.c         | 9 +++------
 3 files changed, 9 insertions(+), 8 deletions(-)
include/qom/object_interfaces.h +4 -0
index 4d513fb329..46b0861457 100644
@@ -9,9 +9,13 @@
 #define USER_CREATABLE_CLASS(klass) \
      OBJECT_CLASS_CHECK(UserCreatableClass, (klass), \
                         TYPE_USER_CREATABLE)
+#define IS_USER_CREATABLE_CLASS(klass) \
+    object_class_dynamic_cast(OBJECT_CLASS(oc), TYPE_USER_CREATABLE)
 #define USER_CREATABLE_GET_CLASS(obj) \
      OBJECT_GET_CLASS(UserCreatableClass, (obj), \
                       TYPE_USER_CREATABLE)
+#define IS_USER_CREATABLE(obj) \
+    object_dynamic_cast(OBJECT(obj), TYPE_USER_CREATABLE)
 #define USER_CREATABLE(obj) \
      INTERFACE_CHECK(UserCreatable, (obj), \
                      TYPE_USER_CREATABLE)
qom/object.c +2 -2
index 75d1d48944..0703e8e4ff 100644
@@ -424,7 +424,7 @@ void object_initialize_childv(Object *parentobj, const char *propname,
         goto out;
     }
 
-    if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
+    if (IS_USER_CREATABLE(obj)) {
         user_creatable_complete(obj, &local_err);
         if (local_err) {
             object_unparent(obj);
@@ -605,7 +605,7 @@ Object *object_new_with_propv(const char *typename,
         goto error;
     }
 
-    if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
+    if (IS_USER_CREATABLE(obj)) {
         user_creatable_complete(obj, &local_err);
         if (local_err) {
             object_unparent(obj);
qom/object_interfaces.c +0 -3
index 72b97a8bed..e3084bc04a 100644
@@ -10,18 +10,15 @@
 
 void user_creatable_complete(Object *obj, Error **errp)
 {
-
     UserCreatableClass *ucc;
-    UserCreatable *uc =
-        (UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE);
 

qom/object_interfaces.c line 21

Quoted 10 lines
qom/object_interfaces.c +3 -3
-    if (!uc) {
+    if (!IS_USER_CREATABLE(obj)) {
         return;
     }
 
-    ucc = USER_CREATABLE_GET_CLASS(uc);
+    ucc = USER_CREATABLE_GET_CLASS(obj);
     if (ucc->complete) {
-        ucc->complete(uc, errp);
+        ucc->complete(USER_CREATABLE(obj), errp);
                         ^^^
Quoted 3 lines

even though function becomes more concise,
this will call expensive dynamic cast 2nd time (IS_USER_CREATABLE was the 1st and discarded) so I'm not sure is a good idea to regress startup time for readability.

(INTERFACE_CHECK is a nop if CONFIG_QOM_CAST_DEBUG is not enabled, so I don't understand how it would regress startup time.

Signature · 1 line
Eduardo
#4 lore raw

Re: [Qemu-devel] [PATCH 1/9] qom/user-creatable: add a few helper macros

Quoted 81 lines · On Fri, 26 Oct 2018 12:13:21 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 76 lines · Igor Mammedov
Quoted 62 lines · On Wed, 12 Sep 2018 16:55:23 +0400 Marc-André Lureau…

Improve a bit code readability.

---
 include/qom/object_interfaces.h | 4 ++++
 qom/object.c                    | 4 ++--
 qom/object_interfaces.c         | 9 +++------
 3 files changed, 9 insertions(+), 8 deletions(-)
include/qom/object_interfaces.h +4 -0
index 4d513fb329..46b0861457 100644
@@ -9,9 +9,13 @@
 #define USER_CREATABLE_CLASS(klass) \
      OBJECT_CLASS_CHECK(UserCreatableClass, (klass), \
                         TYPE_USER_CREATABLE)
+#define IS_USER_CREATABLE_CLASS(klass) \
+    object_class_dynamic_cast(OBJECT_CLASS(oc), TYPE_USER_CREATABLE)
 #define USER_CREATABLE_GET_CLASS(obj) \
      OBJECT_GET_CLASS(UserCreatableClass, (obj), \
                       TYPE_USER_CREATABLE)
+#define IS_USER_CREATABLE(obj) \
+    object_dynamic_cast(OBJECT(obj), TYPE_USER_CREATABLE)
 #define USER_CREATABLE(obj) \
      INTERFACE_CHECK(UserCreatable, (obj), \
                      TYPE_USER_CREATABLE)
qom/object.c +2 -2
index 75d1d48944..0703e8e4ff 100644
@@ -424,7 +424,7 @@ void object_initialize_childv(Object *parentobj, const char *propname,
         goto out;
     }
 
-    if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
+    if (IS_USER_CREATABLE(obj)) {
         user_creatable_complete(obj, &local_err);
         if (local_err) {
             object_unparent(obj);
@@ -605,7 +605,7 @@ Object *object_new_with_propv(const char *typename,
         goto error;
     }
 
-    if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
+    if (IS_USER_CREATABLE(obj)) {
         user_creatable_complete(obj, &local_err);
         if (local_err) {
             object_unparent(obj);
qom/object_interfaces.c +0 -3
index 72b97a8bed..e3084bc04a 100644
@@ -10,18 +10,15 @@
 
 void user_creatable_complete(Object *obj, Error **errp)
 {
-
     UserCreatableClass *ucc;
-    UserCreatable *uc =
-        (UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE);
 

qom/object_interfaces.c line 21

Quoted 10 lines
qom/object_interfaces.c +3 -3
-    if (!uc) {
+    if (!IS_USER_CREATABLE(obj)) {
         return;
     }
 
-    ucc = USER_CREATABLE_GET_CLASS(uc);
+    ucc = USER_CREATABLE_GET_CLASS(obj);
     if (ucc->complete) {
-        ucc->complete(uc, errp);
+        ucc->complete(USER_CREATABLE(obj), errp);  
                         ^^^
Quoted 3 lines

even though function becomes more concise,
this will call expensive dynamic cast 2nd time (IS_USER_CREATABLE was the 1st and discarded) so I'm not sure is a good idea to regress startup time for readability.

Quoted 2 lines

(INTERFACE_CHECK is a nop if CONFIG_QOM_CAST_DEBUG is not enabled, so I don't understand how it would regress startup time.

Isn't it enabled by default though?
Maybe we should flip default to disabled then cast should be ok and enable it when generic '--debug' is enabled.

#5 lore raw

Re: [Qemu-devel] [PATCH 1/9] qom/user-creatable: add a few helper macros

Quoted 84 lines · Igor Mammedov
Quoted 81 lines · On Fri, 26 Oct 2018 12:13:21 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 79 lines · Igor Mammedov
Quoted 62 lines · On Wed, 12 Sep 2018 16:55:23 +0400 Marc-André Lureau…

Improve a bit code readability.

---
 include/qom/object_interfaces.h | 4 ++++
 qom/object.c                    | 4 ++--
 qom/object_interfaces.c         | 9 +++------
 3 files changed, 9 insertions(+), 8 deletions(-)
include/qom/object_interfaces.h +4 -0
index 4d513fb329..46b0861457 100644
@@ -9,9 +9,13 @@
 #define USER_CREATABLE_CLASS(klass) \
      OBJECT_CLASS_CHECK(UserCreatableClass, (klass), \
                         TYPE_USER_CREATABLE)
+#define IS_USER_CREATABLE_CLASS(klass) \
+    object_class_dynamic_cast(OBJECT_CLASS(oc), TYPE_USER_CREATABLE)
 #define USER_CREATABLE_GET_CLASS(obj) \
      OBJECT_GET_CLASS(UserCreatableClass, (obj), \
                       TYPE_USER_CREATABLE)
+#define IS_USER_CREATABLE(obj) \
+    object_dynamic_cast(OBJECT(obj), TYPE_USER_CREATABLE)
 #define USER_CREATABLE(obj) \
      INTERFACE_CHECK(UserCreatable, (obj), \
                      TYPE_USER_CREATABLE)
qom/object.c +2 -2
index 75d1d48944..0703e8e4ff 100644
@@ -424,7 +424,7 @@ void object_initialize_childv(Object *parentobj, const char *propname,
         goto out;
     }
 
-    if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
+    if (IS_USER_CREATABLE(obj)) {
         user_creatable_complete(obj, &local_err);
         if (local_err) {
             object_unparent(obj);
@@ -605,7 +605,7 @@ Object *object_new_with_propv(const char *typename,
         goto error;
     }
 
-    if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
+    if (IS_USER_CREATABLE(obj)) {
         user_creatable_complete(obj, &local_err);
         if (local_err) {
             object_unparent(obj);
qom/object_interfaces.c +0 -3
index 72b97a8bed..e3084bc04a 100644
@@ -10,18 +10,15 @@
 
 void user_creatable_complete(Object *obj, Error **errp)
 {
-
     UserCreatableClass *ucc;
-    UserCreatable *uc =
-        (UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE);
 

qom/object_interfaces.c line 21

Quoted 10 lines
qom/object_interfaces.c +3 -3
-    if (!uc) {
+    if (!IS_USER_CREATABLE(obj)) {
         return;
     }
 
-    ucc = USER_CREATABLE_GET_CLASS(uc);
+    ucc = USER_CREATABLE_GET_CLASS(obj);
     if (ucc->complete) {
-        ucc->complete(uc, errp);
+        ucc->complete(USER_CREATABLE(obj), errp);  
                         ^^^

even though function becomes more concise,
this will call expensive dynamic cast 2nd time (IS_USER_CREATABLE was the 1st and discarded) so I'm not sure is a good idea to regress startup time for readability.

Quoted 5 lines
Quoted 2 lines

(INTERFACE_CHECK is a nop if CONFIG_QOM_CAST_DEBUG is not enabled, so I don't understand how it would regress startup time.

Isn't it enabled by default though?
Maybe we should flip default to disabled then cast should be ok and enable it when generic '--debug' is enabled.

This is called only once for each -object option. Even if QOM debugging is enabled by default I don't see why it wouldn't be OK to call object_dynamic_cast_assert() here.

Signature · 1 line
Eduardo
#6 lore raw

Re: [Qemu-devel] [PATCH 1/9] qom/user-creatable: add a few helper macros

Hi

Quoted 76 lines · Eduardo Habkost
Quoted 74 lines · Igor Mammedov
Quoted 71 lines · On Fri, 26 Oct 2018 12:13:21 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 70 lines · Igor Mammedov
Quoted 67 lines · On Wed, 12 Sep 2018 16:55:23 +0400 Marc-André Lureau…

Improve a bit code readability.

---
 include/qom/object_interfaces.h | 4 ++++
 qom/object.c                    | 4 ++--
 qom/object_interfaces.c         | 9 +++------
 3 files changed, 9 insertions(+), 8 deletions(-)
include/qom/object_interfaces.h +4 -0
index 4d513fb329..46b0861457 100644
@@ -9,9 +9,13 @@
 #define USER_CREATABLE_CLASS(klass) \
      OBJECT_CLASS_CHECK(UserCreatableClass, (klass), \
                         TYPE_USER_CREATABLE)
+#define IS_USER_CREATABLE_CLASS(klass) \
+    object_class_dynamic_cast(OBJECT_CLASS(oc), TYPE_USER_CREATABLE)
 #define USER_CREATABLE_GET_CLASS(obj) \
      OBJECT_GET_CLASS(UserCreatableClass, (obj), \
                       TYPE_USER_CREATABLE)
+#define IS_USER_CREATABLE(obj) \
+    object_dynamic_cast(OBJECT(obj), TYPE_USER_CREATABLE)
 #define USER_CREATABLE(obj) \
      INTERFACE_CHECK(UserCreatable, (obj), \
                      TYPE_USER_CREATABLE)
qom/object.c +2 -2
index 75d1d48944..0703e8e4ff 100644
@@ -424,7 +424,7 @@ void object_initialize_childv(Object *parentobj, const char *propname,
         goto out;
     }
 
-    if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
+    if (IS_USER_CREATABLE(obj)) {
         user_creatable_complete(obj, &local_err);
         if (local_err) {
             object_unparent(obj);
@@ -605,7 +605,7 @@ Object *object_new_with_propv(const char *typename,
         goto error;
     }
 
-    if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
+    if (IS_USER_CREATABLE(obj)) {
         user_creatable_complete(obj, &local_err);
         if (local_err) {
             object_unparent(obj);
qom/object_interfaces.c +1 -4
index 72b97a8bed..e3084bc04a 100644
@@ -10,18 +10,15 @@
 
 void user_creatable_complete(Object *obj, Error **errp)
 {
-
     UserCreatableClass *ucc;
-    UserCreatable *uc =
-        (UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE);
 
-    if (!uc) {
+    if (!IS_USER_CREATABLE(obj)) {
         return;
     }
 
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

qom/object_interfaces.c line 21

Quoted 5 lines
qom/object_interfaces.c +2 -2
-    ucc = USER_CREATABLE_GET_CLASS(uc);
+    ucc = USER_CREATABLE_GET_CLASS(obj);
     if (ucc->complete) {
-        ucc->complete(uc, errp);
+        ucc->complete(USER_CREATABLE(obj), errp);
                         ^^^

even though function becomes more concise,
this will call expensive dynamic cast 2nd time (IS_USER_CREATABLE was the 1st and discarded) so I'm not sure is a good idea to regress startup time for readability.

I hope it's not measurable, unless we create billions of objects. Do you want some figures?

Quoted 10 lines
Quoted 6 lines
Quoted 3 lines

(INTERFACE_CHECK is a nop if CONFIG_QOM_CAST_DEBUG is not enabled, so I don't understand how it would regress startup time.

Isn't it enabled by default though?
Maybe we should flip default to disabled then cast should be ok and enable it when generic '--debug' is enabled.

This is called only once for each -object option. Even if QOM debugging is enabled by default I don't see why it wouldn't be OK to call object_dynamic_cast_assert() here.

Yes, imho it's very marginal. Thus I would value more readability.

Alternatively, we can consider replacing ucc->complete(USER_CREATABLE(obj), errp); by ucc->complete((UserCreatable*)obj, errp); to get back to the same number of dynamic_cast calls.

#7 lore raw

Re: [Qemu-devel] [PATCH 1/9] qom/user-creatable: add a few helper macros

Quoted 89 lines · On Tue, 30 Oct 2018 13:26:40 +0400 Marc-André Lureau…

Hi

Quoted 76 lines · Eduardo Habkost
Quoted 74 lines · Igor Mammedov
Quoted 71 lines · On Fri, 26 Oct 2018 12:13:21 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 70 lines · Igor Mammedov
Quoted 67 lines · On Wed, 12 Sep 2018 16:55:23 +0400 Marc-André Lureau…

Improve a bit code readability.

---
 include/qom/object_interfaces.h | 4 ++++
 qom/object.c                    | 4 ++--
 qom/object_interfaces.c         | 9 +++------
 3 files changed, 9 insertions(+), 8 deletions(-)
include/qom/object_interfaces.h +4 -0
index 4d513fb329..46b0861457 100644
@@ -9,9 +9,13 @@
 #define USER_CREATABLE_CLASS(klass) \
      OBJECT_CLASS_CHECK(UserCreatableClass, (klass), \
                         TYPE_USER_CREATABLE)
+#define IS_USER_CREATABLE_CLASS(klass) \
+    object_class_dynamic_cast(OBJECT_CLASS(oc), TYPE_USER_CREATABLE)
 #define USER_CREATABLE_GET_CLASS(obj) \
      OBJECT_GET_CLASS(UserCreatableClass, (obj), \
                       TYPE_USER_CREATABLE)
+#define IS_USER_CREATABLE(obj) \
+    object_dynamic_cast(OBJECT(obj), TYPE_USER_CREATABLE)
 #define USER_CREATABLE(obj) \
      INTERFACE_CHECK(UserCreatable, (obj), \
                      TYPE_USER_CREATABLE)
qom/object.c +2 -2
index 75d1d48944..0703e8e4ff 100644
@@ -424,7 +424,7 @@ void object_initialize_childv(Object *parentobj, const char *propname,
         goto out;
     }
 
-    if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
+    if (IS_USER_CREATABLE(obj)) {
         user_creatable_complete(obj, &local_err);
         if (local_err) {
             object_unparent(obj);
@@ -605,7 +605,7 @@ Object *object_new_with_propv(const char *typename,
         goto error;
     }
 
-    if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
+    if (IS_USER_CREATABLE(obj)) {
         user_creatable_complete(obj, &local_err);
         if (local_err) {
             object_unparent(obj);
qom/object_interfaces.c +1 -4
index 72b97a8bed..e3084bc04a 100644
@@ -10,18 +10,15 @@
 
 void user_creatable_complete(Object *obj, Error **errp)
 {
-
     UserCreatableClass *ucc;
-    UserCreatable *uc =
-        (UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE);
 
-    if (!uc) {
+    if (!IS_USER_CREATABLE(obj)) {
         return;
     }
 
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

qom/object_interfaces.c line 21

Quoted 5 lines
qom/object_interfaces.c +2 -2
-    ucc = USER_CREATABLE_GET_CLASS(uc);
+    ucc = USER_CREATABLE_GET_CLASS(obj);
     if (ucc->complete) {
-        ucc->complete(uc, errp);
+        ucc->complete(USER_CREATABLE(obj), errp);  
                         ^^^

even though function becomes more concise,
this will call expensive dynamic cast 2nd time (IS_USER_CREATABLE was the 1st and discarded) so I'm not sure is a good idea to regress startup time for readability.

Quoted 2 lines

I hope it's not measurable, unless we create billions of objects. Do you want some figures?

I recall penalty was big enough for QEMU, that we added qom debug option, in case of -object, the cost could be multiplied by hundreds

Quoted 11 lines
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

(INTERFACE_CHECK is a nop if CONFIG_QOM_CAST_DEBUG is not enabled, so I don't understand how it would regress startup time.

Isn't it enabled by default though?
Maybe we should flip default to disabled then cast should be ok and enable it when generic '--debug' is enabled.

This is called only once for each -object option. Even if QOM debugging is enabled by default I don't see why it wouldn't be OK to call object_dynamic_cast_assert() here.

Yes, imho it's very marginal. Thus I would value more readability.

Probably not marginal for folks who are trying to reduce every tiny bit of start up time.

Considering readablity change here doesn't really make a difference, I'd pick performance. i.e. do cast and then reuse result later.

Quoted 4 lines

Alternatively, we can consider replacing ucc->complete(USER_CREATABLE(obj), errp); by ucc->complete((UserCreatable*)obj, errp); to get back to the same number of dynamic_cast calls.

Unsafe casts (foo*) typically frowned upon but it should be safe since one gets here after IS_USER_CREATABLE check, so I don't really care in this case. But I'd drop user_creatable_complete() hunk, so that original cast result is being reused.

#8 lore raw

Re: [Qemu-devel] [PATCH 1/9] qom/user-creatable: add a few helper macros

Quoted 92 lines · Igor Mammedov
Quoted 89 lines · On Tue, 30 Oct 2018 13:26:40 +0400 Marc-André Lureau…

Hi

Quoted 85 lines · Eduardo Habkost
Quoted 83 lines · Igor Mammedov
Quoted 80 lines · On Fri, 26 Oct 2018 12:13:21 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 79 lines · Igor Mammedov
Quoted 62 lines · On Wed, 12 Sep 2018 16:55:23 +0400 Marc-André Lureau…

Improve a bit code readability.

---
 include/qom/object_interfaces.h | 4 ++++
 qom/object.c                    | 4 ++--
 qom/object_interfaces.c         | 9 +++------
 3 files changed, 9 insertions(+), 8 deletions(-)
include/qom/object_interfaces.h +4 -0
index 4d513fb329..46b0861457 100644
@@ -9,9 +9,13 @@
 #define USER_CREATABLE_CLASS(klass) \
      OBJECT_CLASS_CHECK(UserCreatableClass, (klass), \
                         TYPE_USER_CREATABLE)
+#define IS_USER_CREATABLE_CLASS(klass) \
+    object_class_dynamic_cast(OBJECT_CLASS(oc), TYPE_USER_CREATABLE)
 #define USER_CREATABLE_GET_CLASS(obj) \
      OBJECT_GET_CLASS(UserCreatableClass, (obj), \
                       TYPE_USER_CREATABLE)
+#define IS_USER_CREATABLE(obj) \
+    object_dynamic_cast(OBJECT(obj), TYPE_USER_CREATABLE)
 #define USER_CREATABLE(obj) \
      INTERFACE_CHECK(UserCreatable, (obj), \
                      TYPE_USER_CREATABLE)
qom/object.c +2 -2
index 75d1d48944..0703e8e4ff 100644
@@ -424,7 +424,7 @@ void object_initialize_childv(Object *parentobj, const char *propname,
         goto out;
     }
 
-    if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
+    if (IS_USER_CREATABLE(obj)) {
         user_creatable_complete(obj, &local_err);
         if (local_err) {
             object_unparent(obj);
@@ -605,7 +605,7 @@ Object *object_new_with_propv(const char *typename,
         goto error;
     }
 
-    if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
+    if (IS_USER_CREATABLE(obj)) {
         user_creatable_complete(obj, &local_err);
         if (local_err) {
             object_unparent(obj);
qom/object_interfaces.c +0 -3
index 72b97a8bed..e3084bc04a 100644
@@ -10,18 +10,15 @@
 
 void user_creatable_complete(Object *obj, Error **errp)
 {
-
     UserCreatableClass *ucc;
-    UserCreatable *uc =
-        (UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE);
 

qom/object_interfaces.c line 21

Quoted 10 lines
qom/object_interfaces.c +3 -3
-    if (!uc) {
+    if (!IS_USER_CREATABLE(obj)) {
         return;
     }
 
-    ucc = USER_CREATABLE_GET_CLASS(uc);
+    ucc = USER_CREATABLE_GET_CLASS(obj);
     if (ucc->complete) {
-        ucc->complete(uc, errp);
+        ucc->complete(USER_CREATABLE(obj), errp);  
                         ^^^

even though function becomes more concise,
this will call expensive dynamic cast 2nd time (IS_USER_CREATABLE was the 1st and discarded) so I'm not sure is a good idea to regress startup time for readability.

Quoted 4 lines
Quoted 2 lines

I hope it's not measurable, unless we create billions of objects. Do you want some figures?

I recall penalty was big enough for QEMU, that we added qom debug option, in case of -object, the cost could be multiplied by hundreds

This sounds like premature optimization. Did you measure how many nanoseconds we're saving per -object option?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

(INTERFACE_CHECK is a nop if CONFIG_QOM_CAST_DEBUG is not enabled, so I don't understand how it would regress startup time.

Isn't it enabled by default though?
Maybe we should flip default to disabled then cast should be ok and enable it when generic '--debug' is enabled.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

This is called only once for each -object option. Even if QOM debugging is enabled by default I don't see why it wouldn't be OK to call object_dynamic_cast_assert() here.

Yes, imho it's very marginal. Thus I would value more readability.

Probably not marginal for folks who are trying to reduce every tiny bit of start up time.

These people should be disabling QOM debugging, then.

Quoted 4 lines

Considering readablity change here doesn't really make a difference, I'd pick performance. i.e. do cast and then reuse result later.

Quoted 8 lines
Quoted 4 lines

Alternatively, we can consider replacing ucc->complete(USER_CREATABLE(obj), errp); by ucc->complete((UserCreatable*)obj, errp); to get back to the same number of dynamic_cast calls.

Unsafe casts (foo*) typically frowned upon but it should be safe since one gets here after IS_USER_CREATABLE check, so I don't really care in this case. But I'd drop user_creatable_complete() hunk, so that original cast result is being reused.

Please don't do that. Readability, safety, and consistency are more important. For the few users where QOM debugging has a measurable performance impact, we already have a mechanism to disable it.

Signature · 1 line
Eduardo
#9 lore raw

Re: [Qemu-devel] [PATCH 1/9] qom/user-creatable: add a few helper macros

Quoted 93 lines · On Tue, 30 Oct 2018 20:07:17 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 92 lines · Igor Mammedov
Quoted 89 lines · On Tue, 30 Oct 2018 13:26:40 +0400 Marc-André Lureau…

Hi

Quoted 85 lines · Eduardo Habkost
Quoted 83 lines · Igor Mammedov
Quoted 80 lines · On Fri, 26 Oct 2018 12:13:21 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 79 lines · Igor Mammedov
Quoted 62 lines · On Wed, 12 Sep 2018 16:55:23 +0400 Marc-André Lureau…

Improve a bit code readability.

---
 include/qom/object_interfaces.h | 4 ++++
 qom/object.c                    | 4 ++--
 qom/object_interfaces.c         | 9 +++------
 3 files changed, 9 insertions(+), 8 deletions(-)
include/qom/object_interfaces.h +4 -0
index 4d513fb329..46b0861457 100644
@@ -9,9 +9,13 @@
 #define USER_CREATABLE_CLASS(klass) \
      OBJECT_CLASS_CHECK(UserCreatableClass, (klass), \
                         TYPE_USER_CREATABLE)
+#define IS_USER_CREATABLE_CLASS(klass) \
+    object_class_dynamic_cast(OBJECT_CLASS(oc), TYPE_USER_CREATABLE)
 #define USER_CREATABLE_GET_CLASS(obj) \
      OBJECT_GET_CLASS(UserCreatableClass, (obj), \
                       TYPE_USER_CREATABLE)
+#define IS_USER_CREATABLE(obj) \
+    object_dynamic_cast(OBJECT(obj), TYPE_USER_CREATABLE)
 #define USER_CREATABLE(obj) \
      INTERFACE_CHECK(UserCreatable, (obj), \
                      TYPE_USER_CREATABLE)
qom/object.c +2 -2
index 75d1d48944..0703e8e4ff 100644
@@ -424,7 +424,7 @@ void object_initialize_childv(Object *parentobj, const char *propname,
         goto out;
     }
 
-    if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
+    if (IS_USER_CREATABLE(obj)) {
         user_creatable_complete(obj, &local_err);
         if (local_err) {
             object_unparent(obj);
@@ -605,7 +605,7 @@ Object *object_new_with_propv(const char *typename,
         goto error;
     }
 
-    if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
+    if (IS_USER_CREATABLE(obj)) {
         user_creatable_complete(obj, &local_err);
         if (local_err) {
             object_unparent(obj);
qom/object_interfaces.c +0 -3
index 72b97a8bed..e3084bc04a 100644
@@ -10,18 +10,15 @@
 
 void user_creatable_complete(Object *obj, Error **errp)
 {
-
     UserCreatableClass *ucc;
-    UserCreatable *uc =
-        (UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE);
 

qom/object_interfaces.c line 21

Quoted 10 lines
qom/object_interfaces.c +3 -3
-    if (!uc) {
+    if (!IS_USER_CREATABLE(obj)) {
         return;
     }
 
-    ucc = USER_CREATABLE_GET_CLASS(uc);
+    ucc = USER_CREATABLE_GET_CLASS(obj);
     if (ucc->complete) {
-        ucc->complete(uc, errp);
+        ucc->complete(USER_CREATABLE(obj), errp);    
                         ^^^

even though function becomes more concise,
this will call expensive dynamic cast 2nd time (IS_USER_CREATABLE was the 1st and discarded) so I'm not sure is a good idea to regress startup time for readability.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

I hope it's not measurable, unless we create billions of objects. Do you want some figures?

I recall penalty was big enough for QEMU, that we added qom debug option, in case of -object, the cost could be multiplied by hundreds

This sounds like premature optimization. Did you measure how many nanoseconds we're saving per -object option?

it's not optimization, it's about not making code worse and using resources reasonably object_dynamic_cast() with IS_USER_CREATABLE().

I'd replace object_dynamic_cast() with IS_FOO() in places where we just test but do not use the result for a better readability. But is we need the result later I'd keep object_dynamic_cast(), it's not much worse but allows us to reuse the result of cast.

Quoted 33 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

(INTERFACE_CHECK is a nop if CONFIG_QOM_CAST_DEBUG is not enabled, so I don't understand how it would regress startup time.

Isn't it enabled by default though?
Maybe we should flip default to disabled then cast should be ok and enable it when generic '--debug' is enabled.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

This is called only once for each -object option. Even if QOM debugging is enabled by default I don't see why it wouldn't be OK to call object_dynamic_cast_assert() here.

Yes, imho it's very marginal. Thus I would value more readability.

Probably not marginal for folks who are trying to reduce every tiny bit of start up time.

These people should be disabling QOM debugging, then.

Quoted 4 lines

Considering readablity change here doesn't really make a difference, I'd pick performance. i.e. do cast and then reuse result later.

Quoted 8 lines
Quoted 4 lines

Alternatively, we can consider replacing ucc->complete(USER_CREATABLE(obj), errp); by ucc->complete((UserCreatable*)obj, errp); to get back to the same number of dynamic_cast calls.

Unsafe casts (foo*) typically frowned upon but it should be safe since one gets here after IS_USER_CREATABLE check, so I don't really care in this case. But I'd drop user_creatable_complete() hunk, so that original cast result is being reused.

Please don't do that. Readability, safety, and consistency are more important. For the few users where QOM debugging has a measurable performance impact, we already have a mechanism to disable it.

#10 lore raw

Re: [Qemu-devel] [PATCH 1/9] qom/user-creatable: add a few helper macros

Quoted 18 lines · Igor Mammedov
Quoted 15 lines · On Tue, 30 Oct 2018 20:07:17 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 14 lines · Igor Mammedov
Quoted 11 lines · On Tue, 30 Oct 2018 13:26:40 +0400 Marc-André Lureau…

Hi

Quoted 8 lines · Eduardo Habkost
Quoted 6 lines · Igor Mammedov
Quoted 3 lines · On Fri, 26 Oct 2018 12:13:21 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 2 lines · Igor Mammedov

On Wed, 12 Sep 2018 16:55:23 +0400
Marc-André Lureau <[email protected]> wrote:

[...]

Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines

void user_creatable_complete(Object *obj, Error **errp) {

(quoted diff) +3 -6
-
     UserCreatableClass *ucc;
-    UserCreatable *uc =
-        (UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE);
 
-    if (!uc) {
+    if (!IS_USER_CREATABLE(obj)) {
         return;
     }
 
-    ucc = USER_CREATABLE_GET_CLASS(uc);
+    ucc = USER_CREATABLE_GET_CLASS(obj);
     if (ucc->complete) {
-        ucc->complete(uc, errp);
+        ucc->complete(USER_CREATABLE(obj), errp);    
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
                         ^^^

even though function becomes more concise,
this will call expensive dynamic cast 2nd time (IS_USER_CREATABLE was the 1st and discarded) so I'm not sure is a good idea to regress startup time for readability.

I hope it's not measurable, unless we create billions of objects. Do you want some figures?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

I recall penalty was big enough for QEMU, that we added qom debug option, in case of -object, the cost could be multiplied by hundreds

This sounds like premature optimization. Did you measure how many nanoseconds we're saving per -object option?

it's not optimization, it's about not making code worse and using resources reasonably object_dynamic_cast() with IS_USER_CREATABLE().

How exactly is the code worse?

Quoted 5 lines

I'd replace object_dynamic_cast() with IS_FOO() in places where we just test but do not use the result for a better readability. But is we need the result later I'd keep object_dynamic_cast(), it's not much worse but allows us to reuse the result of cast.

Readability is orders of magnitude more important to me.

This is not readable:
(UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE)

This is readable:
USER_CREATABLE(obj)

If the overhead of the extra object_dynamic_cast() call is too much, it's already possible to disable QOM cast debugging.

Quoted 1 line

[...]

Signature · 1 line
Eduardo
#11 lore raw

Re: [Qemu-devel] [PATCH 1/9] qom/user-creatable: add a few helper macros

Quoted 47 lines · On Thu, 1 Nov 2018 12:02:03 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 18 lines · Igor Mammedov
Quoted 15 lines · On Tue, 30 Oct 2018 20:07:17 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 14 lines · Igor Mammedov
Quoted 11 lines · On Tue, 30 Oct 2018 13:26:40 +0400 Marc-André Lureau…

Hi

Quoted 8 lines · Eduardo Habkost
Quoted 6 lines · Igor Mammedov
Quoted 3 lines · On Fri, 26 Oct 2018 12:13:21 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 2 lines · Igor Mammedov

On Wed, 12 Sep 2018 16:55:23 +0400
Marc-André Lureau <[email protected]> wrote:

[...]

Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines

void user_creatable_complete(Object *obj, Error **errp) {

(quoted diff) +3 -6
-
     UserCreatableClass *ucc;
-    UserCreatable *uc =
-        (UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE);
 
-    if (!uc) {
+    if (!IS_USER_CREATABLE(obj)) {
         return;
     }
 
-    ucc = USER_CREATABLE_GET_CLASS(uc);
+    ucc = USER_CREATABLE_GET_CLASS(obj);
     if (ucc->complete) {
-        ucc->complete(uc, errp);
+        ucc->complete(USER_CREATABLE(obj), errp);      
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
                         ^^^

even though function becomes more concise,
this will call expensive dynamic cast 2nd time (IS_USER_CREATABLE was the 1st and discarded) so I'm not sure is a good idea to regress startup time for readability.

I hope it's not measurable, unless we create billions of objects. Do you want some figures?

I recall penalty was big enough for QEMU, that we added qom debug option, in case of -object, the cost could be multiplied by hundreds

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

This sounds like premature optimization. Did you measure how many nanoseconds we're saving per -object option?

it's not optimization, it's about not making code worse and using resources reasonably object_dynamic_cast() with IS_USER_CREATABLE().

How exactly is the code worse?

making it slower /doesn't matter how much/ when there is better way to do it.
Anyways the point is moot as Mark rewrote it in another way (better) so this question won't arise.

Quoted 8 lines
Quoted 5 lines

I'd replace object_dynamic_cast() with IS_FOO() in places where we just test but do not use the result for a better readability. But is we need the result later I'd keep object_dynamic_cast(), it's not much worse but allows us to reuse the result of cast.

Readability is orders of magnitude more important to me.

Quoted 8 lines

This is not readable:
(UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE)

This is readable:
USER_CREATABLE(obj)

If the overhead of the extra object_dynamic_cast() call is too much, it's already possible to disable QOM cast debugging.

I'm typically on the side of simplifying code and readability but in this case I have to disagree, out of context ^^^ it might look fine but with full context

uc = (UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE) if(uc)
call(uc)

vs

if(IS_USER_CREATABLE(obj))
// discard above hidden cast result and do it again call(USER_CREATABLE(obj))

the former is not horrible enough to warrant doing senseless discard. So lets agree to disagree :)

Quoted 3 lines
Quoted 2 lines

[...]

#12 lore raw

PATCH 2/9 accel: register global_props like machine globals

In reply to Marc-André Lureau

global_props is only used for Xen xen_compat_props. It's a static array of GlobalProperty, like machine globals in SET_MACHINE_COMPAT(). Let's register the globals the same way, without extra copy allocation.

---
 include/hw/qdev-properties.h | 29 -----------------------------
 accel/accel.c                |  9 ++++++++-
 hw/core/qdev-properties.c    | 21 ---------------------
 3 files changed, 8 insertions(+), 51 deletions(-)
include/hw/qdev-properties.h +0 -29
index 4f60cc88f3..a95f4a73eb 100644
@@ -255,35 +255,6 @@ void qdev_prop_set_globals(DeviceState *dev);
 void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
                                     Property *prop, const char *value);
 
-/**
- * register_compat_prop:
- *
- * Register internal (not user-provided) global property, changing the
- * default value of a given property in a device type.  This can be used
- * for enabling machine-type compatibility or for enabling
- * accelerator-specific defaults in devices.
- *
- * The property values set using this function must be always valid and
- * never report setter errors, as the property will have
- * GlobalProperty::errp set to &error_abort.
- *
- * User-provided global properties should override internal global
- * properties, so callers of this function should ensure that it is
- * called before user-provided global properties are registered.
- *
- * @driver: Device type to be affected
- * @property: Property whose default value is going to be changed
- * @value: New default value for the property
- */
-void register_compat_prop(const char *driver, const char *property,
-                          const char *value);
-/*
- * register_compat_props_array(): using register_compat_prop(), which
- * only registers internal global properties (which has lower priority
- * than user-provided global properties)
- */
-void register_compat_props_array(GlobalProperty *prop);
-
 /**
  * qdev_property_add_static:
  * @dev: Device to add the property to.
accel/accel.c +8 -1
index 966b2d8f53..3da26eb90f 100644
@@ -34,6 +34,7 @@
 #include "qom/object.h"
 #include "qemu/error-report.h"
 #include "qemu/option.h"
+#include "qapi/error.h"
 
 static const TypeInfo accel_type = {
     .name = TYPE_ACCEL,
@@ -121,7 +122,13 @@ void configure_accelerator(MachineState *ms)
 void accel_register_compat_props(AccelState *accel)
 {
     AccelClass *class = ACCEL_GET_CLASS(accel);
-    register_compat_props_array(class->global_props);
+    GlobalProperty *prop = class->global_props;
+
+    for (; prop && prop->driver; prop++) {
+        /* Any compat_props must never cause error */
+        prop->errp = &error_abort;
+        qdev_prop_register_global(prop);
+    }
 }
 
 void accel_setup_post(MachineState *ms)
hw/core/qdev-properties.c +0 -21
index 35072dec1e..ab61d502fd 100644
@@ -1180,27 +1180,6 @@ void qdev_prop_register_global(GlobalProperty *prop)
     global_props = g_list_append(global_props, prop);
 }
 
-void register_compat_prop(const char *driver,
-                          const char *property,
-                          const char *value)
-{
-    GlobalProperty *p = g_new0(GlobalProperty, 1);
-
-    /* Any compat_props must never cause error */
-    p->errp = &error_abort;
-    p->driver = driver;
-    p->property = property;
-    p->value = value;
-    qdev_prop_register_global(p);
-}
-
-void register_compat_props_array(GlobalProperty *prop)
-{
-    for (; prop && prop->driver; prop++) {
-        register_compat_prop(prop->driver, prop->property, prop->value);
-    }
-}
-
 void qdev_prop_register_global_list(GlobalProperty *props)
 {
     int i;
Signature · 1 line
2.19.0.rc1
Reviewed-by on v1 2/9
#13 lore raw

Re: [Qemu-devel] [PATCH 2/9] accel: register global_props like machine globals

Quoted 1 line · On Wed, 12 Sep 2018 16:55:24 +0400 Marc-André Lureau…

global_props is only used for Xen xen_compat_props. It's a static

minor nit:
should be AccelClass::global_props

Quoted 4 lines

array of GlobalProperty, like machine globals in SET_MACHINE_COMPAT(). Let's register the globals the same way, without extra copy allocation.

otherwise looks good to me, CCing xen folks since it concerns them.

Quoted 95 lines
---
 include/hw/qdev-properties.h | 29 -----------------------------
 accel/accel.c                |  9 ++++++++-
 hw/core/qdev-properties.c    | 21 ---------------------
 3 files changed, 8 insertions(+), 51 deletions(-)
include/hw/qdev-properties.h +0 -29
index 4f60cc88f3..a95f4a73eb 100644
@@ -255,35 +255,6 @@ void qdev_prop_set_globals(DeviceState *dev);
 void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
                                     Property *prop, const char *value);
 
-/**
- * register_compat_prop:
- *
- * Register internal (not user-provided) global property, changing the
- * default value of a given property in a device type.  This can be used
- * for enabling machine-type compatibility or for enabling
- * accelerator-specific defaults in devices.
- *
- * The property values set using this function must be always valid and
- * never report setter errors, as the property will have
- * GlobalProperty::errp set to &error_abort.
- *
- * User-provided global properties should override internal global
- * properties, so callers of this function should ensure that it is
- * called before user-provided global properties are registered.
- *
- * @driver: Device type to be affected
- * @property: Property whose default value is going to be changed
- * @value: New default value for the property
- */
-void register_compat_prop(const char *driver, const char *property,
-                          const char *value);
-/*
- * register_compat_props_array(): using register_compat_prop(), which
- * only registers internal global properties (which has lower priority
- * than user-provided global properties)
- */
-void register_compat_props_array(GlobalProperty *prop);
-
 /**
  * qdev_property_add_static:
  * @dev: Device to add the property to.
accel/accel.c +8 -1
index 966b2d8f53..3da26eb90f 100644
@@ -34,6 +34,7 @@
 #include "qom/object.h"
 #include "qemu/error-report.h"
 #include "qemu/option.h"
+#include "qapi/error.h"
 
 static const TypeInfo accel_type = {
     .name = TYPE_ACCEL,
@@ -121,7 +122,13 @@ void configure_accelerator(MachineState *ms)
 void accel_register_compat_props(AccelState *accel)
 {
     AccelClass *class = ACCEL_GET_CLASS(accel);
-    register_compat_props_array(class->global_props);
+    GlobalProperty *prop = class->global_props;
+
+    for (; prop && prop->driver; prop++) {
+        /* Any compat_props must never cause error */
+        prop->errp = &error_abort;
+        qdev_prop_register_global(prop);
+    }
 }
 
 void accel_setup_post(MachineState *ms)
hw/core/qdev-properties.c +0 -14
index 35072dec1e..ab61d502fd 100644
@@ -1180,27 +1180,6 @@ void qdev_prop_register_global(GlobalProperty *prop)
     global_props = g_list_append(global_props, prop);
 }
 
-void register_compat_prop(const char *driver,
-                          const char *property,
-                          const char *value)
-{
-    GlobalProperty *p = g_new0(GlobalProperty, 1);
-
-    /* Any compat_props must never cause error */
-    p->errp = &error_abort;
-    p->driver = driver;
-    p->property = property;
-    p->value = value;
-    qdev_prop_register_global(p);
-}
-

hw/core/qdev-properties.c void qdev_prop_register_global(GlobalProperty *prop) · line 1185

Quoted 10 lines
hw/core/qdev-properties.c +0 -7
-void register_compat_props_array(GlobalProperty *prop)
-{
-    for (; prop && prop->driver; prop++) {
-        register_compat_prop(prop->driver, prop->property, prop->value);
-    }
-}
-
 void qdev_prop_register_global_list(GlobalProperty *props)
 {
     int i;

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#14 lore raw

PATCH 3/9 qdev: move qdev_prop_register_global_list() to tests

In reply to Marc-André Lureau

The function is only used by a test, move it there.

---
 include/hw/qdev-properties.h   |  1 -
 hw/core/qdev-properties.c      |  9 ---------
 tests/test-qdev-global-props.c | 18 ++++++++++++++----
 3 files changed, 14 insertions(+), 14 deletions(-)
include/hw/qdev-properties.h +0 -1
index a95f4a73eb..3ab9cd2eb6 100644
@@ -249,7 +249,6 @@ void qdev_prop_set_enum(DeviceState *dev, const char *name, int value);
 void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
 
 void qdev_prop_register_global(GlobalProperty *prop);
-void qdev_prop_register_global_list(GlobalProperty *props);
 int qdev_prop_check_globals(void);
 void qdev_prop_set_globals(DeviceState *dev);
 void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
hw/core/qdev-properties.c +0 -9
index ab61d502fd..bd84c4ea4c 100644
@@ -1180,15 +1180,6 @@ void qdev_prop_register_global(GlobalProperty *prop)
     global_props = g_list_append(global_props, prop);
 }
 
-void qdev_prop_register_global_list(GlobalProperty *props)
-{
-    int i;
-
-    for (i = 0; props[i].driver != NULL; i++) {
-        qdev_prop_register_global(props+i);
-    }
-}
-
 int qdev_prop_check_globals(void)
 {
     GList *l;
tests/test-qdev-global-props.c +14 -4
index d81b0862d5..d8596e6637 100644
@@ -89,6 +89,16 @@ static void test_static_prop(void)
     g_test_trap_assert_stdout("");
 }
 
+static void register_global_list(GlobalProperty *props)
+{
+    int i;
+
+    for (i = 0; props[i].driver != NULL; i++) {
+        qdev_prop_register_global(props + i);
+    }
+}
+
+
 /* Test setting of static property using global properties */
 static void test_static_globalprop_subprocess(void)
 {
@@ -98,7 +108,7 @@ static void test_static_globalprop_subprocess(void)
         {}
     };
 
-    qdev_prop_register_global_list(props);
+    register_global_list(props);
 
     mt = STATIC_TYPE(object_new(TYPE_STATIC_PROPS));
     qdev_init_nofail(DEVICE(mt));
@@ -216,7 +226,7 @@ static void test_dynamic_globalprop_subprocess(void)
     };
     int all_used;
 
-    qdev_prop_register_global_list(props);
+    register_global_list(props);
 
     mt = DYNAMIC_TYPE(object_new(TYPE_DYNAMIC_PROPS));
     qdev_init_nofail(DEVICE(mt));
@@ -261,7 +271,7 @@ static void test_dynamic_globalprop_nouser_subprocess(void)
     };
     int all_used;
 
-    qdev_prop_register_global_list(props);
+    register_global_list(props);
 
     mt = DYNAMIC_TYPE(object_new(TYPE_DYNAMIC_PROPS));
     qdev_init_nofail(DEVICE(mt));
@@ -299,7 +309,7 @@ static void test_subclass_global_props(void)
         {}
     };
 
-    qdev_prop_register_global_list(props);
+    register_global_list(props);
 
     mt = STATIC_TYPE(object_new(TYPE_SUBCLASS));
     qdev_init_nofail(DEVICE(mt));
Signature · 1 line
2.19.0.rc1
#15 lore raw

Re: [Qemu-devel] [PATCH 3/9] qdev: move qdev_prop_register_global_list() to tests

Quoted 46 lines · On Wed, 12 Sep 2018 16:55:25 +0400 Marc-André Lureau…

The function is only used by a test, move it there.

---
 include/hw/qdev-properties.h   |  1 -
 hw/core/qdev-properties.c      |  9 ---------
 tests/test-qdev-global-props.c | 18 ++++++++++++++----
 3 files changed, 14 insertions(+), 14 deletions(-)
include/hw/qdev-properties.h +0 -1
index a95f4a73eb..3ab9cd2eb6 100644
@@ -249,7 +249,6 @@ void qdev_prop_set_enum(DeviceState *dev, const char *name, int value);
 void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
 
 void qdev_prop_register_global(GlobalProperty *prop);
-void qdev_prop_register_global_list(GlobalProperty *props);
 int qdev_prop_check_globals(void);
 void qdev_prop_set_globals(DeviceState *dev);
 void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
hw/core/qdev-properties.c +0 -9
index ab61d502fd..bd84c4ea4c 100644
@@ -1180,15 +1180,6 @@ void qdev_prop_register_global(GlobalProperty *prop)
     global_props = g_list_append(global_props, prop);
 }
 
-void qdev_prop_register_global_list(GlobalProperty *props)
-{
-    int i;
-
-    for (i = 0; props[i].driver != NULL; i++) {
-        qdev_prop_register_global(props+i);
-    }
-}
-
 int qdev_prop_check_globals(void)
 {
     GList *l;
tests/test-qdev-global-props.c +0 -0
index d81b0862d5..d8596e6637 100644

tests/test-qdev-global-props.c static void test_static_prop(void) · line 92

Quoted 4 lines
tests/test-qdev-global-props.c +1 -0
@@ -89,6 +89,16 @@ static void test_static_prop(void)
     g_test_trap_assert_stdout("");
 }
 
+static void register_global_list(GlobalProperty *props)

naming looks too ambiguous, I'd keep original name or maybe use something more specific, like 'register_global_properties'

Quoted 48 lines
tests/test-qdev-global-props.c +13 -4
+{
+    int i;
+
+    for (i = 0; props[i].driver != NULL; i++) {
+        qdev_prop_register_global(props + i);
+    }
+}
+
+
 /* Test setting of static property using global properties */
 static void test_static_globalprop_subprocess(void)
 {
@@ -98,7 +108,7 @@ static void test_static_globalprop_subprocess(void)
         {}
     };
 
-    qdev_prop_register_global_list(props);
+    register_global_list(props);
 
     mt = STATIC_TYPE(object_new(TYPE_STATIC_PROPS));
     qdev_init_nofail(DEVICE(mt));
@@ -216,7 +226,7 @@ static void test_dynamic_globalprop_subprocess(void)
     };
     int all_used;
 
-    qdev_prop_register_global_list(props);
+    register_global_list(props);
 
     mt = DYNAMIC_TYPE(object_new(TYPE_DYNAMIC_PROPS));
     qdev_init_nofail(DEVICE(mt));
@@ -261,7 +271,7 @@ static void test_dynamic_globalprop_nouser_subprocess(void)
     };
     int all_used;
 
-    qdev_prop_register_global_list(props);
+    register_global_list(props);
 
     mt = DYNAMIC_TYPE(object_new(TYPE_DYNAMIC_PROPS));
     qdev_init_nofail(DEVICE(mt));
@@ -299,7 +309,7 @@ static void test_subclass_global_props(void)
         {}
     };
 
-    qdev_prop_register_global_list(props);
+    register_global_list(props);
 
     mt = STATIC_TYPE(object_new(TYPE_SUBCLASS));
     qdev_init_nofail(DEVICE(mt));
#16 lore raw

PATCH 4/9 qom/globals: move qdev globals to qom

In reply to Marc-André Lureau

Move the global properties handling to QOM. For now, this is just a simple moving & renaming and the globals are only applied to TYPE_DEVICE. The following patches will generalize the global handling to other object types.

---
 include/hw/qdev-core.h         | 20 ---------
 include/hw/qdev-properties.h   |  4 +-
 include/qom/globals.h          | 32 +++++++++++++++
 accel/accel.c                  |  2 +-
 hw/core/machine.c              |  2 +-
 hw/core/qdev-properties.c      | 67 ------------------------------
 hw/core/qdev.c                 |  2 +-
 qom/cpu.c                      |  2 +-
 qom/globals.c                  | 75 ++++++++++++++++++++++++++++++++++
 target/i386/cpu.c              |  2 +-
 target/sparc/cpu.c             |  2 +-
 tests/test-qdev-global-props.c |  6 +--
 vl.c                           |  8 ++--
 qom/Makefile.objs              |  2 +-
 14 files changed, 122 insertions(+), 104 deletions(-)
 create mode 100644 include/qom/globals.h
 create mode 100644 qom/globals.c
include/hw/qdev-core.h +0 -20
index f1fd0f8736..9e4695d03f 100644
@@ -246,26 +246,6 @@ struct PropertyInfo {
     ObjectPropertyRelease *release;
 };
 
-/**
- * GlobalProperty:
- * @user_provided: Set to true if property comes from user-provided config
- * (command-line or config file).
- * @used: Set to true if property was used when initializing a device.
- * @errp: Error destination, used like first argument of error_setg()
- *        in case property setting fails later. If @errp is NULL, we
- *        print warnings instead of ignoring errors silently. For
- *        hotplugged devices, errp is always ignored and warnings are
- *        printed instead.
- */
-typedef struct GlobalProperty {
-    const char *driver;
-    const char *property;
-    const char *value;
-    bool user_provided;
-    bool used;
-    Error **errp;
-} GlobalProperty;
-
 /*** Board API.  This should go away once we have a machine config file.  ***/
 
 DeviceState *qdev_create(BusState *bus, const char *name);
include/hw/qdev-properties.h +1 -3
index 3ab9cd2eb6..c8b727f081 100644
@@ -4,6 +4,7 @@
 #include "qapi/qapi-types-block.h"
 #include "qapi/qapi-types-misc.h"
 #include "hw/qdev-core.h"
+#include "qom/globals.h"
 
 /*** qdev-properties.c ***/
 
@@ -248,9 +249,6 @@ void qdev_prop_set_enum(DeviceState *dev, const char *name, int value);
 /* FIXME: Remove opaque pointer properties.  */
 void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
 
-void qdev_prop_register_global(GlobalProperty *prop);
-int qdev_prop_check_globals(void);
-void qdev_prop_set_globals(DeviceState *dev);
 void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
                                     Property *prop, const char *value);
 
include/qom/globals.h new file +32 -0
new file mode 100644
index 0000000000..28a0390233
@@ -0,0 +1,32 @@
+#ifndef QOM_GLOBALS
+#define QOM_GLOBALS
+
+#include "qom/object.h"
+
+/**
+ * GlobalProperty:
+ * @user_provided: Set to true if property comes from user-provided config
+ * (command-line or config file).
+ * @used: Set to true if property was used when initializing a device.
+ * @errp: Error destination, used like first argument of error_setg()
+ *        in case property setting fails later. If @errp is NULL, we
+ *        print warnings instead of ignoring errors silently. For
+ *        hotplugged devices, errp is always ignored and warnings are
+ *        printed instead.
+ */
+typedef struct GlobalProperty {
+    const char *driver;
+    const char *property;
+    const char *value;
+    bool user_provided;
+    bool used;
+    Error **errp;
+} GlobalProperty;
+
+void object_property_register_global(GlobalProperty *prop);
+
+void object_property_set_globals(Object *obj);
+
+int object_property_check_globals(void);
+
+#endif
accel/accel.c +1 -1
index 3da26eb90f..6916e0d63d 100644
@@ -127,7 +127,7 @@ void accel_register_compat_props(AccelState *accel)
     for (; prop && prop->driver; prop++) {
         /* Any compat_props must never cause error */
         prop->errp = &error_abort;
-        qdev_prop_register_global(prop);
+        object_property_register_global(prop);
     }
 }
 
hw/core/machine.c +1 -1
index 6b68e1218f..5f532939e4 100644
@@ -855,7 +855,7 @@ void machine_register_compat_props(MachineState *machine)
         p = g_array_index(mc->compat_props, GlobalProperty *, i);
         /* Machine compat_props must never cause errors: */
         p->errp = &error_abort;
-        qdev_prop_register_global(p);
+        object_property_register_global(p);
     }
 }
 
hw/core/qdev-properties.c +0 -67

73 lines not on this page · raw message

hw/core/qdev.c +1 -1
index 529b82de18..473060b551 100644
@@ -976,7 +976,7 @@ static void device_initfn(Object *obj)
 
 static void device_post_init(Object *obj)
 {
-    qdev_prop_set_globals(DEVICE(obj));
+    object_property_set_globals(obj);
 }
 
 /* Unlink device from bus and free the structure.  */
qom/cpu.c +1 -1
index 92599f3541..aaabe67648 100644
@@ -314,7 +314,7 @@ static void cpu_common_parse_features(const char *typename, char *features,
             prop->property = g_strdup(featurestr);
             prop->value = g_strdup(val);
             prop->errp = &error_fatal;
-            qdev_prop_register_global(prop);
+            object_property_register_global(prop);
         } else {
             error_setg(errp, "Expected key=value format, found %s.",
                        featurestr);
qom/globals.c new file +75 -0

75 lines not on this page · raw message

target/i386/cpu.c +1 -1
index f24295e6e4..ead1f67805 100644
@@ -3414,7 +3414,7 @@ static void x86_cpu_parse_featurestr(const char *typename, char *features,
         prop->property = g_strdup(name);
         prop->value = g_strdup(val);
         prop->errp = &error_fatal;
-        qdev_prop_register_global(prop);
+        object_property_register_global(prop);
     }
 
     if (ambiguous) {
target/sparc/cpu.c +1 -1
index 0f090ece54..3fde246d0d 100644
@@ -112,7 +112,7 @@ cpu_add_feat_as_prop(const char *typename, const char *name, const char *val)
     prop->property = g_strdup(name);
     prop->value = g_strdup(val);
     prop->errp = &error_fatal;
-    qdev_prop_register_global(prop);
+    object_property_register_global(prop);
 }
 
 /* Parse "+feature,-feature,feature=foo" CPU feature string */
tests/test-qdev-global-props.c +3 -3
index d8596e6637..9dffdf336d 100644
@@ -94,7 +94,7 @@ static void register_global_list(GlobalProperty *props)
     int i;
 
     for (i = 0; props[i].driver != NULL; i++) {
-        qdev_prop_register_global(props + i);
+        object_property_register_global(props + i);
     }
 }
 
@@ -233,7 +233,7 @@ static void test_dynamic_globalprop_subprocess(void)
 
     g_assert_cmpuint(mt->prop1, ==, 101);
     g_assert_cmpuint(mt->prop2, ==, 102);
-    all_used = qdev_prop_check_globals();
+    all_used = object_property_check_globals();
     g_assert_cmpuint(all_used, ==, 1);
     g_assert(props[0].used);
     g_assert(props[1].used);
@@ -278,7 +278,7 @@ static void test_dynamic_globalprop_nouser_subprocess(void)
 
     g_assert_cmpuint(mt->prop1, ==, 101);
     g_assert_cmpuint(mt->prop2, ==, 102);
-    all_used = qdev_prop_check_globals();
+    all_used = object_property_check_globals();
     g_assert_cmpuint(all_used, ==, 0);
     g_assert(props[0].used);
     g_assert(props[1].used);
vl.c +4 -4
index 5ba06adf78..03b8bda0ac 100644
@@ -903,7 +903,7 @@ static void configure_rtc(QemuOpts *opts)
                 .value    = "slew",
             };
 
-            qdev_prop_register_global(&slew_lost_ticks);
+            object_property_register_global(&slew_lost_ticks);
         } else if (!strcmp(value, "none")) {
             /* discard is default */
         } else {
@@ -2872,7 +2872,7 @@ static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)
     g->value    = qemu_opt_get(opts, "value");
     g->user_provided = true;
     g->errp = &error_fatal;
-    qdev_prop_register_global(g);
+    object_property_register_global(g);
     return 0;
 }
 
@@ -3564,7 +3564,7 @@ int main(int argc, char **argv, char **envp)
                     .value    = "slew",
                 };
 
-                qdev_prop_register_global(&slew_lost_ticks);
+                object_property_register_global(&slew_lost_ticks);
                 warn_report("This option is deprecated, "
                             "use '-rtc driftfix=slew' instead.");
                 break;
@@ -4623,7 +4623,7 @@ int main(int argc, char **argv, char **envp)
         }
     }
 
-    qdev_prop_check_globals();
+    object_property_check_globals();
     if (vmstate_dump_file) {
         /* dump and exit */
         dump_vmstate_json_to_file(vmstate_dump_file);
qom/Makefile.objs +1 -1
index 516349eec3..723851ff28 100644
@@ -1,4 +1,4 @@
 qom-obj-y = object.o container.o qom-qobject.o
-qom-obj-y += object_interfaces.o
+qom-obj-y += object_interfaces.o globals.o
 
 common-obj-y = cpu.o
Signature · 1 line
2.19.0.rc1
#17 lore raw

PATCH 5/9 qom/globals: generalize object_property_set_globals()

In reply to Marc-André Lureau

Handle calls of object_property_set_globals() with any object type, but only apply globals to TYPE_DEVICE & TYPE_USER_CREATABLE.

---
 qom/globals.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
qom/globals.c +14 -8
index 587f4a1b5c..8664baebe0 100644
@@ -15,22 +15,28 @@ void object_property_register_global(GlobalProperty *prop)
 
 void object_property_set_globals(Object *obj)
 {
-    DeviceState *dev = DEVICE(obj);
     GList *l;
+    DeviceState *dev = (DeviceState *)object_dynamic_cast(obj, TYPE_DEVICE);
+
+    if (!dev && !IS_USER_CREATABLE(obj)) {
+        /* only TYPE_DEVICE and TYPE_USER_CREATABLE support globals */
+        return;
+    }
 
     for (l = global_props; l; l = l->next) {
         GlobalProperty *prop = l->data;
         Error *err = NULL;
 
-        if (object_dynamic_cast(OBJECT(dev), prop->driver) == NULL) {
+        if (object_dynamic_cast(obj, prop->driver) == NULL) {
             continue;
         }
         prop->used = true;
-        object_property_parse(OBJECT(dev), prop->value, prop->property, &err);
+        object_property_parse(obj, prop->value, prop->property, &err);
         if (err != NULL) {
             error_prepend(&err, "can't apply global %s.%s=%s: ",
                           prop->driver, prop->property, prop->value);
-            if (!dev->hotplugged && prop->errp) {
+
+            if (dev && !dev->hotplugged && prop->errp) {
                 error_propagate(prop->errp, err);
             } else {
                 assert(prop->user_provided);
@@ -56,15 +62,15 @@ int object_property_check_globals(void)
             continue;
         }
         oc = object_class_by_name(prop->driver);
-        oc = object_class_dynamic_cast(oc, TYPE_DEVICE);
-        if (!oc) {
+        dc = (DeviceClass *)object_class_dynamic_cast(oc, TYPE_DEVICE);
+        if (!IS_USER_CREATABLE_CLASS(oc) && !dc) {
             warn_report("global %s.%s has invalid class name",
                         prop->driver, prop->property);
             ret = 1;
             continue;
         }
-        dc = DEVICE_CLASS(oc);
-        if (!dc->hotpluggable && !prop->used) {
+
+        if (dc && !dc->hotpluggable) {
             warn_report("global %s.%s=%s not used",
                         prop->driver, prop->property, prop->value);
             ret = 1;
Signature · 1 line
2.19.0.rc1
#18 lore raw

Re: [Qemu-devel] [PATCH 5/9] qom/globals: generalize object_property_set_globals()

Quoted 14 lines · On Wed, 12 Sep 2018 16:55:27 +0400 Marc-André Lureau…

Handle calls of object_property_set_globals() with any object type, but only apply globals to TYPE_DEVICE & TYPE_USER_CREATABLE.

---
 qom/globals.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
qom/globals.c +0 -0
index 587f4a1b5c..8664baebe0 100644
@@ -15,22 +15,28 @@ void object_property_register_global(GlobalProperty *prop)
 

qom/globals.c void object_property_register_global(GlobalProperty *prop) · line 24

Quoted 10 lines
qom/globals.c +6 -1
 void object_property_set_globals(Object *obj)
 {
-    DeviceState *dev = DEVICE(obj);
     GList *l;
+    DeviceState *dev = (DeviceState *)object_dynamic_cast(obj, TYPE_DEVICE);
+
+    if (!dev && !IS_USER_CREATABLE(obj)) {
+        /* only TYPE_DEVICE and TYPE_USER_CREATABLE support globals */
+        return;
+    }

more dynamic casts but now imposed on every create object :(

Maybe we should add ObjectClass::check/set_globals hook? It would be cheap to check and only objects we intend to work with it would be affected. On top of that hooks could be different so that device/user_creatable specifics won't be in generic code (like it's implemented here).

Quoted 41 lines
qom/globals.c +8 -7
     for (l = global_props; l; l = l->next) {
         GlobalProperty *prop = l->data;
         Error *err = NULL;
 
-        if (object_dynamic_cast(OBJECT(dev), prop->driver) == NULL) {
+        if (object_dynamic_cast(obj, prop->driver) == NULL) {
             continue;
         }
         prop->used = true;
-        object_property_parse(OBJECT(dev), prop->value, prop->property, &err);
+        object_property_parse(obj, prop->value, prop->property, &err);
         if (err != NULL) {
             error_prepend(&err, "can't apply global %s.%s=%s: ",
                           prop->driver, prop->property, prop->value);
-            if (!dev->hotplugged && prop->errp) {
+
+            if (dev && !dev->hotplugged && prop->errp) {
                 error_propagate(prop->errp, err);
             } else {
                 assert(prop->user_provided);
@@ -56,15 +62,15 @@ int object_property_check_globals(void)
             continue;
         }
         oc = object_class_by_name(prop->driver);
-        oc = object_class_dynamic_cast(oc, TYPE_DEVICE);
-        if (!oc) {
+        dc = (DeviceClass *)object_class_dynamic_cast(oc, TYPE_DEVICE);
+        if (!IS_USER_CREATABLE_CLASS(oc) && !dc) {
             warn_report("global %s.%s has invalid class name",
                         prop->driver, prop->property);
             ret = 1;
             continue;
         }
-        dc = DEVICE_CLASS(oc);
-        if (!dc->hotpluggable && !prop->used) {
+
+        if (dc && !dc->hotpluggable) {
             warn_report("global %s.%s=%s not used",
                         prop->driver, prop->property, prop->value);
             ret = 1;
#19 lore raw

Re: [Qemu-devel] [PATCH 5/9] qom/globals: generalize object_property_set_globals()

Hi

Quoted 30 lines · Igor Mammedov
Quoted 14 lines · On Wed, 12 Sep 2018 16:55:27 +0400 Marc-André Lureau…

Handle calls of object_property_set_globals() with any object type, but only apply globals to TYPE_DEVICE & TYPE_USER_CREATABLE.

---
 qom/globals.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
qom/globals.c +0 -0
index 587f4a1b5c..8664baebe0 100644
@@ -15,22 +15,28 @@ void object_property_register_global(GlobalProperty *prop)
 

qom/globals.c void object_property_register_global(GlobalProperty *prop) · line 24

Quoted 10 lines
qom/globals.c +6 -1
 void object_property_set_globals(Object *obj)
 {
-    DeviceState *dev = DEVICE(obj);
     GList *l;
+    DeviceState *dev = (DeviceState *)object_dynamic_cast(obj, TYPE_DEVICE);
+
+    if (!dev && !IS_USER_CREATABLE(obj)) {
+        /* only TYPE_DEVICE and TYPE_USER_CREATABLE support globals */
+        return;
+    }

more dynamic casts but now imposed on every create object :(

Quoted 5 lines

Maybe we should add ObjectClass::check/set_globals hook? It would be cheap to check and only objects we intend to work with it would be affected. On top of that hooks could be different so that device/user_creatable specifics won't be in generic code (like it's implemented here).

I don't think adding a few casts during object creation will impact negatively in a measurable way.

However I'll add an additional patch to the series to implement what I think you suggested.

thanks

Quoted 43 lines
Quoted 42 lines
qom/globals.c +8 -7
     for (l = global_props; l; l = l->next) {
         GlobalProperty *prop = l->data;
         Error *err = NULL;
 
-        if (object_dynamic_cast(OBJECT(dev), prop->driver) == NULL) {
+        if (object_dynamic_cast(obj, prop->driver) == NULL) {
             continue;
         }
         prop->used = true;
-        object_property_parse(OBJECT(dev), prop->value, prop->property, &err);
+        object_property_parse(obj, prop->value, prop->property, &err);
         if (err != NULL) {
             error_prepend(&err, "can't apply global %s.%s=%s: ",
                           prop->driver, prop->property, prop->value);
-            if (!dev->hotplugged && prop->errp) {
+
+            if (dev && !dev->hotplugged && prop->errp) {
                 error_propagate(prop->errp, err);
             } else {
                 assert(prop->user_provided);
@@ -56,15 +62,15 @@ int object_property_check_globals(void)
             continue;
         }
         oc = object_class_by_name(prop->driver);
-        oc = object_class_dynamic_cast(oc, TYPE_DEVICE);
-        if (!oc) {
+        dc = (DeviceClass *)object_class_dynamic_cast(oc, TYPE_DEVICE);
+        if (!IS_USER_CREATABLE_CLASS(oc) && !dc) {
             warn_report("global %s.%s has invalid class name",
                         prop->driver, prop->property);
             ret = 1;
             continue;
         }
-        dc = DEVICE_CLASS(oc);
-        if (!dc->hotpluggable && !prop->used) {
+
+        if (dc && !dc->hotpluggable) {
             warn_report("global %s.%s=%s not used",
                         prop->driver, prop->property, prop->value);
             ret = 1;
#20 lore raw

Re: [Qemu-devel] [PATCH 5/9] qom/globals: generalize object_property_set_globals()

Quoted 33 lines · On Tue, 30 Oct 2018 16:16:43 +0400 Marc-André Lureau…

Hi

Quoted 30 lines · Igor Mammedov
Quoted 14 lines · On Wed, 12 Sep 2018 16:55:27 +0400 Marc-André Lureau…

Handle calls of object_property_set_globals() with any object type, but only apply globals to TYPE_DEVICE & TYPE_USER_CREATABLE.

---
 qom/globals.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
qom/globals.c +0 -0
index 587f4a1b5c..8664baebe0 100644
@@ -15,22 +15,28 @@ void object_property_register_global(GlobalProperty *prop)
 

qom/globals.c void object_property_register_global(GlobalProperty *prop) · line 24

Quoted 10 lines
qom/globals.c +6 -1
 void object_property_set_globals(Object *obj)
 {
-    DeviceState *dev = DEVICE(obj);
     GList *l;
+    DeviceState *dev = (DeviceState *)object_dynamic_cast(obj, TYPE_DEVICE);
+
+    if (!dev && !IS_USER_CREATABLE(obj)) {
+        /* only TYPE_DEVICE and TYPE_USER_CREATABLE support globals */
+        return;
+    }  

more dynamic casts but now imposed on every create object :(

Quoted 8 lines
Quoted 5 lines

Maybe we should add ObjectClass::check/set_globals hook? It would be cheap to check and only objects we intend to work with it would be affected. On top of that hooks could be different so that device/user_creatable specifics won't be in generic code (like it's implemented here).

I don't think adding a few casts during object creation will impact negatively in a measurable way.

When it's applied to every object created as opposed to -object CLI option, it will add up. For example 512 x 2 (cpus + apic) ~ 1000 x cast_cost, for pc-dimm 255 x 3 (backend + memory_region + pc-dimm) ~ 800 x cast_cost, We can have more backends of other types, basically everything QOM will incur tiny extra cost.
I'm just thinking about worst case scenario.

Quoted 2 lines

However I'll add an additional patch to the series to implement what I think you suggested.

thanks,
for this patch also important to keep Device vs UserCreatable parts separate instead of dumping evrything into one pit.

Quoted 45 lines

thanks

Quoted 43 lines
Quoted 42 lines
qom/globals.c +8 -7
     for (l = global_props; l; l = l->next) {
         GlobalProperty *prop = l->data;
         Error *err = NULL;
 
-        if (object_dynamic_cast(OBJECT(dev), prop->driver) == NULL) {
+        if (object_dynamic_cast(obj, prop->driver) == NULL) {
             continue;
         }
         prop->used = true;
-        object_property_parse(OBJECT(dev), prop->value, prop->property, &err);
+        object_property_parse(obj, prop->value, prop->property, &err);
         if (err != NULL) {
             error_prepend(&err, "can't apply global %s.%s=%s: ",
                           prop->driver, prop->property, prop->value);
-            if (!dev->hotplugged && prop->errp) {
+
+            if (dev && !dev->hotplugged && prop->errp) {
                 error_propagate(prop->errp, err);
             } else {
                 assert(prop->user_provided);
@@ -56,15 +62,15 @@ int object_property_check_globals(void)
             continue;
         }
         oc = object_class_by_name(prop->driver);
-        oc = object_class_dynamic_cast(oc, TYPE_DEVICE);
-        if (!oc) {
+        dc = (DeviceClass *)object_class_dynamic_cast(oc, TYPE_DEVICE);
+        if (!IS_USER_CREATABLE_CLASS(oc) && !dc) {
             warn_report("global %s.%s has invalid class name",
                         prop->driver, prop->property);
             ret = 1;
             continue;
         }
-        dc = DEVICE_CLASS(oc);
-        if (!dc->hotpluggable && !prop->used) {
+
+        if (dc && !dc->hotpluggable) {
             warn_report("global %s.%s=%s not used",
                         prop->driver, prop->property, prop->value);
             ret = 1;  
#21 lore raw

PATCH 6/9 qom/object: set globals when initializing object

In reply to Marc-André Lureau

Set globals for all objects, although only TYPE_DEVICE & TYPE_USER_CREATABLE can have globals for now.

---
 hw/core/qdev.c | 6 ------
 qom/object.c   | 2 ++
 2 files changed, 2 insertions(+), 6 deletions(-)
hw/core/qdev.c +0 -6
index 473060b551..28c6c8d7c9 100644
@@ -974,11 +974,6 @@ static void device_initfn(Object *obj)
     QLIST_INIT(&dev->gpios);
 }
 
-static void device_post_init(Object *obj)
-{
-    object_property_set_globals(obj);
-}
-
 /* Unlink device from bus and free the structure.  */
 static void device_finalize(Object *obj)
 {
@@ -1103,7 +1098,6 @@ static const TypeInfo device_type_info = {
     .parent = TYPE_OBJECT,
     .instance_size = sizeof(DeviceState),
     .instance_init = device_initfn,
-    .instance_post_init = device_post_init,
     .instance_finalize = device_finalize,
     .class_base_init = device_class_base_init,
     .class_init = device_class_init,
qom/object.c +2 -0
index 0703e8e4ff..025ad0e191 100644
@@ -12,6 +12,7 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
+#include "qom/globals.h"
 #include "qom/object.h"
 #include "qom/object_interfaces.h"
 #include "qemu/cutils.h"
@@ -382,6 +383,7 @@ static void object_initialize_with_type(void *data, size_t size, TypeImpl *type)
     obj->properties = g_hash_table_new_full(g_str_hash, g_str_equal,
                                             NULL, object_property_free);
     object_init_with_type(obj, type);
+    object_property_set_globals(obj);
     object_post_init_with_type(obj, type);
 }
 
Signature · 1 line
2.19.0.rc1
#22 lore raw

Re: [Qemu-devel] [PATCH 6/9] qom/object: set globals when initializing object

Quoted 46 lines · On Wed, 12 Sep 2018 16:55:28 +0400 Marc-André Lureau…

Set globals for all objects, although only TYPE_DEVICE & TYPE_USER_CREATABLE can have globals for now.

---
 hw/core/qdev.c | 6 ------
 qom/object.c   | 2 ++
 2 files changed, 2 insertions(+), 6 deletions(-)
hw/core/qdev.c +0 -6
index 473060b551..28c6c8d7c9 100644
@@ -974,11 +974,6 @@ static void device_initfn(Object *obj)
     QLIST_INIT(&dev->gpios);
 }
 
-static void device_post_init(Object *obj)
-{
-    object_property_set_globals(obj);
-}
-
 /* Unlink device from bus and free the structure.  */
 static void device_finalize(Object *obj)
 {
@@ -1103,7 +1098,6 @@ static const TypeInfo device_type_info = {
     .parent = TYPE_OBJECT,
     .instance_size = sizeof(DeviceState),
     .instance_init = device_initfn,
-    .instance_post_init = device_post_init,
     .instance_finalize = device_finalize,
     .class_base_init = device_class_base_init,
     .class_init = device_class_init,
qom/object.c +1 -0
index 0703e8e4ff..025ad0e191 100644
@@ -12,6 +12,7 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
+#include "qom/globals.h"
 #include "qom/object.h"
 #include "qom/object_interfaces.h"
 #include "qemu/cutils.h"

qom/object.c static void object_initialize_with_type(void *data, size_t size, TypeImpl *type) · line 387

Quoted 5 lines
qom/object.c +1 -0
@@ -382,6 +383,7 @@ static void object_initialize_with_type(void *data, size_t size, TypeImpl *type)
     obj->properties = g_hash_table_new_full(g_str_hash, g_str_equal,
                                             NULL, object_property_free);
     object_init_with_type(obj, type);
+    object_property_set_globals(obj);
     object_post_init_with_type(obj, type);

this would somewhat inverse post_init call chain,
if there weren't any other instance_post_init() users that would be fine but it potentially can break arm_cpu_post_init() since globals would be set before the later finishes creating per instance properties.

arm cpu feature setting code is spread across initfn/post_init/realize and it's unreadable mess.
Maybe we should get rid of instance_post_init() altogether and explicitly call arm_cpu_post_init() from each initfn().

Quoted 2 lines
qom/object.c +0 -0
 }
 
#23 lore raw

PATCH 7/9 tests: add user-creatable test to test-qdev-global-props

In reply to Marc-André Lureau

Add a TYPE_USER_CREATABLE object global property check.

Rename the test, since it is no longer QDev-specific.

---
 ...dev-global-props.c => test-global-props.c} | 128 ++++++++++++++++--
 tests/Makefile.include                        |   4 +-
 2 files changed, 117 insertions(+), 15 deletions(-)
 rename tests/{test-qdev-global-props.c => test-global-props.c} (74%)
tests/test-global-props.c renamed from tests/test-qdev-global-props.c +115 -13
similarity index 74%
rename from tests/test-qdev-global-props.c
rename to tests/test-global-props.c
index 9dffdf336d..1c725245bc 100644
@@ -27,7 +27,100 @@
 #include "hw/qdev.h"
 #include "qom/object.h"
 #include "qapi/visitor.h"
+#include "qom/object_interfaces.h"
 
+#define TYPE_DUMMY "qemu-dummy"
+
+typedef struct DummyObject DummyObject;
+typedef struct DummyObjectClass DummyObjectClass;
+
+#define DUMMY_OBJECT(obj)                           \
+    OBJECT_CHECK(DummyObject, (obj), TYPE_DUMMY)
+
+struct DummyObject {
+    Object parent_obj;
+
+    char *sv;
+};
+
+struct DummyObjectClass {
+    ObjectClass parent_class;
+};
+
+static void dummy_set_sv(Object *obj,
+                         const char *value,
+                         Error **errp)
+{
+    DummyObject *dobj = DUMMY_OBJECT(obj);
+
+    g_free(dobj->sv);
+    dobj->sv = g_strdup(value);
+}
+
+static char *dummy_get_sv(Object *obj,
+                          Error **errp)
+{
+    DummyObject *dobj = DUMMY_OBJECT(obj);
+
+    return g_strdup(dobj->sv);
+}
+
+
+
+static void dummy_class_init(ObjectClass *cls, void *data)
+{
+    object_class_property_add_str(cls, "sv",
+                                  dummy_get_sv,
+                                  dummy_set_sv,
+                                  NULL);
+}
+
+
+static void dummy_finalize(Object *obj)
+{
+    DummyObject *dobj = DUMMY_OBJECT(obj);
+
+    g_free(dobj->sv);
+}
+
+
+static const TypeInfo dummy_info = {
+    .name          = TYPE_DUMMY,
+    .parent        = TYPE_OBJECT,
+    .instance_size = sizeof(DummyObject),
+    .instance_finalize = dummy_finalize,
+    .class_size = sizeof(DummyObjectClass),
+    .class_init = dummy_class_init,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_USER_CREATABLE },
+        { }
+    }
+};
+
+static void test_global_props_uc_subprocess(void)
+{
+    DummyObject *d;
+    static GlobalProperty gp = {
+        TYPE_DUMMY, "sv", "foobar",
+    };
+
+    d = DUMMY_OBJECT(object_new(TYPE_DUMMY));
+    g_assert_null(d->sv);
+    object_unref(OBJECT(d));
+
+    object_property_register_global(&gp);
+    d = DUMMY_OBJECT(object_new(TYPE_DUMMY));
+    g_assert_cmpstr(d->sv, ==, "foobar");
+    object_unref(OBJECT(d));
+}
+
+static void test_global_props_uc(void)
+{
+    g_test_trap_subprocess("/global-props/usercreatable/subprocess", 0, 0);
+    g_test_trap_assert_passed();
+    g_test_trap_assert_stderr("");
+    g_test_trap_assert_stdout("");
+}
 
 #define TYPE_STATIC_PROPS "static_prop_type"
 #define STATIC_TYPE(obj) \
@@ -83,7 +176,8 @@ static void test_static_prop_subprocess(void)
 
 static void test_static_prop(void)
 {
-    g_test_trap_subprocess("/qdev/properties/static/default/subprocess", 0, 0);
+    g_test_trap_subprocess("/global-props/qdev/static/default/subprocess",
+                           0, 0);
     g_test_trap_assert_passed();
     g_test_trap_assert_stderr("");
     g_test_trap_assert_stdout("");
@@ -119,7 +213,7 @@ static void test_static_globalprop_subprocess(void)
 
 static void test_static_globalprop(void)
 {
-    g_test_trap_subprocess("/qdev/properties/static/global/subprocess", 0, 0);
+    g_test_trap_subprocess("/global-props/qdev/static/global/subprocess", 0, 0);
     g_test_trap_assert_passed();
     g_test_trap_assert_stderr("");
     g_test_trap_assert_stdout("");
@@ -245,7 +339,8 @@ static void test_dynamic_globalprop_subprocess(void)
 
 static void test_dynamic_globalprop(void)
 {
-    g_test_trap_subprocess("/qdev/properties/dynamic/global/subprocess", 0, 0);
+    g_test_trap_subprocess("/global-props/qdev/dynamic/global/subprocess",
+                           0, 0);
     g_test_trap_assert_passed();
     g_test_trap_assert_stderr_unmatched("*prop1*");
     g_test_trap_assert_stderr_unmatched("*prop2*");
@@ -290,7 +385,8 @@ static void test_dynamic_globalprop_nouser_subprocess(void)
 
 static void test_dynamic_globalprop_nouser(void)
 {
-    g_test_trap_subprocess("/qdev/properties/dynamic/global/nouser/subprocess", 0, 0);
+    g_test_trap_subprocess("/global-props/qdev"
+                           "/dynamic/global/nouser/subprocess", 0, 0);
     g_test_trap_assert_passed();
     g_test_trap_assert_stderr("");
     g_test_trap_assert_stdout("");
@@ -323,6 +419,7 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
 
     module_call_init(MODULE_INIT_QOM);
+    type_register_static(&dummy_info);
     type_register_static(&static_prop_type);
     type_register_static(&subclass_type);
     type_register_static(&dynamic_prop_type);
@@ -330,27 +427,32 @@ int main(int argc, char **argv)
     type_register_static(&nohotplug_type);
     type_register_static(&nondevice_type);
 
-    g_test_add_func("/qdev/properties/static/default/subprocess",
+    g_test_add_func("/global-props/usercreatable/subprocess",
+                    test_global_props_uc_subprocess);
+    g_test_add_func("/global-props/usercreatable",
+                    test_global_props_uc);
+
+    g_test_add_func("/global-props/qdev/static/default/subprocess",
                     test_static_prop_subprocess);
-    g_test_add_func("/qdev/properties/static/default",
+    g_test_add_func("/global-props/qdev/static/default",
                     test_static_prop);
 
-    g_test_add_func("/qdev/properties/static/global/subprocess",
+    g_test_add_func("/global-props/qdev/static/global/subprocess",
                     test_static_globalprop_subprocess);
-    g_test_add_func("/qdev/properties/static/global",
+    g_test_add_func("/global-props/qdev/static/global",
                     test_static_globalprop);
 
-    g_test_add_func("/qdev/properties/dynamic/global/subprocess",
+    g_test_add_func("/global-props/qdev/dynamic/global/subprocess",
                     test_dynamic_globalprop_subprocess);
-    g_test_add_func("/qdev/properties/dynamic/global",
+    g_test_add_func("/global-props/qdev/dynamic/global",
                     test_dynamic_globalprop);
 
-    g_test_add_func("/qdev/properties/dynamic/global/nouser/subprocess",
+    g_test_add_func("/global-props/qdev/dynamic/global/nouser/subprocess",
                     test_dynamic_globalprop_nouser_subprocess);
-    g_test_add_func("/qdev/properties/dynamic/global/nouser",
+    g_test_add_func("/global-props/qdev/dynamic/global/nouser",
                     test_dynamic_globalprop_nouser);
 
-    g_test_add_func("/qdev/properties/global/subclass",
+    g_test_add_func("/global-props/qdev/global/subclass",
                     test_subclass_global_props);
 
     g_test_run();
tests/Makefile.include +2 -2
index 87c81d1dcc..080b218fd3 100644
@@ -128,7 +128,7 @@ check-unit-y += tests/test-qht-par$(EXESUF)
 gcov-files-test-qht-par-y = util/qht.c
 check-unit-y += tests/test-bitops$(EXESUF)
 check-unit-y += tests/test-bitcnt$(EXESUF)
-check-unit-y += tests/test-qdev-global-props$(EXESUF)
+check-unit-y += tests/test-global-props$(EXESUF)
 check-unit-y += tests/check-qom-interface$(EXESUF)
 gcov-files-check-qom-interface-y = qom/object.c
 check-unit-y += tests/check-qom-proplist$(EXESUF)
@@ -657,7 +657,7 @@ tests/qht-bench$(EXESUF): tests/qht-bench.o $(test-util-obj-y)
 tests/test-bufferiszero$(EXESUF): tests/test-bufferiszero.o $(test-util-obj-y)
 tests/atomic_add-bench$(EXESUF): tests/atomic_add-bench.o $(test-util-obj-y)
 
-tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \
+tests/test-global-props$(EXESUF): tests/test-global-props.o \
 	hw/core/qdev.o hw/core/qdev-properties.o hw/core/hotplug.o\
 	hw/core/bus.o \
 	hw/core/irq.o \
Signature · 1 line
2.19.0.rc1
#24 lore raw

PATCH 8/9 hw/i386: add pc-i440fx-3.1 & pc-q35-3.1

In reply to Marc-André Lureau

The following patch is going to add compatiblity parameters.

---
 include/hw/i386/pc.h |  5 ++++-
 hw/i386/pc_piix.c    | 15 ++++++++++++---
 hw/i386/pc_q35.c     | 13 +++++++++++--
 3 files changed, 27 insertions(+), 6 deletions(-)
include/hw/i386/pc.h +4 -1
index 6894f37df1..09b0365a8e 100644
@@ -294,7 +294,10 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t);
 int e820_get_num_entries(void);
 bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
 
-#define PC_COMPAT_2_12 \
+#define PC_COMPAT_3_0 \
+    HW_COMPAT_3_0
+
+#define PC_COMPAT_2_12                          \
     HW_COMPAT_2_12 \
     {\
         .driver   = TYPE_X86_CPU,\
hw/i386/pc_piix.c +12 -3
index dc09466b3e..7092d6d13f 100644
@@ -428,21 +428,30 @@ static void pc_i440fx_machine_options(MachineClass *m)
     machine_class_allow_dynamic_sysbus_dev(m, TYPE_RAMFB_DEVICE);
 }
 
-static void pc_i440fx_3_0_machine_options(MachineClass *m)
+static void pc_i440fx_3_1_machine_options(MachineClass *m)
 {
     pc_i440fx_machine_options(m);
     m->alias = "pc";
     m->is_default = 1;
 }
 
+DEFINE_I440FX_MACHINE(v3_1, "pc-i440fx-3.1", NULL,
+                      pc_i440fx_3_1_machine_options);
+
+static void pc_i440fx_3_0_machine_options(MachineClass *m)
+{
+    pc_i440fx_3_1_machine_options(m);
+    m->is_default = 0;
+    m->alias = NULL;
+    SET_MACHINE_COMPAT(m, PC_COMPAT_3_0);
+}
+
 DEFINE_I440FX_MACHINE(v3_0, "pc-i440fx-3.0", NULL,
                       pc_i440fx_3_0_machine_options);
 
 static void pc_i440fx_2_12_machine_options(MachineClass *m)
 {
     pc_i440fx_3_0_machine_options(m);
-    m->is_default = 0;
-    m->alias = NULL;
     SET_MACHINE_COMPAT(m, PC_COMPAT_2_12);
 }
 
hw/i386/pc_q35.c +11 -2
index 532241e3f8..4702bb13c4 100644
@@ -311,19 +311,28 @@ static void pc_q35_machine_options(MachineClass *m)
     m->max_cpus = 288;
 }
 
-static void pc_q35_3_0_machine_options(MachineClass *m)
+static void pc_q35_3_1_machine_options(MachineClass *m)
 {
     pc_q35_machine_options(m);
     m->alias = "q35";
 }
 
+DEFINE_Q35_MACHINE(v3_1, "pc-q35-3.1", NULL,
+                   pc_q35_3_1_machine_options);
+
+static void pc_q35_3_0_machine_options(MachineClass *m)
+{
+    pc_q35_3_1_machine_options(m);
+    m->alias = NULL;
+    SET_MACHINE_COMPAT(m, PC_COMPAT_3_0);
+}
+
 DEFINE_Q35_MACHINE(v3_0, "pc-q35-3.0", NULL,
                     pc_q35_3_0_machine_options);
 
 static void pc_q35_2_12_machine_options(MachineClass *m)
 {
     pc_q35_3_0_machine_options(m);
-    m->alias = NULL;
     SET_MACHINE_COMPAT(m, PC_COMPAT_2_12);
 }
 
Signature · 1 line
2.19.0.rc1
#25 lore raw

PATCH 9/9 hostmem-ram: use whole path for memory region name with >= 3.1

In reply to Marc-André Lureau

hostmem-file and hostmem-memfd use the whole object path for the memory region name, but hostname-ram uses only the path component (the basename):

qemu -m 1024 -object memory-backend-ram,id=mem,size=1G -numa node,memdev=mem -monitor stdio (qemu) info ramblock
Block Name PSize Offset Used Total
mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000

qemu -m 1024 -object memory-backend-file,id=mem,size=1G,mem-path=/tmp/foo -numa node,memdev=mem -monitor stdio (qemu) info ramblock
Block Name PSize Offset Used Total
/objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000

qemu -m 1024 -object memory-backend-memfd,id=mem,size=1G -numa node,memdev=mem -monitor stdio (qemu) info ramblock
Block Name PSize Offset Used Total
/objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000

Use the whole path name with >= 3.1. Having a consistent naming allow to migrate to different hostmem backends.

---
 include/hw/compat.h    |  6 +++++-
 backends/hostmem-ram.c | 47 ++++++++++++++++++++++++++++++++++++++----
 2 files changed, 48 insertions(+), 5 deletions(-)
include/hw/compat.h +5 -1
index 6f4d5fc647..8ce7a7057b 100644
@@ -2,7 +2,11 @@
 #define HW_COMPAT_H
 
 #define HW_COMPAT_3_0 \
-    /* empty */
+    {\
+        .driver   = "memory-backend-ram",\
+        .property = "x-component-name",\
+        .value    = "true",\
+    },
 
 #define HW_COMPAT_2_12 \
     {\
backends/hostmem-ram.c +43 -4

75 lines not on this page · raw message

Signature · 1 line
2.19.0.rc1
Reviewed-by on v1 9/9
#26 lore raw

Re: [Qemu-devel] [PATCH 9/9] hostmem-ram: use whole path for memory region name with >= 3.1

Quoted 33 lines · * Marc-André Lureau ([email protected]) wrote:

hostmem-file and hostmem-memfd use the whole object path for the memory region name, but hostname-ram uses only the path component (the basename):

qemu -m 1024 -object memory-backend-ram,id=mem,size=1G -numa node,memdev=mem -monitor stdio (qemu) info ramblock
Block Name PSize Offset Used Total
mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000

qemu -m 1024 -object memory-backend-file,id=mem,size=1G,mem-path=/tmp/foo -numa node,memdev=mem -monitor stdio (qemu) info ramblock
Block Name PSize Offset Used Total
/objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000

qemu -m 1024 -object memory-backend-memfd,id=mem,size=1G -numa node,memdev=mem -monitor stdio (qemu) info ramblock
Block Name PSize Offset Used Total
/objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000

Use the whole path name with >= 3.1. Having a consistent naming allow to migrate to different hostmem backends.

---
 include/hw/compat.h    |  6 +++++-
 backends/hostmem-ram.c | 47 ++++++++++++++++++++++++++++++++++++++----
 2 files changed, 48 insertions(+), 5 deletions(-)
include/hw/compat.h +0 -0
index 6f4d5fc647..8ce7a7057b 100644

include/hw/compat.h line 9

Quoted 9 lines
include/hw/compat.h +5 -1
@@ -2,7 +2,11 @@
 #define HW_COMPAT_H
 
 #define HW_COMPAT_3_0 \
-    /* empty */
+    {\
+        .driver   = "memory-backend-ram",\
+        .property = "x-component-name",\
+        .value    = "true",\
+    },

I don't think this needs to be an 'x-' - I think we originally used those just for eXperimental things.

However, that's a minor nit, so:

Quoted 86 lines
include/hw/compat.h +0 -0
 #define HW_COMPAT_2_12 \
     {\
backends/hostmem-ram.c +43 -4
index 7ddd08d370..a9eb99cf1b 100644
@@ -16,21 +16,56 @@
 
 #define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram"
 
+typedef struct RamMemoryBackend {
+    HostMemoryBackend parent;
+
+    bool component_name;
+} RamMemoryBackend;
+
+#define RAM_BACKEND(obj) \
+    OBJECT_CHECK(RamMemoryBackend, (obj), TYPE_MEMORY_BACKEND_RAM)
+
+static char *
+ram_backend_get_name(RamMemoryBackend *self)
+{
+    /* < 3.1 use the component as memory region name */
+    if (self->component_name) {
+        return object_get_canonical_path_component(OBJECT(self));
+    }
+
+    return object_get_canonical_path(OBJECT(self));
+}
 
 static void
 ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
 {
-    char *path;
+    char *name;
 
     if (!backend->size) {
         error_setg(errp, "can't create backend with size 0");
         return;
     }
 
-    path = object_get_canonical_path_component(OBJECT(backend));
-    memory_region_init_ram_shared_nomigrate(&backend->mr, OBJECT(backend), path,
+    name = ram_backend_get_name(RAM_BACKEND(backend));
+    memory_region_init_ram_shared_nomigrate(&backend->mr, OBJECT(backend), name,
                            backend->size, backend->share, errp);
-    g_free(path);
+    g_free(name);
+}
+
+static bool
+ram_backend_get_component_name(Object *obj, Error **errp)
+{
+    RamMemoryBackend *self = RAM_BACKEND(obj);
+
+    return self->component_name;
+}
+
+static void
+ram_backend_set_component_name(Object *obj, bool value, Error **errp)
+{
+    RamMemoryBackend *self = RAM_BACKEND(obj);
+
+    self->component_name = value;
 }
 
 static void
@@ -39,11 +74,15 @@ ram_backend_class_init(ObjectClass *oc, void *data)
     HostMemoryBackendClass *bc = MEMORY_BACKEND_CLASS(oc);
 
     bc->alloc = ram_backend_memory_alloc;
+    object_class_property_add_bool(oc, "x-component-name",
+        ram_backend_get_component_name,
+        ram_backend_set_component_name, &error_abort);
 }
 
 static const TypeInfo ram_backend_info = {
     .name = TYPE_MEMORY_BACKEND_RAM,
     .parent = TYPE_MEMORY_BACKEND,
+    .instance_size = sizeof(RamMemoryBackend),
     .class_init = ram_backend_class_init,
 };
 
Signature · 1 line
2.19.0.rc1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#27 lore raw

Re: [Qemu-devel] [PATCH 9/9] hostmem-ram: use whole path for memory region name with >= 3.1

In reply to Marc-André Lureau
Quoted 1 line · On Wed, 12 Sep 2018 16:55:31 +0400 Marc-André Lureau…

hostmem-file and hostmem-memfd use the whole object path

maybe add something along the lines:

consisting from user supplied 'id' and ...

Quoted 3 lines

for the
memory region name, but hostname-ram uses only the path component (the basename):

so path component would mean a concrete thing.

Quoted 53 lines

qemu -m 1024 -object memory-backend-ram,id=mem,size=1G -numa node,memdev=mem -monitor stdio (qemu) info ramblock
Block Name PSize Offset Used Total
mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000

qemu -m 1024 -object memory-backend-file,id=mem,size=1G,mem-path=/tmp/foo -numa node,memdev=mem -monitor stdio (qemu) info ramblock
Block Name PSize Offset Used Total
/objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000

qemu -m 1024 -object memory-backend-memfd,id=mem,size=1G -numa node,memdev=mem -monitor stdio (qemu) info ramblock
Block Name PSize Offset Used Total
/objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000

Use the whole path name with >= 3.1. Having a consistent naming allow to migrate to different hostmem backends.

---
 include/hw/compat.h    |  6 +++++-
 backends/hostmem-ram.c | 47 ++++++++++++++++++++++++++++++++++++++----
 2 files changed, 48 insertions(+), 5 deletions(-)
include/hw/compat.h +5 -1
index 6f4d5fc647..8ce7a7057b 100644
@@ -2,7 +2,11 @@
 #define HW_COMPAT_H
 
 #define HW_COMPAT_3_0 \
-    /* empty */
+    {\
+        .driver   = "memory-backend-ram",\
+        .property = "x-component-name",\
+        .value    = "true",\
+    },
 
 #define HW_COMPAT_2_12 \
     {\
backends/hostmem-ram.c +3 -0
index 7ddd08d370..a9eb99cf1b 100644
@@ -16,21 +16,56 @@
 
 #define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram"
 
+typedef struct RamMemoryBackend {
+    HostMemoryBackend parent;
+

backends/hostmem-ram.c line 31

Quoted 10 lines
backends/hostmem-ram.c +10 -0
+    bool component_name;
+} RamMemoryBackend;
+
+#define RAM_BACKEND(obj) \
+    OBJECT_CHECK(RamMemoryBackend, (obj), TYPE_MEMORY_BACKEND_RAM)
+
+static char *
+ram_backend_get_name(RamMemoryBackend *self)
+{
+    /* < 3.1 use the component as memory region name */

I'd drop comment here, it belongs more to HW_COMPAT_...

Quoted 45 lines
backends/hostmem-ram.c +26 -4
+    if (self->component_name) {
+        return object_get_canonical_path_component(OBJECT(self));
+    }
+
+    return object_get_canonical_path(OBJECT(self));
+}
 
 static void
 ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
 {
-    char *path;
+    char *name;
 
     if (!backend->size) {
         error_setg(errp, "can't create backend with size 0");
         return;
     }
 
-    path = object_get_canonical_path_component(OBJECT(backend));
-    memory_region_init_ram_shared_nomigrate(&backend->mr, OBJECT(backend), path,
+    name = ram_backend_get_name(RAM_BACKEND(backend));
+    memory_region_init_ram_shared_nomigrate(&backend->mr, OBJECT(backend), name,
                            backend->size, backend->share, errp);
-    g_free(path);
+    g_free(name);
+}
+
+static bool
+ram_backend_get_component_name(Object *obj, Error **errp)
+{
+    RamMemoryBackend *self = RAM_BACKEND(obj);
+
+    return self->component_name;
+}
+
+static void
+ram_backend_set_component_name(Object *obj, bool value, Error **errp)
+{
+    RamMemoryBackend *self = RAM_BACKEND(obj);
+
+    self->component_name = value;
 }
 
 static void

backends/hostmem-ram.c ram_backend_class_init(ObjectClass *oc, void *data) · line 77

Quoted 4 lines
backends/hostmem-ram.c +1 -0
@@ -39,11 +74,15 @@ ram_backend_class_init(ObjectClass *oc, void *data)
     HostMemoryBackendClass *bc = MEMORY_BACKEND_CLASS(oc);
 
     bc->alloc = ram_backend_memory_alloc;
+    object_class_property_add_bool(oc, "x-component-name",

If we would convert initial RAM to backend/frontend model, we would actually need to keep current ramblock naming scheme for ram_backend and even do this /i.e. non path variant/ for other backends to keep migration stream compatible.

How about adding this property to generic memory-backend and naming it something like 'x-use-canonical-path-for-ramblock-id'

I wonder if there is a point to use path for ramblock at all, considering that it is single name space for all backends anyways. Maybe by default we should just use 'id' everywhere?

backends/hostmem-ram.c ram_backend_class_init(ObjectClass *oc, void *data) · line 79

Quoted 2 lines
backends/hostmem-ram.c +2 -0
+        ram_backend_get_component_name,
+        ram_backend_set_component_name, &error_abort);

+ object_class_property_set_description(...)

Quoted 9 lines
backends/hostmem-ram.c +1 -0
 }
 
 static const TypeInfo ram_backend_info = {
     .name = TYPE_MEMORY_BACKEND_RAM,
     .parent = TYPE_MEMORY_BACKEND,
+    .instance_size = sizeof(RamMemoryBackend),
     .class_init = ram_backend_class_init,
 };
 
#28 lore raw
In reply to Marc-André Lureau

Hi

Quoted 13 lines · Marc-André Lureau

Hi,

The migration code expects the RAM block name to match between the source and destination. However the backend type may change, so it is possible (so far) to migrate from a hostmem-file to a hostmem-memfd for example.

However, hostmem backends use inconsistent RAM naming, which can cause a name mismatch. hostmem-file and hostmem-memfd use the whole object path as memory name, while -ram use only the "component" (or basename) of the path.

Quoted 4 lines

This series adds global/compat property support for objects others than TYPE_DEVICE (only TYPE_USER_CREATABLE for now), and a new compat property "x-component-name" to hostmem-ram. Machines >= 3.1 will use the whole path for the -ram memory name (like -file and -memfd).

The series now has a minor conflict in vl.c. I can resend if necessary.

Anyone to review the qdev/qom changes?

thanks

Quoted 44 lines

Marc-André Lureau (9):
qom/user-creatable: add a few helper macros
accel: register global_props like machine globals
qdev: move qdev_prop_register_global_list() to tests qom/globals: move qdev globals to qom
qom/globals: generalize object_property_set_globals() qom/object: set globals when initializing object
tests: add user-creatable test to test-qdev-global-props hw/i386: add pc-i440fx-3.1 & pc-q35-3.1
hostmem-ram: use whole path for memory region name with >= 3.1

 include/hw/compat.h                           |   6 +-
 include/hw/i386/pc.h                          |   5 +-
 include/hw/qdev-core.h                        |  20 ---
 include/hw/qdev-properties.h                  |  34 +---
 include/qom/globals.h                         |  32 ++++
 include/qom/object_interfaces.h               |   4 +
 accel/accel.c                                 |   9 +-
 backends/hostmem-ram.c                        |  47 +++++-
 hw/core/machine.c                             |   2 +-
 hw/core/qdev-properties.c                     |  97 -----------
 hw/core/qdev.c                                |   6 -
 hw/i386/pc_piix.c                             |  15 +-
 hw/i386/pc_q35.c                              |  13 +-
 qom/cpu.c                                     |   2 +-
 qom/globals.c                                 |  81 ++++++++++
 qom/object.c                                  |   6 +-
 qom/object_interfaces.c                       |   9 +-
 target/i386/cpu.c                             |   2 +-
 target/sparc/cpu.c                            |   2 +-
 ...dev-global-props.c => test-global-props.c} | 150 +++++++++++++++---
 vl.c                                          |   8 +-
 qom/Makefile.objs                             |   2 +-
 tests/Makefile.include                        |   4 +-
 23 files changed, 350 insertions(+), 206 deletions(-)
 create mode 100644 include/qom/globals.h
 create mode 100644 qom/globals.c
 rename tests/{test-qdev-global-props.c => test-global-props.c} (71%)

--
2.19.0.rc1

Signature · 1 line
Marc-André Lureau