All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [RFC][PATCH 0/21] QEMU Object Model
Date: Tue, 26 Jul 2011 14:59:10 +0200	[thread overview]
Message-ID: <4E2EBA1E.90006@redhat.com> (raw)
In-Reply-To: <1311558293-5855-1-git-send-email-aliguori@us.ibm.com>

On 07/25/2011 03:44 AM, Anthony Liguori wrote:
> Hi,
>
> This series is the rough beginnings of the QEMU Object Model.  This is basically
> qdev generalized on steroids.
>
> This series includes the core infrastructure, a strawman Device type, and
> the beginnings of the conversion of CharDriverState.  This is in a rougher
> state than I would like it to be but I wanted to get the concepts on the list
> as soon as possible.
>
> My plan is to drop the Device parts from future versions of the series and just
> focus on backends to start with.

I am not sure of how the Device and Char/Block/NetworkDriver bits relate 
to each other.  It seems to me that they are two very different families 
of objects, and we should treat them differently.

For host devices (Char/Block/Network) we have a relatively simple 
interface but we need a richer way to create and destroy the objects at 
runtime.  We have it already for block and network, we don't for char, 
but it is done ad hoc for each hierarchy.  We do not have a deep 
hierarchy, in fact there is no hierarchy at all (only one abstract class 
per subsystem).

Honestly, it is not too bad.  It may not be the cleanest code, but is it 
worth the kind of ramifications that your patch has?  Of course, the 
answer could be "yes" if the same model can be applied to devices. 
Devices do have the same introspection needs more or less, and I like 
your ideas there.  However, the requirements are very different in terms 
of composition.

Also because there is no hierarchy, composition in host devices can be 
done very easily.  A decorator for char/block devices, such as a "tee" 
device, can treat the wrapped object(s) the same independent of the 
actual class.  A simple vtable works very well.  GObject would also do 
well, unifying the introspection at the cost of significantly more 
boilerplate.

     (Of course, we could rewrite QEMU in Vala).

For *guest* devices, however, this is not the case.  The PCI host needs 
to know that the device on the other end is a PCI device.  Even the 
simplest bus, for example I2C, has methods defined on its children.

So, the most important point, it seems to me, is to support composition 
effectively.  There need not be any hierarchy at all---not even the 
two-level hierarchy we have now, everything can inherit from 
DeviceState---but the combination between devices must be:

1) in a flexible manner, so that it can express complex topologies (as 
long as "plugs" and "sockets" have the same shape of course);

2) in an easily introspectable manner, so that migration and QMP and so 
on work very well in the presence of said topologies;

3) in a precise manner, so that the two devices being connected can 
interact effectively;


The current qdev fails completely at (1).  (2) is very limited if you 
consider qdev only; qdev+VMState is at least decent, though nowhere near 
the potential of QOM.

However, qdev gets (3) right by making interaction between the parent 
and the child go through a bus object that knows the details of both. 
In particular, bus objects and their vtable structures are very 
effective in qdev because they provide flexibility and avoid impedence 
mismatch, with a very limited amount of boilerplate.

By contrast, the plug/socket model in QOM achieves (1) and (2), but in 
my opinion it fails at (3).  The model for example is not effective in 
specifying the properties of the socket, which are roughly are the bus 
properties and the fields added by DeviceState abstract subclasses in 
the current qdev; it is not clear where they would live in QOM.  Perhaps 
in the parent device or in an intermediate object between the parent and 
the child; if the latter, it looks like a lot of pointer chasing and a 
conversion nightmare.


Based on my earlier conversations with Peter, I thought a bit on how to 
do more incremental changes to qdev in order to overcome the 
inflexibility.  Here is a rough overview of the steps:


1) make properties more flexible.  In particular, we *absolutely* need 
array properties, either static or dynamic.  The current special casing 
of GPIO pins is required exactly because we do not have arrays of 
properties.

Also, since arrays occur a lot in the device state, array properties 
would also be required to be able to introspect on run-time properties 
(which are now part of VMState only).  However, I am not going to 
consider run-time introspection much more.  It is "a simple matter of 
programming" if your general introspection design is done right.


2) add more kinds of first-class (user specifiable) properties.  GPIO 
pins, for example, which are already part of qdev but cannot be 
specified by the user on the command line.  Possibly memory regions too. 
  Anything that can be used to configure a device (with respect to the 
main bus or to its parent) should be a property.


3) at this point, you can get rid of the specialties of SysBus devices. 
  IRQs are an array of GPIO properties, same for memory regions.  SysBus 
devices can use a naked DeviceState structure.

At this point, many embedded devices could be entirely described in 
terms of configuration files, except for legacy options (-serial kind) 
and for the few devices that attach directly to the CPU.  This without 
the need to define artificial buses that do not exist in real hardware.


4) add support for compound properties.  A compound properties is such 
that you define a property named (coincidence...) "bus" and you get 
automatically "bus.parent", "bus.addr", "bus.romfile", "bus.rombar" etc.


5) convert buses to compound properties.  Rather than inheriting from 
PCIDevice, a PCI device would inherit straight from DeviceState and 
include a PCIDevice struct that defines the backlink from a device to 
its parent.  Note that since we're using C, this is not a big change 
from what we're doing now!  (Inheritance by containment is a special 
case of containment.)  And it allows to define very flexibly a device 
that would have to sit on two or more buses in the current qdev model. 
More importantly, it keeps the effectiveness of the qbus ops model, 
while removing the constraint of a tree topology.


It is only when this is done, that we should reconsider introspection 
and see if it is useful/sensible to unify the host and guest device 
object models.

Because the host models we have now, with all the defects they may have, 
*work*.  The guest models hardly work for anything but PCs, and even 
then only for the subset of devices which are interesting to 
hot-plug/unplug.  And so it is from them that we should start designing.

Thoughts?

Paolo

  parent reply	other threads:[~2011-07-26 12:59 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-25  1:44 [Qemu-devel] [RFC][PATCH 0/21] QEMU Object Model Anthony Liguori
2011-07-25  1:44 ` [Qemu-devel] [PATCH 01/21] qom: add make infrastructure Anthony Liguori
2011-07-25  1:44 ` [Qemu-devel] [PATCH 02/21] qom: convert QAPI to use Qconfig build system Anthony Liguori
2011-07-25  1:44 ` [Qemu-devel] [PATCH 03/21] qom: Add core type system Anthony Liguori
2011-07-25  1:44 ` [Qemu-devel] [PATCH 04/21] qom: add Plug class Anthony Liguori
2011-07-25  1:44 ` [Qemu-devel] [PATCH 05/21] plug: add Plug property type Anthony Liguori
2011-07-25  1:44 ` [Qemu-devel] [PATCH 06/21] plug: add socket " Anthony Liguori
2011-07-25  1:44 ` [Qemu-devel] [PATCH 07/21] plug: add generated property types Anthony Liguori
2011-07-25  1:44 ` [Qemu-devel] [PATCH 08/21] qom: add plug_create QMP command Anthony Liguori
2011-07-25  1:44 ` [Qemu-devel] [PATCH 09/21] qom: add plug_list " Anthony Liguori
2011-07-25  1:44 ` [Qemu-devel] [PATCH 10/21] qom: add plug_get " Anthony Liguori
2011-07-25  1:44 ` [Qemu-devel] [PATCH 11/21] qom: add plug_set " Anthony Liguori
2011-07-25  1:44 ` [Qemu-devel] [PATCH 12/21] qom: add plug_list_props " Anthony Liguori
2011-07-25  1:44 ` [Qemu-devel] [PATCH 13/21] qom: add plug_destroy command Anthony Liguori
2011-07-25  1:44 ` [Qemu-devel] [PATCH 14/21] qom: add example qsh command Anthony Liguori
2011-07-25  1:44 ` [Qemu-devel] [PATCH 15/21] qom: add Device class Anthony Liguori
2011-07-27 15:10   ` Peter Maydell
2011-07-27 16:07     ` Anthony Liguori
2011-07-25  1:44 ` [Qemu-devel] [PATCH 16/21] qom-devices: add a Pin class Anthony Liguori
2011-07-25  1:44 ` [Qemu-devel] [PATCH 17/21] qom: add CharDriver class Anthony Liguori
2011-07-25  1:44 ` [Qemu-devel] [PATCH 18/21] qom-chrdrv: add memory character driver Anthony Liguori
2011-07-25  1:44 ` [Qemu-devel] [PATCH 19/21] qom-chrdrv: add Socket base class Anthony Liguori
2011-07-25  1:44 ` [Qemu-devel] [PATCH 20/21] qom-chrdrv: add TCPServer class Anthony Liguori
2011-07-25  1:44 ` [Qemu-devel] [PATCH 21/21] qom-chrdrv: add UnixServer Anthony Liguori
2011-07-25 11:21 ` [Qemu-devel] [RFC][PATCH 0/21] QEMU Object Model Kevin Wolf
2011-07-25 12:45   ` Anthony Liguori
2011-07-25 13:08     ` Kevin Wolf
2011-07-25 13:10       ` Anthony Liguori
2011-07-26 12:59 ` Paolo Bonzini [this message]
2011-07-26 14:02   ` Anthony Liguori
2011-07-26 14:35     ` Paolo Bonzini
2011-07-26 15:34       ` Anthony Liguori
2011-07-26 18:26         ` Paolo Bonzini
2011-07-26 19:23           ` Anthony Liguori
2011-07-27  8:55             ` Paolo Bonzini
2011-07-27 12:48               ` Anthony Liguori
2011-07-27 15:33                 ` Paolo Bonzini
2011-07-27 16:19                   ` Anthony Liguori
2011-07-27 16:28                   ` Anthony Liguori
2011-07-27 18:51                     ` Paolo Bonzini
2011-07-27 20:01                       ` Anthony Liguori
2011-07-28  7:36                         ` Paolo Bonzini
2011-07-28 12:46                           ` Anthony Liguori
2011-07-28 13:50                             ` Paolo Bonzini
2011-07-28 14:03                               ` Anthony Liguori
2011-07-28 14:41                                 ` Paolo Bonzini
2011-07-28 15:04                                   ` Anthony Liguori
2011-07-28 15:47                                     ` Paolo Bonzini
2011-07-28 17:59                                       ` Anthony Liguori
2011-07-29  7:19                                         ` Paolo Bonzini
2011-07-27 21:33     ` Peter Maydell
2011-07-27 22:31       ` Anthony Liguori

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=4E2EBA1E.90006@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=aliguori@us.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.