Re: [patch v2 04/14] x86/irq: Make irqstats array based

From: Radu Rendec

Date: Wed Mar 25 2026 - 15:20:54 EST


On Tue, 2026-03-24 at 16:32 -0400, Radu Rendec wrote:
> On Tue, 2026-03-24 at 21:21 +0100, Thomas Gleixner wrote:
> > On Tue, Mar 24 2026 at 20:54, Thomas Gleixner wrote:
> >
> > > On Mon, Mar 23 2026 at 15:24, Radu Rendec wrote:
> > > > On Fri, 2026-03-20 at 14:21 +0100, Thomas Gleixner wrote:
> > > > >  arch/x86/include/asm/hardirq.h      |   69 +++++-----
> > > >
> > > > I believe this breaks scripts/gdb/linux/interrupts.py, particularly the
> > > > x86_show_irqstat() function, which still expects individual members in
> > > > struct irq_cpustat_t.
> > >
> > > Uurg. I did not even know this exists. Let me try to polish the snake.
> >
> > Something like the below should work, now I have to figure out how to
> > test it.
>
> At a glance, it looks about right (although I haven't tested it). The
> test procedure involves running the kernel in a Qemu VM and attaching
> with gdb to Qemu's gdb server (apologies if I'm just stating the
> obvious here). It's briefly described here:
> Documentation/dev-tools/gdb-kernel-debugging.rst
>
> The documentation doesn't elaborate on Qemu parameters. I'm using
> something like this:
>
> qemu-system-x86_64 -nographic -m 1G -accel kvm -machine q35,hpet=off -cpu host -smp 4 \
>         -netdev bridge,br=vbr-nat,id=net0 -device virtio-net-pci,mac=52:54:98:aa:bb:cc,netdev=net0 \
>         -drive file=root.img,format=raw,if=virtio \
>         -kernel bzImage \
>         -append "console=ttyS0 root=/dev/vda1 rw nokaslr" \
>         -s
>
> Happy to help if something doesn't quite work for you.
>
> > ----
> > --- a/scripts/gdb/linux/interrupts.py
> > +++ b/scripts/gdb/linux/interrupts.py
> > @@ -97,8 +97,8 @@ irq_desc_type = utils.CachedType("struct
> >          text += "%*s: %10u\n" % (prec, "ERR", cnt['counter'])
> >      return text
> >  
> > -def x86_show_irqstat(prec, pfx, field, desc):
> > -    irq_stat = gdb.parse_and_eval("&irq_stat")
> > +def x86_show_irqstat(prec, pfx, idx, desc):
> > +    irq_stat = gdb.parse_and_eval("&irq_stat.counts[IRQ_COUNT_%s]" %idx)
> >      text = "%*s: " % (prec, pfx)
> >      for cpu in cpus.each_online_cpu():
> >          stat = cpus.per_cpu(irq_stat, cpu)
> > @@ -118,32 +118,51 @@ irq_desc_type = utils.CachedType("struct
> >      text = x86_show_irqstat(prec, "NMI", '__nmi_count', 'Non-maskable interrupts')
> >  
> >      if constants.LX_CONFIG_X86_LOCAL_APIC:
> > -        text += x86_show_irqstat(prec, "LOC", 'apic_timer_irqs', "Local timer interrupts")
> > -        text += x86_show_irqstat(prec, "SPU", 'irq_spurious_count', "Spurious interrupts")
> > -        text += x86_show_irqstat(prec, "PMI", 'apic_perf_irqs', "Performance monitoring interrupts")
> > -        text += x86_show_irqstat(prec, "IWI", 'apic_irq_work_irqs', "IRQ work interrupts")
> > -        text += x86_show_irqstat(prec, "RTR", 'icr_read_retry_count', "APIC ICR read retries")
> > +        text += x86_show_irqstat(prec, "LOC", 'APIC_TIMER', "Local timer interrupts")
> > +        text += x86_show_irqstat(prec, "SPU", 'SPURIOUS', "Spurious interrupts")
> > +        text += x86_show_irqstat(prec, "PMI", 'APIC_PERF', "Performance monitoring interrupts")
> > +        text += x86_show_irqstat(prec, "IWI", 'IRQ_WORK', "IRQ work interrupts")
> > +        text += x86_show_irqstat(prec, "RTR", 'ICR_READ_RETRY', "APIC ICR read retries")
> >          if utils.gdb_eval_or_none("x86_platform_ipi_callback") is not None:
> > -            text += x86_show_irqstat(prec, "PLT", 'x86_platform_ipis', "Platform interrupts")
> > +            text += x86_show_irqstat(prec, "PLT", 'X86_PLATFORM_IPI', "Platform interrupts")
> >  
> >      if constants.LX_CONFIG_SMP:
> > -        text += x86_show_irqstat(prec, "RES", 'irq_resched_count', "Rescheduling interrupts")
> > -        text += x86_show_irqstat(prec, "CAL", 'irq_call_count', "Function call interrupts")
> > -        text += x86_show_irqstat(prec, "TLB", 'irq_tlb_count', "TLB shootdowns")
> > +        text += x86_show_irqstat(prec, "RES", 'RESCHEDULE', "Rescheduling interrupts")
> > +        text += x86_show_irqstat(prec, "CAL", 'CALL_FUNCTION', "Function call interrupts")
> > +
> > +    text += x86_show_irqstat(prec, "TLB", 'TLB', "TLB shootdowns")
> >  
> >      if constants.LX_CONFIG_X86_THERMAL_VECTOR:
> > -        text += x86_show_irqstat(prec, "TRM", 'irq_thermal_count', "Thermal events interrupts")
> > +        text += x86_show_irqstat(prec, "TRM", 'THERMAL_APIC', "Thermal events interrupts")
> >  
> >      if constants.LX_CONFIG_X86_MCE_THRESHOLD:
> > -        text += x86_show_irqstat(prec, "THR", 'irq_threshold_count', "Threshold APIC interrupts")
> > +        text += x86_show_irqstat(prec, "THR", 'THRESHOLD_APIC', "Threshold APIC interrupts")
> >  
> >      if constants.LX_CONFIG_X86_MCE_AMD:
> > -        text += x86_show_irqstat(prec, "DFR", 'irq_deferred_error_count', "Deferred Error APIC interrupts")
> > +        text += x86_show_irqstat(prec, "DFR", 'DEFERRED_ERROR', "Deferred Error APIC interrupts")
> >  
> >      if constants.LX_CONFIG_X86_MCE:
> >          text += x86_show_mce(prec, "&mce_exception_count", "MCE", "Machine check exceptions")
> >          text += x86_show_mce(prec, "&mce_poll_count", "MCP", "Machine check polls")
> >  
> > +    if constants.LX_CONFIG_X86_HV_CALLBACK_VECTOR:
> > +        text += x86_show_irqstat(prec, 'HYP', 'HYPERVISOR_CALLBACK', 'Hypervisor callback interrupts')
> > +
> > +    if constants.LX_CONFIG_HYPERV:
> > +        text += x86_show_irqstat(prec, 'HRE', 'HYPERV_REENLIGHTENMENT', 'Hyper-V reenlightenment interrupts')
> > +        text += x86_show_irqstat(prec, 'HVS', 'HYPERV_STIMER0', 'Hyper-V stimer0 interrupts')
> > +
> > +    if constants.LX_CONFIG_KVM:
> > +        text += x86_show_irqstat(prec, "PIN", 'POSTED_INTR', 'Posted-interrupt notification event')
> > +        text += x86_show_irqstat(prec, "NPI", 'POSTED_INTR_NESTED', 'Nested posted-interrupt event')
> > +        text += x86_show_irqstat(prec, "PIW", 'POSTED_INTR_WAKEUP', 'Posted-interrupt wakeup event')
> > +
> > +    if constants.LX_CONFIG_GUEST_PERF_EVENTS:
> > +        text += x86_show_irqstat(prec, "VPMI", 'PERF_GUEST_MEDIATED_PMI', 'Perf Guest Mediated PMI')
> > +
> > +    if constants.LX_CONFIG_X86_POSTED_MSI:
> > +        text += x86_show_irqstat(prec, "PIN", 'POSTED_MSI_NOTIFICATION', 'Posted MSI notification event')
> > +
> >      text += show_irq_err_count(prec)
> >  
> >      if constants.LX_CONFIG_X86_IO_APIC:
> > @@ -151,11 +170,6 @@ irq_desc_type = utils.CachedType("struct
> >          if cnt is not None:
> >              text += "%*s: %10u\n" % (prec, "MIS", cnt['counter'])
> >  
> > -    if constants.LX_CONFIG_KVM:
> > -        text += x86_show_irqstat(prec, "PIN", 'kvm_posted_intr_ipis', 'Posted-interrupt notification event')
> > -        text += x86_show_irqstat(prec, "NPI", 'kvm_posted_intr_nested_ipis', 'Nested posted-interrupt event')
> > -        text += x86_show_irqstat(prec, "PIW", 'kvm_posted_intr_wakeup_ipis', 'Posted-interrupt wakeup event')
> > -
> >      return text
> >  
> >  def arm_common_show_interrupts(prec):

I tested it, and it's very close but requires a few extra changes,
which I included as a patch at the bottom.

There's one more gotcha: in the next patch (patch 5) you rename nr_irqs
to total_nr_irqs, and the change must be applied to interrupts.py as
well. It's used at the beginning of the LxInterruptList.invoke()
function.

One other issue I came across is that the fields below are not defined
for me (even though the corresponding config options do exist in the
kernel config file):
constants.LX_CONFIG_X86_HV_CALLBACK_VECTOR
constants.LX_CONFIG_HYPERV
constants.LX_CONFIG_GUEST_PERF_EVENTS
constants.LX_CONFIG_X86_POSTED_MSI

I didn't spend the time to figure out why. I'm pretty sure this is
completely unrelated to your changes.

--- a/scripts/gdb/linux/interrupts.py
+++ b/scripts/gdb/linux/interrupts.py
@@ -102,20 +102,12 @@ def x86_show_irqstat(prec, pfx, idx, desc):
text = "%*s: " % (prec, pfx)
for cpu in cpus.each_online_cpu():
stat = cpus.per_cpu(irq_stat, cpu)
- text += "%10u " % (stat[field])
- text += " %s\n" % (desc)
- return text
-
-def x86_show_mce(prec, var, pfx, desc):
- pvar = gdb.parse_and_eval(var)
- text = "%*s: " % (prec, pfx)
- for cpu in cpus.each_online_cpu():
- text += "%10u " % (cpus.per_cpu(pvar, cpu).dereference())
+ text += "%10u " % (stat.dereference())
text += " %s\n" % (desc)
return text

def x86_show_interupts(prec):
- text = x86_show_irqstat(prec, "NMI", '__nmi_count', 'Non-maskable interrupts')
+ text = x86_show_irqstat(prec, "NMI", 'NMI', 'Non-maskable interrupts')

if constants.LX_CONFIG_X86_LOCAL_APIC:
text += x86_show_irqstat(prec, "LOC", 'APIC_TIMER', "Local timer interrupts")
@@ -142,8 +134,8 @@ def x86_show_interupts(prec):
text += x86_show_irqstat(prec, "DFR", 'DEFERRED_ERROR', "Deferred Error APIC interrupts")

if constants.LX_CONFIG_X86_MCE:
- text += x86_show_mce(prec, "&mce_exception_count", "MCE", "Machine check exceptions")
- text += x86_show_mce(prec, "&mce_poll_count", "MCP", "Machine check polls")
+ text += x86_show_irqstat(prec, "MCE", "MCE_EXCEPTION", "Machine check exceptions")
+ text += x86_show_irqstat(prec, "MCP", "MCE_POLL", "Machine check polls")

if constants.LX_CONFIG_X86_HV_CALLBACK_VECTOR:
text += x86_show_irqstat(prec, 'HYP', 'HYPERVISOR_CALLBACK', 'Hypervisor callback interrupts')