From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:55880) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RpoJd-0002kz-TY for qemu-devel@nongnu.org; Tue, 24 Jan 2012 16:54:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RpoJZ-0001dp-Of for qemu-devel@nongnu.org; Tue, 24 Jan 2012 16:54:09 -0500 Message-ID: <4F1F2875.3050509@codemonkey.ws> Date: Tue, 24 Jan 2012 15:53:57 -0600 From: Anthony Liguori MIME-Version: 1.0 References: <1327433600-7403-1-git-send-email-aliguori@us.ibm.com> <1327433600-7403-28-git-send-email-aliguori@us.ibm.com> <4F1F0E2D.2020706@web.de> <4F1F12E7.2020309@us.ibm.com> <4F1F1C28.4040600@web.de> <4F1F1E91.50609@codemonkey.ws> <4F1F233B.8040804@web.de> In-Reply-To: <4F1F233B.8040804@web.de> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: convert to QEMU Object Model List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jan Kiszka Cc: Peter Maydell , "Michael S. Tsirkin" , Alexander Graf , qemu-devel@nongnu.org, Blue Swirl , =?ISO-8859-15?Q?Andreas_F=E4rber?= , qemu-ppc@nongnu.org, Paul Brook , Aurelien Jarno , Gerd Hoffmann On 01/24/2012 03:31 PM, Jan Kiszka wrote: > On 2012-01-24 22:11, Anthony Liguori wrote: >> On 01/24/2012 03:01 PM, Jan Kiszka wrote: >>> On 2012-01-24 21:21, Anthony Liguori wrote: >>>>> Also, I see a lot of programmatic initialization and a lot of repeating >>>>> patterns (specifically regarding trivial class initialization) - there >>>>> is no better alternative? >>>> >>>> Not really, no. It looks bad now because you have DeviceInfo still. >>>> Once DeviceInfo goes away, all of the initialization will happen in the >>>> class_init function. >>>> >>>> The design of QOM is such that a lot of what was previously done via >>>> declarative structures is now done imperatively. But the code bloat >>>> that came in this patch series will decrease significantly with the next >>>> series as we eliminate DeviceInfo. >>> >>> Are there examples of fully converted devices to get an impression? >> >> https://github.com/aliguori/qemu/tree/qom-rebase.8 >> >> Has everything fully converted (including BusState). >> >> If you look at qdev.[ch], you'll notice the remaining qdev >> infrastructure becomes greatly simplified. > > But I don't get yet why all these repeating initialization tasks need to > be open-coded instead of remaining declarative. It would look like: static void device_generic_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); DeviceTypeInfo *ti = data; if (ti->reset) { dc->reset = ti->reset; } if (ti->vmsd) { dc->vmsd = ti->vmsd; } } void device_type_register_static(DeviceTypeInfo *ti) { TypeInfo ti = { .class_init = device_generic_class_init, .class_data = ti, // ... } type_register_static(&ti); } But I don't like this. The problem is that the declarative syntax we have doesn't distinguish between "not-specified" and "zero-initialized". It's also tempting to just drop the if (ti->reset) check but that means that you unconditionally override the base class implementation even if it's not specified. I don't see any tangible benefits to a declarative syntax except that it makes it harder to get right because you have to write per-base class initialization functions and it's very easy to get polymorphism wrong there. We're not talking about a code size difference. It's a wash in terms of number of lines of code. Imperative allows you to explicit zero-initialize, accept the previous version (from the base class), or override with a new value. Regards, Anthony Liguori > > Jan >