Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 14: Kernel Activities


unique identification. The kernel scans the list of all registered handlers until it finds a matching element
(with a matchingdev_id). Only then can the entry be removed.

Registering Interrupts


The mechanisms discussed above are effective only for interrupts raised by an interrupt request from a
system peripheral. But the kernel must also take care of interrupts raised either by the processor itself or
by software mechanisms in an executing user process. In contrast to IRQs, the kernel need not provide
an interface for this kind of interrupt in order to dynamically register handlers. This is because the num-
bers used are made known at initialization time and do not change thereafter. Registering of interrupts,
exceptions, and traps is performed at kernel initialization time, and their reservations do not change at
run time.

The platform-specific kernel sources have very few commonalities, not surprising in view of the some-
times large technical differences. Even though theconcepts behind some variants may be similar, their
concrete implementation differs strongly from platform to platform. This is because implementation must
walk a fine line between C and assembly language code in order to do justice to the specific features of a
system.

The greatest similarity between the various platforms is a filename.arch/arch/kernel/traps.ccontains
the system-specific implementation for registering interrupt handlers.

The outcome of all implementations is that a handler function is invoked automatically when an interrupt
occurs. Because interrupt sharing is not supported for system interrupts, all that need be done is to
establish a link between the interrupt number and function pointer.

Generally, the kernel responds to interrupts in one of two ways.

❑ A signal is sent to the current user process to inform it that an error has occurred. On IA-32
and AMD64 systems, for example, a division by 0 is signaled by interrupt 0. The automatically
invoked assembly language routinedivide_errorsends theSIGPFEsignal to the user process.
❑ The kernel corrects the error situation invisibly to the user process. This is the case on, for
example, IA-32 systems, where interrupt 14 is used to signal a page fault, which the kernel can
then correct by employing the methods described in Chapter 18.

14.1.7 Servicing IRQs


Once an IRQ handler has been registered, the handler routine is executed each time an interrupt occurs.
The problem again arises as to how to reconcile the differences between the various platforms. Owing
to the nature of things, the differences are not restricted to various C functions with platform-specific
implementations but start deep down in the domain of the manually optimized assembly language code
used for low-level processing.

Fortunately, several structural similarities between the individual platforms can be identified. For
example, the interrupt action on each platform comprises three parts, as discussed earlier. The entry
path switches from user mode to kernel mode, then theactual handler routine executes, and finally the
kernel switches back to user mode. Even though much assembly language code is involved, there are at
least some C fragments that are similar on all platforms. These are discussed below.
Free download pdf