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

Interrupt execution

Returning from an interrupt

Interrupt/Exception nesting

../_images/ditaa-e64238e31c9d1500c15e6d92c6a543aef95515aa.png

Interrupt context

  • runs as a result of an IRQ (not of an exception)
  • there is no ‘process’ context associated
  • can’t trigger a context switch
    • no sleep
    • no schedule
    • no user memory access

Interrupt handling

../_images/ditaa-5a402cd7f81a0ddbe1a435bc3ab7949828f731f0.png

Deferrable actions in Linux

  • implemented using deferrable functions
  • 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 IRQ

  • init: open_softirq()
  • activation: raise_softirq()
  • execution: do_softirq()
  • it runs
    • after an interrupt handler
    • from the ksoftirqd kernel thread

Types of soft IRQ

  • HI_SOFTIRQ
  • TIMER_SOFTIRQ
  • NET_TX_SOFTIRQ
  • NET_RX_SOFTIRQ
  • BLOCK_SOFTIRQ
  • TASKLET_SOFTIRQ
  • HRTIMER_SOFTIRQ

ksoftirqd

  • minimum priority kernel thread
  • runs self raised softirqs
  • trade-off between softirqs and process/kernel threads

Tasklets

  • implemented on top of soft IRQ
    • TASKLET_SOFITIRQ, HI_SOFTIRQ
  • init: tasklet_init
  • activation: tasklet_schedule
  • masking: tasklet_disable(), tasklet_enable()

Workqueues

  • implemented on top of kernel threads
    • TASKLET_SOFITIRQ, HI_SOFTIRQ
  • init: INIT_WORK
  • activation: schedule_work()

Timers

  • implemented on top of TIMER_SOFTIRQ
  • init: setup_timer
  • activation: mod_timer