Linux Kernel Organization - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Linux Kernel Organization

Description:

Kernel Services. User programs ... Kernel Services. POSIX.1 functions are implemented in the kernel, device ... without a terminal. execute in background ... – PowerPoint PPT presentation

Number of Views:118
Avg rating:3.0/5.0
Slides: 19
Provided by: Itha5
Category:

less

Transcript and Presenter's Notes

Title: Linux Kernel Organization


1
LinuxKernel 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.

2
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.

3
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.

4
Device Drivers
Linux Kernel
Device Driver Interface
Modules
Module Interface
5
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.

6
Interrupts Fetch-decode-execute cycle
  • InterruptRequest FALSE
  • while (haltFlag not set during execution)
  • IR memoryPC
  • PC
  • execute(IR)
  • if (InterruptRequest)
  • save_PC( )
  • restore_PC(IRQ) / branch to the ISR for this
    IRQ/

7
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.

8
Interrupts
  • Solution disable interrupts
  • kernel function cli( ) sets interrupt-enable flag
    to FALSE.
  • kernel function sti( ) sets interrupt-enable flag
    to TRUE.

9
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)

10
User Space Program Calls System
public POSIX.1 System Call Interface
Kernel
Private Implementation
11
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

12
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.
  • In Linux, the process executing the user program
    also executes the kernel programs when a system
    call is made.
  • Before system call a process is executing user
    code.
  • After call same process is executing kernel code.
  • Process remains the same.

13
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!

14
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.

15
1. switch CPU to supervisor mode
Mode
1
2. Look up a branch address in a kernel space
table
s
Branch Table
2
3. Branch to a trusted OS function
trap
3
Trusted Code
Supervisor
User
16
Linux System Call
  1. For system call F, a stub procedure is used to
    invoke F (stub is named F)
  2. stub is linked into the user-space calling
    program.
  3. When process executes the call to F at runtime,
    control is transferred to the stub procedure, not
    directly to kernel.
  4. Stub procedure validates the parameter values
    being passed to the kernel procedure.
  5. The stub procedure executes a trap instruction
    that switches the CPU to supervisory mode.
  6. Stub then branches (via kernel table) to entry
    point for the target kernel function.

17
Linux System Call
  • kernel functions are executed as if they are in a
    critical section.
  • system call keeps CPU until it finishes
  • can only be interrupted by IRQ.
  • Thus a kernel function can update kernel data
    structures without being interrupted.
  • When you write a kernel function, cannot write
    code that will block!
  • Could develop a race condition between a system
    call and a ISR.

18
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
Write a Comment
User Comments (0)
About PowerShow.com