SO2 Lecture 04 - Interrupts

Interrupts

Interrupts

Exceptions

Quiz: interrupt terminology

For each of the following term on the left select all the terms from right that best describe them.

  • Watchdog
  • Demand paging
  • Division by zero
  • Timer
  • System call
  • Breakpoint
  • Exception
  • Interrupt
  • Maskable
  • Nonmaskable
  • Trap
  • Fault

Programmable Interrupt Controller

 

../_images/ditaa-5db1739b80a83b12505e4ff749b5e69fccd01f1b.png

Interrupt controllers in SMP systems

 

../_images/ditaa-9d23d02ebdff6eeb6bec8044480f055de9852ecc.png

Enabling/disabling the interrupts

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

Interrupt priorities

 

../_images/ditaa-8b00a68b494f72d54b5fad38c88f7265aadaaa0e.png

Quiz: hardware concepts

Which of the following statements are true?

Interrupt Descriptor Table

Linux IRQ vector layout

 

../_images/ditaa-5b3c93f6e612d0cc0e4d4837d92a443627405262.png

Interrupt descriptor table entry (gate)

 

../_images/ditaa-eff5e0e3b58ce239d5310b22b89c0927be5853bd.png

Interrupt handler address

 

../_images/ditaa-b2023fce22479e20bbe08fd76eed87e9a0527688.png

Interrupt handler stack

 

../_images/ditaa-85b69602726fa6143fc3ba0ffdb492454864aacf.png

Handling an interrupt request

Returning from an interrupt

Inspecting the x86 interrupt handling

 

Quiz: x86 interrupt handling

The following gdb commands are used to determine the handler for the int80 based system call exception. Select and arrange the commands or output of the commands in the correct order.

(void *) 0xc15de780 <entry_SYSENTER_32>

set $idtr_addr=($idtr_entry>>48<<16)|($idtr_entry&0xffff)

print (void*)$idtr_addr

set $idtr = 0xff800000

(void *) 0xc15de874 <entry_INT80_32>

set $idtr = 0xff801000

set $idtr_entry = *(uint64_t*)($idtr + 8 * 128)

monitor info registers

Interrupt handling in Linux

 

../_images/ditaa-da31e3d17a4d55e5c3dbc0bd5903306418a896ca.png

IRQ and exception nesting in Linux

Interrupt/Exception nesting

 

../_images/ditaa-2e49ca6ac606dab4b2b53231cfbe85ff06312d36.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

  • Schedule callback functions to run a later time
  • Interrupt context deferrable actions
  • Process context deferrable actions
  • APIs for initialization, scheduling and masking

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 IRQs

/* PLEASE, avoid to allocate new softirqs, if you need not _really_ high
   frequency threaded job scheduling. For almost all the purposes
   tasklets are more than enough. F.e. all serial device BHs et
   al. should be converted to tasklets, not to softirqs.
*/

enum
{
  HI_SOFTIRQ=0,
  TIMER_SOFTIRQ,
  NET_TX_SOFTIRQ,
  NET_RX_SOFTIRQ,
  BLOCK_SOFTIRQ,
  IRQ_POLL_SOFTIRQ,
  TASKLET_SOFTIRQ,
  SCHED_SOFTIRQ,
  HRTIMER_SOFTIRQ,
  RCU_SOFTIRQ,    /* Preferable RCU should always be the last softirq */

  NR_SOFTIRQS
};

Packet flood example

 

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()

Deferrable actions summary

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

Quiz: Linux interrupt handling

Which of the following phases of interrupt handling runs with interrupts disabled at the CPU level?