From: Markus Armbruster <armbru@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"QEMU Developers" <qemu-devel@nongnu.org>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Eduardo Habkost" <ehabkost@redhat.com>
Subject: Re: [Qemu-devel] qdev properties vs qom object properties
Date: Tue, 06 Jun 2017 09:22:09 +0200 [thread overview]
Message-ID: <87vao91sym.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <87f8f3e0-754d-7de5-4c2a-4b0930adb7fe@redhat.com> (Paolo Bonzini's message of "Mon, 5 Jun 2017 15:32:56 +0200")
Paolo Bonzini <pbonzini@redhat.com> writes:
> On 05/06/2017 15:10, Peter Maydell wrote:
>> I perpetually get confused about qdev properties vs QOM object
>> properties.
>>
>> Why do we have both of these APIs?
>> How do they interact?
>
> qdev properties are just a wrapper around QOM object properties, taking
> care of:
>
> - not allowing to set the property after realize
>
> - providing default values
>
> - letting people use the familiar DEFINE_PROP_* array syntax
It's not just familiar, it's also much easier to reason about, because
it's *data*, not code. For instance, when I see DEFINE_PROP_UINT8(), I
immediately know it's uint8_t. With QOM, I commonly have to figure out
WTF the getter and setter will do at run time. I spent a few hours last
week doing just that, and it sure feels like a severe case of OOPitis to
me.
Message-ID: <877f1ep4xv.fsf@dusky.pond.sub.org>
https://lists.gnu.org/archive/html/qemu-devel/2017-05/msg04353.html
> - pretty printing for "info qtree" (which right now is only used by PCI
> devfn and vlan properties)
>
>> Which is the recommended one for new device code?
>> Do we have a transition plan for old code?
>> Where should I be looking for the documentation on this?
>
> There is no transition plan, qdev properties are not going to go away
> soon unless someone actually makes a plan.
Any plan to replace properties defined as data by properties defined in
code will be a hard sell with me. I think we should go back to data
unless the problem at hand *requires* code.
> Now that there are QOM class properties, it would actually be feasible
> to make qdev_property_add_static define QOM properties on the class
> rather than the object. In other words, instead of
>
> dc->props = virtio_serial_pci_properties;
>
> you'd have something like:
>
> qdev_add_class_properties(klass, usb_tablet_properties);
>
> or even inlined calls like the following:
>
> QDEV_DEFINE_CLASS_PROP_UINT32(klass, "usb_version", USBHIDState,
> usb_version, 2);
> QDEV_DEFINE_CLASS_PROP_STRING(klass, "display", USBHIDState,
> display);
> QDEV_DEFINE_CLASS_PROP_UINT32(klass, "head", USBHIDState, head, 0);
Sufficiently restricted code can be almost as simple as data. Still,
why not make it data? Your examples scream to be data.
>> For a specific example, I see that target/arm is the only code
>> using qdev_property_add_static(), but there's no indication
>> that the function is deprecated or what the right thing to be
>> doing instead is. Any suggestions?
>
> The weird thing in ARM code is that the set of properties depends on the
> CPU model. That's the only reason why it uses
> qdev_property_add_static() as far as I can see.
>
> Paolo
next prev parent reply other threads:[~2017-06-06 7:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-05 13:10 [Qemu-devel] qdev properties vs qom object properties Peter Maydell
2017-06-05 13:32 ` Paolo Bonzini
2017-06-05 13:39 ` Eduardo Habkost
2017-06-06 7:22 ` Markus Armbruster [this message]
2017-06-06 8:48 ` Gerd Hoffmann
2017-06-05 13:36 ` Eduardo Habkost
2017-06-05 13:44 ` Paolo Bonzini
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=87vao91sym.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=ehabkost@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is 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.