Skip to contentSkip to conversation

ioapic: support TYPE_INTERRUPT_STATS_PROVIDER

PATCH In review Peter Xu 2 participants 8 messages Dec 29, 2017 – Jun 27, 2018

lore
Share & tools
lore

Peter Xu

author
#0 lore raw

cover ioapic: support TYPE_INTERRUPT_STATS_PROVIDER

Let ioapic join the big family. At last, I obsoleted "info ioapic", kept the interface but telling people to start use "info pic". We can fully remove it after some releases.

Please review, thanks.

Peter Xu (5):
doc: another fix to "info pic"
ioapic: support "info pic"
ioapic: some proper indents when dump info
ioapic: support "info irq"
hmp: obsolete "info ioapic"

 hmp-commands-info.hx              |  2 +-
 hw/i386/kvm/ioapic.c              | 11 ++-------
 hw/intc/ioapic.c                  | 12 +---------
 hw/intc/ioapic_common.c           | 47 +++++++++++++++++++++++++++++++++++----
 include/hw/i386/ioapic_internal.h |  3 +++
 include/hw/i386/pc.h              |  3 ---
 target/i386/monitor.c             |  8 ++-----
 7 files changed, 52 insertions(+), 34 deletions(-)
Signature · 1 line
2.14.3
author
#1 lore raw

PATCH 1/5 doc: another fix to "info pic"

Something that commit 254316fa1f ("intc: make HMP 'info irq' and 'info pic' commands available on all targets", 2016-10-04) forgot to touch up.

---
 hmp-commands-info.hx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hmp-commands-info.hx +1 -1
index 54c3e5eac6..4ae2df2f86 100644
@@ -198,7 +198,7 @@ ETEXI
 STEXI
 @item info pic
 @findex info pic
-Show i8259 (PIC) state.
+Show PIC state.
 ETEXI
 
     {
Signature · 1 line
2.14.3
author
#2 lore raw

PATCH 2/5 ioapic: support "info pic"

In reply to Peter Xu

People start to use "info pic" for all kinds of irqchip dumps. Let x86 ioapic join the family. It dumps the same thing as "info ioapic".

---
 hw/intc/ioapic_common.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
hw/intc/ioapic_common.c +16 -0
index 3b3d0a7680..c62ba27018 100644
@@ -24,6 +24,7 @@
 #include "monitor/monitor.h"
 #include "hw/i386/ioapic.h"
 #include "hw/i386/ioapic_internal.h"
+#include "hw/intc/intc.h"
 #include "hw/sysbus.h"
 
 /* ioapic_no count start from 0 to MAX_IOAPICS,
@@ -142,6 +143,15 @@ static void ioapic_common_realize(DeviceState *dev, Error **errp)
     ioapic_no++;
 }
 
+static void ioapic_print_info(InterruptStatsProvider *obj,
+                              Monitor *mon)
+{
+    IOAPICCommonState *s = IOAPIC_COMMON(obj);
+
+    ioapic_dispatch_pre_save(s);
+    ioapic_print_redtbl(mon, s);
+}
+
 static const VMStateDescription vmstate_ioapic_common = {
     .name = "ioapic",
     .version_id = 3,
@@ -161,9 +171,11 @@ static const VMStateDescription vmstate_ioapic_common = {
 static void ioapic_common_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    InterruptStatsProviderClass *ic = INTERRUPT_STATS_PROVIDER_CLASS(klass);
 
     dc->realize = ioapic_common_realize;
     dc->vmsd = &vmstate_ioapic_common;
+    ic->print_info = ioapic_print_info;
 }
 
 static const TypeInfo ioapic_common_type = {
@@ -173,6 +185,10 @@ static const TypeInfo ioapic_common_type = {
     .class_size = sizeof(IOAPICCommonClass),
     .class_init = ioapic_common_class_init,
     .abstract = true,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_INTERRUPT_STATS_PROVIDER },
+        { }
+    },
 };
 
 static void ioapic_common_register_types(void)
Signature · 1 line
2.14.3
author
#3 lore raw

PATCH 3/5 ioapic: some proper indents when dump info

In reply to Peter Xu

So that now it looks better when with other irqchips.

---
 hw/intc/ioapic_common.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/intc/ioapic_common.c +4 -4
index c62ba27018..a02c135b24 100644
@@ -59,7 +59,7 @@ void ioapic_print_redtbl(Monitor *mon, IOAPICCommonState *s)
     uint32_t remote_irr = 0;
     int i;
 
-    monitor_printf(mon, "ioapic ver=0x%x id=0x%02x sel=0x%02x",
+    monitor_printf(mon, "ioapic0: ver=0x%x id=0x%02x sel=0x%02x",
                    s->version, s->id, s->ioregsel);
     if (s->ioregsel) {
         monitor_printf(mon, " (redir[%u])\n",
@@ -71,7 +71,7 @@ void ioapic_print_redtbl(Monitor *mon, IOAPICCommonState *s)
         uint64_t entry = s->ioredtbl[i];
         uint32_t delm = (uint32_t)((entry & IOAPIC_LVT_DELIV_MODE) >>
                                    IOAPIC_LVT_DELIV_MODE_SHIFT);
-        monitor_printf(mon, "pin %-2u 0x%016"PRIx64" dest=%"PRIx64
+        monitor_printf(mon, "  pin %-2u 0x%016"PRIx64" dest=%"PRIx64
                        " vec=%-3"PRIu64" %s %-5s %-6s %-6s %s\n",
                        i, entry,
                        (entry >> IOAPIC_LVT_DEST_SHIFT) &
@@ -86,8 +86,8 @@ void ioapic_print_redtbl(Monitor *mon, IOAPICCommonState *s)
         remote_irr |= entry & IOAPIC_LVT_TRIGGER_MODE ?
                         (entry & IOAPIC_LVT_REMOTE_IRR ? (1 << i) : 0) : 0;
     }
-    ioapic_irr_dump(mon, "IRR", s->irr);
-    ioapic_irr_dump(mon, "Remote IRR", remote_irr);
+    ioapic_irr_dump(mon, "  IRR", s->irr);
+    ioapic_irr_dump(mon, "  Remote IRR", remote_irr);
 }
 
 void ioapic_reset_common(DeviceState *dev)
Signature · 1 line
2.14.3
author
#4 lore raw

PATCH 4/5 ioapic: support "info irq"

In reply to Peter Xu

This include both userspace and in-kernel ioapic. Note that the numbers can be inaccurate for kvm-ioapic. One reason is the same with kvm-i8259, that when irqfd is used, irqs can be delivered all inside kernel without our notice. Meanwhile, kvm-ioapic is specially treated when irq numbers <ISA_NUM_IRQS, those irqs will be delivered in kernel too via kvm-i8259 (please refer to kvm_pc_gsi_handler).

---
 hw/i386/kvm/ioapic.c              |  2 ++
 hw/intc/ioapic.c                  |  1 +
 hw/intc/ioapic_common.c           | 23 +++++++++++++++++++++++
 include/hw/i386/ioapic_internal.h |  3 +++
 4 files changed, 29 insertions(+)
hw/i386/kvm/ioapic.c +2 -0
index 98ca480792..0db9a89bd1 100644
@@ -132,8 +132,10 @@ static void kvm_ioapic_reset(DeviceState *dev)
 static void kvm_ioapic_set_irq(void *opaque, int irq, int level)
 {
     KVMIOAPICState *s = opaque;
+    IOAPICCommonState *common = IOAPIC_COMMON(s);
     int delivered;
 
+    ioapic_stat_update_irq(common, irq, level);
     delivered = kvm_set_irq(kvm_state, s->kvm_gsi_base + irq, level);
     apic_report_irq_delivered(delivered);
 }
hw/intc/ioapic.c +1 -0
index 36139a4db6..1f0c76571e 100644
@@ -149,6 +149,7 @@ static void ioapic_set_irq(void *opaque, int vector, int level)
      * the cleanest way of doing it but it should work. */
 
     trace_ioapic_set_irq(vector, level);
+    ioapic_stat_update_irq(s, vector, level);
     if (vector == 0) {
         vector = 2;
     }
hw/intc/ioapic_common.c +23 -0
index a02c135b24..692dc37bb6 100644
@@ -35,6 +35,28 @@
  */
 int ioapic_no;
 
+void ioapic_stat_update_irq(IOAPICCommonState *s, int irq, int level)
+{
+    if (level != s->irq_level[irq]) {
+        s->irq_level[irq] = level;
+        if (level == 1) {
+            s->irq_count[irq]++;
+        }
+    }
+}
+
+static bool ioapic_get_statistics(InterruptStatsProvider *obj,
+                                  uint64_t **irq_counts,
+                                  unsigned int *nb_irqs)
+{
+    IOAPICCommonState *s = IOAPIC_COMMON(obj);
+
+    *irq_counts = s->irq_count;
+    *nb_irqs = IOAPIC_NUM_PINS;
+
+    return true;
+}
+
 static void ioapic_irr_dump(Monitor *mon, const char *name, uint32_t bitmap)
 {
     int i;
@@ -176,6 +198,7 @@ static void ioapic_common_class_init(ObjectClass *klass, void *data)
     dc->realize = ioapic_common_realize;
     dc->vmsd = &vmstate_ioapic_common;
     ic->print_info = ioapic_print_info;
+    ic->get_statistics = ioapic_get_statistics;
 }
 
 static const TypeInfo ioapic_common_type = {
include/hw/i386/ioapic_internal.h +3 -0
index a11d86de46..9848f391bb 100644
@@ -109,10 +109,13 @@ struct IOAPICCommonState {
     uint64_t ioredtbl[IOAPIC_NUM_PINS];
     Notifier machine_done;
     uint8_t version;
+    uint64_t irq_count[IOAPIC_NUM_PINS];
+    int irq_level[IOAPIC_NUM_PINS];
 };
 
 void ioapic_reset_common(DeviceState *dev);
 
 void ioapic_print_redtbl(Monitor *mon, IOAPICCommonState *s);
+void ioapic_stat_update_irq(IOAPICCommonState *s, int irq, int level);
 
 #endif /* QEMU_IOAPIC_INTERNAL_H */
Signature · 1 line
2.14.3
author
#5 lore raw

PATCH 5/5 hmp: obsolete "info ioapic"

In reply to Peter Xu

Let's start to use "info pic" just like other platforms. For now we keep the command for a while so that old users can know what is the new command to use.

---
 hw/i386/kvm/ioapic.c  |  9 ---------
 hw/intc/ioapic.c      | 11 -----------
 include/hw/i386/pc.h  |  3 ---
 target/i386/monitor.c |  8 ++------
 4 files changed, 2 insertions(+), 29 deletions(-)
hw/i386/kvm/ioapic.c +0 -9
index 0db9a89bd1..e6cb468910 100644
@@ -112,15 +112,6 @@ static void kvm_ioapic_put(IOAPICCommonState *s)
     }
 }
 
-void kvm_ioapic_dump_state(Monitor *mon, const QDict *qdict)
-{
-    IOAPICCommonState *s = IOAPIC_COMMON(object_resolve_path("ioapic", NULL));
-
-    assert(s);
-    kvm_ioapic_get(s);
-    ioapic_print_redtbl(mon, s);
-}
-
 static void kvm_ioapic_reset(DeviceState *dev)
 {
     IOAPICCommonState *s = IOAPIC_COMMON(dev);
hw/intc/ioapic.c +0 -11
index 1f0c76571e..aa7f030971 100644
@@ -235,17 +235,6 @@ void ioapic_eoi_broadcast(int vector)
     }
 }
 
-void ioapic_dump_state(Monitor *mon, const QDict *qdict)
-{
-    int i;
-
-    for (i = 0; i < MAX_IOAPICS; i++) {
-        if (ioapics[i] != 0) {
-            ioapic_print_redtbl(mon, ioapics[i]);
-        }
-    }
-}
-
 static uint64_t
 ioapic_mem_read(void *opaque, hwaddr addr, unsigned int size)
 {
include/hw/i386/pc.h +0 -3
index 6f77eb0665..b9f8a79967 100644
@@ -169,9 +169,6 @@ int pic_get_output(DeviceState *d);
 
 /* ioapic.c */
 
-void kvm_ioapic_dump_state(Monitor *mon, const QDict *qdict);
-void ioapic_dump_state(Monitor *mon, const QDict *qdict);
-
 /* Global System Interrupts */
 
 #define GSI_NUM_PINS IOAPIC_NUM_PINS
target/i386/monitor.c +2 -6
index 75e155ffb1..4ff81ae676 100644
@@ -652,10 +652,6 @@ void hmp_info_local_apic(Monitor *mon, const QDict *qdict)
 
 void hmp_info_io_apic(Monitor *mon, const QDict *qdict)
 {
-    if (kvm_irqchip_in_kernel() &&
-        !kvm_irqchip_is_split()) {
-        kvm_ioapic_dump_state(mon, qdict);
-    } else {
-        ioapic_dump_state(mon, qdict);
-    }
+    monitor_printf(mon, "This command is obsolete and will be "
+                   "removed soon. Please use 'info pic' instead.\n");
 }
Signature · 1 line
2.14.3
#6 lore raw
In reply to Peter Xu
Quoted 13 lines · Peter Xu

Let ioapic join the big family. At last, I obsoleted "info ioapic", kept the interface but telling people to start use "info pic". We can fully remove it after some releases.

Please review, thanks.

Peter Xu (5):
doc: another fix to "info pic"
ioapic: support "info pic"
ioapic: some proper indents when dump info
ioapic: support "info irq"
hmp: obsolete "info ioapic"

Quoted 9 lines
 hmp-commands-info.hx              |  2 +-
 hw/i386/kvm/ioapic.c              | 11 ++-------
 hw/intc/ioapic.c                  | 12 +---------
 hw/intc/ioapic_common.c           | 47 +++++++++++++++++++++++++++++++++++----
 include/hw/i386/ioapic_internal.h |  3 +++
 include/hw/i386/pc.h              |  3 ---
 target/i386/monitor.c             |  8 ++-----
 7 files changed, 52 insertions(+), 34 deletions(-)

Queued, better late than never.

Paolo

author
#7 lore raw
Quoted 24 lines · Paolo Bonzini
Quoted 13 lines · Peter Xu

Let ioapic join the big family. At last, I obsoleted "info ioapic", kept the interface but telling people to start use "info pic". We can fully remove it after some releases.

Please review, thanks.

Peter Xu (5):
doc: another fix to "info pic"
ioapic: support "info pic"
ioapic: some proper indents when dump info
ioapic: support "info irq"
hmp: obsolete "info ioapic"

Quoted 9 lines
 hmp-commands-info.hx              |  2 +-
 hw/i386/kvm/ioapic.c              | 11 ++-------
 hw/intc/ioapic.c                  | 12 +---------
 hw/intc/ioapic_common.c           | 47 +++++++++++++++++++++++++++++++++++----
 include/hw/i386/ioapic_internal.h |  3 +++
 include/hw/i386/pc.h              |  3 ---
 target/i386/monitor.c             |  8 ++-----
 7 files changed, 52 insertions(+), 34 deletions(-)
Quoted 1 line

Queued, better late than never.

Thanks, Paolo. :)

Signature · 1 line
Peter Xu