Document 7826223

Report
Recall: Three I/O Methods



Synchronous: Wait for I/O operation to complete.
Asynchronous: Post I/O request and switch to other
work.
DMA (Direct Memory Access): Minimize the involvement
of CPU.
I/O Methods

Asynchronous I/O requires the ability to handle
multiple I/O commands concurrently.



Uses device status table.
Queue waiting requests.
Provides opportunity for scheduling of I/O operations.
Device-Status Table
Storage Hierarchy

Storage systems organized in hierarchy.



Speed
Cost
Capacity
Storage-Device Hierarchy
Caching

Idea is to hold heavily used data in the memory
cache to avoid going to main memory on each access
(up to 500 times faster).

Typical instruction cycle:





Fetch instruction from memory
Fetch operands from memory
Execute instruction.
Many machines have instruction and data caches.
On each memory access, the hardware checks the
cache to see if required data is already is there.
Caching




If in cache, use it.
If not in cache, retrieve from main memory and keep
copy in the cache.
On many machines, main memory is used to cache
frequently used disk blocks.
Caching works well when the application exhibits
“locality of reference” i.e., data used in the recent
past will be used again in the near future.
Performance of Various Levels of Storage
Operating System Structure

A key concept of operating systems is
multiprogramming.





Keep multiple jobs in memory.
When one job blocks on I/O, the CPU immediately
switches to another job.
This keeps CPU and I/O devices fully utilized.
Without multiprogramming, CPU would be idle during I/O
operations.
Developed in the 60s when most computers were
batch systems.


Several jobs were batched together and executed.
No interactions between user and job.
Multiprogramming Batch Systems
Problem: CPU and I/O very expensive.
Solution: Multiplex CPU between multiple jobs.
OS Features Needed for Multiprogramming





Use of disk space to hold jobs not in system.
Job scheduling: Choose jobs to bring into
memory.
Memory management – the system must
allocate the memory to several jobs.
CPU scheduling – the system must choose
among several jobs ready to run.
Allocation of devices.
Time-Sharing Systems–Interactive Computing






Logical extension of multiprogramming.
The CPU is multiplexed among several jobs that are kept
in memory and on disk (the CPU is allocated to a job only
if the job is in memory).
A job swapped in and out of memory to the disk.
On-line communication between the user and the system
is provided; when the operating system finishes the
execution of one command, it seeks the next “control
statement” from the user’s keyboard.
 i.e., the shell
Goal is to give the illusion that each user has own
machine.
Response time is a priority.
Protection of System Resources




I/O Devices
Memory
CPU
Based on different modes of operation:



kernel mode and user mode.
Privileged instructions can be issued only in kernel
mode.
Mode bit in PSW, checked on every instruction.
Protection of I/O Devices


All I/O instructions are privileged instructions.
Only accessed through system calls.
Memory Protection



Must provide memory protection for the interrupt
vector, interrupt service routines, and other
applications address space.
Two registers that determine the range of legal
addresses a program may access:
 Base register – holds the smallest legal physical
memory address.
 Limit register – contains the size of the range
Memory outside the defined range is
protected.
Use of A Base and Limit
Register
Hardware Address Protection
CPU (and OS) Protection


Keep user from monopolizing CPU.
Ensure OS regains control of CPU.
CPU Protection

Timer – interrupts computer after specified period to
ensure operating system maintains control.



Timer is decremented every clock tick.
When timer reaches the value 0, an interrupt occurs.
Timer commonly used to implement time sharing.
Privileged Instructions

Load base and limit registers?
Privileged Instructions


Load base and limit registers?
Set the system timer?
Privileged Instructions



Load base and limit registers?
Set the system timer?
Read the system clock?
Privileged Instructions




Set the system timer?
Read the system clock?
Load base and limit registers?
Open a file?
Privileged Instructions





Load base and limit registers?
Set the system timer?
Read the system clock?
Open a file?
Compile a program and create executable?
Privileged Instructions






Load base and limit registers?
Set the system timer?
Read the system clock?
Open a file?
Compile a program and create executable?
Enable/disable interrupts?
System Calls





Interface between executing program and OS defined by set of
system calls OS provides.
System call causes a TRAP to switch from user to kernel mode
and starts execution at interrupt vector location for TRAP
instruction.
Operating system looks at requested operation and any
parameters passed by the application.
Dispatches the correct system call handler through a table of
pointers to system call handlers.
Handler completes and (may) return to user code at the next
instruction. OS may schedule another process to execute.
Transition from User to Kernel
Mode

Interrupts are driven by both hardware and software.


TRAP when requesting OS service through a system call.
Program generated error

Divide by zero, illegal address, ….

similar documents