From: Eduardo Habkost <ehabkost@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: qemu-devel <qemu-devel@nongnu.org>,
sstabellini <sstabellini@kernel.org>,
xen-devel@lists.xenproject.org, "Bonzini,
Paolo" <pbonzini@redhat.com>,
"Anthony PERARD" <anthony.perard@citrix.com>,
"Igor Mammedov" <imammedo@redhat.com>,
"Andreas Färber" <afaerber@suse.de>
Subject: Re: [Qemu-devel] [PATCH for-3.2 v4 15/28] hw: apply accel compat properties without touching globals
Date: Thu, 29 Nov 2018 14:02:06 -0200 [thread overview]
Message-ID: <20181129160206.GL18284@habkost.net> (raw)
In-Reply-To: <CAMxuvaz0FitnFiSD3Ma9r_7z0oM6A_Z3D2nbAh=YBp3mEC72rg@mail.gmail.com>
On Wed, Nov 28, 2018 at 12:02:21AM +0400, Marc-André Lureau wrote:
> Hi
>
> On Tue, Nov 27, 2018 at 11:40 PM Eduardo Habkost <ehabkost@redhat.com> wrote:
> >
> > On Tue, Nov 27, 2018 at 01:27:48PM +0400, Marc-André Lureau wrote:
> > > Introduce object_apply_global_props() function, to apply compatibility
> > > properties from a GPtrArray.
> > >
> > > For accel compatibility properties, apply them during
> > > device_post_init(), after accel_register_compat_props() has set them.
> > >
> > > To populate the compatibility properties, introduce SET_COMPAT(), a
> > > more generic version of SET_MACHINE_COMPAT() that can set compat
> > > properties on other objects than Machine, and using GPtrArray.
> > >
> > > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > > ---
> > > include/hw/qdev-core.h | 13 +++++++++++++
> > > include/qom/object.h | 3 +++
> > > include/sysemu/accel.h | 4 +---
> > > accel/accel.c | 12 ------------
> > > hw/core/qdev.c | 11 +++++++++++
> > > hw/xen/xen-common.c | 38 +++++++++++++++++++-------------------
> > > qom/object.c | 25 +++++++++++++++++++++++++
> > > vl.c | 2 +-
> > > 8 files changed, 73 insertions(+), 35 deletions(-)
> > >
> > > diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
> > > index a24d0dd566..82afd3c50d 100644
> > > --- a/include/hw/qdev-core.h
> > > +++ b/include/hw/qdev-core.h
> > > @@ -267,6 +267,19 @@ typedef struct GlobalProperty {
> > > Error **errp;
> > > } GlobalProperty;
> > >
> > > +#define SET_COMPAT(S, COMPAT) \
> > > + do { \
> > > + int i; \
> > > + static GlobalProperty props[] = { \
> > > + COMPAT \
> > > + }; \
> > > + for (i = 0; i < G_N_ELEMENTS(props); i++) { \
> > > + g_ptr_array_add((S)->compat_props, (void *)&props[i]); \
> > > + } \
> > > + } while (0)
> >
> > I think this macro would be an acceptable alternative to the
> > existing SET_MACHINE_COMPAT macro trickery, but:
> >
> > > +
> > > +void accel_register_compat_props(const GPtrArray *props);
> > [...]
> > > @@ -185,7 +183,9 @@ static void xen_accel_class_init(ObjectClass *oc, void *data)
> > > ac->init_machine = xen_init;
> > > ac->setup_post = xen_setup_post;
> > > ac->allowed = &xen_allowed;
> > > - ac->global_props = xen_compat_props;
> > > + ac->compat_props = g_ptr_array_new();
> > > +
> > > + SET_COMPAT(ac, XEN_COMPAT);
> >
> > I think this is a step backwards. I like us to be able to
> > register compat properties without macro magic. The existence of
> > SET_MACHINE_COMPAT is a bug and not a feature.
> >
> > If you really want to use GPtrArray instead of a simple
> > GlobalProperty* field (I'm not sure I understand the reasoning
> > behind the choice to use GPtrArray), what about:
>
> Except in the Xen case, It needs to register multiple GlobalProperty*,
> not necessarily from contiguous in memory. That's why we have an array
> of ptr.
If you also need to register multiple properties not from a
contiguous array, would a simple wrapper that does a single
g_ptr_array_add() call be enough?
>
> >
> > static GPtrArray *build_compat_props_array(GlobalProperty *props)
> > {
> > GlobalProperty *p = props;
> > GPtrArray *array = g_ptr_array_new();
> > while (p->driver) {
> > g_ptr_array_add(array, (void *)p);
> > }
> > return array;
> > }
> >
> >
> > static void xen_accel_class_init(ObjectClass *oc, void *data)
> > {
> > ...
> > ac->compat_props = build_compat_props_array(xen_compat_props);
>
> If we would register from one place, that would be fine.
>
> We could replace the macro by a function, then we would have to
> declare the GlobalProperty arrays manually basically.
I would prefer to replace the macro with a function, if possible.
What do you mean by declaring the GlobalProperty arrays manually?
>
> > }
> >
> >
> >
> > > }
> > >
> > > #define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
> > > diff --git a/qom/object.c b/qom/object.c
> > > index 17921c0a71..dbdab0aead 100644
> > > --- a/qom/object.c
> > > +++ b/qom/object.c
> > > @@ -370,6 +370,31 @@ static void object_post_init_with_type(Object *obj, TypeImpl *ti)
> > > }
> > > }
> > >
> > > +void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp)
> > > +{
> > > + Error *err = NULL;
> > > + int i;
> > > +
> > > + if (!props) {
> > > + return;
> > > + }
> > > +
> > > + for (i = 0; i < props->len; i++) {
> > > + GlobalProperty *p = g_ptr_array_index(props, i);
> > > +
> > > + if (object_dynamic_cast(obj, p->driver) == NULL) {
> > > + continue;
> > > + }
> > > + p->used = true;
> > > + object_property_parse(obj, p->value, p->property, &err);
> > > + if (err != NULL) {
> > > + error_prepend(&err, "can't apply global %s.%s=%s: ",
> > > + p->driver, p->property, p->value);
> > > + error_propagate(errp, err);
> > > + }
> > > + }
> > > +}
> > > +
> > > static void object_initialize_with_type(void *data, size_t size, TypeImpl *type)
> > > {
> > > Object *obj = data;
> > > diff --git a/vl.c b/vl.c
> > > index fa25d1ae2d..c06e94271c 100644
> > > --- a/vl.c
> > > +++ b/vl.c
> > > @@ -2963,7 +2963,7 @@ static void user_register_global_props(void)
> > > */
> > > static void register_global_properties(MachineState *ms)
> > > {
> > > - accel_register_compat_props(ms->accelerator);
> > > + accel_register_compat_props(ACCEL_GET_CLASS(ms->accelerator)->compat_props);
> > > machine_register_compat_props(ms);
> > > user_register_global_props();
> > > }
> > > --
> > > 2.20.0.rc1
> > >
> > >
> >
> > --
> > Eduardo
--
Eduardo
next prev parent reply other threads:[~2018-11-29 16:02 UTC|newest]
Thread overview: 94+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-27 9:27 [Qemu-devel] [PATCH for-3.2 v4 00/28] Generalize machine compatibility properties Marc-André Lureau
2018-11-27 9:27 ` [Qemu-devel] [PATCH for-3.2 v4 01/28] target/xtensa: gdbstub fix register counting Marc-André Lureau
2018-11-27 9:27 ` [Qemu-devel] [PATCH for-3.2 v4 02/28] target/xtensa: drop num_[core_]regs from dc232b/dc233c configs Marc-André Lureau
2018-11-27 9:27 ` [Qemu-devel] [PATCH for-3.2 v4 03/28] target/xtensa: xtfpga: provide default memory sizes Marc-André Lureau
2018-11-27 9:27 ` [Qemu-devel] [PATCH for-3.2 v4 04/28] MAINTAINERS: add missing xtensa patterns Marc-André Lureau
2018-11-27 9:27 ` [Qemu-devel] [PATCH for-3.2 v4 05/28] 9p: fix QEMU crash when renaming files Marc-André Lureau
2018-11-27 9:27 ` [Qemu-devel] [PATCH for-3.2 v4 06/28] MAINTAINERS: Assign some more files in the hw/arm/ directory Marc-André Lureau
2018-11-27 9:27 ` [Qemu-devel] [PATCH for-3.2 v4 07/28] MAINTAINERS: Add an ARM SMMU section Marc-André Lureau
2018-11-27 9:27 ` [Qemu-arm] [PATCH for-3.2 v4 08/28] net: cadence_gem: Remove incorrect assert() Marc-André Lureau
2018-11-27 9:27 ` [Qemu-devel] " Marc-André Lureau
2018-11-27 9:27 ` [Qemu-devel] [PATCH for-3.2 v4 09/28] tests: qdev_prop_check_globals() doesn't return "all_used" Marc-André Lureau
2018-11-27 13:40 ` Eduardo Habkost
2018-11-27 9:27 ` [Qemu-devel] [PATCH for-3.2 v4 10/28] qom: make interface types abstract Marc-André Lureau
2018-11-27 9:27 ` Marc-André Lureau
2018-11-27 13:41 ` Eduardo Habkost
2018-11-27 13:41 ` Eduardo Habkost
2018-11-27 13:55 ` Marc-André Lureau
2018-11-27 13:55 ` Marc-André Lureau
2018-11-27 9:27 ` [Qemu-devel] [PATCH for-3.2 v4 11/28] qom: make user_creatable_complete() specific to UserCreatable Marc-André Lureau
2018-11-27 13:45 ` Eduardo Habkost
2018-11-27 9:27 ` [Qemu-devel] [PATCH for-3.2 v4 12/28] accel: register global_props like machine globals Marc-André Lureau
2018-11-27 9:27 ` [Qemu-devel] [PATCH for-3.2 v4 13/28] qdev: move qdev_prop_register_global_list() to tests Marc-André Lureau
2018-11-27 9:27 ` [Qemu-devel] [PATCH for-3.2 v4 14/28] qom: remove unimplemented class_finalize Marc-André Lureau
2018-11-27 12:52 ` Eduardo Habkost
2018-11-28 17:44 ` Igor Mammedov
2018-11-27 9:27 ` [PATCH for-3.2 v4 15/28] hw: apply accel compat properties without touching globals Marc-André Lureau
2018-11-27 9:27 ` [Qemu-devel] " Marc-André Lureau
2018-11-27 19:40 ` Eduardo Habkost
2018-11-27 19:40 ` Eduardo Habkost
2018-11-27 20:02 ` Marc-André Lureau
2018-11-27 20:02 ` Marc-André Lureau
2018-11-29 16:02 ` Eduardo Habkost [this message]
2018-11-29 16:02 ` Eduardo Habkost
2018-11-28 17:49 ` Igor Mammedov
2018-11-28 17:49 ` [Qemu-devel] " Igor Mammedov
2018-11-27 9:27 ` [Qemu-arm] [PATCH for-3.2 v4 16/28] hw: apply machine " Marc-André Lureau
2018-11-27 9:27 ` [Qemu-devel] " Marc-André Lureau
2018-11-27 12:56 ` [Qemu-arm] " Eduardo Habkost
2018-11-27 12:56 ` [Qemu-devel] " Eduardo Habkost
2018-11-27 13:10 ` [Qemu-arm] " Marc-André Lureau
2018-11-27 13:10 ` [Qemu-devel] " Marc-André Lureau
2018-11-27 13:35 ` [Qemu-arm] " Eduardo Habkost
2018-11-27 13:35 ` [Qemu-devel] " Eduardo Habkost
2018-11-28 17:40 ` [Qemu-arm] " Igor Mammedov
2018-11-28 17:40 ` [Qemu-devel] " Igor Mammedov
2018-11-28 17:53 ` [Qemu-arm] " Eduardo Habkost
2018-11-28 17:53 ` [Qemu-devel] " Eduardo Habkost
2018-11-29 10:32 ` Marc-André Lureau
2018-11-29 10:32 ` Marc-André Lureau
2018-11-29 17:50 ` Eduardo Habkost
2018-11-29 17:50 ` Eduardo Habkost
2018-11-29 21:36 ` [Qemu-arm] " Marc-André Lureau
2018-11-29 21:36 ` Marc-André Lureau
2018-11-30 10:55 ` [Qemu-arm] " Igor Mammedov
2018-11-30 10:55 ` Igor Mammedov
2018-11-30 11:41 ` [Qemu-arm] " Eduardo Habkost
2018-11-30 11:41 ` Eduardo Habkost
2018-12-04 13:17 ` [Qemu-arm] " Igor Mammedov
2018-12-04 13:17 ` Igor Mammedov
2018-12-04 18:43 ` [Qemu-arm] " Eduardo Habkost
2018-12-04 18:43 ` Eduardo Habkost
2018-11-30 11:37 ` [Qemu-arm] " Igor Mammedov
2018-11-30 11:37 ` Igor Mammedov
2018-11-29 16:09 ` [Qemu-arm] " Eduardo Habkost
2018-11-29 16:09 ` [Qemu-devel] " Eduardo Habkost
2018-11-29 21:32 ` [Qemu-arm] " Marc-André Lureau
2018-11-29 21:32 ` Marc-André Lureau
2018-11-27 9:27 ` [Qemu-devel] [PATCH for-3.2 v4 17/28] hw: remove SET_MACHINE_COMPAT Marc-André Lureau
2018-11-27 9:27 ` [Qemu-devel] [PATCH for-3.2 v4 18/28] qdev: all globals are now user-provided Marc-André Lureau
2018-11-27 9:27 ` [Qemu-devel] [PATCH for-3.2 v4 19/28] qdev-props: convert global_props to GPtrArray Marc-André Lureau
2018-11-27 9:27 ` [Qemu-devel] [PATCH for-3.2 v4 20/28] qdev-props: remove errp from GlobalProperty Marc-André Lureau
2018-11-27 9:27 ` [Qemu-devel] [PATCH for-3.2 v4 21/28] qdev-props: call object_apply_global_props() Marc-André Lureau
2018-11-27 9:27 ` [Qemu-devel] [PATCH for-3.2 v4 22/28] qom: teach interfaces to implement post-init Marc-André Lureau
2018-11-27 9:27 ` [Qemu-devel] [PATCH for-3.2 v4 23/28] qom: add object_class_get_class_data() Marc-André Lureau
2018-11-27 9:27 ` [Qemu-devel] [PATCH for-3.2 v4 24/28] arm: replace instance_post_init() Marc-André Lureau
2018-11-27 9:27 ` Marc-André Lureau
2018-11-30 11:48 ` [Qemu-arm] " Igor Mammedov
2018-11-30 11:48 ` Igor Mammedov
2018-12-01 20:55 ` [Qemu-arm] " Marc-André Lureau
2018-12-01 20:55 ` Marc-André Lureau
2018-11-27 9:27 ` [Qemu-devel] [PATCH for-3.2 v4 25/28] machine: add compat-props interface Marc-André Lureau
2018-11-29 17:49 ` Eduardo Habkost
2018-11-30 12:34 ` Igor Mammedov
2018-11-30 12:57 ` Eduardo Habkost
2018-11-30 12:39 ` Igor Mammedov
2018-11-27 9:27 ` [Qemu-devel] [PATCH for-3.2 v4 26/28] hw/i386: add pc-i440fx-3.2 & pc-q35-3.2 Marc-André Lureau
2018-11-27 13:01 ` Eduardo Habkost
2018-11-27 9:28 ` [Qemu-arm] [PATCH for-3.2 v4 27/28] hw/arm/virt: add virt-3.2 machine type Marc-André Lureau
2018-11-27 9:28 ` [Qemu-devel] " Marc-André Lureau
2018-11-27 9:28 ` [Qemu-devel] [PATCH for-3.2 v4 28/28] hostmem: use object id for memory region name with >= 3.1 Marc-André Lureau
2018-11-27 9:53 ` [Qemu-devel] [PATCH for-3.2 v4 00/28] Generalize machine compatibility properties Greg Kurz
2018-11-27 9:58 ` Marc-André Lureau
2018-11-29 1:35 ` no-reply
2018-11-29 1:45 ` no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181129160206.GL18284@habkost.net \
--to=ehabkost@redhat.com \
--cc=afaerber@suse.de \
--cc=anthony.perard@citrix.com \
--cc=imammedo@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.