Skip to contentSkip to conversation

intc: change 'info irq' and 'info pic' to be target-agnostic

PATCH In review Hervé Poussineau 4 participants 17 messages Sep 26, 2016 – Sep 30, 2016

lore
Share & tools
lore
#0 lore raw

v2 cover intc: change 'info irq' and 'info pic' to be target-agnostic

Hi,

This patchset aims at genericizing the 'info irq' and 'info pic' HMP commands, so that it is available on all machines and can display details about more than one interrupt controller per machine.

Patch 1 adds a new interface InterruptStatsProvider, which is used to:
- gather statistics for the 'info irq' command
- print some text when 'info pic' is called

Patches 2 to 4 implement InterruptStatsProvider interface on interrupt controllers which have ad-hock code to handle 'info irq'/'info pic' commands.

Patch 5 removes ad-hock code, and replaces it by a generic version. You can get details about multiple interrupt controllers per machine starting here.

Patch 6 makes 'info irq'/'info pic' commands available on all architectures. For example, Alpha clipper machine is now able to display details about the i8259 interrupt controller.

Changes since v1:
- renamed interface from IntCtrl to InterruptStatsProvider

Hervé

Hervé Poussineau (6):
intc: add an interface to gather statistics/informations on interrupt
controllers
intc/i8259: implement InterruptStatsProvider interface intc/slavio_intctl: implement InterruptStatsProvider interface intc/lm32_pic: implement InterruptStatsProvider interface
intc: make HMP 'info irq' and 'info pic' commands use
InterruptStatsProvider interface
intc: make HMP 'info irq' and 'info pic' commands available on all
targets

 hmp-commands-info.hx       | 17 +----------
 hmp.c                      | 65 +++++++++++++++++++++++++++++++++++++++++
 hmp.h                      |  2 ++
 hw/intc/Makefile.objs      |  1 +
 hw/intc/i8259.c            | 73 +++++++++++++++++++++++-----------------------
 hw/intc/intc.c             | 41 ++++++++++++++++++++++++++
 hw/intc/lm32_pic.c         | 63 ++++++++++++++++++---------------------
 hw/intc/slavio_intctl.c    | 67 ++++++++++++++++++++++--------------------
 hw/sparc/sun4m.c           | 15 +---------
 include/hw/i386/pc.h       |  2 --
 include/hw/intc/intc.h     | 30 +++++++++++++++++++
 include/hw/lm32/lm32_pic.h |  3 --
 include/hw/sparc/sun4m.h   |  8 -----
 monitor.c                  |  6 ----
 14 files changed, 241 insertions(+), 152 deletions(-)
 create mode 100644 hw/intc/intc.c
 create mode 100644 include/hw/intc/intc.h
Signature · 1 line
2.1.4
#1 lore raw

PATCH v2 1/6 intc: add an interface to gather statistics/informations on interrupt controllers

This interface will be used by HMP commands 'info irq' and 'info pic'.

---
 hw/intc/Makefile.objs  |  1 +
 hw/intc/intc.c         | 41 +++++++++++++++++++++++++++++++++++++++++
 include/hw/intc/intc.h | 30 ++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+)
 create mode 100644 hw/intc/intc.c
 create mode 100644 include/hw/intc/intc.h
hw/intc/Makefile.objs +1 -0
index 05ec21b..f24c837 100644
@@ -17,6 +17,7 @@ common-obj-$(CONFIG_ARM_GIC) += arm_gicv3.o
 common-obj-$(CONFIG_ARM_GIC) += arm_gicv3_dist.o
 common-obj-$(CONFIG_ARM_GIC) += arm_gicv3_redist.o
 common-obj-$(CONFIG_OPENPIC) += openpic.o
+common-obj-y += intc.o
 
 obj-$(CONFIG_APIC) += apic.o apic_common.o
 obj-$(CONFIG_ARM_GIC_KVM) += arm_gic_kvm.o
hw/intc/intc.c new file +41 -0

41 lines not on this page · raw message

include/hw/intc/intc.h new file +30 -0
new file mode 100644
index 0000000..2a97ea1
@@ -0,0 +1,30 @@
+#ifndef INTC_H
+#define INTC_H
+
+#include "qom/object.h"
+
+#define TYPE_INTERRUPT_STATS_PROVIDER "intctrl"
+
+#define INTERRUPT_STATS_PROVIDER_CLASS(klass) \
+    OBJECT_CLASS_CHECK(InterruptStatsProviderClass, (klass), \
+                       TYPE_INTERRUPT_STATS_PROVIDER)
+#define INTERRUPT_STATS_PROVIDER_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(InterruptStatsProviderClass, (obj), \
+                     TYPE_INTERRUPT_STATS_PROVIDER)
+#define INTERRUPT_STATS_PROVIDER(obj) \
+    INTERFACE_CHECK(InterruptStatsProvider, (obj), \
+                    TYPE_INTERRUPT_STATS_PROVIDER)
+
+typedef struct InterruptStatsProvider {
+    Object parent;
+} InterruptStatsProvider;
+
+typedef struct InterruptStatsProviderClass {
+    InterfaceClass parent;
+
+    bool (*get_statistics)(InterruptStatsProvider *obj, uint64_t **irq_counts,
+                           unsigned int *nb_irqs);
+    void (*print_info)(InterruptStatsProvider *obj, Monitor *mon);
+} InterruptStatsProviderClass;
+
+#endif
Signature · 1 line
2.1.4
#2 lore raw

PATCH v2 2/6 intc/i8259: implement InterruptStatsProvider interface

In reply to Hervé Poussineau
---
 hw/intc/i8259.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
hw/intc/i8259.c +37 -0
index c2607a5..75c8d22 100644
@@ -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 *nb_irqs)
+{
+    PICCommonState *s = PIC_COMMON(obj);
+
+    if (s->master) {
+#ifdef DEBUG_IRQ_COUNT
+        *irq_counts = irq_count;
+        *nb_irqs = ARRAY_SIZE(irq_count);
+#else
+        return false;
+#endif
+    } else {
+        *irq_counts = NULL;
+        *nb_irqs = 0;
+    }
+    return true;
+}
+
+static void pic_print_info(InterruptStatsProvider *obj, Monitor *mon)
+{
+    PICCommonState *s = PIC_COMMON(obj);
+    monitor_printf(mon, "pic%d: irr=%02x imr=%02x isr=%02x hprio=%d "
+                   "irq_base=%02x rr_sel=%d elcr=%02x fnm=%d\n",
+                   s->master ? 0 : 1, s->irr, s->imr, s->isr, s->priority_add,
+                   s->irq_base, s->read_reg_select, s->elcr,
+                   s->special_fully_nested_mode);
+}
+
 static void pic_ioport_write(void *opaque, hwaddr addr64,
                              uint64_t val64, unsigned size)
 {
@@ -503,10 +533,13 @@ static void i8259_class_init(ObjectClass *klass, void *data)
 {
     PICClass *k = PIC_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
+    InterruptStatsProviderClass *ic = INTERRUPT_STATS_PROVIDER_CLASS(klass);
 
     k->parent_realize = dc->realize;
     dc->realize = pic_realize;
     dc->reset = pic_reset;
+    ic->get_statistics = pic_get_statistics;
+    ic->print_info = pic_print_info;
 }
 
 static const TypeInfo i8259_info = {
@@ -515,6 +548,10 @@ static const TypeInfo i8259_info = {
     .parent     = TYPE_PIC_COMMON,
     .class_init = i8259_class_init,
     .class_size = sizeof(PICClass),
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_INTERRUPT_STATS_PROVIDER },
+        { }
+    },
 };
 
 static void pic_register_types(void)
Signature · 1 line
2.1.4
#8 lore raw

PATCH v2 3/6 intc/slavio_intctl: implement InterruptStatsProvider interface

In reply to Hervé Poussineau
---
 hw/intc/slavio_intctl.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
hw/intc/slavio_intctl.c +35 -0
index e82e893..a9acb64 100644
@@ -26,6 +26,7 @@
 #include "hw/sparc/sun4m.h"
 #include "monitor/monitor.h"
 #include "hw/sysbus.h"
+#include "hw/intc/intc.h"
 #include "trace.h"
 
 //#define DEBUG_IRQ_COUNT
@@ -418,6 +419,31 @@ static void slavio_intctl_reset(DeviceState *d)
     slavio_check_interrupts(s, 0);
 }
 
+#ifdef DEBUG_IRQ_COUNT
+static bool slavio_intctl_get_statistics(InterruptStatsProvider *obj,
+                                         uint64_t **irq_counts,
+                                         unsigned int *nb_irqs)
+{
+    SLAVIO_INTCTLState *s = SLAVIO_INTCTL(obj);
+    *irq_counts = s->irq_count;
+    *nb_irqs = ARRAY_SIZE(s->irq_count);
+    return true;
+}
+#endif
+
+static void slavio_intctl_print_info(InterruptStatsProvider *obj, Monitor *mon)
+{
+    SLAVIO_INTCTLState *s = SLAVIO_INTCTL(obj);
+    int i;
+
+    for (i = 0; i < MAX_CPUS; i++) {
+        monitor_printf(mon, "per-cpu %d: pending 0x%08x\n", i,
+                       s->slaves[i].intreg_pending);
+    }
+    monitor_printf(mon, "master: pending 0x%08x, disabled 0x%08x\n",
+                   s->intregm_pending, s->intregm_disabled);
+}
+
 static void slavio_intctl_init(Object *obj)
 {
     DeviceState *dev = DEVICE(obj);
@@ -449,9 +475,14 @@ static void slavio_intctl_init(Object *obj)
 static void slavio_intctl_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    InterruptStatsProviderClass *ic = INTERRUPT_STATS_PROVIDER_CLASS(klass);
 
     dc->reset = slavio_intctl_reset;
     dc->vmsd = &vmstate_intctl;
+#ifdef DEBUG_IRQ_COUNT
+    ic->get_statistics = slavio_intctl_get_statistics;
+#endif
+    ic->print_info = slavio_intctl_print_info;
 }
 
 static const TypeInfo slavio_intctl_info = {
@@ -460,6 +491,10 @@ static const TypeInfo slavio_intctl_info = {
     .instance_size = sizeof(SLAVIO_INTCTLState),
     .instance_init = slavio_intctl_init,
     .class_init    = slavio_intctl_class_init,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_INTERRUPT_STATS_PROVIDER },
+        { }
+    },
 };
 
 static void slavio_intctl_register_types(void)
Signature · 1 line
2.1.4
#12 lore raw

PATCH v2 4/6 intc/lm32_pic: implement InterruptStatsProvider interface

In reply to Hervé Poussineau

We have to change the vmstate version due to changes in statistics counters.

---
 hw/intc/lm32_pic.c | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)
hw/intc/lm32_pic.c +28 -4
index 3dad01c..c045b99 100644
@@ -25,6 +25,7 @@
 #include "hw/sysbus.h"
 #include "trace.h"
 #include "hw/lm32/lm32_pic.h"
+#include "hw/intc/intc.h"
 
 #define TYPE_LM32_PIC "lm32-pic"
 #define LM32_PIC(obj) OBJECT_CHECK(LM32PicState, (obj), TYPE_LM32_PIC)
@@ -38,7 +39,7 @@ struct LM32PicState {
     uint32_t irq_state;
 
     /* statistics */
-    uint32_t stats_irq_count[32];
+    uint64_t stats_irq_count[32];
 };
 typedef struct LM32PicState LM32PicState;
 
@@ -152,6 +153,22 @@ static void pic_reset(DeviceState *d)
     }
 }
 
+static bool lm32_get_statistics(InterruptStatsProvider *obj,
+                                uint64_t **irq_counts, unsigned int *nb_irqs)
+{
+    LM32PicState *s = LM32_PIC(obj);
+    *irq_counts = s->stats_irq_count;
+    *nb_irqs = ARRAY_SIZE(s->stats_irq_count);
+    return true;
+}
+
+static void lm32_print_info(InterruptStatsProvider *obj, Monitor *mon)
+{
+    LM32PicState *s = LM32_PIC(obj);
+    monitor_printf(mon, "lm32-pic: im=%08x ip=%08x irq_state=%08x\n",
+            s->im, s->ip, s->irq_state);
+}
+
 static void lm32_pic_init(Object *obj)
 {
     DeviceState *dev = DEVICE(obj);
@@ -166,13 +183,13 @@ static void lm32_pic_init(Object *obj)
 
 static const VMStateDescription vmstate_lm32_pic = {
     .name = "lm32-pic",
-    .version_id = 1,
-    .minimum_version_id = 1,
+    .version_id = 2,
+    .minimum_version_id = 2,
     .fields = (VMStateField[]) {
         VMSTATE_UINT32(im, LM32PicState),
         VMSTATE_UINT32(ip, LM32PicState),
         VMSTATE_UINT32(irq_state, LM32PicState),
-        VMSTATE_UINT32_ARRAY(stats_irq_count, LM32PicState, 32),
+        VMSTATE_UINT64_ARRAY(stats_irq_count, LM32PicState, 32),
         VMSTATE_END_OF_LIST()
     }
 };
@@ -180,9 +197,12 @@ static const VMStateDescription vmstate_lm32_pic = {
 static void lm32_pic_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    InterruptStatsProviderClass *ic = INTERRUPT_STATS_PROVIDER_CLASS(klass);
 
     dc->reset = pic_reset;
     dc->vmsd = &vmstate_lm32_pic;
+    ic->get_statistics = lm32_get_statistics;
+    ic->print_info = lm32_print_info;
 }
 
 static const TypeInfo lm32_pic_info = {
@@ -191,6 +211,10 @@ static const TypeInfo lm32_pic_info = {
     .instance_size = sizeof(LM32PicState),
     .instance_init = lm32_pic_init,
     .class_init    = lm32_pic_class_init,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_INTERRUPT_STATS_PROVIDER },
+        { }
+    },
 };
 
 static void lm32_pic_register_types(void)
Signature · 1 line
2.1.4
#15 lore raw

PATCH v2 6/6 intc: make HMP 'info irq' and 'info pic' commands available on all targets

In reply to Hervé Poussineau
---
 hmp-commands-info.hx | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
hmp-commands-info.hx +1 -4
index 6a7c476..55d50c4 100644
@@ -172,8 +172,6 @@ STEXI
 Show the command line history.
 ETEXI
 
-#if defined(TARGET_I386) || defined(TARGET_PPC) || defined(TARGET_MIPS) || \
-    defined(TARGET_LM32) || (defined(TARGET_SPARC) && !defined(TARGET_SPARC64))
     {
         .name       = "irq",
         .args_type  = "",
@@ -192,10 +190,9 @@ ETEXI
         .name       = "pic",
         .args_type  = "",
         .params     = "",
-        .help       = "show i8259 (PIC) state",
+        .help       = "show PIC state",
         .cmd        = hmp_info_pic,
     },
-#endif
 
 STEXI
 @item info pic
Signature · 1 line
2.1.4
#13 lore raw

PATCH v2 5/6 intc: make HMP 'info irq' and 'info pic' commands use InterruptStatsProvider interface

In reply to Hervé Poussineau
---
 hmp-commands-info.hx       | 12 ---------
 hmp.c                      | 65 ++++++++++++++++++++++++++++++++++++++++++++++
 hmp.h                      |  2 ++
 hw/intc/i8259.c            | 36 -------------------------
 hw/intc/lm32_pic.c         | 31 ----------------------
 hw/intc/slavio_intctl.c    | 32 -----------------------
 hw/sparc/sun4m.c           | 15 +----------
 include/hw/i386/pc.h       |  2 --
 include/hw/lm32/lm32_pic.h |  3 ---
 include/hw/sparc/sun4m.h   |  8 ------
 monitor.c                  |  6 -----
 11 files changed, 68 insertions(+), 144 deletions(-)
hmp-commands-info.hx +0 -12
index 19729e5..6a7c476 100644
@@ -179,13 +179,7 @@ ETEXI
         .args_type  = "",
         .params     = "",
         .help       = "show the interrupts statistics (if available)",
-#ifdef TARGET_SPARC
-        .cmd        = sun4m_hmp_info_irq,
-#elif defined(TARGET_LM32)
-        .cmd        = lm32_hmp_info_irq,
-#else
         .cmd        = hmp_info_irq,
-#endif
     },
 
 STEXI
@@ -199,13 +193,7 @@ ETEXI
         .args_type  = "",
         .params     = "",
         .help       = "show i8259 (PIC) state",
-#ifdef TARGET_SPARC
-        .cmd        = sun4m_hmp_info_pic,
-#elif defined(TARGET_LM32)
-        .cmd        = lm32_hmp_info_pic,
-#else
         .cmd        = hmp_info_pic,
-#endif
     },
 #endif
 
hmp.c +65 -0

77 lines not on this page · raw message

hmp.h +2 -0
index 0876ec0..184769c 100644
@@ -36,6 +36,8 @@ void hmp_info_blockstats(Monitor *mon, const QDict *qdict);
 void hmp_info_vnc(Monitor *mon, const QDict *qdict);
 void hmp_info_spice(Monitor *mon, const QDict *qdict);
 void hmp_info_balloon(Monitor *mon, const QDict *qdict);
+void hmp_info_irq(Monitor *mon, const QDict *qdict);
+void hmp_info_pic(Monitor *mon, const QDict *qdict);
 void hmp_info_pci(Monitor *mon, const QDict *qdict);
 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict);
 void hmp_info_tpm(Monitor *mon, const QDict *qdict);
hw/intc/i8259.c +0 -36
index 75c8d22..fe9ecd6 100644
@@ -461,42 +461,6 @@ static void pic_realize(DeviceState *dev, Error **errp)
     pc->parent_realize(dev, errp);
 }
 
-void hmp_info_pic(Monitor *mon, const QDict *qdict)
-{
-    int i;
-    PICCommonState *s;
-
-    if (!isa_pic) {
-        return;
-    }
-    for (i = 0; i < 2; i++) {
-        s = i == 0 ? PIC_COMMON(isa_pic) : slave_pic;
-        monitor_printf(mon, "pic%d: irr=%02x imr=%02x isr=%02x hprio=%d "
-                       "irq_base=%02x rr_sel=%d elcr=%02x fnm=%d\n",
-                       i, s->irr, s->imr, s->isr, s->priority_add,
-                       s->irq_base, s->read_reg_select, s->elcr,
-                       s->special_fully_nested_mode);
-    }
-}
-
-void hmp_info_irq(Monitor *mon, const QDict *qdict)
-{
-#ifndef DEBUG_IRQ_COUNT
-    monitor_printf(mon, "irq statistic code not compiled.\n");
-#else
-    int i;
-    int64_t count;
-
-    monitor_printf(mon, "IRQ statistics:\n");
-    for (i = 0; i < 16; i++) {
-        count = irq_count[i];
-        if (count > 0) {
-            monitor_printf(mon, "%2d: %" PRId64 "\n", i, count);
-        }
-    }
-#endif
-}
-
 qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq)
 {
     qemu_irq *irq_set;
hw/intc/lm32_pic.c +0 -31
index c045b99..09e1511 100644
@@ -43,35 +43,6 @@ struct LM32PicState {
 };
 typedef struct LM32PicState LM32PicState;
 
-static LM32PicState *pic;
-void lm32_hmp_info_pic(Monitor *mon, const QDict *qdict)
-{
-    if (pic == NULL) {
-        return;
-    }
-
-    monitor_printf(mon, "lm32-pic: im=%08x ip=%08x irq_state=%08x\n",
-            pic->im, pic->ip, pic->irq_state);
-}
-
-void lm32_hmp_info_irq(Monitor *mon, const QDict *qdict)
-{
-    int i;
-    uint32_t count;
-
-    if (pic == NULL) {
-        return;
-    }
-
-    monitor_printf(mon, "IRQ statistics:\n");
-    for (i = 0; i < 32; i++) {
-        count = pic->stats_irq_count[i];
-        if (count > 0) {
-            monitor_printf(mon, "%2d: %u\n", i, count);
-        }
-    }
-}
-
 static void update_irq(LM32PicState *s)
 {
     s->ip |= s->irq_state;
@@ -177,8 +148,6 @@ static void lm32_pic_init(Object *obj)
 
     qdev_init_gpio_in(dev, irq_handler, 32);
     sysbus_init_irq(sbd, &s->parent_irq);
-
-    pic = s;
 }
 
 static const VMStateDescription vmstate_lm32_pic = {
hw/intc/slavio_intctl.c +0 -32
index a9acb64..84e0bee 100644
@@ -211,38 +211,6 @@ static const MemoryRegionOps slavio_intctlm_mem_ops = {
     },
 };
 
-void slavio_pic_info(Monitor *mon, DeviceState *dev)
-{
-    SLAVIO_INTCTLState *s = SLAVIO_INTCTL(dev);
-    int i;
-
-    for (i = 0; i < MAX_CPUS; i++) {
-        monitor_printf(mon, "per-cpu %d: pending 0x%08x\n", i,
-                       s->slaves[i].intreg_pending);
-    }
-    monitor_printf(mon, "master: pending 0x%08x, disabled 0x%08x\n",
-                   s->intregm_pending, s->intregm_disabled);
-}
-
-void slavio_irq_info(Monitor *mon, DeviceState *dev)
-{
-#ifndef DEBUG_IRQ_COUNT
-    monitor_printf(mon, "irq statistic code not compiled.\n");
-#else
-    SLAVIO_INTCTLState *s = SLAVIO_INTCTL(dev);
-    int i;
-    int64_t count;
-
-    s = SLAVIO_INTCTL(dev);
-    monitor_printf(mon, "IRQ statistics:\n");
-    for (i = 0; i < 32; i++) {
-        count = s->irq_count[i];
-        if (count > 0)
-            monitor_printf(mon, "%2d: %" PRId64 "\n", i, count);
-    }
-#endif
-}
-
 static const uint32_t intbit_to_level[] = {
     2, 3, 5, 7, 9, 11, 13, 2,   3, 5, 7, 9, 11, 13, 12, 12,
     6, 13, 4, 10, 8, 9, 11, 0,  0, 0, 0, 15, 15, 15, 15, 0,
hw/sparc/sun4m.c +1 -14
index 478fda8..b3915e4 100644
@@ -159,20 +159,6 @@ static void nvram_init(Nvram *nvram, uint8_t *macaddr,
     }
 }
 
-static DeviceState *slavio_intctl;
-
-void sun4m_hmp_info_pic(Monitor *mon, const QDict *qdict)
-{
-    if (slavio_intctl)
-        slavio_pic_info(mon, slavio_intctl);
-}
-
-void sun4m_hmp_info_irq(Monitor *mon, const QDict *qdict)
-{
-    if (slavio_intctl)
-        slavio_irq_info(mon, slavio_intctl);
-}
-
 void cpu_check_irqs(CPUSPARCState *env)
 {
     CPUState *cs;
@@ -873,6 +859,7 @@ static void dummy_fdc_tc(void *opaque, int irq, int level)
 static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
                           MachineState *machine)
 {
+    DeviceState *slavio_intctl;
     const char *cpu_model = machine->cpu_model;
     unsigned int i;
     void *iommu, *espdma, *ledma, *nvram;
include/hw/i386/pc.h +0 -2
index ab8e319..73178ae 100644
@@ -181,8 +181,6 @@ qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq);
 qemu_irq *kvm_i8259_init(ISABus *bus);
 int pic_read_irq(DeviceState *d);
 int pic_get_output(DeviceState *d);
-void hmp_info_pic(Monitor *mon, const QDict *qdict);
-void hmp_info_irq(Monitor *mon, const QDict *qdict);
 
 /* ioapic.c */
 
include/hw/lm32/lm32_pic.h +0 -3
index 189fa38..e6479b8 100644
@@ -8,7 +8,4 @@ uint32_t lm32_pic_get_im(DeviceState *d);
 void lm32_pic_set_ip(DeviceState *d, uint32_t ip);
 void lm32_pic_set_im(DeviceState *d, uint32_t im);
 
-void lm32_hmp_info_pic(Monitor *mon, const QDict *qdict);
-void lm32_hmp_info_irq(Monitor *mon, const QDict *qdict);
-
 #endif /* QEMU_HW_LM32_PIC_H */
include/hw/sparc/sun4m.h +0 -8
index 9c17425..580d87b 100644
@@ -24,14 +24,6 @@ static inline void sparc_iommu_memory_write(void *opaque,
     sparc_iommu_memory_rw(opaque, addr, buf, len, 1);
 }
 
-/* slavio_intctl.c */
-void slavio_pic_info(Monitor *mon, DeviceState *dev);
-void slavio_irq_info(Monitor *mon, DeviceState *dev);
-
-/* sun4m.c */
-void sun4m_hmp_info_pic(Monitor *mon, const QDict *qdict);
-void sun4m_hmp_info_irq(Monitor *mon, const QDict *qdict);
-
 /* sparc32_dma.c */
 #include "hw/sparc/sparc32_dma.h"
 
monitor.c +0 -6
index 83c4edf..d26c3bc 100644
@@ -81,12 +81,6 @@
 #include "qemu/cutils.h"
 #include "qapi/qmp/dispatch.h"
 
-/* for hmp_info_irq/pic */
-#if defined(TARGET_SPARC)
-#include "hw/sparc/sun4m.h"
-#endif
-#include "hw/lm32/lm32_pic.h"
-
 #if defined(TARGET_S390X)
 #include "hw/s390x/storage-keys.h"
 #endif
Signature · 1 line
2.1.4
#16 lore raw
In reply to Hervé Poussineau
Quoted 13 lines · Hervé Poussineau

Hi,

This patchset aims at genericizing the 'info irq' and 'info pic' HMP commands, so that it is available on all machines and can display details about more than one interrupt controller per machine.

Patch 1 adds a new interface InterruptStatsProvider, which is used to:
- gather statistics for the 'info irq' command
- print some text when 'info pic' is called

Patches 2 to 4 implement InterruptStatsProvider interface on interrupt controllers which have ad-hock code to handle 'info irq'/'info pic' commands.

Quoted 6 lines

Patch 5 removes ad-hock code, and replaces it by a generic version. You can get details about multiple interrupt controllers per machine starting here.

Patch 6 makes 'info irq'/'info pic' commands available on all architectures. For example, Alpha clipper machine is now able to display details about the i8259 interrupt controller.

Thanks for doing this. I didn't spot your first version of this, but it's a rather more thorough approach to some cleanups I attempted a while back, but never got around to completing. Looks like a nice approach.

Quoted 35 lines

Changes since v1:
- renamed interface from IntCtrl to InterruptStatsProvider

Hervé

Hervé Poussineau (6):
intc: add an interface to gather statistics/informations on interrupt
controllers
intc/i8259: implement InterruptStatsProvider interface intc/slavio_intctl: implement InterruptStatsProvider interface intc/lm32_pic: implement InterruptStatsProvider interface
intc: make HMP 'info irq' and 'info pic' commands use
InterruptStatsProvider interface
intc: make HMP 'info irq' and 'info pic' commands available on all
targets

 hmp-commands-info.hx       | 17 +----------
 hmp.c                      | 65 +++++++++++++++++++++++++++++++++++++++++
 hmp.h                      |  2 ++
 hw/intc/Makefile.objs      |  1 +
 hw/intc/i8259.c            | 73 +++++++++++++++++++++++-----------------------
 hw/intc/intc.c             | 41 ++++++++++++++++++++++++++
 hw/intc/lm32_pic.c         | 63 ++++++++++++++++++---------------------
 hw/intc/slavio_intctl.c    | 67 ++++++++++++++++++++++--------------------
 hw/sparc/sun4m.c           | 15 +---------
 include/hw/i386/pc.h       |  2 --
 include/hw/intc/intc.h     | 30 +++++++++++++++++++
 include/hw/lm32/lm32_pic.h |  3 --
 include/hw/sparc/sun4m.h   |  8 -----
 monitor.c                  |  6 ----
 14 files changed, 241 insertions(+), 152 deletions(-)
 create mode 100644 hw/intc/intc.c
 create mode 100644 include/hw/intc/intc.h
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#3 lore raw

Re: [Qemu-devel] [PATCH v2 2/6] intc/i8259: implement InterruptStatsProvider interface

In reply to Hervé Poussineau
Quoted 19 lines · Hervé Poussineau
---
 hw/intc/i8259.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
hw/intc/i8259.c +1 -0
index c2607a5..75c8d22 100644
@@ -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);

hw/intc/i8259.c static void pic_reset(DeviceState *dev) · line 262

Quoted 10 lines
hw/intc/i8259.c +8 -0
 }
 
+static bool pic_get_statistics(InterruptStatsProvider *obj,
+                               uint64_t **irq_counts, unsigned int *nb_irqs)
+{
+    PICCommonState *s = PIC_COMMON(obj);
+
+    if (s->master) {
+#ifdef DEBUG_IRQ_COUNT
+        *irq_counts = 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'm wondering if a safer interface might be to actually copy out a snapshot of the counts, which the caller is responsible for freeing.

Quoted 49 lines
hw/intc/i8259.c +28 -0
+        *nb_irqs = ARRAY_SIZE(irq_count);
+#else
+        return false;
+#endif
+    } else {
+        *irq_counts = NULL;
+        *nb_irqs = 0;
+    }
+    return true;
+}
+
+static void pic_print_info(InterruptStatsProvider *obj, Monitor *mon)
+{
+    PICCommonState *s = PIC_COMMON(obj);
+    monitor_printf(mon, "pic%d: irr=%02x imr=%02x isr=%02x hprio=%d "
+                   "irq_base=%02x rr_sel=%d elcr=%02x fnm=%d\n",
+                   s->master ? 0 : 1, s->irr, s->imr, s->isr, s->priority_add,
+                   s->irq_base, s->read_reg_select, s->elcr,
+                   s->special_fully_nested_mode);
+}
+
 static void pic_ioport_write(void *opaque, hwaddr addr64,
                              uint64_t val64, unsigned size)
 {
@@ -503,10 +533,13 @@ static void i8259_class_init(ObjectClass *klass, void *data)
 {
     PICClass *k = PIC_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
+    InterruptStatsProviderClass *ic = INTERRUPT_STATS_PROVIDER_CLASS(klass);
 
     k->parent_realize = dc->realize;
     dc->realize = pic_realize;
     dc->reset = pic_reset;
+    ic->get_statistics = pic_get_statistics;
+    ic->print_info = pic_print_info;
 }
 
 static const TypeInfo i8259_info = {
@@ -515,6 +548,10 @@ static const TypeInfo i8259_info = {
     .parent     = TYPE_PIC_COMMON,
     .class_init = i8259_class_init,
     .class_size = sizeof(PICClass),
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_INTERRUPT_STATS_PROVIDER },
+        { }
+    },
 };
 
 static void pic_register_types(void)
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#9 lore raw

Re: [Qemu-devel] [PATCH v2 3/6] intc/slavio_intctl: implement InterruptStatsProvider interface

In reply to Hervé Poussineau

Are slavio_pic_info and slavio_irq_info still used after this patch?

Quoted 79 lines · Hervé Poussineau
---
 hw/intc/slavio_intctl.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
hw/intc/slavio_intctl.c +35 -1
index e82e893..a9acb64 100644
@@ -26,6 +26,7 @@
 #include "hw/sparc/sun4m.h"
 #include "monitor/monitor.h"
 #include "hw/sysbus.h"
+#include "hw/intc/intc.h"
 #include "trace.h"
 
 //#define DEBUG_IRQ_COUNT
@@ -418,6 +419,31 @@ static void slavio_intctl_reset(DeviceState *d)
     slavio_check_interrupts(s, 0);
 }
 
+#ifdef DEBUG_IRQ_COUNT
+static bool slavio_intctl_get_statistics(InterruptStatsProvider *obj,
+                                         uint64_t **irq_counts,
+                                         unsigned int *nb_irqs)
+{
+    SLAVIO_INTCTLState *s = SLAVIO_INTCTL(obj);
+    *irq_counts = s->irq_count;
+    *nb_irqs = ARRAY_SIZE(s->irq_count);
+    return true;
+}
+#endif
+
+static void slavio_intctl_print_info(InterruptStatsProvider *obj, Monitor *mon)
+{
+    SLAVIO_INTCTLState *s = SLAVIO_INTCTL(obj);
+    int i;
+
+    for (i = 0; i < MAX_CPUS; i++) {
+        monitor_printf(mon, "per-cpu %d: pending 0x%08x\n", i,
+                       s->slaves[i].intreg_pending);
+    }
+    monitor_printf(mon, "master: pending 0x%08x, disabled 0x%08x\n",
+                   s->intregm_pending, s->intregm_disabled);
+}
+
 static void slavio_intctl_init(Object *obj)
 {
     DeviceState *dev = DEVICE(obj);
@@ -449,9 +475,14 @@ static void slavio_intctl_init(Object *obj)
 static void slavio_intctl_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    InterruptStatsProviderClass *ic = INTERRUPT_STATS_PROVIDER_CLASS(klass);
 
     dc->reset = slavio_intctl_reset;
     dc->vmsd = &vmstate_intctl;
+#ifdef DEBUG_IRQ_COUNT
+    ic->get_statistics = slavio_intctl_get_statistics;
+#endif
+    ic->print_info = slavio_intctl_print_info;
 }
 
 static const TypeInfo slavio_intctl_info = {
@@ -460,6 +491,10 @@ static const TypeInfo slavio_intctl_info = {
     .instance_size = sizeof(SLAVIO_INTCTLState),
     .instance_init = slavio_intctl_init,
     .class_init    = slavio_intctl_class_init,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_INTERRUPT_STATS_PROVIDER },
+        { }
+    },
 };
 
 static void slavio_intctl_register_types(void)
--

2.1.4

Signature · 4 lines
Regards,
Artyom Tarasenko

SPARC and PPC PReP under qemu blog: http://tyom.blogspot.com/search/label/qemu
#10 lore raw

Re: [Qemu-devel] [PATCH v2 3/6] intc/slavio_intctl: implement InterruptStatsProvider interface

Quoted 1 line · Artyom Tarasenko

Are slavio_pic_info and slavio_irq_info still used after this patch?

After this patch, yes.
However, slavio_pic_info/slavio_irq_info (and sun4m_hmp_info_pic/sun4m_hmp_info_irq) will be removed in patch 5/6.

Hervé

Quoted 84 lines · Hervé Poussineau
Quoted 79 lines
---
 hw/intc/slavio_intctl.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
hw/intc/slavio_intctl.c +35 -1
index e82e893..a9acb64 100644
@@ -26,6 +26,7 @@
 #include "hw/sparc/sun4m.h"
 #include "monitor/monitor.h"
 #include "hw/sysbus.h"
+#include "hw/intc/intc.h"
 #include "trace.h"
 
 //#define DEBUG_IRQ_COUNT
@@ -418,6 +419,31 @@ static void slavio_intctl_reset(DeviceState *d)
     slavio_check_interrupts(s, 0);
 }
 
+#ifdef DEBUG_IRQ_COUNT
+static bool slavio_intctl_get_statistics(InterruptStatsProvider *obj,
+                                         uint64_t **irq_counts,
+                                         unsigned int *nb_irqs)
+{
+    SLAVIO_INTCTLState *s = SLAVIO_INTCTL(obj);
+    *irq_counts = s->irq_count;
+    *nb_irqs = ARRAY_SIZE(s->irq_count);
+    return true;
+}
+#endif
+
+static void slavio_intctl_print_info(InterruptStatsProvider *obj, Monitor *mon)
+{
+    SLAVIO_INTCTLState *s = SLAVIO_INTCTL(obj);
+    int i;
+
+    for (i = 0; i < MAX_CPUS; i++) {
+        monitor_printf(mon, "per-cpu %d: pending 0x%08x\n", i,
+                       s->slaves[i].intreg_pending);
+    }
+    monitor_printf(mon, "master: pending 0x%08x, disabled 0x%08x\n",
+                   s->intregm_pending, s->intregm_disabled);
+}
+
 static void slavio_intctl_init(Object *obj)
 {
     DeviceState *dev = DEVICE(obj);
@@ -449,9 +475,14 @@ static void slavio_intctl_init(Object *obj)
 static void slavio_intctl_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    InterruptStatsProviderClass *ic = INTERRUPT_STATS_PROVIDER_CLASS(klass);
 
     dc->reset = slavio_intctl_reset;
     dc->vmsd = &vmstate_intctl;
+#ifdef DEBUG_IRQ_COUNT
+    ic->get_statistics = slavio_intctl_get_statistics;
+#endif
+    ic->print_info = slavio_intctl_print_info;
 }
 
 static const TypeInfo slavio_intctl_info = {
@@ -460,6 +491,10 @@ static const TypeInfo slavio_intctl_info = {
     .instance_size = sizeof(SLAVIO_INTCTLState),
     .instance_init = slavio_intctl_init,
     .class_init    = slavio_intctl_class_init,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_INTERRUPT_STATS_PROVIDER },
+        { }
+    },
 };
 
 static void slavio_intctl_register_types(void)
--

2.1.4

#4 lore raw

Re: [Qemu-devel] [PATCH v2 2/6] intc/i8259: implement InterruptStatsProvider interface

In reply to David Gibson
Quoted 34 lines · David Gibson
Quoted 19 lines · Hervé Poussineau
---
 hw/intc/i8259.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
hw/intc/i8259.c +1 -0
index c2607a5..75c8d22 100644
@@ -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);

hw/intc/i8259.c static void pic_reset(DeviceState *dev) · line 262

Quoted 10 lines
hw/intc/i8259.c +8 -0
 }
 
+static bool pic_get_statistics(InterruptStatsProvider *obj,
+                               uint64_t **irq_counts, unsigned int *nb_irqs)
+{
+    PICCommonState *s = PIC_COMMON(obj);
+
+    if (s->master) {
+#ifdef DEBUG_IRQ_COUNT
+        *irq_counts = 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.

Quoted 5 lines

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 = ...;
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 updated on each get_statistics() call.

Quoted 2 lines

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é

Quoted 12 lines
Quoted 12 lines
hw/intc/i8259.c +11 -0
+        *nb_irqs = ARRAY_SIZE(irq_count);
+#else
+        return false;
+#endif
+    } else {
+        *irq_counts = NULL;
+        *nb_irqs = 0;
+    }
+    return true;
+}
+
#5 lore raw

Re: [Qemu-devel] [PATCH v2 2/6] intc/i8259: implement InterruptStatsProvider interface

Quoted 35 lines · Hervé Poussineau
Quoted 34 lines · David Gibson
Quoted 19 lines · Hervé Poussineau
---
 hw/intc/i8259.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
hw/intc/i8259.c +1 -0
index c2607a5..75c8d22 100644
@@ -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);

hw/intc/i8259.c static void pic_reset(DeviceState *dev) · line 262

Quoted 10 lines
hw/intc/i8259.c +8 -0
 }
 
+static bool pic_get_statistics(InterruptStatsProvider *obj,
+                               uint64_t **irq_counts, unsigned int *nb_irqs)
+{
+    PICCommonState *s = PIC_COMMON(obj);
+
+    if (s->master) {
+#ifdef DEBUG_IRQ_COUNT
+        *irq_counts = 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.

Quoted 8 lines
Quoted 5 lines

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:

Ok, that's a pretty strong argument.

Quoted 20 lines

my_device_irq_handler(int n)
{
MyDeviceState *s = ...;
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

Quoted 8 lines

For your intc, you'll need to have a second array irq_count, which is updated on each get_statistics() call.

Quoted 2 lines

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.

True.

I still feel a bit uneasy without having some sort of description of the length of validity of the pointer. With the current implementation and use cases, it seems like "until the BQL is next dropped" would be about right. Does that seem like it's correct to you?

Quoted 16 lines

Hervé

Quoted 12 lines
Quoted 12 lines
hw/intc/i8259.c +11 -0
+        *nb_irqs = ARRAY_SIZE(irq_count);
+#else
+        return false;
+#endif
+    } else {
+        *irq_counts = NULL;
+        *nb_irqs = 0;
+    }
+    return true;
+}
+
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#6 lore raw

Re: [Qemu-devel] [PATCH v2 2/6] intc/i8259: implement InterruptStatsProvider interface

Quoted 76 lines · David Gibson
Quoted 35 lines · Hervé Poussineau
Quoted 34 lines · David Gibson
Quoted 19 lines · Hervé Poussineau
---
 hw/intc/i8259.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
hw/intc/i8259.c +1 -0
index c2607a5..75c8d22 100644
@@ -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);

hw/intc/i8259.c static void pic_reset(DeviceState *dev) · line 262

Quoted 10 lines
hw/intc/i8259.c +8 -0
 }
 
+static bool pic_get_statistics(InterruptStatsProvider *obj,
+                               uint64_t **irq_counts, unsigned int *nb_irqs)
+{
+    PICCommonState *s = PIC_COMMON(obj);
+
+    if (s->master) {
+#ifdef DEBUG_IRQ_COUNT
+        *irq_counts = 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.

Quoted 8 lines
Quoted 5 lines

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:

Ok, that's a pretty strong argument.

Quoted 20 lines

my_device_irq_handler(int n)
{
MyDeviceState *s = ...;
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

Quoted 8 lines

For your intc, you'll need to have a second array irq_count, which is updated on each get_statistics() call.

Quoted 2 lines

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.

Quoted 6 lines

True.

I still feel a bit uneasy without having some sort of description of the length of validity of the pointer. With the current implementation and use cases, it seems like "until the BQL is next dropped" would be about right. Does that seem like it's correct to you?

Yes, it seems correct.
I can add in interface header that:
"Returned pointer and statistics must remain valid until the BQL is next dropped"

Does it require a v3?

Quoted 18 lines
Quoted 17 lines

Hervé

Quoted 12 lines
Quoted 12 lines
hw/intc/i8259.c +11 -0
+        *nb_irqs = ARRAY_SIZE(irq_count);
+#else
+        return false;
+#endif
+    } else {
+        *irq_counts = NULL;
+        *nb_irqs = 0;
+    }
+    return true;
+}
+
Reviewed-by
#7 lore raw

Re: [Qemu-devel] [PATCH v2 2/6] intc/i8259: implement InterruptStatsProvider interface

Quoted 84 lines · Hervé Poussineau
Quoted 76 lines · David Gibson
Quoted 35 lines · Hervé Poussineau
Quoted 34 lines · David Gibson
Quoted 19 lines · Hervé Poussineau
---
 hw/intc/i8259.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
hw/intc/i8259.c +1 -0
index c2607a5..75c8d22 100644
@@ -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);

hw/intc/i8259.c static void pic_reset(DeviceState *dev) · line 262

Quoted 10 lines
hw/intc/i8259.c +8 -0
 }
 
+static bool pic_get_statistics(InterruptStatsProvider *obj,
+                               uint64_t **irq_counts, unsigned int *nb_irqs)
+{
+    PICCommonState *s = PIC_COMMON(obj);
+
+    if (s->master) {
+#ifdef DEBUG_IRQ_COUNT
+        *irq_counts = 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.

Quoted 8 lines
Quoted 5 lines

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:

Ok, that's a pretty strong argument.

Quoted 20 lines

my_device_irq_handler(int n)
{
MyDeviceState *s = ...;
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

Quoted 8 lines

For your intc, you'll need to have a second array irq_count, which is updated on each get_statistics() call.

Quoted 2 lines

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.

Quoted 6 lines

True.

I still feel a bit uneasy without having some sort of description of the length of validity of the pointer. With the current implementation and use cases, it seems like "until the BQL is next dropped" would be about right. Does that seem like it's correct to you?

Quoted 4 lines

Yes, it seems correct.
I can add in interface header that:
"Returned pointer and statistics must remain valid until the BQL is next dropped"

Ok, makes sense.

Quoted 1 line

Does it require a v3?

Not for my sake.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#11 lore raw

Re: [Qemu-devel] [PATCH v2 3/6] intc/slavio_intctl: implement InterruptStatsProvider interface

In reply to Hervé Poussineau
Quoted 9 lines · Hervé Poussineau
Quoted 2 lines · Artyom Tarasenko

Are slavio_pic_info and slavio_irq_info still used after this patch?

After this patch, yes.
However, slavio_pic_info/slavio_irq_info (and sun4m_hmp_info_pic/sun4m_hmp_info_irq) will be removed in patch 5/6.

Oh. The 5/6 somehow didn't make it to my inbox, so I missed it.

Quoted 91 lines
Quoted 90 lines
Quoted 82 lines · Hervé Poussineau
---
 hw/intc/slavio_intctl.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
hw/intc/slavio_intctl.c +26 -0
index e82e893..a9acb64 100644
@@ -26,6 +26,7 @@
 #include "hw/sparc/sun4m.h"
 #include "monitor/monitor.h"
 #include "hw/sysbus.h"
+#include "hw/intc/intc.h"
 #include "trace.h"
 
 //#define DEBUG_IRQ_COUNT
@@ -418,6 +419,31 @@ static void slavio_intctl_reset(DeviceState *d)
     slavio_check_interrupts(s, 0);
 }
 
+#ifdef DEBUG_IRQ_COUNT
+static bool slavio_intctl_get_statistics(InterruptStatsProvider *obj,
+                                         uint64_t **irq_counts,
+                                         unsigned int *nb_irqs)
+{
+    SLAVIO_INTCTLState *s = SLAVIO_INTCTL(obj);
+    *irq_counts = s->irq_count;
+    *nb_irqs = ARRAY_SIZE(s->irq_count);
+    return true;
+}
+#endif
+
+static void slavio_intctl_print_info(InterruptStatsProvider *obj,
 Monitor *mon)
+{
+    SLAVIO_INTCTLState *s = SLAVIO_INTCTL(obj);
+    int i;
+
+    for (i = 0; i < MAX_CPUS; i++) {
+        monitor_printf(mon, "per-cpu %d: pending 0x%08x\n", i,
+                       s->slaves[i].intreg_pending);
+    }
+    monitor_printf(mon, "master: pending 0x%08x, disabled 0x%08x\n",
+                   s->intregm_pending, s->intregm_disabled);
+}
+
 static void slavio_intctl_init(Object *obj)
 {
     DeviceState *dev = DEVICE(obj);
hw/intc/slavio_intctl.c +5 -0
@@ -449,9 +475,14 @@ static void slavio_intctl_init(Object *obj)
 static void slavio_intctl_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    InterruptStatsProviderClass *ic =
 INTERRUPT_STATS_PROVIDER_CLASS(klass);
 
     dc->reset = slavio_intctl_reset;
     dc->vmsd = &vmstate_intctl;
+#ifdef DEBUG_IRQ_COUNT
+    ic->get_statistics = slavio_intctl_get_statistics;
+#endif
+    ic->print_info = slavio_intctl_print_info;
 }
 

static const TypeInfo slavio_intctl_info = {

hw/intc/slavio_intctl.c +4 -1
@@ -460,6 +491,10 @@ static const TypeInfo slavio_intctl_info = {
     .instance_size = sizeof(SLAVIO_INTCTLState),
     .instance_init = slavio_intctl_init,
     .class_init    = slavio_intctl_class_init,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_INTERRUPT_STATS_PROVIDER },
+        { }
+    },
 };
 
 static void slavio_intctl_register_types(void)
--

2.1.4

Signature · 4 lines
Regards,
Artyom Tarasenko

SPARC and PPC PReP under qemu blog: http://tyom.blogspot.com/search/label/qemu
#14 lore raw

Re: [Qemu-devel] [PATCH v2 5/6] intc: make HMP 'info irq' and 'info pic' commands use InterruptStatsProvider interface

In reply to Hervé Poussineau
Quoted 104 lines · Hervé Poussineau
---
 hmp-commands-info.hx       | 12 ---------
 hmp.c                      | 65 ++++++++++++++++++++++++++++++++++++++++++++++
 hmp.h                      |  2 ++
 hw/intc/i8259.c            | 36 -------------------------
 hw/intc/lm32_pic.c         | 31 ----------------------
 hw/intc/slavio_intctl.c    | 32 -----------------------
 hw/sparc/sun4m.c           | 15 +----------
 include/hw/i386/pc.h       |  2 --
 include/hw/lm32/lm32_pic.h |  3 ---
 include/hw/sparc/sun4m.h   |  8 ------
 monitor.c                  |  6 -----
 11 files changed, 68 insertions(+), 144 deletions(-)
hmp-commands-info.hx +0 -12
index 19729e5..6a7c476 100644
@@ -179,13 +179,7 @@ ETEXI
         .args_type  = "",
         .params     = "",
         .help       = "show the interrupts statistics (if available)",
-#ifdef TARGET_SPARC
-        .cmd        = sun4m_hmp_info_irq,
-#elif defined(TARGET_LM32)
-        .cmd        = lm32_hmp_info_irq,
-#else
         .cmd        = hmp_info_irq,
-#endif
     },
 
 STEXI
@@ -199,13 +193,7 @@ ETEXI
         .args_type  = "",
         .params     = "",
         .help       = "show i8259 (PIC) state",
-#ifdef TARGET_SPARC
-        .cmd        = sun4m_hmp_info_pic,
-#elif defined(TARGET_LM32)
-        .cmd        = lm32_hmp_info_pic,
-#else
         .cmd        = hmp_info_pic,
-#endif
     },
 #endif
 
hmp.c +42 -0
index 336e7bf..ec2e9ce 100644
@@ -36,6 +36,7 @@
 #include "qemu-io.h"
 #include "qemu/cutils.h"
 #include "qemu/error-report.h"
+#include "hw/intc/intc.h"
 
 #ifdef CONFIG_SPICE
 #include <spice/enums.h>
@@ -787,6 +788,70 @@ static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
     }
 }
 
+static int hmp_info_irq_foreach(Object *obj, void *opaque)
+{
+    InterruptStatsProvider *intc;
+    InterruptStatsProviderClass *k;
+    Monitor *mon = opaque;
+
+    if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
+        intc = INTERRUPT_STATS_PROVIDER(obj);
+        k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
+        uint64_t *irq_counts;
+        unsigned int nb_irqs, i;
+        if (k->get_statistics &&
+            k->get_statistics(intc, &irq_counts, &nb_irqs)) {
+            if (nb_irqs > 0) {
+                monitor_printf(mon, "IRQ statistics for %s:\n",
+                               object_get_typename(obj));
+                for (i = 0; i < nb_irqs; i++) {
+                    if (irq_counts[i] > 0) {
+                        monitor_printf(mon, "%2d: %" PRId64 "\n", i,
+                                       irq_counts[i]);
+                    }
+                }
+            }
+        } else {
+            monitor_printf(mon, "IRQ statistics not available for %s.\n",
+                           object_get_typename(obj));
+        }
+    }
+
+    return 0;
+}
+
+void hmp_info_irq(Monitor *mon, const QDict *qdict)
+{
+    object_child_foreach_recursive(object_get_root(),
+                                   hmp_info_irq_foreach, mon);
+}
+
+static int hmp_info_pic_foreach(Object *obj, void *opaque)
+{
+    InterruptStatsProvider *intc;

hmp.c static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) · line 841

Quoted 10 lines
hmp.c +10 -0
+    InterruptStatsProviderClass *k;
+    Monitor *mon = opaque;
+
+    if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
+        intc = INTERRUPT_STATS_PROVIDER(obj);
+        k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
+        if (k->print_info) {
+            k->print_info(intc, mon);
+        } else {
+            monitor_printf(mon, "PIC informations not available for %s.\n",

Replacing with "Interrupt controller information", otherwise I'm queuing the series.

Paolo

Quoted 263 lines
hmp.c +13 -0
+                           object_get_typename(obj));
+        }
+    }
+
+    return 0;
+}
+
+void hmp_info_pic(Monitor *mon, const QDict *qdict)
+{
+    object_child_foreach_recursive(object_get_root(),
+                                   hmp_info_pic_foreach, mon);
+}
+
 void hmp_info_pci(Monitor *mon, const QDict *qdict)
 {
     PciInfoList *info_list, *info;
hmp.h +2 -0
index 0876ec0..184769c 100644
@@ -36,6 +36,8 @@ void hmp_info_blockstats(Monitor *mon, const QDict *qdict);
 void hmp_info_vnc(Monitor *mon, const QDict *qdict);
 void hmp_info_spice(Monitor *mon, const QDict *qdict);
 void hmp_info_balloon(Monitor *mon, const QDict *qdict);
+void hmp_info_irq(Monitor *mon, const QDict *qdict);
+void hmp_info_pic(Monitor *mon, const QDict *qdict);
 void hmp_info_pci(Monitor *mon, const QDict *qdict);
 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict);
 void hmp_info_tpm(Monitor *mon, const QDict *qdict);
hw/intc/i8259.c +0 -36
index 75c8d22..fe9ecd6 100644
@@ -461,42 +461,6 @@ static void pic_realize(DeviceState *dev, Error **errp)
     pc->parent_realize(dev, errp);
 }
 
-void hmp_info_pic(Monitor *mon, const QDict *qdict)
-{
-    int i;
-    PICCommonState *s;
-
-    if (!isa_pic) {
-        return;
-    }
-    for (i = 0; i < 2; i++) {
-        s = i == 0 ? PIC_COMMON(isa_pic) : slave_pic;
-        monitor_printf(mon, "pic%d: irr=%02x imr=%02x isr=%02x hprio=%d "
-                       "irq_base=%02x rr_sel=%d elcr=%02x fnm=%d\n",
-                       i, s->irr, s->imr, s->isr, s->priority_add,
-                       s->irq_base, s->read_reg_select, s->elcr,
-                       s->special_fully_nested_mode);
-    }
-}
-
-void hmp_info_irq(Monitor *mon, const QDict *qdict)
-{
-#ifndef DEBUG_IRQ_COUNT
-    monitor_printf(mon, "irq statistic code not compiled.\n");
-#else
-    int i;
-    int64_t count;
-
-    monitor_printf(mon, "IRQ statistics:\n");
-    for (i = 0; i < 16; i++) {
-        count = irq_count[i];
-        if (count > 0) {
-            monitor_printf(mon, "%2d: %" PRId64 "\n", i, count);
-        }
-    }
-#endif
-}
-
 qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq)
 {
     qemu_irq *irq_set;
hw/intc/lm32_pic.c +0 -31
index c045b99..09e1511 100644
@@ -43,35 +43,6 @@ struct LM32PicState {
 };
 typedef struct LM32PicState LM32PicState;
 
-static LM32PicState *pic;
-void lm32_hmp_info_pic(Monitor *mon, const QDict *qdict)
-{
-    if (pic == NULL) {
-        return;
-    }
-
-    monitor_printf(mon, "lm32-pic: im=%08x ip=%08x irq_state=%08x\n",
-            pic->im, pic->ip, pic->irq_state);
-}
-
-void lm32_hmp_info_irq(Monitor *mon, const QDict *qdict)
-{
-    int i;
-    uint32_t count;
-
-    if (pic == NULL) {
-        return;
-    }
-
-    monitor_printf(mon, "IRQ statistics:\n");
-    for (i = 0; i < 32; i++) {
-        count = pic->stats_irq_count[i];
-        if (count > 0) {
-            monitor_printf(mon, "%2d: %u\n", i, count);
-        }
-    }
-}
-
 static void update_irq(LM32PicState *s)
 {
     s->ip |= s->irq_state;
@@ -177,8 +148,6 @@ static void lm32_pic_init(Object *obj)
 
     qdev_init_gpio_in(dev, irq_handler, 32);
     sysbus_init_irq(sbd, &s->parent_irq);
-
-    pic = s;
 }
 
 static const VMStateDescription vmstate_lm32_pic = {
hw/intc/slavio_intctl.c +0 -32
index a9acb64..84e0bee 100644
@@ -211,38 +211,6 @@ static const MemoryRegionOps slavio_intctlm_mem_ops = {
     },
 };
 
-void slavio_pic_info(Monitor *mon, DeviceState *dev)
-{
-    SLAVIO_INTCTLState *s = SLAVIO_INTCTL(dev);
-    int i;
-
-    for (i = 0; i < MAX_CPUS; i++) {
-        monitor_printf(mon, "per-cpu %d: pending 0x%08x\n", i,
-                       s->slaves[i].intreg_pending);
-    }
-    monitor_printf(mon, "master: pending 0x%08x, disabled 0x%08x\n",
-                   s->intregm_pending, s->intregm_disabled);
-}
-
-void slavio_irq_info(Monitor *mon, DeviceState *dev)
-{
-#ifndef DEBUG_IRQ_COUNT
-    monitor_printf(mon, "irq statistic code not compiled.\n");
-#else
-    SLAVIO_INTCTLState *s = SLAVIO_INTCTL(dev);
-    int i;
-    int64_t count;
-
-    s = SLAVIO_INTCTL(dev);
-    monitor_printf(mon, "IRQ statistics:\n");
-    for (i = 0; i < 32; i++) {
-        count = s->irq_count[i];
-        if (count > 0)
-            monitor_printf(mon, "%2d: %" PRId64 "\n", i, count);
-    }
-#endif
-}
-
 static const uint32_t intbit_to_level[] = {
     2, 3, 5, 7, 9, 11, 13, 2,   3, 5, 7, 9, 11, 13, 12, 12,
     6, 13, 4, 10, 8, 9, 11, 0,  0, 0, 0, 15, 15, 15, 15, 0,
hw/sparc/sun4m.c +1 -14
index 478fda8..b3915e4 100644
@@ -159,20 +159,6 @@ static void nvram_init(Nvram *nvram, uint8_t *macaddr,
     }
 }
 
-static DeviceState *slavio_intctl;
-
-void sun4m_hmp_info_pic(Monitor *mon, const QDict *qdict)
-{
-    if (slavio_intctl)
-        slavio_pic_info(mon, slavio_intctl);
-}
-
-void sun4m_hmp_info_irq(Monitor *mon, const QDict *qdict)
-{
-    if (slavio_intctl)
-        slavio_irq_info(mon, slavio_intctl);
-}
-
 void cpu_check_irqs(CPUSPARCState *env)
 {
     CPUState *cs;
@@ -873,6 +859,7 @@ static void dummy_fdc_tc(void *opaque, int irq, int level)
 static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
                           MachineState *machine)
 {
+    DeviceState *slavio_intctl;
     const char *cpu_model = machine->cpu_model;
     unsigned int i;
     void *iommu, *espdma, *ledma, *nvram;
include/hw/i386/pc.h +0 -2
index ab8e319..73178ae 100644
@@ -181,8 +181,6 @@ qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq);
 qemu_irq *kvm_i8259_init(ISABus *bus);
 int pic_read_irq(DeviceState *d);
 int pic_get_output(DeviceState *d);
-void hmp_info_pic(Monitor *mon, const QDict *qdict);
-void hmp_info_irq(Monitor *mon, const QDict *qdict);
 
 /* ioapic.c */
 
include/hw/lm32/lm32_pic.h +0 -3
index 189fa38..e6479b8 100644
@@ -8,7 +8,4 @@ uint32_t lm32_pic_get_im(DeviceState *d);
 void lm32_pic_set_ip(DeviceState *d, uint32_t ip);
 void lm32_pic_set_im(DeviceState *d, uint32_t im);
 
-void lm32_hmp_info_pic(Monitor *mon, const QDict *qdict);
-void lm32_hmp_info_irq(Monitor *mon, const QDict *qdict);
-
 #endif /* QEMU_HW_LM32_PIC_H */
include/hw/sparc/sun4m.h +0 -8
index 9c17425..580d87b 100644
@@ -24,14 +24,6 @@ static inline void sparc_iommu_memory_write(void *opaque,
     sparc_iommu_memory_rw(opaque, addr, buf, len, 1);
 }
 
-/* slavio_intctl.c */
-void slavio_pic_info(Monitor *mon, DeviceState *dev);
-void slavio_irq_info(Monitor *mon, DeviceState *dev);
-
-/* sun4m.c */
-void sun4m_hmp_info_pic(Monitor *mon, const QDict *qdict);
-void sun4m_hmp_info_irq(Monitor *mon, const QDict *qdict);
-
 /* sparc32_dma.c */
 #include "hw/sparc/sparc32_dma.h"
 
monitor.c +0 -6
index 83c4edf..d26c3bc 100644
@@ -81,12 +81,6 @@
 #include "qemu/cutils.h"
 #include "qapi/qmp/dispatch.h"
 
-/* for hmp_info_irq/pic */
-#if defined(TARGET_SPARC)
-#include "hw/sparc/sun4m.h"
-#endif
-#include "hw/lm32/lm32_pic.h"
-
 #if defined(TARGET_S390X)
 #include "hw/s390x/storage-keys.h"
 #endif