From: Anthony Liguori <anthony@codemonkey.ws>
To: Paul Brook <paul@codesourcery.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [RFC] New device API
Date: Wed, 06 May 2009 08:35:35 -0500 [thread overview]
Message-ID: <4A019227.1020707@codemonkey.ws> (raw)
In-Reply-To: <200905060204.32068.paul@codesourcery.com>
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
>
>
>
next prev parent reply other threads:[~2009-05-06 13:35 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-05 11:31 [Qemu-devel] [RFC] New device API Paul Brook
2009-05-05 15:56 ` Blue Swirl
2009-05-05 16:17 ` Paul Brook
2009-05-05 16:26 ` Blue Swirl
2009-05-05 16:35 ` Paul Brook
2009-05-05 18:22 ` Anthony Liguori
2009-05-05 22:42 ` Edgar E. Iglesias
2009-05-06 0:52 ` Paul Brook
2009-05-06 1:04 ` Paul Brook
2009-05-06 13:35 ` Anthony Liguori [this message]
2009-05-09 20:55 ` Anthony Liguori
2009-05-09 21:06 ` Paul Brook
2009-05-10 1:34 ` Anthony Liguori
2009-05-09 22:52 ` malc
2009-05-10 1:35 ` Anthony Liguori
2009-05-10 6:50 ` Andreas Färber
2009-05-10 18:38 ` malc
2009-05-10 1:37 ` Anthony Liguori
2009-05-05 22:25 ` Edgar E. Iglesias
2009-05-08 1:54 ` Zachary Amsden
2009-05-08 11:28 ` Paul Brook
2009-05-08 13:47 ` Anthony Liguori
2009-05-09 1:21 ` Zachary Amsden
2009-05-09 13:36 ` Anthony Liguori
2009-05-08 5:27 ` Marcelo Tosatti
2009-05-08 10:44 ` Paul Brook
2009-05-28 13:53 ` Markus Armbruster
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=4A019227.1020707@codemonkey.ws \
--to=anthony@codemonkey.ws \
--cc=paul@codesourcery.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.