|
From: | Anthony Liguori |
Subject: | Re: [Qemu-devel] [RFC] New device API |
Date: | Wed, 06 May 2009 08:35:35 -0500 |
User-agent: | Thunderbird 2.0.0.21 (X11/20090320) |
Paul Brook wrote:
On Wednesday 06 May 2009, Paul Brook wrote:The attached patch is my attempt at a new internal API for device creation in qemu.Instead of recreating constructors, I think we should just use GCC's constructor attribute. This gives us ordering which will be important when dealing with buses.The reason I'm not using constructors is because you have to workaround ordering issues. All constructors are run before main(), so there's a very limited amount they can actually do, and constructor priorities are not available on all hosts.
I was going to make an argument that you want to have multiple constructors in a single file. However, I think this is wrong. I think you want to make sure that you only register one device per file.
Oh, the other thing is that constructors don't work when you put objects in a static library. You need am explicit dependency to pull in objects.
I think I'd be happier if we just made it a little less connected. So, something like:
static DeviceType *qdev_register(const char *name, int size, qdev_initfn init, void *opaque) { } device_init(qdev_register); Then: #! /bin/sh # Call device init functions. file="$1" shift devices="$@" echo '/* Generated by gen_devices.sh */' > $file echo '#include "sysemu.h"' >> $file echo "void register_devices(void)" >> $file echo "{" >> $file for x in $devices ; do sed -e 's:$device_init(\(.*)\);$:#qdevice \1:g' | grep '#qdevice' | cut -f2- -d' ' | while read DEVICE_INIT; do echo "{ extern void qemu_do_device_init_${DEVICE_INIT}(void); qemu_do_device_init_${DEVICE_INIT}(); }" done done echo "}" >> $file And: #define device_init(func) \ void qemu_do_device_init ## func (void) { \ func(); \ } This requires that device_init() functions always are unique names. It also means we can switch to constructors down the road if we wanted to and that problem goes away. Also, it introduces a saner way to introduce priority. We can have device_init(), pci_device_init(), virtio_device_init(), etc. I haven't tried any of this code BTW. Regards, Anthony Liguori
Paul
[Prev in Thread] | Current Thread | [Next in Thread] |