Download presentation
Presentation is loading. Please wait.
1
Avishai Wool lecture 9 - 1 Introduction to Systems Programming Lecture 9 Input-Output Devices
2
Avishai Wool lecture 9 - 2 I/O Software Organization
3
Avishai Wool lecture 9 - 3 Layers of the I/O system
4
Avishai Wool lecture 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
5
Avishai Wool lecture 9 - 5 Device Drivers Logical position of device drivers is shown here Communications between drivers and device controllers goes over the bus
6
Avishai Wool lecture 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.
7
Avishai Wool lecture 9 - 7 Disks Arm Platter Track Read/Write Head
8
Avishai Wool lecture 9 - 8 Disk Terminology Disk Cylinders (concentric circles) Cylinder Tracks (one per read-write head) Tracks Sectors (sequentially around the track) –Sector == Block
9
Avishai Wool lecture 9 - 9 Disk Parameters msec
10
Avishai Wool lecture 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.
11
Avishai Wool lecture 9 - 11 Disk Layout Affects Performance 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
12
Avishai Wool lecture 9 - 12 What goes on inside the disk
13
Avishai Wool lecture 9 - 13 Disk Geometry Physical geometry of a disk with two zones
14
Avishai Wool lecture 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)
15
Avishai Wool lecture 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”
16
Avishai Wool lecture 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
17
Avishai Wool lecture 9 - 17 An illustration of cylinder skew
18
Avishai Wool lecture 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].
19
Avishai Wool lecture 9 - 19 Disk Interleaving No interleaving Single interleaving Double interleaving
20
Avishai Wool lecture 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
21
Avishai Wool lecture 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
22
Avishai Wool lecture 9 - 22 Disk Scheduling
23
Avishai Wool lecture 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!
24
Avishai Wool lecture 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
25
Avishai Wool lecture 9 - 25 Shortest Seek First (SSF) Initial position Pending requests Go to requested cylinder that is closest to the head position Better average seek time than FCFS Unfair: cylinders near edges served more slowly
26
Avishai Wool lecture 9 - 26 The elevator algorithm Go “up” and service all upward requests Then go “down” and serve the downward requests
27
Avishai Wool lecture 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
28
Avishai Wool lecture 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
29
Avishai Wool lecture 9 - 29 RAID
30
Avishai Wool lecture 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.
31
Avishai Wool lecture 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
32
Avishai Wool lecture 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
33
Avishai Wool lecture 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.
34
Avishai Wool lecture 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
35
Avishai Wool lecture 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
36
Avishai Wool lecture 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
37
Avishai Wool lecture 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
38
Avishai Wool lecture 9 - 38 RAID-5: Distributed Parity drive Like RAID-4 but parity strips spread over all disks More complicated controller & crash recovery process
39
Avishai Wool lecture 9 - 39 Clocks
40
Avishai Wool lecture 9 - 40 Clock Hardware A programmable clock
41
Avishai Wool lecture 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.
42
Avishai Wool lecture 9 - 42 Maintaining the time of day With battery-powered backup clock for when power is off
43
Avishai Wool lecture 9 - 43 Simulating multiple timers with a single clock “Delta-list”
44
Avishai Wool lecture 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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.