From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34097) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1boxSG-0003aH-6n for qemu-devel@nongnu.org; Tue, 27 Sep 2016 14:50:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1boxSC-0002yx-0I for qemu-devel@nongnu.org; Tue, 27 Sep 2016 14:50:12 -0400 Received: from smtp3-g21.free.fr ([2a01:e0c:1:1599::12]:11390) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1boxSB-0002mo-P7 for qemu-devel@nongnu.org; Tue, 27 Sep 2016 14:50:07 -0400 References: <1474921408-24710-1-git-send-email-hpoussin@reactos.org> <1474921408-24710-3-git-send-email-hpoussin@reactos.org> <20160927041138.GF30322@umbus.fritz.box> From: =?UTF-8?Q?Herv=c3=a9_Poussineau?= Message-ID: Date: Tue, 27 Sep 2016 20:49:47 +0200 MIME-Version: 1.0 In-Reply-To: <20160927041138.GF30322@umbus.fritz.box> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2 2/6] intc/i8259: implement InterruptStatsProvider interface List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: David Gibson Cc: qemu-devel@nongnu.org, Paolo Bonzini , "Michael S. Tsirkin" , Luiz Capitulino Le 27/09/2016 =E0 06:11, David Gibson a =E9crit : > On Mon, Sep 26, 2016 at 10:23:24PM +0200, Herv=E9 Poussineau wrote: >> Signed-off-by: Herv=E9 Poussineau >> --- >> hw/intc/i8259.c | 37 +++++++++++++++++++++++++++++++++++++ >> 1 file changed, 37 insertions(+) >> >> diff --git a/hw/intc/i8259.c b/hw/intc/i8259.c >> index c2607a5..75c8d22 100644 >> --- a/hw/intc/i8259.c >> +++ b/hw/intc/i8259.c >> @@ -29,6 +29,7 @@ >> #include "qemu/timer.h" >> #include "qemu/log.h" >> #include "hw/isa/i8259_internal.h" >> +#include "hw/intc/intc.h" >> >> /* debug PIC */ >> //#define DEBUG_PIC >> @@ -251,6 +252,35 @@ static void pic_reset(DeviceState *dev) >> pic_init_reset(s); >> } >> >> +static bool pic_get_statistics(InterruptStatsProvider *obj, >> + uint64_t **irq_counts, unsigned int *n= b_irqs) >> +{ >> + PICCommonState *s =3D PIC_COMMON(obj); >> + >> + if (s->master) { >> +#ifdef DEBUG_IRQ_COUNT >> + *irq_counts =3D irq_count; > > So, the irq_counts return parameter is set to point at an internal > structure of the intc, in this and the other implementations. > > Is that safe, without some contract about how long the array pointer > is valid and/or correct? Could it be a problem if in future we tried > to implement this for an intc that doesn't keep irq stats as a simple > array (e.g. kept the count in a structure also containing other > information for each irq)? I implemented the interface with more than 15 interrupt controllers in hw= /intc. It worked well for all of them. In fact, most of the times, the device is= doing something like: my_device_irq_handler(int n) { MyDeviceState *s =3D ...; qemu_irq_raise(s->master_irq); } realize() { qemu_allocate_irqs(my_device_irq_handler, NB_IRQS) } It's quite easy to add in MyDeviceState: uint64_t irq_count[NB_IRQS] in MyDeviceState; and adding in my_device_irq_handler s->irq_count[n]++; We can maybe add a note on the interface that: - the pointer must remain valid for the whole life of the device, - the contents may stale, but must not be invalid For your intc, you'll need to have a second array irq_count, which is upd= ated on each get_statistics() call. > I'm wondering if a safer interface might be to actually copy out a > snapshot of the counts, which the caller is responsible for freeing. In that case, all implementations will have to do g_malloc + memcpy, and = caller will have to call g_free. That's possible, but IMO less easy to implement on device side. Herv=E9 > >> + *nb_irqs =3D ARRAY_SIZE(irq_count); >> +#else >> + return false; >> +#endif >> + } else { >> + *irq_counts =3D NULL; >> + *nb_irqs =3D 0; >> + } >> + return true; >> +} >> +