Escolar Documentos
Profissional Documentos
Cultura Documentos
Fred Kuhns
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
Computer Systems
• Computer Systems
– Hardware and software combine to solve specific problems
– Two software categories: 1) Application software, 2) System software
• Goals of an OS
– User Environment: Execution environment, Error detection and handling,
Protection and security, Fault tolerance and failure recovery
– Resource Management: Time and space management; Synchronization and
deadlock handling; Accounting and status information
• Driving Concepts
– Abstraction: manage complexity, create an extended machine.
– Virtualization: Permits controlled sharing and isolation (enables process
model and isolation)
– Resource management: implicit/explicit allocation and policy control.
Performance critical, competing goals of maximizing utilization, minimizing
overhead, providing fair/predictable access to system resources.
• Resource Sharing: apparent (logical) concurrency or true (parallel)
concurrency
– abstract machines transparently share resources
– concurrent programs may also elect to explicitly share resources
– Space-multiplexed orTime-multiplexed
Fred Kuhns (01/17/09) CS422 – Operating Systems Concepts 2
Common Abstractions: Process and Resource
An application consists of one or more processes, a set of resources and state
Resources
Processes
File F0
Process P0
File F1
Process P1
... ...
File FM
Process PN
memory Ri
...
CPU
display Rj
Operating System
other
CPU DRAM DISKS NET other
other
Fred Kuhns (01/17/09) CS422 – Operating Systems Concepts 3
Computations, Processes and Threads
Interrupts
Disabled
Interrupts
Enabled
Fetch Next Execute Check for &
START
Instruction Instruction Process Int
HALT
Processor
Device table
dispatcher clock handler
(interrupt handler) X
Bus
Timer
…
Process P2
Memory mappings
event terminate
wait
Blocked
Exit
suspend
admit dispatch
New Ready Running
preempt
suspend terminate
admit event wait
activate
suspend
Ready Blocked
Blocked Exit
Suspend event Suspend activate
Suspended Processes
(possibly on backing store)
P1
P2
P3
System ...
(dispatch)
time
• Medium-term scheduler
– allocates memory for process.
– invoked periodically or as needed.
P P P P P P
Process 1 Process 2
user
L L L L Int kthr
kernel ......
...
P P P
hardware
Fred Kuhns (01/17/09) CS422 – Operating Systems Concepts 25
CPU Scheduling
• Understand CPU-I/O burst cycle
• Components: short-term scheduler, dispatcher
• Criteria: CPU utilization, Throughput, Turnaround time, Waiting
time, Response time
• Algorithms: FIFO, Shortest-Job-First, Priority-based,
Round-robin, Multilevel Queue, Multilevel feedback
queue
• Priority-based scheduling, static versus dynamic
priorities
– Solution to starvation problem?
• Preemptive versus nonpreemptive schemes
• Typical goals: Interactive Systems, Batch Systems,
Real-time Systems
• timers and clock handler
• Priority inversion
From Silberschatz, Galvin and Gagne, “Operating Systems Concepts”, 6th eidtion, Wiley, 2002.
• 2) Hold-and-wait:
– A process must hold at least one allocated resource while awaiting one or
more resources held by other processes.
• 3) No preemption:
– Resources not forcibly removed from a process holding it, the holding
process must voluntarily released it.
• 4) Circular wait
– a closed chain of processes exists, such that each process holds at least
one resource needed by the next process in the chain.
Fred Kuhns (01/17/09) CS422 – Operating Systems Concepts 31
Example of a Resource Allocation Graph
R1 R2 R1 R2 R1 R2
P1 P2 P3 P1 P2 P3 P1 P2 P3
R3 R4 R3 R4 R3 R4
Initial: P3 requests R3 P2 releases R1,
No Deadlock (Deadlock) P3 requests R3
(No Deadlock:
• If graph contains no cycles ⇒ Why not?)
– no deadlock.
• If graph contains a cycle ⇒
– if only one instance per resource type, then deadlock.
– if several instances per resource type, possibility of deadlock.
Fred Kuhns (01/17/09) CS422 – Operating Systems Concepts 32
Approaches to Deadlock Handling
• Ensure system never enters a deadlocked state: Use
protocol to prevent or avoid deadlock:
– deadlock prevention scheme - ensure that at least one of the
necessary conditions cannot hold.
– deadlock avoidance scheme - requires the OS know in advance the
resource usage requirements of all processes. Then for each
request the OS decides if it could lead to a deadlock before
granting.
• Allow the system to enter a deadlock state and then
recover (detection and recovery).
– system implements an algorithm for deadlock detection, if so then
recover
• Assume deadlocks never occur in the system
– used by most operating systems, including UNIX.
Arithmetic-Logical Unit
(ALU) Control Unit
Device Controller
Primary Memory Device Controller
Device
Device Controller
Device
Device Controller
Device
Device
Address
Fred Kuhns (01/17/09) CS422 – Operating Systems Concepts 36
Typical Process Address Space
Low Address
(0x00000000)
Text (shared)
Initialized Data
Unitialized Data
Process
Address space Heap (Dynamic)
stack (dynamic)
22K
6K
Last Best Fit
allocated 18K
block (14K) 2K
8K 8K
6K 6K
Allocated block
14K Free block 14K
Next Fit
36K
20K
Before After
Fred Kuhns (01/17/09) CS422 – Operating Systems Concepts 39
Hardware Support for Relocation
Relative address
Process Control
Base Register Block
Adder Program
Absolute
Bounds Register Comparator address
Data
Interrupt to
operating system
Stack
Process image in
main memory
CPU
Unitialized data
DRAM Stack and heap
Low Address
(0x00000000) Text (shared) Allocated virtual pages
Initialized Data
app1 Unitialized Data Swap
Address space Heap (Dynamic) Disk
UFS
High Address stack (dynamic)
(0x7fffffff) Environment
Text and
initialized data app1
process process
Copy Copy
Page tables
X bits Y bits
Virtual address virtual page number offset in page
add
start of page table PTE
M R control bits frame number