Title: Review for Midterm
1Review for Midterm
- Fred Kuhns
- (fredk_at_arl.wustl.edu, http//www.arl.wustl.edu/fr
edk) - Department of Computer Science and Engineering
- Washington University in St. Louis
2Computer Systems
- Consists of hardware and software that combine to
solve some identified problem. That is, it
implements an application. - Software solves some problem entertainment,
information management, scientific problem
solving etc. - Hardware provides the provides basic computing
resources (Processor(s), Memory, System Bus and
I/O modules). - Software is divided into two categories
- Application software specialized for the
problem domain. - System software general programming
environment. Simplifies application programming
and can be used for different application
domains. - Users include people, computers or applications.
3System Software
- Primary goals
- User environment Execute user programs and make
solving user problems easier. - Resource Management Make the computer system
convenient to use - Examples of system software
- run-time system provides language specific
libraries , such as I/O, graphics and math. - database management systems
- windowing system
- Operating system interface to hardware,
resource abstractions and sharing.
4Operating Systems
- Requirements
- Resource abstractions (data and special
devices) - Process abstraction (i.e. instance of a program)
- Sharing and isolation
- Management dimensions
- Time Space Synchronization and deadlock
Accounting and status information - Functions
- Device, Process, Resource, Memory and File
management - Implementation issues
- Protection (modes) Trusted control program
(kernel) Requesting services (system calls) - Issues
- Performance protection and security
correctness maintainability commercial
standards and open systems.
5Resources
- Resource
- abstraction that represents any hardware or
software component - models components and their operation
- Resource Sharing sharing in a multiprogramming
environment - Space-multiplexed vs. Time-multiplexed
- isolate resource access to implement allocation
policy - authorized versus non-authorized sharing
- OS implements
- fundamental abstraction of hardware components
- core mechanisms to manage resource sharing
6Model and Core Abstractions
- Basic model access, transform and store
information. - Abstractions facilitate processing and
conceptualization. - Common abstractions in modern systems
- Process basic unit of computation
- Program in execution.
- encapsulates notion of computation and resource
ownership - File basic unit of information storage.
- typically persistent storage is used for files
- also non-persistent such as memory based files
and file systems - A resource must satisfy
- a process must request it from the OS
- a process must suspend operation until resource
is allocated
7Processes and Resources
An application consists of one or more processes,
a set of resources and state
Resources
Processes
...
...
memory Ri
...
CPU
display Rj
Operating System
8Multiprogramming and Process Model
traces for P1, P2 and P3
P1
P2
P3
Shared Code (Program)
9OS Organization
10OS Techniques
- Controlling access to hardware
- hardware support for privilege levels typically
two user and system - Use trusted program (Kernel) for privileged
operations, resource management, protection
enforcement (isolation), and sharing. - Users request OS services using a well defined
interface that validates user. - Common schemes System calls or Message passing
11Typical System Call Approach
execution environment
application
trap
libraries
user
System call interface
kernel
System Services
Kernel interface
handlers
File Subsystem
Memory Subsystem
hardware
12Typical Message Passing Approach
Client
microkernel
13Microkernels
- Small operating system core containing essential
OS functions. - Most services implemented as external subsystems
device drivers file systems virtual memory
manager windowing system and security - Design
- Primitive memory management mapping each virtual
page to a physical page frame grant, map and
flush. - Inter-process communication
- I/O and interrupt management
- Benefits
- Portability isolate port specific code to
microkernel - Reliability modular design, small microkernel,
simpler validation - Uniform interface all services are provided by
means of message passing - Extensibility allows the addition of new
services - Flexibility existing features can be subtracted
- Distributed system support message are sent
without knowing what the target machine is or
where it is located - Object-oriented operating system components are
objects with clearly defined interfaces that can
be interconnected to form software
14(No Transcript)
15Basic Concepts - UNIX
- Two privilege levels user and system mode
- Process has "protected" address space -
protection - Process share same kernel space - efficiency
- Per process state in kernel - efficiency
- Per process kernel stack, practical
considerations - system versus process context virtual property
- Kernel is trusted program that runs directly on
HW - Loaded at boot time and initializes system,
creates initial system processes. , remains in
memory and manages the system - Resource manager/mediator
- Well defined entry points syscalls, exceptions
or interrupts. - Performs privileged operations.
- Entry into the Kernel
- Synchronous System call interface Hardware
exceptions - Asynchronous Hardware interrupts
- Scheduled System processes - swapper and
pagedaemon.
16Mode, Space and Context
Privileged
user
kernel
mode
context
process
Application (user code)
System calls Exceptions
kernel
X not allowed
Interrupts, System tasks
system space
17Von Neumann Architecture
Central Processing Unit (CPU)
18Computer Architecture Processor
CPU
Memory
0
PC
1
MAR
IR
Instruction
Reg N
MBR
Reg 1
Reg 0
Instruction
I/O AR
Instruction
execution unit
I/O BR
Data
Devices
Data
Data
Data
.
.
Buffers
N
MBR - Memory Buffer Register I/O AR -
Input/Output Address Register I/O BE -
Input/Output Buffer Register
PC - Program Counter IR - Instruction
Register MAR - Memory Address Register
19Instruction Cycle
Interrupt Cycle
Execute Cycle
Fetch Cycle
Interrupts Disabled
Fetch Next Instruction
Execute Instruction
Check for Process Int
START
Interrupts Enabled
HALT
20Interrupts
Processor
Device table
dispatcher (interrupt handler)
X
Bus
command
status
rt-counter
Timer
Example clock interrupt is generated every 10ms,
used by OS for accounting and resource (CPU)
sharing.
21I/O and Devices
Processor
Device table
dispatcher (interrupt handler)
X
Bus
command
status
data 0
data 1
Device Controller (firmware and logic)
...
data N-1
Device X
22I/O Techniques
- Direct I/O with polling, aka Programmed I/O
- Processor does all the work. Poll for results.
- Interrupt Driven I/O
- Device notifies CPU when I/O operation complete
- Memory Mapped I/O
- rather than reading/writing to controller
registers the device is mapped into the OS memory
space - increased efficiency
- Direct memory access (DMA)
- DMA controller read and write directly to memory,
freeing the CPU to do other things. - CPU notified when DMA complete
23The Process Model
- Process Sequential execution, characterized by
trace - notion of execution and resource ownership
- Resource allocations
- Explicit Memory, Files, Others
- Implicit CPU, interleave execution fairness,
deadlines, throughput - State kept in Process Control Block
- Process state, Program counter, CPU registers,
CPU scheduling information, Memory-management
information, Accounting information, I/O status
information - Process scheduling queues may migrate between
queues - Job queue Ready queue Device queues.
- Context Switch
- system saves state of old process and load the
saved state of new process. - Context-switch time is overhead the system does
no useful work while switching. - Time dependent on hardware support.
24Resource Schedulers
- Long-term scheduler job scheduler
- selects which processes should be brought into
the ready queue. - invoked infrequently (seconds, minutes)
- controls the degree of multiprogramming
- Medium-term scheduler
- allocates memory for process.
- invoked periodically or as needed.
- Short-term scheduler CPU scheduler
- selects which process should be executed next and
allocates CPU. - invoked frequently (ms)
25Example Process Representation
Process P2 State
Hardware State (registers)
init P0
Program counter
Kernel Process Table
P0 HW state resources
Process P3
Memory base
Process State (logical)
P2 HW state resources
Process P1
PN HW state resources
Process P2
26Typical Process States
suspend
dispatch
admit
time-out
suspend
event
release
admit
activate
wait
suspend
event
activate
27Cooperating Processes
- Independent process cannot affect or be affected
by the execution of another process. - Cooperating process can affect or be affected by
the execution of another process - Advantages of process cooperation
- Information sharing Computation speed-up
Modularity Convenience - Dangers of process cooperation
- Data corruption, deadlocks, increased complexity
- Requires processes to synchronize their
processing - Cooperating processes require special mechanisms
for synchronization, deadlock control and
communication
28IPC Mechanisms
- Mechanisms used for communication and
synchronization - Message Passing Shared Memory Synchronization
Debugging Event Notification - Message passing
- no shared variables two operations for fixed or
variable sized message send(message),
receive(message) - Processes exchange messages over a communication
link. - Implementation of communication link (logical
properties) - Direct or Indirect (Naming)
- Synchronization blocking versus non-blocking
- Buffering Zero, bounded or unbounded. Automatic
or Explicit buffering - Send-by-copy or send-by-reference
- fixed or variable sized messages
29Direct versus Indirect
- Direct
- Link Properties established automatically
between pairs explicit addressing one link per
pair of communicating processes symmetric or
asymmetric addressing - Disadvantage explicit use of ID
- Indirect
- Link properties use common mailbox link may be
shared by multiple processes Supports multiple
links between process pairs - Ownership
- Processes only owner may receive, others can
write - Kernel creator may read. Read permission may be
transferred to other processes. - Disadvantages more complex management
30Multiprocessor Systems
- Motivations Performance, Fault tolerance
- Architectures SISD, SIMD, MISD, MIMD
- Classifications Tightly or Loosely coupled
- Memory Access UMA, NUMA, NORMA
- OS Structure Separate Supervisor, Master/Slave,
SMP
31Multiprocessors
MultiProcessor
SIMD
MIMD
Shared Memory (tightly coupled)
Distributed Memory (loosely coupled)
Symmetric (SMP)
Clusters
Master/Slave
32Typical SMP System
CPU
CPU
CPU
CPU
500MHz
cache
MMU
cache
MMU
cache
MMU
cache
MMU
System/Memory Bus
- Issues
- Memory contention
- Limited bus BW
- I/O contention
- Cache coherence
I/O subsystem
50ns
Bridge
INT
ether
System Functions (timer, BIOS, reset)
scsi
- Typical I/O Bus
- 33MHz/32bit (132MB/s)
- 66MHz/64bit (528MB/s)
video
33SMP Operating Systems
- Design Issues
- Threads - effectiveness of parallelism depends on
performance of primitives used to express and
control concurrency. - Process Synchronization more than disabling
interrupts - Process Scheduling Global versus Local (per
CPU) Task affinity for a particular CPU
resource accounting inter-thread dependencies - Memory Management cache coherence memory access
synchronization balancing overhead with
increased concurrency - Reliability and fault Tolerance
- Defintions
- Parallelism degree to which a multiprocessor
application achieves parallel execution - Concurrency Maximum parallelism an application
can achieve with unlimited processors - System Concurrency supports multiple threads of
control - User Concurrency User space threads (coroutines)
provide a natural programming model for
concurrent applications.
34Threads
Multithreaded Process Model
Single-Threaded Process Model
Thread
Thread
Thread
Thread Control Block
Thread Control Block
Thread Control Block
Process Control Block
User Stack
Process Control Block
User Stack
User Stack
User Stack
Kernel Stack
User Address Space
User Address Space
Kernel Stack
Kernel Stack
Kernel Stack
35Thread Concepts
- Process Model Resource ownership and dispatching
- Thread model separates the notion of execution
from the Process abstraction - Represents an execution path and computational
state - All threads of a process share a common address
space. - One or more threads per process, each having
- Execution state Saved thread context when not
running Execution stack Per-thread static
storage for local variables Shared access to
process resources - Effectiveness of parallel computing depends on
the performance of the primitives used to express
and control parallelism - Thread model is useful for expressing the
intrinsic concurrency of a program regardless of
resulting performance
36Thread Support
- User space threads implemented in user space
system library - Examples POSIX Pthreads, Mach C-threads, Solaris
threads - Benefits no modifications required to kernel
flexible and low cost - Drawbacks can not block without blocking entire
process no parallelism (not recognized by
kernel) - Kernel level threads kernel support thread is
the basic scheduling entity - Examples Windows 95/98/NT/2000, Solaris, Tru64
UNIX, Linux - Benefits coordination between scheduling and
synchronization less overhead than a process
suitable for parallel application - Drawbacks more expensive than user-level
threads generality leads to greater overhead - Combined Approach support both models
- Benefits Less time to do the following
- create a new thread terminate a thread switch
between two threads within the same process
communicate.
37Threading Models
- User threads Many-to-One
- kernel threads One-to-One
- Mixed user and kernel Many-to-Many
38Relationships
39Threading Issues
- fork and exec duplicate one, some or all
threads? - Cancellation cancel the target thread and free
resources - asynchronous cancellation VS deferred
cancellation - Signals generation, posting and delivery
- synchronous signals should go to thread causing
the signal - what about asynchronous signals?
- Bounding the number of threads created in a
dynamic environment - use thread pools
- Al threads share some address space
- use of thread specific data
40Solaris Threading Model
Process 2
Process 1
user
Int kthr
kernel
hardware
41Concurrency
- Concurrent programs may exhibit a dependency on
process/thread execution sequence or processor
speed - Race condition final value of the shared data
may depend on the order in which it was accessed - Prevent race conditions, concurrent processes
synchronize their access to the shared memory
locations known as the critical section problem - There are two basic issues resulting from the
need to support concurrency - Mutual exclusion combines a sequence of actions
into a critical section which appear to execute
atomically - Conditional synchronization. Processes/threads
must be able to wait for the data to arrive or
constraints (assertions) to be satisfied. - Avoiding race conditions
- Disjoint variables Weakened assertions Global
invariants Synchronization - At-Most-Once property only one variable may be
in the read and write set of two or more
processes
42Critical Section Problem
- Entry/exit protocol satisfies
- Mutual Exclusion At most one in CS
- Absence of deadlock 2 or more then at least one
enters CS - Absence of Unnecessary delay if attempting to
enter CS and others not in CS (or exited) then
process must enter - Eventual entry cant wait forever no
starvation.
Task A while (True) entry protocol
critical section exit protocol
non-critical section
43Concurrency What toKnow
- Be able to asses mutual exclusion algorithm using
the 4 properties on previous slide - Busy waiting versus conditional synchronization
- be able to describe lost wakeup problem
- Be ble to describe and understand the example
solutions for - consumer-producer bounded-buffer readers and
writers dining philosophers - Understand the following
- interrupt blocking, Petersons solution hardware
instruction support (test_and_set instruction)
44Concurrency
- Understand and be able to show an example
implementation of semaphores and monitors using
primitive spin locks and condition variables.
45Deadlock
- Be able to define the term deadlock
- Know the necessary conditions for a deadlock to
exist - Know and be able to use/construct the resource
allocation graph - Know the approaches to deadlock handling and be
able to work out a detailed example - prevention ensure one of the necessary
conditions does not hold - avoidance know in advance resource requirements
then asses each request - detection and recovery
46Scheduling
- Understand the concept of a burst cycle and the
difference between I/O and CPU bound processes - Be able to construct a gantt chart illustrating
the behavior of any of the scheduling algorithms
we have covered. - Policy versus mechanism
- all material covered today