irqchip test driver/sandbox
v2 cover irqchip test driver/sandbox
This is a dummy irqchip driver that implements three different types of IRQ chips, requests interrupts like a real device driver would do, and provides the ability to manually trigger any of these interrupts. The main reason why I wrote it was to be able to hack on the kernel IRQ core without depending on any hardware (even virtual, inside a VM). But it can also be used as an example for implementing irqchip drivers.
The irqchip setup/layout is described in detail in a comment block at the top of the driver's source file, so I'm not repeating it here. Two "leaf" IRQ domains are implemented: hierarchical and multiplexing. These are attached to an additional "root" domain, which is similar to APIC (x86_64) or GIC (arm64). Interrupts are simulated by calling the generic interrupt handling function on the "root" domain, in a workqueue context and with local interrupts disabled.
A few notes on the implementation:
- The driver cannot be compiled as a loadable module, and the only reason is because it uses irq_move_irq(), which is not exported. I could not find a better way to make IRQ affinity control for the "root" domain work on x86. This is also documented in the source code.
- The driver uses a write-only module parameter with a custom handler as the interface to trigger simulated interrupts. While this slightly abuses the module parameter API, it's very simple to implement and also keeps the sysfs file confined in the module's own "namespace" at /sys/module/irqc_test. Of course, setting the parameter on the kernel command line makes no sense but doesn't have any side effect either.
---
Changes in v2:
- Fix sysfs file mode on module parameter
- Add "depends" to Kconfig to prevent build failures on unsupported architectures (no IRQ domain hierarchy support e.g. x86_32)
- Link to v1: https://lore.kernel.org/all/[email protected]/
---
Radu Rendec (1):
samples: Add irqchip test driver
samples/Kconfig | 11 + samples/Makefile | 1 + samples/irqchip/Makefile | 1 + samples/irqchip/irqc_test.c | 576 ++++++++++++++++++++++++++++++++++++ 4 files changed, 589 insertions(+) create mode 100644 samples/irqchip/Makefile create mode 100644 samples/irqchip/irqc_test.c
Signature · 1 line
2.51.0
PATCH v2 1/1 samples: Add irqchip test driver
Add a test driver that demonstrates implementation of multiple IRQ chip types and their domains. The driver implements:
- Root IRQ chip simulating direct CPU interrupt lines
- Hierarchical IRQ domain with 1:1 parent mapping
- Interrupt multiplexer domain with chained interrupts
The driver supports simulating interrupt handling by triggering fake interrupts via sysfs parameter, with CPU affinity simulation using targeted work items.
This serves as a reference implementation and testing sandbox for IRQ chip driver development and debugging.
--- samples/Kconfig | 11 + samples/Makefile | 1 + samples/irqchip/Makefile | 1 + samples/irqchip/irqc_test.c | 576 ++++++++++++++++++++++++++++++++++++ 4 files changed, 589 insertions(+) create mode 100644 samples/irqchip/Makefile create mode 100644 samples/irqchip/irqc_test.c
samples/Kconfig +11 -0
@@ -320,6 +320,17 @@ config SAMPLE_HUNG_TASK Reading these files with multiple processes triggers hung task detection by holding locks for a long time (256 seconds). +config SAMPLE_IRQCHIP + bool "Test IRQ chip driver" + depends on IRQ_DOMAIN_HIERARCHY + help + Build a driver that demonstrates the implementation of multiple IRQ + chip types (root, hierarchical, multiplexing). It serves as a + reference implementation for IRQ chip driver development, showcasing + different domain management patterns and interrupt routing mechanisms. + It supports simulation of interrupt handling with CPU affinity through + sysfs parameters. + source "samples/rust/Kconfig" source "samples/damon/Kconfig"
samples/Makefile +1 -0
@@ -10,6 +10,7 @@ obj-$(CONFIG_SAMPLE_CONNECTOR) += connector/ obj-$(CONFIG_SAMPLE_FANOTIFY_ERROR) += fanotify/ subdir-$(CONFIG_SAMPLE_HIDRAW) += hidraw obj-$(CONFIG_SAMPLE_HW_BREAKPOINT) += hw_breakpoint/ +obj-$(CONFIG_SAMPLE_IRQCHIP) += irqchip/ obj-$(CONFIG_SAMPLE_KDB) += kdb/ obj-$(CONFIG_SAMPLE_KFIFO) += kfifo/ obj-$(CONFIG_SAMPLE_KOBJECT) += kobject/
samples/irqchip/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_SAMPLE_IRQCHIP) += irqc_test.o
samples/irqchip/irqc_test.c new file +576 -0
576 lines not on this page · raw message
Signature · 1 line
2.51.0