Title: Uppsala University Operating Systems
1Uppsala UniversityOperating Systems
Input Output Brahim Hnichhttp//www.csd.uu.se/b
rahim/os1.html
2Overview I
- Principles of I/O hardware
- I/O devices
- device controllers
- direct memory access (DMA)
- Principles of I/O software
- goals
- interrupt handlers
- device drivers
- device dependent I/O software
- user space I/O software
- Disks
- disk hardware
- disk arm scheduling,
- Summary
3Principles of I/O Hardware
- Different view points
- Programming I/O devices
- NOT designing, building, maintaining I/O devices
- Here only necessary background to understand how
to program I/O devices
4I/O Devices
- Block devices store information in fixed size
blocks, each one with its own address - common block sizes 128 Bytes- 1024 Bytes
- it is possible to read or write each block
independently of all other ones - example disks
- Character devices delivers or accepts a stream
of characters, without regard to any block
structure - it is not addressable and does not have any seek
operation - examples terminals, line printers, paper tapes,
punch cards, network interfaces, mice, and most
other devices that are not disk-like - Clocks or memory mapped screens
- Device drivers low-level software hiding the
device specific details to the file system (deals
with abstract block devices)
5Device Controllers
- Device mechanical component of I/O unit
- Device controller (adapter) electronic component
of I/O unit (often printed circuit card), and the
OS deals with that - Communication between CPU and controllers
- micro- and mini-computers single-bus model
- mainframes multiple buses and specialized I/O
computers (I/O channels) - Memory mapped I/O registers of the controller
(to communicate with the CPU) are part of the
regular memory address space
Disk drives
printer
Controller-device interface
CPU
Memory
Disk controller
Printer controller
Other Controllers
System bus
6Direct Memory Access (DMA)
- Many controllers for block devices support DMA
- a DMA transfer is done entirely by the controller
Drive
CPU
Memory
Disk controller
Buffer
Count
DMA registers
Memory address
Count
System bus
7
0
7
0
7
0
7
0
7
0
5
0
1
1
1
1
6
4
3
3
2
No interleaving
Single interleaving
Double interleaving
2
2
2
2
5
1
6
6
7
3
4
3
4
3
4
3
4
5
2
1
4
7Principles of I/O Software I
- Goals
- organize software as a series of layers
- device independent
- uniform naming
- error handling
- synchronous (blocking) versus asynchronous
(interrupt-driven) transfers - sharable versus dedicated devices
- I/O software is structured in four layers
- interrupt handlers
- device drivers
- device-dependent OS software
- user level software
8Principles of I/O Software II
- Interrupt handlers
- at a very low level of the OS
- (block) unblock processes (by using semaphores,
condition variables,) - Device drivers
- device dependent code
- each device driver handles one device type or one
class of closely related devices - issues commands to the device controller(s),
i.e., to the device registers - only the device driver knows about sectors,
tracks, cylinders, heads, arm motion, interleave
factors, motor drives, head setting times, and
all other mechanics of making a disk work
properly - accepts request from the device-independent
software above
9Principles of I/O Software III
- Device-independent I/O software (functions that
are common to all devices) - uniform interfacing for the device drivers
- device naming (major and minor device number)
- device protection
- providing a device-independent block size
- buffering
- storage allocation
- allocating and releasing dedicated devices
- error reporting
- User-space I/O software (small part)
- libraries linked together with user programs
(system calls) - spooling system daemon, spooling directory
10Principles of I/O Software IV
- Layers of I/O system and main functions of each
layer
I/O reply
layers
User processes
Make I/O call format I/O spooling
I/O request
Device-independent software
Naming, protection, blocking, buffering,
allocation
Device drivers
Setup device registers checks status
Interrupt handlers
Wakeup driver when I/O completed
Hardware
Perform I/O operation
11Disks
- Properties and advantages over main memory
- storage capacity available is much larger
- price per bit is much lower
- information is not lost when power is turned off
- Hardware
- platters, cylinders, tracks, sectors, arms, heads
- overlapped seeks
Head
Arm
Actuator
Platter
Outer track
Sector
Inner track
12Disk Arm Scheduling Algorithms I
- The time to read or write a disk block is
determined by 3 factors - the seek time the time to move the arm to the
proper cylinder (most important) - the rotational delay the time for the proper
sector to rotate under the head - the actual transfer time
- Three algorithms
- FCFS (first come, first served) the disk driver
accepts the request one at a time and carries
then out in that order - SSF (shortest seek first)
- Elevator algorithm
PENDING REQUESTS
SSF
INITIAL POSITION
X
X
X
X
X
X
X
Time
0 5 10 15
20 25 30
35 39
13Disk Arm Scheduling Algorithms II
Elevator Algorithm
PENDING REQUESTS
INITIAL POSITION
X
X
X
X
X
X
X
Time
0 5 10 15
20 25 30
35 39
14Summary
- Input / output important but often ignored topic
(substantial fraction of OS is concerned with
I/O) - Hardware and software
- Next Lectures?
- Deadlocks
- Unix