Professional Documents
Culture Documents
n Terminology
● Synchronous I/O — CPU execution waits
CPU
Di sk Pr in t er Tape Drive Memory while I/O proceeds
Cont ro ller Cont r oller Co nt ro ller Cont r oller
I/ O commands
Disk (Virt ual Memory)
CPU I/ O device
Disk (File Syst em)
dat a dat a
SLOW Backup Tape LA RGE
memory
● OS allocates buffer in memory, tells I/O n At a given level, memory may not be as
device to use that buffer big or as fast as you’d like it be
● I/O device operates asynchronously with ● Tradeoffs between size and speed
CPU, interrupts CPU when finished
● Used for most high-speed I/O devices n Principle of Locality of Reference leads
(e.g., disks, communication interfaces) to caching
● When info is needed, look on this level
● If it’s not on this level, get it from the next
slower level, and save a copy here in
case it’s needed again sometime soon
3 Spring 1997, Lecture 03 4 Spring 1997, Lecture 03
Magnetic Disks Protection
n To prevent illegal I/O, or simultaneous n Must protect OS’s memory from user
I/O requests from multiple processes, programs (can’t overwrite, can’t access)
perform all I/O via privileged instructions ● Must protect memory of one process from
● User programs must make a system call another process
to the OS to perform I/O ● Must not protect memory of user process
from OS
n When user process makes a system call:
● A trap (software-generated interrupt) n Simplest and most common technique:
occurs, which causes:
● Base register —smallest legal address
n The appropriate trap handler to be invoked
using the trap vector ● Limit register — size of address range
n Kernel mode to be set ● Base and limit registers are loaded by OS
● Trap handler: before running a particular process
n Saves state ● CPU checks each address (instruction &
n Performs requested I/O (if appropriate) data) generated in user mode
n Restores state, sets user mode, and n Any attempt to access memory outside the
returns to calling program legal range results in a trap to the OS
n Use a timer to prevent CPU from being n Need for OS services often drives
hogged by one process (either inclusion of architectural features in CPU:
maliciously, or due to an infinite loop) OS Service Hardware Support
● Set timer to interrupt OS after a specified I/O interrupts
period (small fraction of a second) memory-mapped I/O
● When interrupt occurs, control transfers caching
to OS, which decides which process to Data access memory hierarchies
execute for next time interval (maybe the file systems
same process, maybe another one)
Protection system calls
n Also use timer to implement time sharing kernel & user mode
privileged instructions
● At end of each time interval, OS switches interrupts & traps
to another process base & limit registers
● Context switch = save state of that Scheduling & timers
process, update Process Control Block Error recovery
for each of the two processes, restore
state of next process