Professional Documents
Culture Documents
Kernel Organization
Linux is a monolithic kernel
Processes and resource management,
memory management, file management all
implemented in a single executable
software module
Data structures for each aspect of kernel
accessible by all.
Kernel Extensions
Two types of extensions to the kernel
possible:
device drivers and interrupt handlers. These
execute in kernel mode.
modules, a independent software unit. Can be
installed dynamically as the system runs.
Modules
Interface between module and kernel more
general that interface between device driver
and kernel
Modules can be used to implement device
drivers.
Project 4 has the object of writing a module.
Modules
Modules
ModuleInterface
Interface
Module
DeviceDriver
DriverInterface
Interface
Device
Device
DeviceDrivers
Drivers
Linux
LinuxKernel
Kernel
Interrupts
Kernel reacts to requests from any active,
external entity.
Interrupt. An electronic signal produced by
an external component.
fielded by the CPU hardware
CPU begins executing different process to deal
with the interrupt
often result of I/O completion or clock.
Interrupts
Fetch-decode-execute cycle
InterruptRequest = FALSE;
Interrupts
Problem: interrupt can be interrupted.
if ISR is saving the state of a process and is
interrupted, may not complete
when second ISR is finished, first ISR will not
restore state correctly.
called a race condition
if A occurs before B, system changes to one state
if B occurs before A, system changes to different state.
Interrupts
Solution: disable interrupts
kernel function cli( ) sets interrupt-enable flag to
FALSE.
kernel function sti( ) sets interrupt-enable flag to
TRUE.
Kernel Services
User programs view kernel as an ADT.
interface to the ADT is the system call
interface
Linux conforms to POSIX.1 specification
(same as UNIX).
Implementation of different kernel versions
of Linux can vary, but all implement the
same system call interface (usually)
Kernel
Private Implementation
Kernel Services
POSIX.1 functions are implemented in the kernel,
device drivers, and modules.
Some system call functions might be user-space
programs (eg, threads)
Internal software is passive
does not have any internal thread of execution
is simply a collection of functions and data structures
Kernel Services
user code is active;
makes a procedure call on POSIX.1
a process outside the kernel begins to execute kernel code
when it makes a system call.
Kernel Services
Problem:
changing hardware mode bit is a privileged instruction.
user code cant change mode bit when makes sys call
normal function call is a link to the function code; but
this would link the user program into the kernel.
thus kernel code is readable by the user code
so user code could copy the mode change instruction to
its space and execute!
Kernel Services
Solution: CPU contains a hardware trap instruction
causes branch to a prespecified address (could be a
function of the instruction operand)
also switches mode to supervisor
trap is not privileged
destination is determined by set of addresses in kernel
space.
addresses point to kernel code.
trap
3
3. Branch to a trusted
OS function
Trusted
Code
User
Supervisor
Daemons
process that is executed without a terminal
execute in background
perform critical services, e.g., respond to
incoming network packets.
name usually ends in d
examples: syslogd, crond, lpd