Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 14: Kernel Activities


mode stack. However, this alone is not sufficient. Because the kernel also uses CPU resources to execute
its code, the entry path must save the current register status of the user application in order to restore it
upon termination of interrupt activities. This is the same mechanism used for context switching during
scheduling. When kernel mode is entered, only part of the complete register set is saved. The kernel does
not use all available registers. Because, for example, no floating point operations are used in kernel code
(only integer calculations are made), there is no need to save the floating point registers.^3 Their value
does not change when kernel code is executed. The platform-specific data structurept_regsthat lists all
registers modified in kernel mode is defined to take account of the differences between the various CPUs
(Section 14.1.7 takes a closer look at this). Low-level routines coded in assembly language are responsible
for filling the structure.


Interrupt
Handler

Scheduling
necessary?

Signals?

Restore registers

Deliver signals
to process

Activate
user stack

Switch to
kernel stack

Save registers

Interrupt
schedule

Figure 14-2: Handling an interrupt.

In the exit path the kernel checks whether


❑ the scheduler should select a new process to replace the old process.
❑ there are signals that must be delivered to the process.

Only when these two questions have been answered can the kernel devote itself to completing its regular
tasks after returning from an interrupt; that is, restoring the register set, switching to the user mode
stack, switching to an appropriate processor mode for user applications, or switching to a different
protection ring.^4


Because interaction between C and assembly language code is required, particular care must be taken
to correctly design data exchange between the assembly language level and C level. The corresponding
code is located inarch/arch/kernel/entry.Sand makes thorough use of the specific characteristics
of the individual processors. For this reason, the contents of this file should be modified as seldom as
possible — and then only with great care.


(^3) Some architectures (e.g., IA-64) do not adhere to this rule but use a few registers from the floating comma set and save them each
time kernel mode is entered. The bulk of the floating point registers remain ‘‘untouched‘‘ by the kernel, and no explicit floating point
operations are used.
(^4) Some processors make this switch automatically without being requested explicitly to do so by the kernel.

Free download pdf