About UsResearchOpportunities
PublicationsResourcesSite Map
 

ECE 385 - Learning about interrupts

This topic is covered in great detail, and rather nicely in the online device drivers book in chapter 9.

What is an interrupt?

From Wikipedia, the free encyclopedia
  • An interrupt is a signal from a device which typically results in a context switch.
  • Usually provide a way to start software routines in response to asynchronous electronic events. These events are signalled to the processor via interrupt requests (IRQ). The processor and interrupt code make a context switch into a specifically written routine to handle the interrupt. This routine is called the interrupt service routine.
  • Interrupts were originated to avoid wasting time in polling.
  • Rather than polling, the computer can do useful work until an event has occurred.
Interrupts remain in modern computers because they permit a computer to have prompt responses to electronic events, while performing other work.

Interrupt Types

    Typical interrupt types include:
  • timer interrupts
  • disk interrupts
  • power-off interrupts
Other interrupts exist to transfer data bytes using UARTs, or Ethernet, sense key-presses, control motors, or anything else the equipment must do.

A classic timer interrupt just interrupts periodically from a counter or the power-line. The operating system counts the interrupts to keep time.

The timer interrupt may also be used to reschedule the priorities of running processes. Counters are popular, but some older computers used the power line because power companies control the power-line frequency with an atomic clock.

A disk interrupt signals the completion of a data transfer from or to the disk peripheral. A process waiting to read or write a file starts up again.

A power-off interrupt predicts or requests a loss of power. It allows the computer equipment to perform an orderly shutdown.

Features of an ISR

  • Interrupt routines generally have a short execution time.
  • Most interrupt routines do not allow themselves to be interrupted, because they store saved context on a stack, and if interrupted many times, the stack could overflow.
  • An interrupt routine frequently needs to be able to respond to a further interrupt from the same source.
  • Some processors support a hierarchy of interrupt priorities, allowing a certain kinds of interrupts to occur while processing lower priority interrupts.
  • Processors also often have a mechanism referred to as interrupt disable which allows software to prevent interrupts from interfering with communication between interrupt-code and non-interrupt code.

Enabling and Disabling Interrupts

  • cli() - used to disable interrupts
  • sti() - used to enable interrupts
  • In typical operating systems, it is a bad idea to use these calls directly. However, when using micro-controller, perfectly acceptable.
Read chapter 9 of the device drivers book for details.

Interrupt lines are usually limited (can be as few as 16), so care must be taken in implementation of ISRs.

Installing Interrupt Handlers

int request_irq(unsigned int irq,
   void (*handler)(int, void *, struct pt_regs *),
   unsigned long flags, 
   const char *dev_name,
   void *dev_id);

void free_irq(unsigned int irq, void *dev_id);
The online device drivers book covers these functions. You will need them for the next lab.

Interrupts and the /proc file system

You have undoubtedly had some experience with the /proc file system from the last lab. The /proc file system will also report how many interrupts have occurred on a particular line.
corey@little:~$ cat /proc/interrupts 
           CPU0       
  0: 2358153317          XT-PIC  timer
  1:     619859          XT-PIC  i8042
  2:          0          XT-PIC  cascade
  5:    1136843          XT-PIC  ohci1394, uhci_hcd
  9:          2          XT-PIC  acpi, ehci_hcd
 10:          0          XT-PIC  uhci_hcd
 11:   14751528          XT-PIC  uhci_hcd, eth0
 12:    1085502          XT-PIC  Intel 82801DB-ICH4
 14:    2693132          XT-PIC  ide0
 15:        117          XT-PIC  ide1
NMI:          0 
ERR:          0

Top halves and bottom halves

As mentioned, interrupts should be dealt with quickly. However, what if a significant amount of work needs to be done in the interrupt?

The usual solution is scheduling a bottom-half

    Top-halves
  • Initially responds to the interrupt
  • Must work quickly
  • May disable interrupts while processing
  • Save device data for the bottom-half to process
  • Schedules a bottom-half for further processing
    Bottom-halves
  • Perform longish tasks
  • Do not disable interrupts
  • Since mid-2.3 kernels tasklets are the preferred means for bottom-half processing.
A good example of top-half bottom-half processing is an ethernet card. The top half executes when a packet is received (an interrupt occurs), but the bottom half takes care of disassembling the packet and processing it.

You can read more about tasklets and bottom-half processing the the online device drivers book. However, for the lab, you may just use top-half processing.