qemu-devel
[Top][All Lists]
Advanced

[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: Paolo Bonzini
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
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]