From: Paolo Bonzini <pbonzini@redhat.com>
To: Claudio Fontana <cfontana@suse.de>
Cc: Eduardo Habkost <ehabkost@redhat.com>,
qemu-devel <qemu-devel@nongnu.org>
Subject: Re: all class init functions for all types in QEMU are called in select_machine(). Expected?
Date: Fri, 12 Mar 2021 10:46:21 +0100 [thread overview]
Message-ID: <b852304c-2123-f84f-2667-3682e7f48569@redhat.com> (raw)
In-Reply-To: <bdc8dbaf-8d63-833a-3e57-7e823a321486@suse.de>
On 12/03/21 10:31, Claudio Fontana wrote:
> Hello Paolo and all,
>
> while debugging a class init ordering issue, I noticed that
>
> _all_ class init functions for all types registered in the QEMU QOM are called in select_machine().
> Expected?
>
> In particular it happens here:
>
> static MachineClass *select_machine(void)
> {
> GSList *machines = object_class_get_list(TYPE_MACHINE, false);
>
>
> object_class_get_list() ->
> object_class_foreach() ->
> g_hash_table_foreach() ->
> object_class_foreach_tramp ->
> type_initialize(type);
>
> Is this really desired? It looks suspect to me.
It is not a problem because class_init should be idempotent. Changing
QEMU to not do this would not be impossible, but most likely not worth
the effort. To do this, I think one would have to reimplement all of
object_class_dynamic_cast to operate on TypeInfos (so for example walk
all interfaces in the type info instead of using class->interfaces).
> If not here, where should be the right place, for example, for CPU class inits to be called?
The first time they're used, upon a call to one of object_new,
object_initialize, object_class_get_list or object_class_foreach.
> At the very least I would put a comment there around the beginning of select_machine() saying:
>
> /* all types, all classes in QOM are initialized here, as a result of the object_class_get_list call */
No, it's just a side effect that is not (or should not) be visible.
Paolo
next prev parent reply other threads:[~2021-03-12 9:48 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-12 9:31 all class init functions for all types in QEMU are called in select_machine(). Expected? Claudio Fontana
2021-03-12 9:45 ` Philippe Mathieu-Daudé
2021-03-12 9:58 ` Claudio Fontana
2021-03-12 10:07 ` Paolo Bonzini
2021-03-12 10:25 ` Claudio Fontana
2021-03-12 10:39 ` Paolo Bonzini
2021-03-12 11:51 ` Claudio Fontana
2021-03-12 12:02 ` Paolo Bonzini
2021-03-12 13:40 ` Claudio Fontana
2021-03-12 14:00 ` Claudio Fontana
2021-03-12 17:04 ` Paolo Bonzini
2021-03-12 17:24 ` Claudio Fontana
2021-03-12 17:30 ` Paolo Bonzini
2021-03-12 9:46 ` Paolo Bonzini [this message]
2021-03-12 9:49 ` Claudio Fontana
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=b852304c-2123-f84f-2667-3682e7f48569@redhat.com \
--to=pbonzini@redhat.com \
--cc=cfontana@suse.de \
--cc=ehabkost@redhat.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).