From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M1hHj-0004r8-Tt for qemu-devel@nongnu.org; Wed, 06 May 2009 09:35:43 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M1hHf-0004jV-0g for qemu-devel@nongnu.org; Wed, 06 May 2009 09:35:43 -0400 Received: from [199.232.76.173] (port=38481 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M1hHe-0004jP-SX for qemu-devel@nongnu.org; Wed, 06 May 2009 09:35:38 -0400 Received: from an-out-0708.google.com ([209.85.132.251]:11726) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1M1hHe-0005Kx-EU for qemu-devel@nongnu.org; Wed, 06 May 2009 09:35:38 -0400 Received: by an-out-0708.google.com with SMTP id d11so50816and.37 for ; Wed, 06 May 2009 06:35:37 -0700 (PDT) Message-ID: <4A019227.1020707@codemonkey.ws> Date: Wed, 06 May 2009 08:35:35 -0500 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [RFC] New device API References: <200905051231.09759.paul@codesourcery.com> <4A0083F5.7050606@codemonkey.ws> <200905060152.02351.paul@codesourcery.com> <200905060204.32068.paul@codesourcery.com> In-Reply-To: <200905060204.32068.paul@codesourcery.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paul Brook Cc: qemu-devel@nongnu.org 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 > > >