From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Andreas Färber" <afaerber@suse.de>
Subject: [Qemu-devel] Object instantiation vs. device realization: what to do when?
Date: Thu, 14 Feb 2019 17:21:08 +0100 [thread overview]
Message-ID: <87wom249zf.fsf@dusky.pond.sub.org> (raw)
One of qdev's perennial sources of confusion is what to do at object
instantiation time, i.e. in TypeInfo::instance_init(), and what to do at
device realization time, i.e. in DeviceClass::realize(). qdev-core.h's
comment falls short:
* # Realization #
* Devices are constructed in two stages,
* 1) object instantiation via object_initialize() and
* 2) device realization via #DeviceState:realized property.
* The former may not fail (and must not abort or exit, since it is called
* during device introspection already), and the latter may return error
* information to the caller and must be re-entrant.
* Trivial field initializations should go into #TypeInfo.instance_init.
As usual, "trivial" was too trivial to explain; the reader is trusted to
figure it out himself. Well, I'm afraid I'm not to be trusted.
The easy part is "can fail means it's not trivial", because
::instance_init() must not fail.
What about side effects? If you already understand how introspection
works, or perhaps even if you read carefully and paranoidly, then "since
it is called during device introspection already" implies "guest-visible
side-effects would be disastrous". So guest-visible side-effect also
means it's not trivial.
* Operations depending on @props static properties should go into @realize.
Actually, these *have* to go into realize(), because properties get set
between ::instance_init() and ::realize().
Even if I had a precise definition of "trivial field initializations",
I'd still wonder where operations should go that are neither such
trivial field initializations, nor depend on @props.
* After successful realization, setting static properties will fail.
*
* As an interim step, the #DeviceState:realized property can also be
* set with qdev_init_nofail().
* In the future, devices will propagate this state change to their children
* and along busses they expose.
This sentence is five years old. Any progress? If not, any intentions
to make progress?
* The point in time will be deferred to machine creation, so that values
* set in @realize will not be introspectable beforehand. Therefore devices
* must not create children during @realize; they should initialize them via
* object_initialize() in their own #TypeInfo.instance_init and forward the
* realization events appropriately.
This is mostly greek to me. Pity the developer who knows less about
qdev than I do.
*
* Any type may override the @realize and/or @unrealize callbacks but needs
* to call the parent type's implementation if keeping their functionality
* is desired. Refer to QOM documentation for further discussion and examples.
"Refer to QOM documentation"... okay, but this comment needs to make
sense without having to read the 3000+ lines under include/qom/ (which
by the way requires finding it first; I'd expect the naive reader to
look under docs/ and draw a blank).
Can we come up with clear guidelines on how to split work between
::instance_init() and ::realize()?
next reply other threads:[~2019-02-14 16:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-14 16:21 Markus Armbruster [this message]
2019-02-14 16:33 ` [Qemu-devel] Object instantiation vs. device realization: what to do when? Peter Maydell
2019-02-15 7:03 ` Thomas Huth
2019-02-18 19:08 ` Markus Armbruster
2019-02-14 16:58 ` Paolo Bonzini
2019-02-18 16:01 ` Markus Armbruster
2019-02-18 16:38 ` Paolo Bonzini
2019-02-19 10:38 ` Igor Mammedov
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=87wom249zf.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=afaerber@suse.de \
--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.