Skip to contentSkip to conversation

Unified device model

Qemu-devel Stanislav Shwartsman 7 participants 15 messages Apr 8, 2006 – Apr 9, 2006

lore
Share & tools
lore
#0 lore raw

Hello All,

It is not a secret that all open source emulators (QEMU, Bochs, Xen) use the same emulated devices and mostly copy-paste their emulation one from another.

I don't know who originally wrote the device models but now Bochs and QEMU maintain two similar implementations of the same devices.

If one of the teams fixes the implementation or add functionality, another team mostly copy-paste the changes to their model.

Xen project forked from QEMU and want to stay in touch with Bochs and QEMU device models and contribute the changes to make the model better.

I am wondering about making unified device models architecture for open source simulators.

The device models will be used in QEMU, Bochs, Xen and other open source simulators which would use the device models.

I know about two professional teams working in simulation which would like to use these device models in their simulator and

could enrich the device library with new devices device interfaces, for example with AGP and 3D graphics.

Bochs is already in middle of definition of new true pluginable devices architecture.

In near future Bochs devices will fully separatable from Bochs binary and when could be developed separately from Bochs.

I call to QEMU developers join to this project and come with their requirements to plugin architecture.

I don't know if QEMU supports device plugins now but I would like to see QEMU a part of this idea,

I would like to get single device shared library which could be loaded to Bochs and QEMU and work perfectly for both.

This will eliminate the need to maintain two separate implementations of the same devices,

these implementations very fast will converge to single one, C or C++ based, Bochs or QEMU based, doesn't matter.

I am listening for your opinions !

Thanks,

Stanislav

#1 lore raw
Quoted 7 lines · Stanislav Shwartsman

Hello All,

It is not a secret that all open source emulators (QEMU, Bochs, Xen) use the same emulated devices and mostly copy-paste their emulation one from another.

While from my understanding Xen uses qemu's hardware emulation for it's VT support, this is not really true otherwise.

The devices emulated by qemu and bochs are quite similar, but the code looks completely different (appears to be a ground-up rewrite).

Quoted 6 lines

I don't know who originally wrote the device models but now Bochs and QEMU maintain two similar implementations of the same devices.

If one of the teams fixes the implementation or add functionality, another team mostly copy-paste the changes to their model.

I don't know how well Bochs and qemu keep in touch with each other. I've never seen a Bochs developer announce themselves here, though.

Quoted 3 lines

Xen project forked from QEMU and want to stay in touch with Bochs and QEMU device models and contribute the changes to make the model better.

Not true. Xen is completely independent. Unless you are refering to the hardware emulation - which I believe is qemu's stuff.

Quoted 7 lines

I am wondering about making unified device models architecture for open source simulators.

The device models will be used in QEMU, Bochs, Xen and other open source simulators which would use the device models.

I would support this idea, if it was possible.

Quoted 9 lines

I know about two professional teams working in simulation which would like to use these device models in their simulator and

could enrich the device library with new devices device interfaces, for example with AGP and 3D graphics.

Bochs is already in middle of definition of new true pluginable devices architecture.

This is welcome news.

Quoted 9 lines

In near future Bochs devices will fully separatable from Bochs binary and when could be developed separately from Bochs.

I call to QEMU developers join to this project and come with their requirements to plugin architecture.

I don't know if QEMU supports device plugins now but I would like to see QEMU a part of this idea,

I would as well.

Quoted 12 lines

I would like to get single device shared library which could be loaded to Bochs and QEMU and work perfectly for both.

This will eliminate the need to maintain two separate implementations of the same devices,

these implementations very fast will converge to single one, C or C++ based, Bochs or QEMU based, doesn't matter.

I am listening for your opinions !

The primary reason given for not making a plugin API for qemu hardware emulation is that qemu isn't stable enough - the code changes too often to support a stable API.

Still, it might be easier to add support for plugins based on an external API, rather than trying to keep a qemu plugin API consistent.

Quoted 10 lines

Thanks,

Stanislav

_______________________________________________
Qemu-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/qemu-devel

Signature · 2 lines
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.
#2 lore raw

Hi,

Quoted 11 lines · Jim C. Brown
Quoted 4 lines · Stanislav Shwartsman

It is not a secret that all open source emulators (QEMU, Bochs, Xen) use the same emulated devices and mostly copy-paste their emulation one from another.

While from my understanding Xen uses qemu's hardware emulation for it's VT support, this is not really true otherwise.

The devices emulated by qemu and bochs are quite similar, but the code looks completely different (appears to be a ground-up rewrite).

IIRC bochs does it in C++. Which makes it rather impossible to share code :-(

Ciao,
Dscho

#3 lore raw

Well, not completely impossible, but it would require some really ugly "glue" code. And, the glue would have to happen outside of QEMU (i.e. like in the BOCHS code), to keep C++ out of QEMU.

To have a truly portable API, it should definitely have C language "bindings". I'm sure this could be added to the BOCHS implementation somehow if this is important.

- Leo Reiter

Quoted 4 lines · Johannes Schindelin

IIRC bochs does it in C++. Which makes it rather impossible to share code :-(

Ciao,
Dscho

Signature · 8 lines
Leonardo E. Reiter
Vice President of Product Development, CTO

Win4Lin, Inc.
Virtual Computing from Desktop to Data Center
Main: +1 512 339 7979
Fax: +1 512 532 6501
http://www.win4lin.com
#4 lore raw

Currently Bochs plugins APCI already begins with such C-language bindings. But inside the device is C++ based and derives from Bochs device model. It has the same log writer and debugging interface as any other Bochs module but nothing more.

Could you look into the Bochs devices code and plugin code, I think you could say how much it is compatible fro QEMU and if there is something that we should consider to change ...

Stanislav

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Leonardo E. Reiter
Sent: Saturday, April 08, 2006 9:27 PM
To: [email protected]
Subject: Re: [Qemu-devel] Unified device model

Well, not completely impossible, but it would require some really ugly "glue" code. And, the glue would have to happen outside of QEMU (i.e. like in the BOCHS code), to keep C++ out of QEMU.

To have a truly portable API, it should definitely have C language "bindings". I'm sure this could be added to the BOCHS implementation somehow if this is important.

- Leo Reiter

Quoted 5 lines · Johannes Schindelin

IIRC bochs does it in C++. Which makes it rather impossible to share code :-(

Ciao,
Dscho

Signature · 14 lines
Leonardo E. Reiter
Vice President of Product Development, CTO

Win4Lin, Inc.
Virtual Computing from Desktop to Data Center
Main: +1 512 339 7979
Fax: +1 512 532 6501
http://www.win4lin.com


_______________________________________________
Qemu-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/qemu-devel
#5 lore raw
In reply to Johannes Schindelin
Quoted 6 lines · Johannes Schindelin

IIRC bochs does it in C++. Which makes it rather impossible to share code :-(

Ciao,
Dscho

This is why I guessed qemu was a rewrite-from-scratch - C++ code is forbidden in qemu.

Fortunately this does not prevent a properly designed binary plugin API.

Signature · 2 lines
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.
#6 lore raw
In reply to Jim C. Brown

Hi again,

Quoted 9 lines
Quoted 3 lines

It is not a secret that all open source emulators (QEMU, Bochs, Xen) use the same emulated devices and mostly copy-paste their emulation one from another.

While from my understanding Xen uses qemu's hardware emulation for it's VT support, this is not really true otherwise.

The devices emulated by qemu and bochs are quite similar, but the code looks completely different (appears to be a ground-up rewrite).

I am talking about the device models only. Inside CPU emulation QEMU, Bochs and Xen are completely different, but they use the same devices for full system emulation and they most likely want to move forward together. The devices system of QEMU and Bochs become outdate, it is required to add ACPI compliance and emulate new modern ACPI compatible devices, currently emulated i440FX already not so represent the real life and most of the modern OSes already have no support for it.

Quoted 7 lines
Quoted 4 lines

I don't know who originally wrote the device models but now Bochs and QEMU maintain two similar implementations of the same devices. If one of the teams fixes the implementation or add functionality, another team mostly copy-paste the changes to their model.

I don't know how well Bochs and qemu keep in touch with each other. I've never seen a Bochs developer announce themselves here, though.

So may we should ;)
At least I see the code changes from Bochs migrating to QEMU and vise versa when I am looking into the code.

Quoted 5 lines
Quoted 2 lines

Xen project forked from QEMU and want to stay in touch with Bochs and QEMU device models and contribute the changes to make the model better.

Not true. Xen is completely independent. Unless you are refering to the hardware emulation - which I believe is qemu's stuff.

I know that it is completely independent project. But their device models could be called separate project Xen-HWEMU and it is fork from QEMU.

Quoted 6 lines
Quoted 4 lines

I am wondering about making unified device models architecture for open source simulators.
The device models will be used in QEMU, Bochs, Xen and other open source simulators which would use the device models.

I would support this idea, if it was possible.

Why not ?
You always could consider to add simple modules C++ to QEMU or build C++ device -> C device interface bridge ...
I don't know all the possibilities, but I am sure there are more.

Quoted 8 lines
Quoted 6 lines

I know about two professional teams working in simulation which would like to use these device models in their simulator and
could enrich the device library with new devices device interfaces, for example with AGP and 3D graphics.
Bochs is already in middle of definition of new true pluginable devices architecture.

This is welcome news.

Currently we are thinking about making user-plugin PCI devices and when later user-plugin for any device. The C++ hierarchy for now might be:
bx_devmodel_c - bx_pcidev_c - bx_user_pcidev_c

The plans are to take one of the Bochs PCI devices and convert it into user-level plugin which should not be compiled with Bochs and even not known at compile time, but loaded at runtime if selected in runtime config file. When any other device models could be added, even with closed-sources and commercial licenses.

Quoted 6 lines

The primary reason given for not making a plugin API for qemu hardware emulationis that qemu isn't stable enough - the code changes too often to support a stable API.

Still, it might be easier to add support for plugins based on an external API, rather than trying to keep a qemu plugin API consistent.

Ok, I didn't knew that QEMU is so unstable. But at least there are several trivial requirements from plugin architecture which you could mention here and I am still not thought about it. I know, basically I am writing the definition in my idle time and Volker supporting me. But it is not enough
...

Thanks,
Stanislav

#7 lore raw
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines

I am wondering about making unified device models architecture for open source simulators.
The device models will be used in QEMU, Bochs, Xen and other open source simulators which would use the device models.

I would support this idea, if it was possible.

Why not ?
You always could consider to add simple modules C++ to QEMU or build C++ device -> C device interface bridge ...

I think to be acceptable to qemu (and probably also for Xen) the devices would have to be written in C. C++ is more pain that it's worth in this context. Of course there's no reason why we couldn't use the subset of C that's also valid C++. You could also write C++ wrappers round the interface for bochs to use.

I'm not a fan of binary plugins (for the same reasons I'm don't like binary kernel modules), and don't think there's any real need to them. I can't see any good reasons why open source devices would need to be broken out into a separate shared library.

If you do want to accommodate proprietary binary plugins then C++ is a really bad idea. The C++/libstdc++ ABI simply isn't stable enough to make this a realistic option.

Paul

#8 lore raw
Quoted 6 lines · Paul Brook

I think to be acceptable to qemu (and probably also for Xen) the devices would have to be written in C. C++ is more pain that it's worth in this context. Of course there's no reason why we couldn't use the subset of C that's also valid C++. You could also write C++ wrappers round the interface for bochs to use.

Same here.

Quoted 2 lines

I'm not a fan of binary plugins (for the same reasons I'm don't like binary kernel modules), and don't think there's any real need to them.

A binary plugin API and a source plugin API (one that requires each driver device to be recompiled for each of the platforms (Xen, qemu, bochs, etc.) would probably be equally hard to design and maintain.

With a binary plugin API you at least win out.

Quoted 4 lines

I can't see
any good reasons why open source devices would need to be broken out into a separate shared library.

I think the case was already made for this.

Xen's hardware emulation, while based on qemu's, is already ahead in several aspects. A separate library would make it more convenient for these changes to be shared back with qemu. Or with E/OS.

This is actually a completely separate issue from a unified device driver API (as qemu could support the API, but only in source code form, or could require that drivers be linked in statically, etc) and should be recognized as such.

Quoted 3 lines

If you do want to accommodate proprietary binary plugins then C++ is a really bad idea. The C++/libstdc++ ABI simply isn't stable enough to make this a realistic option.

Considering that the ABI does not guarantee compatibility between versions, I am inclined to agree.

No reason the drivers themselves can't be done in C++, but the API itself should be pure C.

Quoted 9 lines

Paul

_______________________________________________
Qemu-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/qemu-devel

Signature · 2 lines
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.
#9 lore raw
Quoted 6 lines
Quoted 2 lines

I'm not a fan of binary plugins (for the same reasons I'm don't like binary kernel modules), and don't think there's any real need to them.

A binary plugin API and a source plugin API (one that requires each driver device to be recompiled for each of the platforms (Xen, qemu, bochs, etc.) would probably be equally hard to design and maintain.

You've missed my point. The only reason I can see for wanting binary plugins is so that people can distribute proprietary closed-source device emulation.

A stable source API is a prerequisite for any sort of binary plugins.

Quoted 9 lines
Quoted 3 lines

I can't see
any good reasons why open source devices would need to be broken out into a separate shared library.

I think the case was already made for this.

Xen's hardware emulation, while based on qemu's, is already ahead in several aspects. A separate library would make it more convenient for these changes to be shared back with qemu. Or with E/OS.

I don't buy that. We either share the same drivers (in which case keeping the two in sync is trivial) or we don't. All of the systems under consideration are [L]GPL licences. We can easily copy the source, so I don't think being able to copy bits of binary goo gains us anything.

I don't think executable size is a valid argument either. Device emulation code generally isn't that big so the overhead of breaking it up into multiple shared libraries would outweigh the benefits of not loading the bits you're not using.

Paul

#10 lore raw
Quoted 1 line · Paul Brook

I don't buy that. We either share the same drivers (in which case keeping the two in sync is trivial) or we don't. All of the systems under consideration are [L]GPL licences. We can easily copy the source, so I don't think being able to copy bits of binary goo gains us anything.

In my experience of writing multiple systems that do the same thing, some shared library code (be it static or dynamic (shared object) in form) makes life much simpler. It can be maintained as a seperate source module, libtool-ized, and made into a nice bit of magic that just needs to be modified once, without manually copying-and-pasting bits back and forth. If it's done statically, it can still be distributed with each source package to ensure compatibility.

Sam

#11 lore raw
In reply to Paul Brook
Quoted 9 lines · Paul Brook
Quoted 6 lines
Quoted 2 lines

I'm not a fan of binary plugins (for the same reasons I'm don't like binary kernel modules), and don't think there's any real need to them.

A binary plugin API and a source plugin API (one that requires each driver device to be recompiled for each of the platforms (Xen, qemu, bochs, etc.) would probably be equally hard to design and maintain.

You've missed my point. The only reason I can see for wanting binary plugins is so that people can distribute proprietary closed-source device emulation.

I agree that proprietary or closed-source device emulation is a bad thing and should not be supported.

Quoted 3 lines

A stable source API is a prerequisite for any sort of binary plugins.

In that case, perhaps a stable source API would be best.

Like I said before, the type of API/sharing (source vs binary API, and static vs shared libraries) is a separate issue from the one we are discussing (should we have or support a unified plugin API?).

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

I can't see
any good reasons why open source devices would need to be broken out into a separate shared library.

I think the case was already made for this.

Quoted 8 lines
Quoted 3 lines

Xen's hardware emulation, while based on qemu's, is already ahead in several aspects. A separate library would make it more convenient for these changes to be shared back with qemu. Or with E/OS.

I don't buy that. We either share the same drivers (in which case keeping the two in sync is trivial) or we don't. All of the systems under consideration are [L]GPL licences. We can easily copy the source, so I don't think being able to copy bits of binary goo gains us anything.

A) Makes it simpler for end users to move devices over (they don't have to know how to cut-and-paste C code)

B) Bochs is not related to qemu at all code-wise, so the cut-and-paste senario doesn't work here. If we want to share drivers with Bochs we'd need at least a source API. (The starter of this thread is a Bochs developer I believe... but correct me if I'm wrong here. :) The alternative is to rewrite Bochs drivers for qemu from scratch (possbly using the Bochs code as a guide) but that is even harder than the qemu-xen case.

C) If they are in a special library (say maintained by a 3rd party group that consists of developers from all the major projects) then maintainance is greatly simplified over time.

Quoted 5 lines

I don't think executable size is a valid argument either. Device emulation code generally isn't that big so the overhead of breaking it up into multiple shared libraries would outweigh the benefits of not loading the bits you're not using.

Perhaps you are right about that. The size of having even 4 or 5 copies of complete PC hardware emulation code isn't so large as to be a problem except on systems that are either embedded or ancient (in which case you probably have no business running 4 different PC emulators anyways).

Personally, it just seems inelegant to have such code duplication.

Quoted 3 lines

Paul

Signature · 2 lines
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.
#12 lore raw

Hello All,

I'll try to answer to everybody in single mail and explain my vision of unified plugin API and why I see them essential.

Yes, I am Bochs developer, but I am more CPU expert and only learning the devices subsystem and dynamic translation subjects so Bochs is a right place for me ;) I am pretty understand all the Bochs code including devices and also have some vision of highly portable and extendable simulator.

Now I'll try to explain how I see the plugin architecture and why I think it essential.

- I am not talking about binary level plugins support and maintenance or sources level.
- I am not talking about open source or closed source, commercial and freeware devices for emulator, but I think the plugin architecture should support both.
- I not think the plugin API should be C++, actually Bochs plugin API is pure-C based. The device itself is written in C++ but it has something like C++ -> C proxy implemented as a part of plugin API. I think here we are agree.
- It is doesn't matter if the plugin is shared or static library, the code size of Bochs or QEMU is so small and I don't think it is important feature to "share" devices in memory.

The keyword is expendability. Now if you would like to write a new device for Bochs or QEMU you cannot open a separate project on SF.net and start development. Even if you need to add some exotic experimental device which is not exists in real life you should interfere with simulator code. Moreover, if you need to add this device to Bochs, QEMU and Xen you basically have to do the work three times !

I hope I am not disclose any secret if I say that HiPEAC beginning a new project of open source full-system simulator, something that could be alternative to SimpleScalar and also have full-system emulation capabilities (platform + power + performance in single box). The simulator would reuse the devices from some existent open source emulator, Bochs or QEMU. But as any academia model it should be highly extendable and super-modular. The ability to add a new device to the system without touching the main simulator kernel is a MUST.

I believe it is right direction too. Somebody could establish a new project of developing new device and when contribute the device when it will be done. In my opinion, it is even not important if the device written in C/C++ or any other language, if it is distributed with sources or not, under commercial license or not. If I could download device binary, plug it in to the simulator and get new capabilities, which were not available before - why not ?

I could provide more and more examples, more and more advantages of this arch and almost no disadvantages. There are a lot of successful examples of products with extendable user plugins where functionality of the product as a very small piece near the variety of plugins written by users.

Now the advantages of making every device separate library (shared or static). When every device is separate library you try to build your emulated system by yourself choosing the CPU core emulator + chipset plugin
+ devices plugins you want. If some set of plugins distributed as single library - they are not separatable one from another. This is only a disadvantage which could simply avoided, so again, why not ?

I am already not talking about devices maintenance. The best example is Brendan BIOS. Brendan started a new project of writing new ACPI-compatible BIOS for open source emulators. His BIOS require ACPI compatibility changes in the device models and CPU emulator and Bochs already started to support his requirements. Currently, when his BIOS will be done, QEMU will remain behind it and not be able to run with it. Anyway, to support the requirements the work should be done 2-3 times, from the beginning for each simulator.

The Bochs will start from some PCI device and try to separate it from the simulator code, compile it stand-alone and make it pluginable in run-time. Why PCI device ? Just because it has more functionality than PC-speaker card and require more interference with core simulator. Actually might be several device models for core plugins (chipset, PCI bus, AGP bus), ISA/PCI cards and COM devices, everything is open. During the separation work I hope to figure out requirements from devices and simulator core for new plugin architecture. In Bochs, a lot of changes required to make it happen, and we believe we'll make it possible until next Bochs 2.3 release.

Thanks,
Stanislav

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Jim C. Brown
Sent: Sunday, April 09, 2006 6:08 PM
To: [email protected]
Subject: Re: [Qemu-devel] Unified device model

Quoted 4 lines · Paul Brook
Quoted 4 lines
Quoted 2 lines

I'm not a fan of binary plugins (for the same reasons I'm don't like binary kernel modules), and don't think there's any real need to them.

A binary plugin API and a source plugin API (one that requires each

driver

Quoted 1 line
Quoted 1 line

device to be recompiled for each of the platforms (Xen, qemu, bochs,

etc.)

Quoted 3 lines
Quoted 1 line

would probably be equally hard to design and maintain.

You've missed my point. The only reason I can see for wanting binary

plugins

Quoted 1 line

is so that people can distribute proprietary closed-source device

emulation.

I agree that proprietary or closed-source device emulation is a bad thing and
should not be supported.

Quoted 3 lines

A stable source API is a prerequisite for any sort of binary plugins.

In that case, perhaps a stable source API would be best.

Like I said before, the type of API/sharing (source vs binary API, and static
vs shared libraries) is a separate issue from the one we are discussing (should
we have or support a unified plugin API?).

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

I can't see
any good reasons why open source devices would need to be broken out

into

Quoted 6 lines
Quoted 6 lines
Quoted 1 line

a separate shared library.

I think the case was already made for this.

Xen's hardware emulation, while based on qemu's, is already ahead in several aspects. A separate library would make it more convenient for

these

Quoted 3 lines
Quoted 1 line

changes to be shared back with qemu. Or with E/OS.

I don't buy that. We either share the same drivers (in which case keeping

the

Quoted 1 line

two in sync is trivial) or we don't. All of the systems under

consideration

Quoted 3 lines

are [L]GPL licences. We can easily copy the source, so I don't think being

able to copy bits of binary goo gains us anything.

A) Makes it simpler for end users to move devices over (they don't have to know
how to cut-and-paste C code)

B) Bochs is not related to qemu at all code-wise, so the cut-and-paste senario
doesn't work here. If we want to share drivers with Bochs we'd need at least a
source API. (The starter of this thread is a Bochs developer I believe... but correct me if I'm wrong here. :) The alternative is to rewrite Bochs drivers for qemu from scratch (possbly using the Bochs code as a guide) but that is even harder than the qemu-xen case.

C) If they are in a special library (say maintained by a 3rd party group that
consists of developers from all the major projects) then maintainance is greatly
simplified over time.

Quoted 4 lines

I don't think executable size is a valid argument either. Device emulation

code generally isn't that big so the overhead of breaking it up into

multiple

Quoted 1 line

shared libraries would outweigh the benefits of not loading the bits

you're

Quoted 1 line

not using.

Perhaps you are right about that. The size of having even 4 or 5 copies of complete PC hardware emulation code isn't so large as to be a problem except on systems that are either embedded or ancient (in which case you probably have
no business running 4 different PC emulators anyways).

Personally, it just seems inelegant to have such code duplication.

Quoted 3 lines

Paul

Signature · 8 lines
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.


_______________________________________________
Qemu-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/qemu-devel
#13 lore raw

Hi,

My feeling is that QEMU already has what is needed to make a "plugin API". In particular, each device driver is clearly separated from the rest of the emulator and adding a new "machine" just consists in adding a new C file instanciating the different devices and processors. The fact that the devices or machines cannot come from a DLL or cannot be compiled separately is a cosmetic issue and could be easily added. I see little advantage in it except to make binary device models which I don't want to promote.

The real issues I see to improve the QEMU device model for the short term are:

- Rename some structures or functions to have a more consistent naming and rename vl.h to something like qemu/qemu.h and eventually split it to have a few subsystems such as isa, pci, usb... The question whether we keep a QEMU prefix is mostly political.

- Implement reproductible execution support and see if API changes are needed in the devices.

- Add explicit contexts in the (rare) cases where there are not already explicit. The API shall allow any number of CPUs and buses. A device tree should be added to give a global name for each device and cpu that can be referenced in the monitor and in the traces.

- Improve the tracing API. It should be possible to enable traces for each instance of a device. The various I/Os and events should be displayed in a uniform way.

- Make it possible to integrate different CPU types and all devices in the same executables without loosing performance. There are some API issues to solve regarding endianness.

- Document the API various functions by adding javadoc comments.

Another interesting point would be to see how to interface with hardware device models (for example written in VHDL and compiled with GHDL).

Looking at the API of other projects such as MAME which are more mature than QEMU or Bochs in the sense that they have far more devices and processors would be interesting too.

Fabrice.

Quoted 210 lines · Stanislav Shwartsman

Hello All,

I'll try to answer to everybody in single mail and explain my vision of unified plugin API and why I see them essential.

Yes, I am Bochs developer, but I am more CPU expert and only learning the devices subsystem and dynamic translation subjects so Bochs is a right place for me ;) I am pretty understand all the Bochs code including devices and also have some vision of highly portable and extendable simulator.

Now I'll try to explain how I see the plugin architecture and why I think it essential.

- I am not talking about binary level plugins support and maintenance or sources level.
- I am not talking about open source or closed source, commercial and freeware devices for emulator, but I think the plugin architecture should support both.
- I not think the plugin API should be C++, actually Bochs plugin API is pure-C based. The device itself is written in C++ but it has something like C++ -> C proxy implemented as a part of plugin API. I think here we are agree.
- It is doesn't matter if the plugin is shared or static library, the code size of Bochs or QEMU is so small and I don't think it is important feature to "share" devices in memory.

The keyword is expendability. Now if you would like to write a new device for Bochs or QEMU you cannot open a separate project on SF.net and start development. Even if you need to add some exotic experimental device which is not exists in real life you should interfere with simulator code. Moreover, if you need to add this device to Bochs, QEMU and Xen you basically have to do the work three times !

I hope I am not disclose any secret if I say that HiPEAC beginning a new project of open source full-system simulator, something that could be alternative to SimpleScalar and also have full-system emulation capabilities (platform + power + performance in single box). The simulator would reuse the devices from some existent open source emulator, Bochs or QEMU. But as any academia model it should be highly extendable and super-modular. The ability to add a new device to the system without touching the main simulator kernel is a MUST.

I believe it is right direction too. Somebody could establish a new project of developing new device and when contribute the device when it will be done. In my opinion, it is even not important if the device written in C/C++ or any other language, if it is distributed with sources or not, under commercial license or not. If I could download device binary, plug it in to the simulator and get new capabilities, which were not available before - why not ?

I could provide more and more examples, more and more advantages of this arch and almost no disadvantages. There are a lot of successful examples of products with extendable user plugins where functionality of the product as a very small piece near the variety of plugins written by users.

Now the advantages of making every device separate library (shared or static). When every device is separate library you try to build your emulated system by yourself choosing the CPU core emulator + chipset plugin
+ devices plugins you want. If some set of plugins distributed as single library - they are not separatable one from another. This is only a disadvantage which could simply avoided, so again, why not ?

I am already not talking about devices maintenance. The best example is Brendan BIOS. Brendan started a new project of writing new ACPI-compatible BIOS for open source emulators. His BIOS require ACPI compatibility changes in the device models and CPU emulator and Bochs already started to support his requirements. Currently, when his BIOS will be done, QEMU will remain behind it and not be able to run with it. Anyway, to support the requirements the work should be done 2-3 times, from the beginning for each simulator.

The Bochs will start from some PCI device and try to separate it from the simulator code, compile it stand-alone and make it pluginable in run-time. Why PCI device ? Just because it has more functionality than PC-speaker card and require more interference with core simulator. Actually might be several device models for core plugins (chipset, PCI bus, AGP bus), ISA/PCI cards and COM devices, everything is open. During the separation work I hope to figure out requirements from devices and simulator core for new plugin architecture. In Bochs, a lot of changes required to make it happen, and we believe we'll make it possible until next Bochs 2.3 release.

Thanks,
Stanislav

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Jim C. Brown
Sent: Sunday, April 09, 2006 6:08 PM
To: [email protected]
Subject: Re: [Qemu-devel] Unified device model

Quoted 4 lines · Paul Brook
Quoted 4 lines
Quoted 2 lines

I'm not a fan of binary plugins (for the same reasons I'm don't like binary kernel modules), and don't think there's any real need to them.

A binary plugin API and a source plugin API (one that requires each

driver

Quoted 1 line
Quoted 1 line

device to be recompiled for each of the platforms (Xen, qemu, bochs,

etc.)

Quoted 3 lines
Quoted 1 line

would probably be equally hard to design and maintain.

You've missed my point. The only reason I can see for wanting binary

plugins

Quoted 1 line

is so that people can distribute proprietary closed-source device

emulation.

I agree that proprietary or closed-source device emulation is a bad thing and
should not be supported.

Quoted 2 lines

A stable source API is a prerequisite for any sort of binary plugins.

In that case, perhaps a stable source API would be best.

Like I said before, the type of API/sharing (source vs binary API, and static
vs shared libraries) is a separate issue from the one we are discussing (should
we have or support a unified plugin API?).

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

I can't see
any good reasons why open source devices would need to be broken out

into

Quoted 6 lines
Quoted 6 lines
Quoted 1 line

a separate shared library.

I think the case was already made for this.

Xen's hardware emulation, while based on qemu's, is already ahead in several aspects. A separate library would make it more convenient for

these

Quoted 3 lines
Quoted 1 line

changes to be shared back with qemu. Or with E/OS.

I don't buy that. We either share the same drivers (in which case keeping

the

Quoted 1 line

two in sync is trivial) or we don't. All of the systems under

consideration

Quoted 4 lines

are [L]GPL licences. We can easily copy the source, so I don't think being

able to copy bits of binary goo gains us anything.

A) Makes it simpler for end users to move devices over (they don't have to know
how to cut-and-paste C code)

B) Bochs is not related to qemu at all code-wise, so the cut-and-paste senario
doesn't work here. If we want to share drivers with Bochs we'd need at least a
source API. (The starter of this thread is a Bochs developer I believe... but correct me if I'm wrong here. :) The alternative is to rewrite Bochs drivers for qemu from scratch (possbly using the Bochs code as a guide) but that is even harder than the qemu-xen case.

C) If they are in a special library (say maintained by a 3rd party group that
consists of developers from all the major projects) then maintainance is greatly
simplified over time.

Quoted 4 lines

I don't think executable size is a valid argument either. Device emulation

code generally isn't that big so the overhead of breaking it up into

multiple

Quoted 1 line

shared libraries would outweigh the benefits of not loading the bits

you're

Quoted 1 line

not using.

Perhaps you are right about that. The size of having even 4 or 5 copies of complete PC hardware emulation code isn't so large as to be a problem except on systems that are either embedded or ancient (in which case you probably have
no business running 4 different PC emulators anyways).

Personally, it just seems inelegant to have such code duplication.

Quoted 2 lines

Paul

#14 lore raw
In reply to Stanislav Shwartsman
Quoted 3 lines · Stanislav Shwartsman

I am talking about the device models only. Inside CPU emulation QEMU, Bochs and Xen are completely different, but they use the same devices for full system emulation and they most likely want to move forward together.

I haven't kept up with Bochs lately, so I have no idea if what qemu emulates and what Bochs emulates are still the same or if the devices supported have divulged.

I do know that the code is completely different (they aren't even in the same language!).

This part of the discussion is getting offtopic tho - how devices are done right now is not important.

Quoted 6 lines

The
devices system of QEMU and Bochs become outdate, it is required to add ACPI compliance and emulate new modern ACPI compatible devices, currently emulated i440FX already not so represent the real life and most of the modern OSes already have no support for it.

Agreed.

Quoted 1 line

So may we should ;)

Agreed.

Quoted 3 lines

At least I see the code changes from Bochs migrating to QEMU and vise versa when I am looking into the code.

You do?

I wasn't aware that bochs took anything from qemu, and the only piece of code that I know that is shared between the two is for the bios.

Quoted 4 lines

Why not ?
You always could consider to add simple modules C++ to QEMU or build C++ device -> C device interface bridge ...
I don't know all the possibilities, but I am sure there are more.

C++ code in qemu is forbidden (by the author and maintainer).

So a plugin API based on C sounds like the best option.

Bochs is unique as it is the only active open source PC emulator/virtualizer that is done in C++. So "Bochs has C++ support" is not a good reason for the API to be based on C++.

Quoted 10 lines
Quoted 9 lines
Quoted 7 lines

I know about two professional teams working in simulation which would like to use these device models in their simulator and
could enrich the device library with new devices device interfaces, for example with AGP and 3D graphics.
Bochs is already in middle of definition of new true pluginable devices architecture.

This is welcome news.

Quoted 7 lines

Currently we are thinking about making user-plugin PCI devices and when later user-plugin for any device. The C++ hierarchy for now might be:
bx_devmodel_c - bx_pcidev_c - bx_user_pcidev_c

The plans are to take one of the Bochs PCI devices and convert it into user-level plugin which should not be compiled with Bochs and even not known at compile time, but loaded at runtime if selected in runtime config file.

Why only PCI devices?

Why not USB, ISA (keyboard, monitor, pc speaker), devices that attach to the serial port (like the current wacom patch), etc?

Also note that it is possible to use C to set up such a hierarchy - perhaps not as natural as in C++, but still doable.

Quoted 2 lines

When any other device models could be added, even with closed-sources and commercial licenses.

I don't support this.

Under what circumstances would commercial qemu/xen/bochs/eos driver devices be a good thing?

I can understand (tho I still dislike) having commercial drivers in say the kernel - if its the only way to get support for a particular device, and that device would make it easier for others to use a different OS (e.g. nvidia under linux so ppl can have good 3d support) then I find it acceptable and tolerable.

But why would we want to do this for qemu et. al.?

Quoted 5 lines
Quoted 4 lines

The primary reason given for not making a plugin API for qemu hardware emulationis that qemu isn't stable enough - the code changes too often to support a stable API.

Quoted 8 lines
Quoted 2 lines

Still, it might be easier to add support for plugins based on an external API, rather than trying to keep a qemu plugin API consistent.

Ok, I didn't knew that QEMU is so unstable. But at least there are several trivial requirements from plugin architecture which you could mention here and I am still not thought about it. I know, basically I am writing the definition in my idle time and Volker supporting me. But it is not enough
...

If I think of anything else, I'll let you know. I do want to see this happen.

Quoted 14 lines

Thanks,
Stanislav

_______________________________________________
Qemu-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/qemu-devel

Signature · 2 lines
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.