qemu-devel
[Top][All Lists]
Advanced

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

Re: Difference between 'current_machine' vs MACHINE(qdev_get_machine())


From: Like Xu
Subject: Re: Difference between 'current_machine' vs MACHINE(qdev_get_machine())
Date: Thu, 9 Jan 2020 23:24:30 +0800
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1

On 2020/1/9 20:01, Paolo Bonzini wrote:
On 09/01/20 12:23, Philippe Mathieu-Daudé wrote:


     current_machine =
MACHINE(object_new_with_class(OBJECT_CLASS(machine_class)));
     object_property_add_child(object_get_root(), "machine",
                               OBJECT(current_machine), &error_abort);

The bigger user of 'current_machine' is the accel/KVM code.

Recently in a0628599f..cc7d44c2e0 "Replace global smp variables with
machine smp properties" we started to use MACHINE(qdev_get_machine()).

qdev_get_machine() resolves the machine in the QOM composition tree.
I am confused by this comment:

   /* qdev_get_machine() can return something that's not TYPE_MACHINE
    * if this is one of the user-only emulators; in that case there's
    * no need to check the ignore_memory_transaction_failures board flag.
    */

Following a0628599f..cc7d44c2e0, a5e0b33119 use 'current_machine' again.

What are the differences between both form, when should we use one or
another (or can we use a single one?). Can this break user-only mode?

I would always use MACHINE(qdev_get_machine()), espeecially outside
vl.c.  Ideally, current_machine would be static within vl.c or even
unused outside the object_property_add_child() that you quote above.

Most of the times, I noticed from a quick grep, we actually want to
access the accelerator, not the machine, so we could add a
qemu_get_accelerator() wrapper that does
MACHINE(qdev_get_machine())->accelerator.

Paolo


I prefer to use MACHINE(qdev_get_machine()) wherever possible.

However, the qdev_get_machine() would return non TYPE_MACHINE object if:
- call qdev_get_machine() before we do "object_property_add_child(object_get_root(), "machine", OBJECT(current_machine), &error_abort);" in vl.c;
- or in the context with '#ifdef CONFIG_USER_ONLY';

Thanks,
Like Xu




reply via email to

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