avishai wool lecture 9 - 1 introduction to systems programming lecture 9 input-output devices
Post on 21-Dec-2015
223 Views
Preview:
TRANSCRIPT
Avishai Woollecture 9 - 1
Introduction to Systems Programming Lecture 9
Input-Output Devices
Avishai Woollecture 9 - 2
I/O Software Organization
Avishai Woollecture 9 - 3
Layers of the I/O system
Avishai Woollecture 9 - 4
Device drivers
• Every I/O controller has its own control registers, timing requirements, and command sets
• Device driver is the device-specific software that talks to the controller (the adapter)
• Usually device driver is written by the device manufacturer
Avishai Woollecture 9 - 5
Device Drivers
• Logical position of device drivers is shown here• Communications between drivers and device controllers goes over the bus
Avishai Woollecture 9 - 6
Generic Device Driver Structure• Check input parameters for validity.• Translate to device terms (e.g., block number
cylinder/track/sector/head).• In use queue. • Activate device if needed (power on, spin motor)• Loop: Send control command, Wait for response.
– Usually implemented via interrupts, not by polling
• Wait for data transfer to complete.• Check for errors.• Pass data and/or status to device-independent code.
Avishai Woollecture 9 - 7
Disks
Arm
Platter
Track
Read/Write Head
Avishai Woollecture 9 - 8
Disk Terminology
• Disk Cylinders (concentric circles)
• Cylinder Tracks (one per read-write head)
• Tracks Sectors (sequentially around the track)– Sector == Block
Avishai Woollecture 9 - 9
Disk Parameters
msec
Avishai Woollecture 9 - 10
Improvement in Disk Technology
• All parameters got better, but not at same rate:
• Seek time: x 7
• Transfer time: x 1300
• Capacity: x 50000
• Surface density improved much more than mechanical performance.
Avishai Woollecture 9 - 11
Disk Layout Affects PerformanceAverageSeek
Rotationaldelay
Read time(1 track)
Number ofSectors/track
20 ms 8.3 ms 16.7 ms 32
256 sector file stored contiguously
Number of tracks = 8
Total time = seek + 8*(track time)
Track time = Rot. Delay + Read time = 8.3 + 16.7 = 25 ms
Total time = 20ms + 8*25ms = 220 ms
256 sector file stored randomly
Total time = 256 * sector time
sector time = seek + Rot. Delay + Read time = 20 + 8.3 + 0.5
= 28.8 ms
Total time = 256 * 28.8ms = 7372.8 ms
•Only one seek overhead
•Rotational delay once for every 32 sectors
•Seek and rotational delay for every sector
Avishai Woollecture 9 - 12
What goes on inside the disk
Avishai Woollecture 9 - 13
Disk Geometry
• Physical geometry of a disk with two zones
Avishai Woollecture 9 - 14
Virtual Disk Geometry
• OS / Driver does not deal with zone
• Disk exports virtual geometry, all tracks have same number of sectors
• IBM PC (BIOS) only allowed 65535 Cyl / 16 Heads / 63 Sectors per track– Max disk size: 31GB
• To avoid: disks use logical block addressing: – driver refers to blocks by number, not by
(cyl/head/sector)
Avishai Woollecture 9 - 15
A disk sector• Before a disk can be used, it needs a low-level format
16 bytes error-correcting code for 512 byte sector is normal.
“my number is sector N”
Avishai Woollecture 9 - 16
Performance through geometry
• Assume 32 sectors per track
• To read 40 sequential sectors:– read 32 sectors from track x– move head to track x+1 (slow!)– read 8 sectors
• by the time head is at track x+1, sector 0 will pass
• need to wait a whole rotation for it to return
Avishai Woollecture 9 - 17
An illustration of cylinder skew
Avishai Woollecture 9 - 18
More geometry tweaks
• Reading a sector includes:1. read data into controller’s buffer
2. compute ECC, correct errors
3. transfer data to main memory
• By the time steps 2+3 done, next sector passes the head [on slow controllers].
Avishai Woollecture 9 - 19
Disk Interleaving
• No interleaving• Single interleaving• Double interleaving
Avishai Woollecture 9 - 20
Dealing with bad blocks
• Disks have manufacturing defects
--> each track has some spare sectors
• During low-level format, a spare can replace the bad block
Avishai Woollecture 9 - 21
Error Handling
• A disk track with a bad sector• Substituting a spare for the bad sector• Shifting all the sectors to bypass the bad one
Avishai Woollecture 9 - 22
Disk Scheduling
Avishai Woollecture 9 - 23
Controller task: Disk Scheduling
• The controller receives a request for a sector, and issues an interrupt when done.
• Keep a queue of pending requests
• Serve them in some non-FIFO order to reduce average waiting time
• This is a type of a scheduling problem!
Avishai Woollecture 9 - 24
Disk Arm Scheduling Algorithms
• Time required to read or write a disk block determined by 3 factors
Seek time Rotational delay Actual transfer time
• Seek time dominates
Avishai Woollecture 9 - 25
Shortest Seek First (SSF)
Initialposition
Pendingrequests
• Go to requested cylinder that is closest to the head position
• Better average seek time than FCFS
• Unfair: cylinders near edges served more slowly
Avishai Woollecture 9 - 26
The elevator algorithm
• Go “up” and service all upward requests
• Then go “down” and serve the downward requests
Avishai Woollecture 9 - 27
Pre-fetching
• Seek time is much slower than transfer time• Controller often reads the whole track into an
internal read-ahead cache even if only one sector is requested
• Different from OS data cache:– OS caches sectors that were read, hoping they will be
needed again– Disk controller caches sectors that were convenient to
read, hoping they may be needed in future
Avishai Woollecture 9 - 28
On-disk sector cache• modern hard disks typically include
512kB to 2MB of RAM, used as a read-ahead cache– when a read request comes in, the accessed
sector is cached– subsequent sectors cached as well
• this has essentially no cost, since the drive heads need only stay over the drive surface for one revolution (approx. 8 ms at 7200 rpm) to read all sectors in a given track– typically takes heads several milliseconds to
move between tracks anyway
Avishai Woollecture 9 - 29
RAID
Avishai Woollecture 9 - 30
RAID
• Redundant Array of Inexpensive Disks
• Idea: use a box with several disks to get:– parallel I/O (can read/write to several disks at once)– fault-tolerance (disk crashes can be masked without
losing data and without down-time)
• Patterson-Gibson-Katz, 1988, suggested 6 RAID schemes, called RAID level 0-5.
Avishai Woollecture 9 - 31
RAID – Cont.
• Appears as a large disk to OS
• All the “intelligence” is in the controller
• Inside the box: e.g., a SCSI bus with several disks
Avishai Woollecture 9 - 32
RAID-0: Stripping
• Virtual disk sectors split into strips of k sectors• Strips placed on disks cyclically
• No overhead• Maximal parallelism• No fault tolerance (worse than single disk).• Not “real” RAID – no redundancy
Avishai Woollecture 9 - 33
RAID-1: Mirroring
• Every disk has a copy (a mirror)• Simple• Write does 2 I/O, Read can be from either copy
• 100% overhead• Excellent fault tolerance • 2 disk operations per write, can read either copy.
Avishai Woollecture 9 - 34
RAID-2: ECC across disks
• Use Error-Correcting Code (ECC) – example: 4 data bits, 3 parity bits
• Spread each word’s bits across the disks
• Disk drives have to be perfectly synchronized• Lower overhead than RAID-1 (depends on ECC)• Complicated, expensive controller
Avishai Woollecture 9 - 35
RAID-3: Parity Disk
• Single parity disk, stores XOR of other disks.
• Provides 1-disk crash tolerance – crashed disk position known.
• Disk drives need to be synchronized.
• Low overhead (1/N for N disks)
• No parallelism
Avishai Woollecture 9 - 36
RAID-4: Parity + Stripping
• Like RAID 3 but with strip-for-strip parity
• No drive synchronization.
• Each write causes 2 reads (data, parity) and 2 writes (new data, new parity)
• Parity drive can become a bottleneck
Avishai Woollecture 9 - 37
Writing to a Raid-4 Disk
• Initially: S0 S1 S2 S3 P03 = 0
• Want to write value V into strip 0:– Read S0– Compute ΔS = S0 V– Write V into strip 0 (replace S0)– Read P03– Write (P03 ΔS) as new parity
• Verify:– V S1 S2 S3 (P03 ΔS) = … = 0
Avishai Woollecture 9 - 38
RAID-5: Distributed Parity drive
• Like RAID-4 but parity strips spread over all disks
• More complicated controller & crash recovery process
Avishai Woollecture 9 - 39
Clocks
Avishai Woollecture 9 - 40
Clock Hardware
A programmable clock
Avishai Woollecture 9 - 41
Square-Wave mode
Repeat:
• Holding register copied into counter
• Each pulse decrements the counter
• When counter == 0, interrupt CPU
• Each interrupt is a clock tick.
Avishai Woollecture 9 - 42
Maintaining the time of day
• With battery-powered backup clock for when power is off
Avishai Woollecture 9 - 43
Simulating multiple timers with a single clock“Delta-list”
Avishai Woollecture 9 - 44
Concepts for Review• Device Driver• Disk Platter• Disk Arm• Cylinder/Track/Sector• Seek time• Cylinder skew• Disk Interleaving• Disk arm scheduling:
– SSF– Elevator
• Pre-fetching• RAID• RAID-0: Stripping• RAID-1: Mirroring• RAID-4: Parity +
Stripping• Programmable clock• Timer Delta-list
top related