You are on page 1of 58

Silberschatz, Galvin and Gagne 2009

Operating System Concepts 8


th
Edition,
Introduction
Modified by M.Rebaudengo - 2010
1.2
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
What is an Operating System?
! A program that acts as an intermediary between a
user of a computer and the computer hardware
! Operating system goals:
" Execute user programs and make solving user
problems easier
" Make the computer system convenient to use
" Use the computer hardware in an efcient manner
1.3
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Computer System Structure
! Computer system can be divided into four components
" Hardware provides basic computing resources
! CPU, memory, I/O devices
" Operating system
! Controls and coordinates use of hardware among various
applications and users
" Application programs dene the ways in which the system
resources are used to solve the computing problems of the
users
! Word processors, compilers, web browsers, database
systems, video games
" Users
! People, machines, other computers
1.4
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Four Components of a Computer System
1.5
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Operating System Definition

! From the computer's point of view, the operating system is the program
most involved with the hardware
! OS is a resource allocator
" Manages all resources (CPU time, memory space, le-storage space,
I/O devices, etc.)
" resource allocation is important where many users access the same
computer
" Decides between conicting requests for efcient and fair resource use
! OS is a control program
" Controls execution of programs to prevent errors and improper use of
the computer
" It is especially concerned with the operation and control of I/O devices.
1.6
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Operating System Definition (Cont.)
! No universally accepted denition of what is part of the operating system
! The one program running at all times on the computer
" usually called kernel
! Everything else is either a system program (shipped with the operating
system) or an application program.
1.7
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Computer System Organization
! Computer-system operation
" One or more CPUs, device controllers connect through common bus
providing access to shared memory
" Concurrent execution of CPUs and devices competing for memory
cycles
1.8
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Basic anatomy on a CPU (1)
! Some key CPU Components
" Program Counter (PC)
! holds memory address of next instruction
" Instruction Register (IR)
! holds instruction currently being executed
" Registers (Reg. 1..n)
! hold variables and temporary results
" Arithmetic and Logic Unit (ALU)
! performs arithmetic functions and logic operations
1.9
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Basic anatomy on a CPU (2)
! Some key CPU Components
" Memory Address Register (MAR)
! contains address of memory to be read/written
" Memory Data Register (MDR)
! contains memory data read or to be written
" Stack Pointer (SP)
! holds memory address of a stack with a frame for each procedures
local variables & parameters
" Processor Status Word (PSW)
! contains the mode bit and various control bits
1.10
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Program execution
! Instruction sets
" different for different machines
" all have load and store instructions for moving items between memory
and registers
" many instructions for comparing and combining values in registers and
putting result in a register
! Fetch/Decode/Execute cycle
" fetch next instruction pointed to by PC
" decode it to nd its type and operands
" execute it
" repeat
1.11
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Fetch/decode/execute cycle
PC
MDR
IR
MAR
Reg. n
Reg. 1

ALU
CPU
Memory
1.12
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Fetch/decode/execute cycle
PC
MDR
IR
MAR
Reg. n
Reg. 1

ALU
CPU
Memory
While (1) {
Fetch instruction from memory
Execute instruction
(Get other operands if necessary)
Store result
}
1.13
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Fetch/decode/execute cycle
PC
MDR
IR
MAR
Reg. n
Reg. 1

ALU
CPU
Memory
While (1) {
Fetch instruction from memory
Execute instruction
(Get other operands if necessary)
Store result
}
1.14
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Fetch/decode/execute cycle
PC
MDR
IR
MAR
Reg. n
Reg. 1

ALU
CPU
Memory
While (1) {
Fetch instruction from memory
Execute instruction
(Get other operands if necessary)
Store result
}
1.15
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Fetch/decode/execute cycle
PC
MDR
IR
MAR
Reg. n
Reg. 1

ALU
CPU
Memory
While (1) {
Fetch instruction from memory
Execute instruction
(Get other operands if necessary)
Store result
}
1.16
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Fetch/decode/execute cycle
PC
MDR
IR
MAR
Reg. n
Reg. 1

ALU
CPU
Memory
While (1) {
Fetch instruction from memory
Execute instruction
(Get other operands if necessary)
Store result
}
1.17
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Fetch/decode/execute cycle
PC
MDR
IR
MAR
Reg. n
Reg. 1

ALU
CPU
Memory
While (1) {
Fetch instruction from memory
Execute instruction
(Get other operands if necessary)
Store result
}
1.18
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Computer Startup
! Bootstrap program is loaded at power-up or reboot
" Typically stored in ROM or EPROM, generally known as rmware
" Initializes all aspects of system (CPU registers, device controllers,
memory contents, etc.)
" Loads operating system kernel and starts execution
! The operating system then starts executing the rst process (init) and waits
for some event to occur.
! The occurrence of an event is signaled by an interrupt from either the
hardware and the software:
" hardware may trigger an interrupt by sending a signal to the CPU
" software may trigger an interrupt by executing a special operation called
system call (or monitor call).
1.19
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Interrupts
! Interrupts is the way by which hardware informs
OS of special conditions that require OSs
attention
! Interrupt causes the CPU not to execute the next
instruction
! Instead, the control is passed to OS
1.20
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Computer-System Operation
! I/O devices and the CPU can execute concurrently
! Each device controller is in charge of a particular device
type
! Each device controller has a local buffer
! CPU moves data from/to main memory to/from local
buffers
! I/O moves from the device to local buffer of controller
! Device controller informs CPU that it has nished its
operation by causing an interrupt
1.21
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Common Functions of Interrupts
! Interrupt transfers control to the interrupt service routine
generally, through the interrupt vector, which contains
the addresses of all the service routines
! Interrupt architecture must save the address of the
interrupted instruction
! A trap is a software-generated interrupt caused either by
an error or a user request
! An operating system is interrupt driven
1.22
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Handling interrupts
! Interrupt handler is a piece of the OS code intended to
do something about the condition which caused the
interrupt
" Pointers to the interrupt handlers are stored in the
interrupt vector
" The interrupt vector is stored at a pre-dened memory
location
1.23
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Handling Interrupts (II)
! When an interrupt occurs:
" The CPU enters kernel mode, and
" passes control to the appropriate interrupt
handler
" the handler address is found using the
interrupt number as an index into the
interrupt vector
1.24
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Interrupt types
! Asynchronous interrupts are generated by
external devices at unpredictable times
! Internal (synchronous) interrupts are generated
synchronously by CPU as a result of an
exceptional condition
" An error condition
" A temporary problem
1.25
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
I/O architecture
1.26
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Servicing an interrupt
! When an interrupt occurs (and is accepted), the execution of the current
program is suspended
! Must save PC and Registers
! A special routine executes to service the interrupt
! In most cases the interrupted program resumes
! The service routine is called an interrupt handler or interrupt service routine
(ISR).
1.27
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Servicing an interrupt
1.28
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Saving Registers
! For the interrupted program to resume, the CPU
status and data registers must be saved
(because they will change during the ISR)
! They are saved before the ISR executes
! They are restored after the ISR executes
! They are saved either
" On the stack (a special area of memory to temporarily
hold information), or
" In a process control block (PCB)
1.29
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Vectored interrupt
1.30
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Direct Memory Access (DMA) structure
! Used for high-speed I/O devices able to transmit information at close
to memory speeds
! Device controller transfers blocks of data from buffer storage directly
to main memory without CPU intervention
! Only one interrupt is generated per block, rather than the one
interrupt per byte.
Request
Peripheral
Device
DMA
Controller
Memory
Acknowledge
CPU
On-Chip-Bus
Interrupt
Bus
Arbiter
1.31
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Program-Controlled I/O (in DMA)
Data bus
Address bus
Control bus
Memory
DMAC
CPU
Disk
The CPU
prepares
the DMAC
1.32
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
DMA
Data bus
Address bus
Control bus
Memory
DMAC
CPU
Disk
The transfer
takes place
1.33
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
I/O Interrupt (in DMA)
Data bus
Address bus
Control bus
Memory
DMAC
CPU
Disk
The DMAC
interrupts the
CPU when the
transfer is
complete
IRQ
1.34
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Storage-Device Hierarchy
1.35
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Storage Structure
! Main memory only large storage media that the CPU can access directly
! Secondary storage extension of main memory that provides large
nonvolatile storage capacity
! Magnetic disks rigid metal or glass platters covered with magnetic
recording material
" Disk surface is logically divided into tracks, which are subdivided into
sectors
" The disk controller determines the logical interaction between the
device and the computer
1.36
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Storage Hierarchy
! Storage systems organized in hierarchy
" The higher levels are more expensive, but they are faster. As we move
down the hierarchy
! Speed: the access time increases
! Cost: the cost per bit decreases
" Volatility:
! registers, cache and main memory lose their contents when the
power to the device is removed.
1.37
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Caching
! Important principle, performed at many levels in a computer (in
hardware, operating system, software)
! Information in use copied from slower to faster storage temporarily
! Faster storage (cache) checked rst to determine if information is
there
" If it is, information used directly from the cache (fast)
" If not, data copied to cache and used there
! Cache smaller than storage being cached
" Cache management important design problem
" Cache size and replacement policy

1.38
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
How a Modern Computer Works
1.39
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Computer-System Architecture
! Most systems use a single general-purpose processor (PDAs through
mainframes)
" Most systems have special-purpose processors as well
! Multiprocessors systems growing in use and importance
" Also known as parallel systems, tightly-coupled systems
" Advantages include
1. Increased throughput (speed-up)
2. Economy of scale
3. Increased reliability graceful degradation or fault tolerance
" Two types
1. Asymmetric Multiprocessing: each processor is assigned a specic
task. A master processor controls the system: it schedules and
allocates work to the slave processors
2. Symmetric Multiprocessing: all processors are peers (no master-
slave relationship exists between processors).

1.40
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Symmetric Multiprocessing Architecture
! Many processes can run simultaneously.
1.41
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
A Dual-Core Design
! Multicore CPUs appear to the operating system as N standard processors.
1.42
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Operating System Structure

! Multiprogramming needed for efciency


" Single user cannot keep CPU and I/O devices busy at all times
" Multiprogramming organizes jobs (code and data) so CPU always has
one to execute
" A subset of total jobs in system is kept in memory
" One job selected and run via job scheduling
" When it has to wait (for I/O for example), OS switches to another job
! Timesharing (multitasking) is logical extension in which CPU switches
jobs so frequently that users can interact with each job while it is running
" Each user has at least one program executing in memory !process
" If several jobs ready to run at the same time ! CPU scheduling
" If processes dont t in memory, swapping moves them in and out to
run
" Virtual memory allows execution of processes not completely in
memory
1.43
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Memory Layout for Multiprogrammed System
! The operating system keeps several jobs in memory simultaneously.
1.44
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Operating-System Operations
! Since the operating system and the users share the hardware and the
software resources of the computer system, it is important to make sure that
an error in a user program could cause problems only for the one program
running
! With sharing, many processes could be affected by a bug in one program
! Dual-mode operation allows OS to protect itself and other system
components
" User mode and kernel mode (or supervisor, system or privileged
mode)
" Mode bit provided by hardware
! Provides ability to distinguish when system is running user code or
kernel code
! Some instructions designated as privileged, only executable in
kernel mode
! System call changes mode to kernel, return from call resets it to user
1.45
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Transition from User to Kernel Mode
! System calls provide the means for a user program to ask the operating
system to perform tasks reserved for the operating system on the user
program's behalf.
1.46
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Transition from User to Kernel Mode
! Timer to prevent innite loop / process hogging resources
" Set interrupt after specic period
" Operating system decrements counter
" When counter reaches 0, an interrupt occurs
" Set up before scheduling process to regain control or terminate program
that exceeds allotted time
1.47
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Process Management
! A process is a program in execution. It is a unit of work
within the system
! Program is a passive entity (like the contents of a le
stored on a disk), process is an active entity
! Process needs resources to accomplish its task
" CPU, memory, I/O, les (given when it is created or
allocated while it is running)
" Initialization data
! Process termination requires reclaim of any reusable
resources

1.48
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Process Management (cont.)
! Single-threaded process has one program counter
specifying location of next instruction to execute
" Process executes instructions sequentially, one at a
time, until completion
! Multi-threaded process has one program counter per
thread
! Typically system has many processes, some user
processes (executing user code), some operating
system processes (executing system code) running
concurrently on one or more CPUs
" Concurrency by multiplexing the CPUs among the
processes / threads
1.49
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Process Management Activities
The operating system is responsible for the following
activities in connection with process management:
! Scheduling processes and threads of the CPUs
! Creating and deleting both user and system processes
! Suspending and resuming processes
! Providing mechanisms for process synchronization
! Providing mechanisms for process communication
! Providing mechanisms for deadlock handling.
1.50
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Memory Management
! Main memory is a large array of words or bytes, where
each word has its own address
! Main memory is a repository of accessible data shared
by the CPU and I/O devices
! CPU reads instructions from main memory during the
instruction-fetch cycle
! CPU reads/writes data from/to main memory during the
data-fetch cycle
! The main memory is the only large storage device that
the CPU is able to address and access directly
! All data in memory before and after processing: to
process data from disk, those data must rst be
transferred to main memory by CPU-generated I/O calls
! All instructions in memory in order to be executed
1.51
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Memory Management (cont.)
! A program, to be executed, must be mapped to absolute
adresses and loaded into memory
! As the program executes, it accesses program
instructions and data from memory by generating these
absolute adresses
! When the program terminates, its memory space is
declared available, and the next program can be loaded
and executed
! To improve the utilization of the CPU and the speed of
the computer's response to its users, general-purpose
computers must keep several programs in memory,
creating a need for memory management
! Many different memory management schemes are used.
1.52
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Memory Management
! Memory management activities
" Keeping track of which parts of memory are currently
being used and by whom
" Deciding which processes (or parts thereof) and data
to move into and out of memory
" Allocating and deallocating memory space as needed

1.53
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Storage Management
! OS provides a uniform, logical view of information
storage
" Abstracts physical properties to logical storage
unit - le
" OS maps les onto physical media and accesses
these les via the storage devices
" Each medium is controlled by device (i.e., disk
drive, tape drive)
! Varying properties include access speed,
capacity, data-transfer rate, access method
(sequential or random)
1.54
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Storage Management
! File-System management
" Files usually organized into directories
" Access control on most systems to determine who can
access in what way (e.g., read, write, append)
" OS activities include
! Creating and deleting les and directories
! Supporting primitives to manipulate les and directories
! Mapping les onto secondary storage
! Backup les onto stable (non-volatile) storage media
1.55
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Mass-Storage Management
! Computer system must provide secondary storage to back up main memory:
" Main memory is too small to accomodate all data and programs
" Data that memory holds are lost when power is lost
! Most programs are stored on a disk until loaded into memory and then use the
disk as both the source and the destination of their processing
! Entire speed of computer operation hinges on disk subsystem and its algorithms
! OS activities
" Free-space management
" Storage allocation
" Disk scheduling
! Some storage need not be fast
" Tertiary storage includes optical storage, magnetic tape
" Varies between WORM (write-once, read-many-times) and RW (read-write)
1.56
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Performance of Various Levels of Storage
1.57
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
Migration of Integer A from Disk to Register
! Multitasking environments must be careful to use most recent value, no
matter where it is stored in the storage hierarchy
! Multiprocessor environment must provide cache coherency in hardware
such that all CPUs have the most recent value in their cache
1.58
Silberschatz, Galvin and Gagne 2009
Operating System Concepts 8
th
Edition
I/O Subsystem
! One purpose of OS is to hide peculiarities of hardware devices from
the user
! I/O subsystem responsible for
" Memory management of I/O including buffering (storing data
temporarily while it is being transferred), caching (storing parts of
data in faster storage for performance)
" General device-driver interface
" Drivers for specic hardware devices

You might also like