request_threaded_irq(9)
π request_threaded_irq(9) β the Kernel API Manual page your bestie actually wants to read π
okay so. this is request_threaded_irq, straight out of the Kernel API Manual, and it's literally the glow-up your interrupt handling has been waiting for. grab a snack π, we're allocating an interrupt line together.
β¨ NAME β¨
request_threaded_irq β allocate an interrupt line π
β¨ SYNOPSIS β¨
int request_threaded_irq (unsigned int irq , irq_handler_t handler ,
irq_handler_t thread_fn , unsigned long irqflags , const char *devname ,
void *dev_id );
six arguments, one function, zero chill. let's go π
πΈ ARGUMENTS πΈ
irqβ the interrupt line you're allocating. this is the one you're claiming, bestie πhandlerβ the function that gets called when the IRQ occurs. it's the primary handler for threaded interrupts. and here's the cute part: ifhandlerisNULLandthread_fn != NULL, the default primary handler gets installed for you. no cap, it just does it π«Άthread_fnβ the function that gets called from the irq handler thread. if it'sNULL, no irq thread is created. periodt πirqflagsβ the interrupt type flags. vibes: specified πdevnameβ an ascii name for the claiming device. cute little nametag energy πdev_idβ a cookie passed back to the handler function πͺ (yes, literally a cookie, iykyk)
π¦ DESCRIPTION π¦
so this call allocates interrupt resources and enables the interrupt line and IRQ handling. from the exact point this call is made, your handler function may be invoked. like, immediately. no warning text, no "3β¦ 2β¦ 1β¦", it's just live π₯
and because your handler function must clear any interrupt the board raises, you have to take care of both things: initialise your hardware, and set up the interrupt handler in the right order. get the order wrong and it's giving chaos π
π§ threaded irq handlers β the split-handler situation
if you want to set up a threaded irq handler for your device, then you need to supply handler and thread_fn. here's the tea:
handleris still called in hard interrupt context and it has to check whether the interrupt originates from the device.- if yes β it needs to disable the interrupt on the device and return
IRQ_WAKE_THREAD, which wakes up the handler thread and runsthread_fn.
this split handler design is necessary to support shared interrupts. it's not a phase, it's a lifestyle β¨
π dev_id rules (important, bestie)
dev_id must be globally unique. normally the address of the device data structure is used as the cookie. and since the handler receives this value, it genuinely makes sense to use it. it's giving "the system was designed for this" π
if your interrupt is shared, you must pass a non-NULL dev_id, because that's required when freeing the interrupt. skip it and you're gonna have a bad time π
π Flags π
IRQF_SHAREDβ interrupt is shared πIRQF_TRIGGER_*β specify active edge(s) or level πIRQF_ONESHOTβ runthread_fnwith interrupt line masked π
π« SEE ALSO π«
kernel file ./kernel/irq/manage.c, plus this whole iconic friend group:
synchronize_hardirq(9), synchronize_irq(9), irq_can_set_affinity(9), irq_can_set_affinity_usr(9), irq_set_thread_affinity(9), irq_affinity_schedule_notify_work(9), irq_update_affinity_desc(9), irq_set_affinity(9), irq_force_affinity(9), irq_set_affinity_notifier(9), irq_set_vcpu_affinity(9), disable_irq_nosync(9), disable_irq(9), disable_hardirq(9), disable_nmi_nosync(9), enable_irq(9), enable_nmi(9), irq_set_irq_wake(9), irq_wake_thread(9), free_irq(9), request_any_context_irq(9), request_nmi(9), irq_percpu_is_enabled(9), free_percpu_irq(9), request_percpu_irq_affinity(9), request_percpu_nmi(9), prepare_percpu_nmi(9), teardown_percpu_nmi(9), irq_get_irqchip_state(9), irq_set_irqchip_state(9), irq_has_action(9), irq_check_status_bit(9)
and that's the whole page, bestie π«Ά this came out of ./kernel/irq, dated October 2026, and the header up top says request_threaded_irq(9) β go forth and allocate responsibly, mwah π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms