Ch01 - Introduction
Ch01 - Introduction
user programs and make solving user problems easier" the computer system convenient to use" the computer hardware in an efcient manner"
1.2!
Operating system!
Controls
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" machines, other computers"
Users!
People,
1.3!
1.4!
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" 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."
OS is a control program!
1.5!
1.6!
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.7!
1.8!
memory address of a stack with a frame for each procedure s local variables & parameters" the mode bit and various control bits"
1.9!
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 next instruction pointed to by PC" decode it to nd its type and operands" execute it" repeat"
Fetch/Decode/Execute cycle"
1.10!
Fetch/decode/execute cycle
CPU PC IR
Memory
ALU
Reg. 1 Reg. n
MAR MDR
1.11!
Fetch/decode/execute cycle
CPU PC IR
Memory
ALU
Reg. 1 Reg. n
MAR MDR
While (1) { Fetch instruction from memory Execute instruction (Get other operands if necessary) Store result }
1.12!
Fetch/decode/execute cycle
CPU PC IR
Memory
ALU
Reg. 1 Reg. n
MAR MDR
While (1) { Fetch instruction from memory Execute instruction (Get other operands if necessary) Store result }
1.13!
Fetch/decode/execute cycle
CPU PC IR
Memory
ALU
Reg. 1 Reg. n
MAR MDR
While (1) { Fetch instruction from memory Execute instruction (Get other operands if necessary) Store result }
1.14!
Fetch/decode/execute cycle
CPU PC IR
Memory
ALU
Reg. 1 Reg. n
MAR MDR
While (1) { Fetch instruction from memory Execute instruction (Get other operands if necessary) Store result }
1.15!
Fetch/decode/execute cycle
CPU PC IR
Memory
ALU
Reg. 1 Reg. n
MAR MDR
While (1) { Fetch instruction from memory Execute instruction (Get other operands if necessary) Store result }
1.16!
Fetch/decode/execute cycle
CPU PC IR
Memory
ALU
Reg. 1 Reg. n
MAR MDR
While (1) { Fetch instruction from memory Execute instruction (Get other operands if necessary) Store result }
1.17!
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
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.18!
Interrupts
Interrupts is the way by which hardware informs
instruction"
Instead, the control is passed to OS"
1.19!
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
1.20!
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
1.21!
Handling interrupts
Interrupt handler is a piece of the OS code intended to
to the interrupt handlers are stored in the interrupt vector! interrupt vector is stored at a pre-dened memory location"
1.22!
passes the
control to the appropriate interrupt handler " handler address is found using the interrupt number as an index into the interrupt vector!
1.23!
Interrupt types
Asynchronous interrupts are generated by
error condition"
temporary problem"
1.24!
I/O architecture
1.25!
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.26!
Servicing an interrupt
1.27!
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 In
the stack (a special area of memory to temporarily hold information), or" a process control block (PCB)!
1.28!
Vectored interrupt
1.29!
to memory speeds"
Device controller transfers blocks of data from buffer storage directly
CPU Interrupt
Memory
DMA Controller
Operating System Concepts 8th Edition!
Peripheral Device
Silberschatz, Galvin and Gagne 2009 !
1.31!
DMA
Data bus Address bus Control bus CPU DMAC Memory Disk The transfer takes place
1.32!
IRQ
1.33!
Storage-Device Hierarchy
1.34!
Storage Structure
Main memory only large storage media that the CPU can access directly! Secondary storage extension of main memory that provides large
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.35!
Storage Hierarchy
Storage systems organized in hierarchy"
The higher levels are more expensive, but they are faster. As we move down the hierarchy"
Speed: Cost:
Volatility:"
registers,
cache and main memory lose their contents when the power to the device is removed."
1.36!
Caching
Important principle, performed at many levels in a computer (in
there"
If it is, information used directly from the cache (fast)" If not, data copied to cache and used there" Cache management important design problem" Cache size and replacement policy"
"
1.37!
1.38!
Computer-System Architecture
Most systems use a single general-purpose processor (PDAs through
mainframes)"
Most systems have special-purpose processors as well" Also known as parallel systems, tightly-coupled systems" Advantages include"
1. 2. 3.
Increased throughput (speed-up)" Economy of scale" Increased reliability graceful degradation or fault tolerance" Asymmetric Multiprocessing: each processor is assigned a specic task. A master processor controls the system: it schedules and allocates work to the slave processors" Symmetric Multiprocessing: all processors are peers (no masterslave relationship exists between processors)."
1.39! Silberschatz, Galvin and Gagne 2009 !
Two types"
1.
2.
"
1.40!
A Dual-Core Design
1.41!
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 don t t in memory, swapping moves them in and out to run"
1.42!
1.43!
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.44!
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.45!
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.46!
Process Management
A process is a program in execution. It is a unit of work
memory, I/O, les (given when it is created or allocated while it is running)" data"
Initialization
resources"
"
1.47!
program counter
specifying location of next instruction to execute" executes instructions sequentially, one at a time, until completion"
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
1.48!
1.49!
Memory Management
Main memory is a large array of words or bytes, where
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
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"
Operating System Concepts 8th Edition! 1.50! Silberschatz, Galvin and Gagne 2009 !
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."
Operating System Concepts 8th Edition! 1.51! Silberschatz, Galvin and Gagne 2009 !
Memory Management
Memory management activities"
Keeping
track of which parts of memory are currently being used and by whom" which processes (or parts thereof) and data to move into and out of memory" and deallocating memory space as needed"
Deciding
Allocating
"
1.52!
Storage Management
OS provides a uniform, logical view of information
storage"
Abstracts OS
physical properties to logical storage unit - le! maps les onto physical media and accesses these les via the storage devices" medium is controlled by device (i.e., disk drive, tape drive)"
Varying
Each
properties include access speed, capacity, data-transfer rate, access method (sequential or random)"
1.53!
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" primitives to manipulate les and directories" les onto secondary storage"
1.54!
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
Free-space management" Storage allocation" Disk scheduling" Tertiary storage includes optical storage, magnetic tape" Varies between WORM (write-once, read-many-times) and RW (read-write)"
1.55!
1.56!
such that all CPUs have the most recent value in their cache"
1.57!
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"
1.58!