Interrupts

Interrupts

Exceptions

Hardware (PIC)

../_images/ditaa-f2e7fcf366f75599766f77babb74ffebbc7f79e3.png

Hardware (APIC)

../_images/ditaa-f0124fcd03ddd32134f414c160e247355ab306bc.png

Enabling/disabling the interrupts

  • cli (CLear Interrupt flag)
  • sti (SeT Interrupt flag)

Interrupt Descriptor Table

Linux IRQ vector layout

../_images/ditaa-dc1532523c503b0c569468d4ed1d7aeb11ed0ed0.png

Interrupt descriptor table entry (gate)

../_images/ditaa-a9d35ab5597ae26c7755a800c13ff62d6b506ebd.png

Interrupt handler address

../_images/ditaa-9b2dd926bf730364e2ca37aeea66fea341a741bf.png

Interrupt handler stack

../_images/ditaa-1e5c09a5a3c85a247e3e154c2ab664ba5ebc134c.png

Handling an interrupt request

Returning from an interrupt

Interrupt handling in Linux

../_images/ditaa-eb56c6fa9d7ffb1693268ef2ca9de9d78a9868a7.png

IRQ nesting in Linux

Interrupt/Exception nesting

../_images/ditaa-8bab5b1e954e998c106f4a97d90ab30c70943cb4.png

Interrupt context

  • it runs as a result of an IRQ (not of an exception)
  • there is no well defined process context associated
  • not allowed to trigger a context switch (no sleep, schedule, or user memory access)

Deferrable actions in Linux

  • softIRQ
    • runs in interrupt context
    • statically allocated
    • same handler may run in parallel on multiple cores
  • tasklet
    • runs in interrupt context
    • can be dinamically allocated
    • same handler runs are serialized
  • workqueues
    • run in process context

Soft IRQs

Soft IRQ APIs:

  • initialize: open_softirq()
  • activation: raise_softirq()
  • masking: local_bh_disable(), local_bh_enable()

Once activated, the callback function do_softirq() runs either:

  • after an interrupt handler or
  • from the ksoftirqd kernel thread

ksoftirqd

  • minimum priority kernel thread
  • runs softirqs after certain limits are reached
  • tries to achieve good latency and avoid process starvation

Types of soft IRQ

  • HI_SOFTIRQ
  • TIMER_SOFTIRQ
  • NET_TX_SOFTIRQ
  • NET_RX_SOFTIRQ
  • BLOCK_SOFTIRQ
  • IRQ_POLL_SOFTIRQ
  • TASKLET_SOFTIRQ
  • SCHED_SOFTIRQ
  • HRTIMER_SOFTIRQ,
  • RCU_SOFTIRQ

Tasklets

Tasklets are a dynamic type (not limited to a fixed number) of deferred work running in interrupt context.

Tasklets API:

  • initialization: tasklet_init()
  • activation: tasklet_schedule()
  • masking: tasklet_disable(), tasklet_enable()

Tasklets are implemented on top of two dedicated softirqs: TASKLET_SOFITIRQ and HI_SOFTIRQ

Tasklets are also serialized, i.e. the same tasklet can only execute on one processor.

Workqueues

Workqueues are a type of deferred work that runs in process context.

They are implemented on top of kernel threads.

Workqueues API:

  • init: INIT_WORK
  • activation: schedule_work()

Timers

Timers are implemented on top of the TIMER_SOFTIRQ

Timer API:

  • initialization: setup_timer()
  • activation: mod_timer()