[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: all class init functions for all types in QEMU are called in select_
From: |
Claudio Fontana |
Subject: |
Re: all class init functions for all types in QEMU are called in select_machine(). Expected? |
Date: |
Fri, 12 Mar 2021 10:49:38 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 |
On 3/12/21 10:46 AM, Paolo Bonzini wrote:
> 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.
Right, this is what I would have expected. Instead everything known to QOM at
that time (there is more stuff added later on),
is initialized right there.
>
>> 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
>
Well it's an interesting side effect to me, seems useful to know (add a comment
at least) when debugging.
Can be found out quickly, but why hide it..
Ciao,
Claudio
- Re: all class init functions for all types in QEMU are called in select_machine(). Expected?, (continued)
- Re: all class init functions for all types in QEMU are called in select_machine(). Expected?, Claudio Fontana, 2021/03/12
- Re: all class init functions for all types in QEMU are called in select_machine(). Expected?, Paolo Bonzini, 2021/03/12
- Re: all class init functions for all types in QEMU are called in select_machine(). Expected?, Claudio Fontana, 2021/03/12
- Re: all class init functions for all types in QEMU are called in select_machine(). Expected?, Paolo Bonzini, 2021/03/12
- Re: all class init functions for all types in QEMU are called in select_machine(). Expected?, Claudio Fontana, 2021/03/12
- Re: all class init functions for all types in QEMU are called in select_machine(). Expected?, Claudio Fontana, 2021/03/12
- Re: all class init functions for all types in QEMU are called in select_machine(). Expected?, Paolo Bonzini, 2021/03/12
- Re: all class init functions for all types in QEMU are called in select_machine(). Expected?, Claudio Fontana, 2021/03/12
- Re: all class init functions for all types in QEMU are called in select_machine(). Expected?, Paolo Bonzini, 2021/03/12
Re: all class init functions for all types in QEMU are called in select_machine(). Expected?, Paolo Bonzini, 2021/03/12
- Re: all class init functions for all types in QEMU are called in select_machine(). Expected?,
Claudio Fontana <=