Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 14: Kernel Activities................................................


14.1 Interrupts


Until kernel 2.4, the only commonality in the implementation of interrupts on the diverse platforms
supported by the Linux kernel used to be that they exist at all — but that’s where the similarity came
to an end. Lots of code (and lots of duplicated functionality) was spread across architecture-specific
components. The situation was improved considerably during the development of kernel 2.6 because
a generic framework for interrupts and IRQs was introduced. Individual platforms are now only
responsible to interact with the hardware on the lowest levels. Everything else is provided by
generic code.

Let’s start our discussion by introducing the most common types of system interrupts as our starting
point before focusing on how they function, what they do, and what problems they cause.

14.1.1 Interrupt Types


Generally, interrupt types can be grouped into two categories:

❑ Synchronous InterruptsandExceptions— Are produced by the CPU itself and are directed at
the program currently executing. Exceptions may be triggered for a variety of reasons: because
of a programming error that occurred at run time (a classical example is division by zero), or
because — as the name suggests — an exceptional situation or an anomalous condition has
arisen and the processor needs ‘‘external‘‘ help to deal with it.
In the first case, the kernel must inform the application that an exception has arisen. It can use,
for example, the signaling mechanism described in Chapter 5. This gives the application an
opportunity to correct the error, issue an appropriate error message, or simply terminate.
An anomalous condition may not necessarily be caused directly by the process but must be
repaired with the help of the kernel. A possible example of this is a page fault that always occurs
when a process attempts to access a page of virtual address space that is not held in RAM. As
discussed in Chapter 4, the kernel must then interact with the CPU to ensure that the desired
data are fetched into RAM. The process can then resume at the point at which the exception
occurred. It does not even notice that there has been a page error because the kernel recovered
the situation automatically.
❑ Asynchronous interrupts— Are the classical interrupt type generated by peripheral devices
and occur at arbitrary times. Unlike synchronousinterrupts, asynchronous interrupts are not
associated with a particular process. They can happen at any time, regardless of the activities the
system is currently performing.^1
Network cards report the arrival of new packages by issuing an associated interrupt. Because
the data reach the system at an arbitrary moment in time, it is highly likely that some process
or other that has nothing to do with the data is currently executing. So as not to disadvantage
this process, the kernel must ensure that the interrupt is processed as quickly as possible by
‘‘buffering‘‘ data so that CPU time can be returned to the process. This is why the kernel needs
mechanisms to defer activities; these are also discussed in this chapter.

What are the common features of the two types of interrupt? If the CPU is not already in kernel mode, it
initiates a switch from user to kernel mode. There it executes a special routine called aninterrupt service

(^1) Because, as you will learn shortly, interrupts can be disabled, this statement is not totally correct. The system can at
least influence when interrupts donotoccur.

Free download pdf