qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: instance_init() and the realize() functions


From: Liviu Ionescu
Subject: Re: instance_init() and the realize() functions
Date: Sat, 18 Jul 2020 13:09:34 +0300


> On 18 Jul 2020, at 12:43, Peter Maydell <peter.maydell@linaro.org> wrote:
> 
> Note that for a lot
> of device state struct members (where they correspond to guest
> registers state), you want to set their values in the
> device's reset method, not in instance_init or realize.
> That's because the guest-visible register state needs to
> be set back to its initial value on a system reset anyway,
> and QEMU guarantees that we will reset a device before
> first use.

Yes, that's a good point, but must be used with caution; since .reset is called 
**after** .realize, if the dynamically allocated structures are not set to 
zero, leaving state members uninitialised up to .reset is risky, it may lead to 
unexpected behaviour during .realize or other parts of the code.

That's why I mentioned that .instance_init should ensure that all members have 
default values and properties associated with them, such that later code, like 
.realize, has a deterministic behaviour.


Of course, for consistent results, both .instance_init and .reset can call a 
common internal function.


Regards,

Liviu




reply via email to

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