1 # SPDX-License-Identifier: GPL-2.0
3 # Copyright 2023 Broadcom
7 from linux import constants
9 from linux import utils
10 from linux import radixtree
12 irq_desc_type = utils.CachedType("struct irq_desc")
14 def irq_settings_is_hidden(desc):
15 return desc['status_use_accessors'] & constants.LX_IRQ_HIDDEN
17 def irq_desc_is_chained(desc):
18 return desc['action'] and desc['action'] == gdb.parse_and_eval("&chained_action")
20 def irqd_is_level(desc):
21 return desc['irq_data']['common']['state_use_accessors'] & constants.LX_IRQD_LEVEL
23 def show_irq_desc(prec, irq):
26 desc = radixtree.lookup(gdb.parse_and_eval("&irq_desc_tree"), irq)
30 desc = desc.cast(irq_desc_type.get_type())
34 if irq_settings_is_hidden(desc):
38 if desc['kstat_irqs']:
39 for cpu in cpus.each_online_cpu():
40 any_count += cpus.per_cpu(desc['kstat_irqs'], cpu)
42 if (desc['action'] == 0 or irq_desc_is_chained(desc)) and any_count == 0:
45 text += "%*d: " % (prec, irq)
46 for cpu in cpus.each_online_cpu():
47 if desc['kstat_irqs']:
48 count = cpus.per_cpu(desc['kstat_irqs'], cpu)
51 text += "%10u" % (count)
54 if desc['irq_data']['chip']:
55 chip = desc['irq_data']['chip']
57 name = chip['name'].string()
61 text += " %8s" % (name)
63 if desc['irq_data']['domain']:
64 text += " %*lu" % (prec, desc['irq_data']['hwirq'])
66 text += " %*s" % (prec, "")
68 if constants.LX_CONFIG_GENERIC_IRQ_SHOW_LEVEL:
69 text += " %-8s" % ("Level" if irqd_is_level(desc) else "Edge")
72 text += "-%-8s" % (desc['name'].string())
74 """ Some toolchains may not be able to provide information about irqaction """
76 gdb.lookup_type("struct irqaction")
77 action = desc['action']
78 if action is not None:
79 text += " %s" % (action['name'].string())
81 action = action['next']
82 if action is not None:
85 text += ", %s" % (action['name'].string())
93 def show_irq_err_count(prec):
94 cnt = utils.gdb_eval_or_none("irq_err_count")
97 text += "%*s: %10u\n" % (prec, "ERR", cnt['counter'])
100 def x86_show_irqstat(prec, pfx, field, desc):
101 irq_stat = gdb.parse_and_eval("&irq_stat")
102 text = "%*s: " % (prec, pfx)
103 for cpu in cpus.each_online_cpu():
104 stat = cpus.per_cpu(irq_stat, cpu)
105 text += "%10u " % (stat[field])
106 text += " %s\n" % (desc)
109 def x86_show_mce(prec, var, pfx, desc):
110 pvar = gdb.parse_and_eval(var)
111 text = "%*s: " % (prec, pfx)
112 for cpu in cpus.each_online_cpu():
113 text += "%10u " % (cpus.per_cpu(pvar, cpu))
114 text += " %s\n" % (desc)
117 def x86_show_interupts(prec):
118 text = x86_show_irqstat(prec, "NMI", '__nmi_count', 'Non-maskable interrupts')
120 if constants.LX_CONFIG_X86_LOCAL_APIC:
121 text += x86_show_irqstat(prec, "LOC", 'apic_timer_irqs', "Local timer interrupts")
122 text += x86_show_irqstat(prec, "SPU", 'irq_spurious_count', "Spurious interrupts")
123 text += x86_show_irqstat(prec, "PMI", 'apic_perf_irqs', "Performance monitoring interrupts")
124 text += x86_show_irqstat(prec, "IWI", 'apic_irq_work_irqs', "IRQ work interrupts")
125 text += x86_show_irqstat(prec, "RTR", 'icr_read_retry_count', "APIC ICR read retries")
126 if utils.gdb_eval_or_none("x86_platform_ipi_callback") is not None:
127 text += x86_show_irqstat(prec, "PLT", 'x86_platform_ipis', "Platform interrupts")
129 if constants.LX_CONFIG_SMP:
130 text += x86_show_irqstat(prec, "RES", 'irq_resched_count', "Rescheduling interrupts")
131 text += x86_show_irqstat(prec, "CAL", 'irq_call_count', "Function call interrupts")
132 text += x86_show_irqstat(prec, "TLB", 'irq_tlb_count', "TLB shootdowns")
134 if constants.LX_CONFIG_X86_THERMAL_VECTOR:
135 text += x86_show_irqstat(prec, "TRM", 'irq_thermal_count', "Thermal events interrupts")
137 if constants.LX_CONFIG_X86_MCE_THRESHOLD:
138 text += x86_show_irqstat(prec, "THR", 'irq_threshold_count', "Threshold APIC interrupts")
140 if constants.LX_CONFIG_X86_MCE_AMD:
141 text += x86_show_irqstat(prec, "DFR", 'irq_deferred_error_count', "Deferred Error APIC interrupts")
143 if constants.LX_CONFIG_X86_MCE:
144 text += x86_show_mce(prec, "&mce_exception_count", "MCE", "Machine check exceptions")
145 text == x86_show_mce(prec, "&mce_poll_count", "MCP", "Machine check polls")
147 text += show_irq_err_count(prec)
149 if constants.LX_CONFIG_X86_IO_APIC:
150 cnt = utils.gdb_eval_or_none("irq_mis_count")
152 text += "%*s: %10u\n" % (prec, "MIS", cnt['counter'])
154 if constants.LX_CONFIG_HAVE_KVM:
155 text += x86_show_irqstat(prec, "PIN", 'kvm_posted_intr_ipis', 'Posted-interrupt notification event')
156 text += x86_show_irqstat(prec, "NPI", 'kvm_posted_intr_nested_ipis', 'Nested posted-interrupt event')
157 text += x86_show_irqstat(prec, "PIW", 'kvm_posted_intr_wakeup_ipis', 'Posted-interrupt wakeup event')
161 def arm_common_show_interrupts(prec):
163 nr_ipi = utils.gdb_eval_or_none("nr_ipi")
164 ipi_desc = utils.gdb_eval_or_none("ipi_desc")
165 ipi_types = utils.gdb_eval_or_none("ipi_types")
166 if nr_ipi is None or ipi_desc is None or ipi_types is None:
174 for ipi in range(nr_ipi):
175 text += "%*s%u:%s" % (prec - 1, "IPI", ipi, sep)
176 desc = ipi_desc[ipi].cast(irq_desc_type.get_type().pointer())
179 for cpu in cpus.each_online_cpu():
180 text += "%10u" % (cpus.per_cpu(desc['kstat_irqs'], cpu))
181 text += " %s" % (ipi_types[ipi].string())
185 def aarch64_show_interrupts(prec):
186 text = arm_common_show_interrupts(prec)
187 text += "%*s: %10lu\n" % (prec, "ERR", gdb.parse_and_eval("irq_err_count"))
190 def arch_show_interrupts(prec):
192 if utils.is_target_arch("x86"):
193 text += x86_show_interupts(prec)
194 elif utils.is_target_arch("aarch64"):
195 text += aarch64_show_interrupts(prec)
196 elif utils.is_target_arch("arm"):
197 text += arm_common_show_interrupts(prec)
198 elif utils.is_target_arch("mips"):
199 text += show_irq_err_count(prec)
201 raise gdb.GdbError("Unsupported architecture: {}".format(target_arch))
205 class LxInterruptList(gdb.Command):
206 """Print /proc/interrupts"""
209 super(LxInterruptList, self).__init__("lx-interruptlist", gdb.COMMAND_DATA)
211 def invoke(self, arg, from_tty):
212 nr_irqs = gdb.parse_and_eval("nr_irqs")
215 while prec < 10 and j <= nr_irqs:
219 gdb.write("%*s" % (prec + 8, ""))
220 for cpu in cpus.each_online_cpu():
221 gdb.write("CPU%-8d" % cpu)
224 if utils.gdb_eval_or_none("&irq_desc_tree") is None:
227 for irq in range(nr_irqs):
228 gdb.write(show_irq_desc(prec, irq))
229 gdb.write(arch_show_interrupts(prec))