Interrupts

Contents

What are interrupts?

Interrupts are used to ask for the execution time on the processor.

Many algorithms are available to decide which order these scheduled tasks are executed in:

In BTEC Computing, you just need to have a rough idea of what these mean, and that there are multiple algorithms.

What if something needs CPU time urgently?

E.g. mouse moved, clock update, I/O

An interrupt serves as a request for the processor to interrupt the currently executing process, so that an event can be processed in a timely manner.

Interrupts allow tasks to ‘jump the queue’ and receive execution time much quicker than it would normally. Interrupts don’t guarantee the execution will break immediately, but just ‘in a timely manner’.

When an interrupt is received

Interrupts are looked for at the beginning of every Fetch-Decode-Execute cycle.

The interrupt, if deemed more important than what is currently executing, breaks the Normal Application Occurs Flow.

The CPU must then store what is currently being run, then the Interrupt Service Routine is executed. After the ISR is complete, the CPU reloads what was being executed before and continues the Normal Application Occurs Flow.

Types of interrupt

There are two types of interrupt: hardware and software.

Hardware

Informs the CPU that devices need execution time. E.g. user presses key on keyboard.

Software

An error occurs (e.g. stack overflow), or it needs to interact with the OS in some way.

Interrupt system

The interrupt system part of the OS will need to…

If there’s more than one interrupt at a time…

For example, if the power button is pressed, this should be dealt with quickly. However, if the mouse is moved, it might be suitable to wait a few milliseconds before managing that event.

The processor responds by suspending its current activities, saving its state, and executing the appropriate ISR.

What about after the ISR is complete?

Before the ISR gets executed, all of the values in the CPU registers must be copied into a memory area called the stack.

The stack acts as a “last in, first out” data store, where data is stored at the bottom of the stack first. If an interrupt is received during an ISR, the ISR data is stored on top of what was saved before the first ISR.

After the registers are stored in the stack, the address of the ISR can be moved into the program counter, so it becomes the next instruction to be executed.

Once the ISR is completed, the content of the registers are returned from the stack to the registers and normal execution is resumed.