1 chapter 5 : input & output i/o hardware (classification, device drivers) i/o hardware...
TRANSCRIPT
1
Chapter 5 : Input & Chapter 5 : Input & OutputOutput
I/O hardware (classification, I/O hardware (classification, device drivers)device drivers)
I/O techniques (programmed, I/O techniques (programmed, interrupt driven, DMA)interrupt driven, DMA)
Structuring I/O softwareStructuring I/O software Disks (performance, arm Disks (performance, arm
scheduling, common disk errors)scheduling, common disk errors) RAID configurationsRAID configurations
2
I/O HardwareI/O Hardware
Classification of I/O devicesClassification of I/O devices Device controllersDevice controllers
3
Classification of I/O Classification of I/O DevicesDevices
Block devicesBlock devices Information is stored in fixed size blocksInformation is stored in fixed size blocks Block sizes range from Block sizes range from 512512--3276832768 bytes bytes I/O is done by reading/writing blocksI/O is done by reading/writing blocks Hard disks, floppies, CD ROMS, tapes are Hard disks, floppies, CD ROMS, tapes are
in this categoryin this category Character devicesCharacter devices
I/O is done as characters (ie., no blocking)I/O is done as characters (ie., no blocking) Terminals, printers, mouse, joysticks are in Terminals, printers, mouse, joysticks are in
this categorythis category
4
Some typical device, network, and data base ratesSome typical device, network, and data base rates
5
Device ControllersDevice Controllers
A controller is an electronic card (PC’s) or a unit A controller is an electronic card (PC’s) or a unit (mainframes) which performs blocking(mainframes) which performs blocking (from serial (from serial bit stream)bit stream), analog signal generation (to move the , analog signal generation (to move the disk arm, to drive CRT tubes in screens), execution disk arm, to drive CRT tubes in screens), execution of I/O commandsof I/O commands
System bus
CPU Memory Controller Controller Controller
Disk
Motherboard
6
I/O TechniquesI/O Techniques
Programmed I/OProgrammed I/O Interrupt-driven I/OInterrupt-driven I/O Direct memory access (DMA)Direct memory access (DMA)
7
Programmed I/OProgrammed I/O
The processor issues an I/O The processor issues an I/O command on behalf of a process to command on behalf of a process to an I/O modulean I/O module
The process The process busy-waitsbusy-waits for the for the operation to be completed before operation to be completed before proceedingproceeding
8
Interrupt-driven I/OInterrupt-driven I/O Processor issues an I/O command on Processor issues an I/O command on
behalf of a processbehalf of a process Process is suspended and the I/O startsProcess is suspended and the I/O starts Processor may execute another processProcessor may execute another process Controller reads a block from the drive Controller reads a block from the drive
serially, bit by bit into controller’s serially, bit by bit into controller’s internal bufferinternal buffer. A checksum is computed . A checksum is computed to verify no reading errorsto verify no reading errors
When I/O is finished, the processor is When I/O is finished, the processor is interrupted to notify that the I/O is overinterrupted to notify that the I/O is over
OS reads controller’s buffer a byte (or OS reads controller’s buffer a byte (or word) at a time into a memory buffer.word) at a time into a memory buffer.
9
Direct Memory Access Direct Memory Access (DMA)(DMA)
A DMA module controls the exchange of data A DMA module controls the exchange of data between main memory and an I/O devicebetween main memory and an I/O device
The processor sends a request for the transfer The processor sends a request for the transfer of a block of data to the DMA module (block of a block of data to the DMA module (block address, memory address and number of address, memory address and number of bytes to transfer) and continues with other bytes to transfer) and continues with other workwork
DMA module interrupts the processor when DMA module interrupts the processor when the entire block has been transferredthe entire block has been transferred
When OS takes over, it does not have to copy When OS takes over, it does not have to copy the disk block to memory; it is already there.the disk block to memory; it is already there.
10
DMA (Cont.)DMA (Cont.) DMA unit is capable of transferring data DMA unit is capable of transferring data
straight from memory to the I/O devicestraight from memory to the I/O device Cycle StealingCycle Stealing: DMA unit makes the CPU : DMA unit makes the CPU
unable to use the bus until the DMA unit unable to use the bus until the DMA unit has finishedhas finished
Instruction execution cycle is suspended, Instruction execution cycle is suspended, NOTNOT interrupted interrupted
DMA has less number of interrupts (usually DMA has less number of interrupts (usually one when I/O is finished to acknowledge). one when I/O is finished to acknowledge). Interrupt driven I/O may need one Interrupt driven I/O may need one interrupt for each character if device has interrupt for each character if device has no internal buffers.no internal buffers.
11
Direct Memory Access Direct Memory Access (DMA)(DMA)
Operation of a DMA transferOperation of a DMA transfer
12
Hardware
Interrupt handlers
Device drivers
Device-independent software
User space software
I/O request I/O reply
I/O system calls (library)
Naming, protection, blocking,
buffering, allocation
Setup device registers; check status
Wakeup driver when I/O completed
Perform I/O operation
Structuring I/O SoftwareStructuring I/O Software
13
User-Space I/O SoftwareUser-Space I/O Software
Library of I/O procedures (ie., Library of I/O procedures (ie., system calls) such as system calls) such as
bytes-read = read (file_descriptor, bytes-read = read (file_descriptor, buffer, buffer, bytes to be read) bytes to be read)
Spooling provides virtual I/O devicesSpooling provides virtual I/O devices
14
Device-Independent I/O Device-Independent I/O SoftwareSoftware
Uniform interface for device Uniform interface for device drivers (ie., different devices)drivers (ie., different devices)
Device namingDevice naming Mapping of symbolic device names Mapping of symbolic device names
to proper device driversto proper device drivers Device protectionDevice protection
In a multi-user system you can not In a multi-user system you can not let all users access all I/O deviceslet all users access all I/O devices
15
Device-Independent I/O Device-Independent I/O Software (Cont.)Software (Cont.)
Provide device independent block Provide device independent block sizesize Physical block sizes for different devices Physical block sizes for different devices
may differ, so we have to provide the may differ, so we have to provide the same logical block sizessame logical block sizes
BufferingBuffering Storage allocation on block devices Storage allocation on block devices
such as diskssuch as disks Allocating and releasing dedicated Allocating and releasing dedicated
devices such as tapesdevices such as tapes
16
Device-Independent I/O Device-Independent I/O Software (Cont.)Software (Cont.)
Error reportingError reporting When a bad block is encountered, the When a bad block is encountered, the
driver repeats the I/O request several driver repeats the I/O request several times and issues an error message if times and issues an error message if data can not be recovereddata can not be recovered
17
Device DriversDevice Drivers
One driver per device or device classOne driver per device or device class Device driverDevice driver
Issues I/O commandsIssues I/O commands Checks the status of I/O device (eg. Checks the status of I/O device (eg.
Floopy drive motor)Floopy drive motor) Queues I/O requestsQueues I/O requests
18
Device DriversDevice Drivers (Cont.) (Cont.)
(a) Without a standard driver interface(a) Without a standard driver interface
(b) With a standard driver interface(b) With a standard driver interface
19
Interrupt HandlersInterrupt Handlers
When an I/O is issued, the process is When an I/O is issued, the process is suspended until I/O is finishedsuspended until I/O is finished
When the I/O is finished, the hardware When the I/O is finished, the hardware causes an interrupt and the execution causes an interrupt and the execution is directed to a special routine is directed to a special routine (interrupt handler)(interrupt handler)
Interrupt handler notifies the device Interrupt handler notifies the device driver which in turn passes this to the driver which in turn passes this to the upper layersupper layers
20
DisksDisks
Heads
Cylinder
Sector
Track
21
DisksDisks (Cont.) (Cont.)
Disk parameters for the original IBM PC floppy Disk parameters for the original IBM PC floppy disk and a Western Digital WD 18300 hard diskdisk and a Western Digital WD 18300 hard disk
22
Disk Performance Disk Performance ParametersParameters
Seek time: Time to move disk arm to Seek time: Time to move disk arm to the required trackthe required track
Rotational delay (rotational latency): Rotational delay (rotational latency): Wait for the correct block to be Wait for the correct block to be under the headunder the head
Seek Rotational Delay
Data Transfer
Access time
23
Approximate Formulas Approximate Formulas for Disk Performance for Disk Performance
Parameters Parameters Seek time (TSeek time (Tss) = ) = m * n + sm * n + swhere where mm = a constant depending on the = a constant depending on the disk drivedisk drive
n n = number of tracks traversed = number of tracks traversed s s = startup time = startup time
Rotational delay (TRotational delay (Trr) = 1 / (2*) = 1 / (2*rr))wherewhere r r is the rotation speed in revolutions is the rotation speed in revolutions per secondper second
Transfer time (TTransfer time (Ttt) = ) = bb / ( / (r*Nr*N))where where bb = number of bytes to be = number of bytes to be transferredtransferred NN = number of bytes on a track = number of bytes on a track
Average access time (TAverage access time (Ta a ) = T) = Ts s + T + Tr r + + TTtt
24
Example (From Example (From “Stallings” Book) “Stallings” Book)
Read a file of 256 sectors (or 8 Read a file of 256 sectors (or 8 tracks) from a disk drive with the tracks) from a disk drive with the following characteristicsfollowing characteristics Average seek time = 20 msecAverage seek time = 20 msec Transfer rate = 1 Mb/sTransfer rate = 1 Mb/s Bytes per sector = 512Bytes per sector = 512 32 sectors per track32 sectors per track Disk rotates at 3600 rpm Disk rotates at 3600 rpm
Consider two cases:Consider two cases: Contiguously StoredContiguously Stored Randomly StoredRandomly Stored
25
File is Stored File is Stored ContiguouslyContiguously
Time to read one track isTime to read one track is
seek + latency + data transfer (1 track - seek + latency + data transfer (1 track - one revolution) =one revolution) =
20 msec + 8.3 msec + 16.7 msec = 45 20 msec + 8.3 msec + 16.7 msec = 45 msecmsec
No seek time for the other 7 tracksNo seek time for the other 7 tracks All tracks = first track + other 7 tracksAll tracks = first track + other 7 tracks
45 msec + 7 * 25 (8.3+16.7) = 220 45 msec + 7 * 25 (8.3+16.7) = 220 msecmsec
26
Randomly StoredRandomly Stored
Time to read one sector (randomly) isTime to read one sector (randomly) is
seek + latency + data transfer (1 seek + latency + data transfer (1 sector) =sector) =
20 msec + 8.3 msec + 0.5 msec = 20 msec + 8.3 msec + 0.5 msec = 28.8 msec28.8 msec
Time to read 256 sectors = 256 * 28.8 Time to read 256 sectors = 256 * 28.8 = 7.37 seconds= 7.37 seconds
27
Disk Scheduling PoliciesDisk Scheduling Policies The order in which sectors are The order in which sectors are
read from the disk has a read from the disk has a tremendous effect on I/O tremendous effect on I/O performance)performance)
Scheduling AlgorithmsScheduling Algorithms FIFOFIFO SSF (Shortest seek first)SSF (Shortest seek first) SCAN (Elevator algorithm) SCAN (Elevator algorithm) C-SCAN (One-way elevator)C-SCAN (One-way elevator) FSCANFSCAN
28
First in, First out (FIFO)First in, First out (FIFO) Disk driver accepts request one at a Disk driver accepts request one at a
time and carries them in that ordertime and carries them in that order No starvationNo starvation Example: Requests for 1, 36, 16, 34, 9, Example: Requests for 1, 36, 16, 34, 9,
12 when positioned on cylinder 11 12 when positioned on cylinder 11 (mean movement = 18.5 cylinders)(mean movement = 18.5 cylinders)
111 12 16 3634
0 10 20 30 40
9
29
Shortest Seek First (SSF)Shortest Seek First (SSF)
Request which requires shortest seek is chosenRequest which requires shortest seek is chosen Possibility of starvation (if requests are clustered)Possibility of starvation (if requests are clustered) Same example : mean movement = 10.2 cylindersSame example : mean movement = 10.2 cylinders
111 12 16 3634
0 10 20 30 40
9
30
SCAN (Elevator SCAN (Elevator Algorithm)Algorithm)
Disk arm moves in one direction, performing Disk arm moves in one direction, performing all requests until no more are needed in that all requests until no more are needed in that direction, then turns around and comes backdirection, then turns around and comes back
Same example : mean movement = 10.0 Same example : mean movement = 10.0 cylinderscylinders
111 12 16 3634
0 10 20 30 40
9
31
SCAN (Cont.)SCAN (Cont.)
Favours Favours Tracks nearest to both Tracks nearest to both innermost and outermost innermost and outermost cylinderscylinders
Latest-arriving requestsLatest-arriving requests
32
C-SCAN (One-way C-SCAN (One-way Elevator)Elevator)
Modification of SCAN where Modification of SCAN where scanning direction is one way scanning direction is one way onlyonly
Once arm reaches the end it Once arm reaches the end it moves back to the startmoves back to the start
33
FSCANFSCAN SSTF, SCAN and C-SCAN SSTF, SCAN and C-SCAN
may suffer from "arm may suffer from "arm stickiness” (starvation for stickiness” (starvation for some requests)some requests)
If multiple new requests If multiple new requests keep arriving for the same keep arriving for the same track the arm gets "stuck"track the arm gets "stuck"
The solution is to maintain The solution is to maintain multiple queuesmultiple queues
34
FSCAN (Cont.)FSCAN (Cont.) Two queues, one being used for Two queues, one being used for
the scan and the other for new the scan and the other for new requests during the scanrequests during the scan
When a scan begins, all new When a scan begins, all new requests are in one of the requests are in one of the queues, with the other being queues, with the other being emptyempty
During the scan, all new During the scan, all new requests are put into the queue requests are put into the queue that was initially emptythat was initially empty
Thus, service of new requests is Thus, service of new requests is deferred until all the old deferred until all the old requests have been processedrequests have been processed
35
Common Disk ErrorsCommon Disk Errors Programming error (e.g., request Programming error (e.g., request
for nonexistant sector)for nonexistant sector) This type of error should not This type of error should not
occur if programming (software occur if programming (software development) is done carefullydevelopment) is done carefully
If such an error is encountered, If such an error is encountered, probably the only thing to do is probably the only thing to do is to terminate the request and to terminate the request and notify the user or programmernotify the user or programmer
36
Common Disk Errors Common Disk Errors (Cont.)(Cont.)
Transient checksum error (e.g., Transient checksum error (e.g., usually caused by dust on the head. usually caused by dust on the head. Mostly for floppies)Mostly for floppies) The read or write operation is The read or write operation is
repeated for a couple of timesrepeated for a couple of times If the operation is not successful If the operation is not successful
the block is marked as bad (Bad the block is marked as bad (Bad CRC)CRC)
Re-formating may cure the errorRe-formating may cure the error
37
Common Disk Errors Common Disk Errors (Cont.)(Cont.)
Permanent checksum error (e.g., Permanent checksum error (e.g., disk block physically damaged)disk block physically damaged) Bad blocks are marked so that Bad blocks are marked so that
device drivers do not access themdevice drivers do not access them Controller error (e.g., controller Controller error (e.g., controller
refuses to accept commands)refuses to accept commands)
38
Common Disk Errors Common Disk Errors (Cont.)(Cont.)
Seek error (e.g., the arm is directed to Seek error (e.g., the arm is directed to cylinder 6 but it goes to 7) cylinder 6 but it goes to 7) The disk arm is positioned on The disk arm is positioned on
cylinders by pulses (one pulse per cylinders by pulses (one pulse per cylinder). When the arm reaches its cylinder). When the arm reaches its destination the cylinder number is destination the cylinder number is checked (written when the drive checked (written when the drive was formatted). If the arm is in a was formatted). If the arm is in a wrong position then a seek error wrong position then a seek error occursoccurs
39
Common Disk Errors Common Disk Errors (Cont.)(Cont.)
Some controllers can correct the Some controllers can correct the seek error by issuing a seek error by issuing a RECALIBRATE commandRECALIBRATE command
This command moves the arm as This command moves the arm as far out as it will go to reset the far out as it will go to reset the arm on cylinder 0. If this does not arm on cylinder 0. If this does not solve the problem then the drive solve the problem then the drive has to be repaired (replaced with has to be repaired (replaced with a new one?)a new one?)
40
RAID (Redundant Array RAID (Redundant Array of Inexpensive Disks)of Inexpensive Disks)
Security (fault tolerance)Security (fault tolerance) PerformancePerformance 0-5 levels are defined0-5 levels are defined
41
RAID 0 LevelRAID 0 Level A file is written (distributed) over several A file is written (distributed) over several
disksdisks This permits multiple reads and writesThis permits multiple reads and writes Consequently speed is improvedConsequently speed is improved But no error correctionBut no error correction
42
RAID 1 (Mirroring)RAID 1 (Mirroring) A file is written on at least two drivesA file is written on at least two drives The other drive becomes a mirror The other drive becomes a mirror
image of the first driveimage of the first drive
43
RAID 1 (Mirroring)RAID 1 (Mirroring)
Reading is improved because of two Reading is improved because of two pathspaths
Writing is slower as the same data Writing is slower as the same data has to be written twicehas to be written twice
Fault tolerance is improved as the Fault tolerance is improved as the failure of two disks at the same time failure of two disks at the same time is lowis low
44
RAID RAID 22 A file is distributed on several disks as in RA file is distributed on several disks as in Raidaid 0 0, ,
but Raid level 2 works on words or bytes basisbut Raid level 2 works on words or bytes basis AAdditional drivedditional drives s contains the parity information contains the parity information
which may be used to reconstruct the file if a which may be used to reconstruct the file if a drive fails (drive fails (See “Hamming Codes” for error See “Hamming Codes” for error correctioncorrection)), ,
45
RAID RAID 22
Raid level 2 requires synchronized Raid level 2 requires synchronized drivesdrives
Reading is Reading is very very fast as all drives can fast as all drives can transfer data (portions of the file)transfer data (portions of the file). In . In one sector reading time n (number one sector reading time n (number of drives) sectors are read inof drives) sectors are read in
Writing is slower Writing is slower because of because of parity parity information (to write parity all information (to write parity all requests must access this drive)requests must access this drive)
46
RAID RAID 33 Raid 3 is a simplifed version of Raid 2Raid 3 is a simplifed version of Raid 2 It uses an additional drive for a parity bit It uses an additional drive for a parity bit
(word/byte)(word/byte) Drives must be synchronizedDrives must be synchronized Provides 1 bit (word/byte) error correctionProvides 1 bit (word/byte) error correction
47
RAID RAID 44 A file is distributed A file is distributed as strips as strips on several on several
disks as in RAID 0disks as in RAID 0 Another drive holds the parity stripAnother drive holds the parity strip Reading is fast as all drives can transfer Reading is fast as all drives can transfer
data (portions of the file) independentlydata (portions of the file) independently Parity drive is heavily usedParity drive is heavily used
48
RAID RAID 55
Raid level 5 is Raid level 4 with Raid level 5 is Raid level 4 with parity information distributed on parity information distributed on all drivesall drives
49
RAID 5RAID 5 Similar to RAID Similar to RAID 44 but parity is but parity is
distributed to all disksdistributed to all disks Fast read and writesFast read and writes Suitable for transaction oriented Suitable for transaction oriented
processing such as on-line banking, processing such as on-line banking, hotel reservations etc.hotel reservations etc.
Total capacity for a RAID 5 system Total capacity for a RAID 5 system with with NN disks = capacity of one disk disks = capacity of one disk * (N-1)* (N-1)
50
Hamming Code Example Hamming Code Example (One Bit Correction)(One Bit Correction)
4 data bits (D3, D5, D6, 4 data bits (D3, D5, D6, D7) – 1 0 1 0 and 3 D7) – 1 0 1 0 and 3 parity bits (P1, P2, P4)- parity bits (P1, P2, P4)- 1 0 11 0 1
P1 makes D3, D5, D7 P1 makes D3, D5, D7 even; P2 makes D3, D6, even; P2 makes D3, D6, D7 even; P4 makes D5, D7 even; P4 makes D5, D6, D7 evenD6, D7 even
Check parities after Check parities after transmission. 0= parity transmission. 0= parity check is correct; 1= check is correct; 1= parity check failedparity check failed
1 10110 0P1 D3 D5P4 D7D6P2
P4P4 P2P2 P1P1 Error Error inin
00 00 00 No No errorerror
00 00 11 P1P1
00 11 00 P2P2
00 11 11 D3D3
11 00 00 P4P4
11 00 11 D5D5
11 11 00 D6D6
11 11 11 D7D7