Input/Output - Sabancı Üniversitesipeople.sabanciuniv.edu/ysaygin/documents/lectures/CS307... ·...
Transcript of Input/Output - Sabancı Üniversitesipeople.sabanciuniv.edu/ysaygin/documents/lectures/CS307... ·...
1
Input/Output
2
I/O Hardwares
Some typical device, network, and data base rates
3
Device Controllers
• I/O devices have components:
– mechanical component
– electronic component
• The electronic component is the device
controller
– may be able to handle multiple devices
• Controller's tasks
– convert serial bit stream to block of bytes
– perform error correction as necessary
4
Device Driver Interface
Device Interface
Printer
Driver
Disk
Driver
Printer
Controller
Disk
Controller
•Device interface is standard for all the I/O devices and in POSIX compliant systems it consists of
Open(), Close(), Read(), Write(), Seek(), and Control() functions.
•Drivers implement the device interface functions specific to a device
5
Device Management
• Device manager is responsible to provide services to the
file manager and application software.
• It has a device independent infrastructure and a collection
of device-dependent drivers
6
I/O Strategies
• I/O with polling
• I/O with interrupts
• DMA I/O
7
I/O With Polling
• CPU is responsible for
– determining if the I/O operation has completed
– Transferring the data between the main memory and the device
controller data registers
• Steps for performing direct I/O with polling (for read operation)
1. Application process requests a read operation
2. The device driver queries the status register to determine if the device is
idle. If the device is busy, the driver waits for it to become idle.
3. The driver stores an input command into the controllers command
register, starting the device
4. The driver repeatedly reads the status register while waiting for the
device to complete the operation
5. The driver copies the contents of the controller’s data registers into the
user’s process space.
8
I/O With Interrupts
• Polling wastes CPU cycles. Interrupts eliminate the need for the
device driver to constantly poll the controller status register
• Instead of polling, the device controller automatically notifies the
device manager when the operation is complete.
• Device manager should have the following parts
– The driver part that initiates the operation
– Device status table
– Interrupt handler
– Device handler
9
I/O With Interrupts
An input operation using interrupts
1. The application process requests a read operation
2. The device driver queries the status register to determine if the
device is idle. If the device is busy, the driver waits for the device to
become idle
3. The device driver stores an input command into the controllers
command register starting the device
4. The device driver saves information regarding the operation that it
began in the device status table. This table contains an entry for
each device in the system. The information saved is the return
address of the original call, and any special parameters for the I/O
operation.
5. The device manager invokes the scheduler (so that some other
process can use the CPU) and terminates
10
I/O With Interrupts
5. When the device completes the operation, it interrupts the CPU, and
causes the interrupt handler to run
6. The interrupt handler determines which device caused the interrupt,
and branches to the device handler for that device
7. The device handler retrieves the pending I/O status information
from the device status table
8. The device handler copies the contents of the controller’s data
registers into the user process’s space
9. The device handler returns control to the application process
11
I/O with DMA
• Used when the hardware has a DMA controller
• DMA controller has access to the system bus independent of the CPU.
• Contains several registers that can be written and read by the CPU
– The control registers specify the I/O port to use, the direction of transfer,
and the unit of transfer
– Memory address register specifies where to write or read
– Byte count register specifies the amount read or written
12
Memory-Mapped I/O (1)
• Separate I/O and memory space
• Memory-mapped I/O
• Hybrid
13
Memory-Mapped I/O (2)
(a) A single-bus architecture
(b) A dual-bus memory architecture
14
Interrupts Revisited
How interrupts happens. Connections between devices and interrupt controller actually use interrupt lines on the bus rather than dedicated wires
15
Disks Disk Hardware (1)
Disk parameters for the original IBM PC floppy disk and a Western Digital WD 18300 hard disk
16
Disk Hardware (2)
• Physical geometry of a disk with two zones
• A possible virtual geometry for this disk
17
Disk Hardware (5)
Recording structure of a CD or CD-ROM
18
Disk Hardware (6)
Logical data layout on a CD-ROM
19
Disk Hardware (7)
• Cross section of a CD-R disk and laser
– not to scale
• Silver CD-ROM has similar structure
– without dye layer
– with pitted aluminum layer instead of gold
20
Disk Hardware (8)
A double sided, dual layer DVD disk
21
Disk Formatting (1)
A disk sector
22
Disk Formatting (2)
An illustration of cylinder skew
23
Disk Formatting (3)
• No interleaving
• Single interleaving
• Double interleaving
24
Disk Arm Scheduling Algorithms (1)
• Time required to read or write a disk
block determined by 3 factors
1. Seek time
2. Rotational delay
3. Actual transfer time
• Seek time dominates
• Error checking is done by controllers
25
Disk Arm Scheduling Algorithms
• FCFS: First Come First Served
– Assume that the initial disk arm position is on cylinder 11
(cylinders are numbered starting from 0)
– If the new requests are 1, 36, 16, 34, 9, 12 (these are cylinder
numbers)
– Then total of 10 + 35 + 20 + 18 + 25 +3 = 111 cylinders will be
traversed
• SSF : Shortest Seek First
– What is the total number of cylinders traversed for the same
requests, 1, 36, 16, 34, 9, 12 ?
• The arm motions of SSF is depicted in the next slide
26
Disk Arm Scheduling Algorithms (2)
Shortest Seek First (SSF) disk scheduling algorithm
Initial
position
Pending
requests
27
SSF
• What could be the disadvantage of SSF?
• Elevator algorithm is proposed to overcome the
disadvantages:
– The direction of the disk arm is important for scheduling decisions
– Disk arm direction going towards higher cylinder numbers is
called UP, and the reverse is called DOWN
– After the current request was processed the next request that is
closest in the direction of the disk arm is processed
– Assuming the disk arm direction is UP, and the requests are :
1,36,16, 34, 9, 12 then what would be the total number of cylinders
traversed?
28
Disk Arm Scheduling Algorithms (3)
The elevator algorithm for scheduling disk requests
29
Error Handling
• Metal oxide coating
• The linear recording density has limits (ex
5000bits/mm)
• High recording density means higher
manufacturing errors
30
Error Handling
• Bad sectors result from manufacturing
defects
• ECC can be used to handle a few defected
bits
• Bigger errors can be handled by
– Controller
– OS
31
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
32
Error Handling
• Errors may occur during the normal operation of
the disk which may be
– Transient (dust etc)
– Can be fixed by the ECC
– Repeated errors: spare sectors should be used before the
sector dies completely
33
Error Handling
• OS can handle bad sectors by re-mapping tables
– Read the entire disk to construct a list of bad sectors
– Both allocated and free blocks need to be tested
– Backup system should also consider bad sectors
• Seek errors may also occur if the disk head can not
be positioned in the right track
• The disk dead needs to be recalibrated when such
an error occurs
34
RAID
• SLED : Single Large Expensive Disk
• The speed of Mechanic v.s. Electronic components
• Parallelism in CPU proved to be effective
• Why not parallelism in I/O? (by Patterson et.al. 1988)
– RAID (Redundant Array of Inexpensive Disks)
• Adopted by the industry as Redundant Array of
Independent Disks
35
RAID
• RAID is a set of disks with a single RAID controller
• Its aim is to improve the fault tolerance and performance with a reasonable cost
• The disks in RAID appear as a single disk to the OS
• There are six different RAID organizations (0…5)
– RAID level 0 : Data striping is employed, i.e., the whole disk consists of strips of size “k-sectors” partitioned into individual disks in round robin fashion
– There is no redundant data storage in this approach
– Is this better for requests of larger or smaller chunks of read requests?
– No performance gain if the requests are one sector at a time!
– What about reliability?
36
37
RAID
• There are six different RAID organizations (0…5)
– RAID level 1: Data striping is used. It also duplicates all the disks.
38
•In the above case we have 4 primary disks and 4 backup disks
•Every strip is written twice!
•Either of the two copies could be read!
39
–How do you think the read and write performance is in RAID level 1?
–Is it fault tolerant?
40
–How do you think the read and write performance is in RAID level 1?
–Is it fault tolerant?
•Write performance is the same
•Read performance can be twice as good
•Fault tolerance is excellent
•Recovery is easy, buy a new drive, and replace it with the one that crashed
41
RAID
• There are six different RAID organizations (0…5)
– RAID level 2: Works in very small granularity striping with hamming code for error detection and correction. For example a byte is divided into 4bit chunks, and 3 parity bits are added to form a 7 bit word which is partitioned bit by bit to 7 disks. Disk drives must be synchronized for read and write.
42
–RAID level 2: Works in very small granularity striping with
hamming code for error detection and correction.
–For example a byte is divided into 4bit chunks, and 3 parity bits
are added to form a 7 bit word which is partitioned bit by bit to 7 disks.
Disk drives must be synchronized for read and write.
43
RAID
• RAID organizations cont’d (0…5)
– RAID level 3 : simplified version of level 2, where only checksum
is stored. It can do error detection but not error correction in case
there are random bit errors. What would be the effect of a single
disk crash?
– RAID level 4: use data striping. With a strip of k bytes, an extra
disk drive stores k-byte long parities constructed by performing an
exclusive or on the strips in each disk.
– RAID level 5: It is like RAID level 4, but parity bits are distributed
over the RAID disks to reduce the risk induced by parity disk
crash.
44
RAID
• RAID organizations cont’d (0…5)
– RAID level 3 : simplified version of level 2, where only checksum
is stored. It can do error detection but not error correction in case
there are random bit errors. What would be the effect of a single
disk crash?
•Assume that one of the drives crashes, can we do •Error detection
•Error correction!
45
Disk Hardware (4)
• Raid levels 3 through 5
• Backup and parity drives are shaded
46
Stable Storage
• RAID deals with correct reads and fault tolerance
against crashes
• How about writes?
• Desired Property:
– When a write is issued, the disk either correctly writes
the data or it does nothing at all (Called Stable Storage)
47
Stable Storage
• Following can be handled:
– A written sector can suddenly become unreadable
– CPU can fail leading to incorrect data
• Following can not be handled:
– Student drops the computer out of the window of a
skyscraper
– Student sets the computer room on fire
– Natural disasters
48
Stable Storage • Stable storage uses a pair of identical disks with the
corresponding blocks form an error-free block
• Stable write:
– Write the block on drive 1
– Read it back and verify it, if not correct repeat the operation
– After n consecutive failures the block is remapped to a spare one
and the operation continues
– After the write to drive 1 succeeds, the corresponding block on
drive 2 is written and re-read until it succeeds
– After the stable write completes, the block is successfully written
to both drives
49
Stable Storage • Stable storage uses a pair of identical disks with the
corresponding blocks form an error-free block
• Stable read:
– First read from drive 1
– If the ECC indicates and error, then reread
– If after n iterations, the error occurs, then the corresponding block
is read from drive 2
• Assumption: probability that the same block in both drives
will go bad is practically 0
50
Stable Storage • Crash recovery
– Scan both disks and compare the corresponding blocks
– If one of the has ECC error, then the good one is written over the
bad one
– If both have ECC good, but they are different, then the block in
drive 1 is overwritten to drive 2.
–
51
Stable Storage
Analysis of the influence of crashes on stable writes
52
Clock Hardware
A programmable clock – Generates a CPU interrupt when the counter is 0
– These are called clock ticks
– Can be programmed to occur very 2 nsecs to 8.6 secs
Computers also have battery-powered to recover the current time when the computer is turned on
Original starting time for windows is 12 AM Jan 1, 1980. For Unix, it is 12 AM, Jan 1 1970.
53
Clock Software
• Clock drivers job:
– Maintain time of day
– Prevent processes from running longer than
they are allowed to
– Accounting CPU usage
– Providing watchdog timers
– etc
54
Clock Software (1)
Three ways to maintain the time of day
55
Simulating multiple virtual clocks
• Maintain a table
• The signal times for all pending timers stored in
the table
• Whenever the time of day is updated, the driver
checks to see if the closest signal has occured
56
Clock Software (2)
Pending signals are for 4203, 4207, 4213, 4215, 4216
Simulating multiple timers with a single clock
57
ALS
– Assume that the initial disk arm position is on cylinder
11 (cylinders are numbered starting from 0)
– If the new requests are 1, 36, 16, 34, 9, 12 (these are
cylinder numbers)
– Total number of tracks traversed by
• SSF?
• Elevator?
58
Character Oriented Terminals RS-232 Terminal Hardware
• An RS-232 terminal communicates with computer 1 bit at a time
• Called a serial line – bits go out in series, 1 bit at a time
• Windows uses COM1 and COM2 ports, first to serial lines
• Computer and terminal are completely independent
59
• Central buffer pool
• Dedicated buffer for each terminal
Input Software (1)
60
Input Software (2)
Characters handled specially in canonical mode
61
Output Software
The ANSI escape sequences • accepted by terminal driver on output • ESC is ASCII character (0x1B) • n,m, and s are optional numeric parameters
62
Display Hardware (1)
Memory-mapped displays
• driver writes directly into display's video RAM
Parallel port
63
Display Hardware (2)
• A video RAM image
– simple monochrome display
– character mode
• Corresponding screen
– the xs are attribute bytes
64
Input Software
• Keyboard driver delivers a number
– driver converts to characters
– uses a ASCII table
• Exceptions, adaptations needed for
other languages
– many OS provide for loadable keymaps
or code pages
65
Output Software for Windows (1)
Sample window located at (200,100) on XGA display
66
Output Software for Windows (2)
Skeleton of a Windows main program (part 1)
67
Output Software for Windows (3)
Skeleton of a Windows main program (part 2)
68
Output Software for Windows (4)
An example rectangle drawn using Rectangle
69
Output Software for Windows (5)
• Copying bitmaps using BitBlt.
– before
– after
70
Output Software for Windows (6)
Examples of character outlines at different point sizes
71
Network Terminals X Windows (1)
Clients and servers in the M.I.T. X Window System
72
X Windows (2)
Skeleton of an X Windows application program
73
The SLIM Network Terminal (1)
The architecture of the SLIM terminal system
74
The SLIM Network Terminal (2)
Messages used in the SLIM protocol from the server to the terminals
75
Power Management (1)
Power consumption of various parts of a laptop computer
76
Power management (2)
The use of zones for backlighting the display
77
Power Management (3)
• Running at full clock speed
• Cutting voltage by two
– cuts clock speed by two,
– cuts power by four
78
Power Management (4)
• Telling the programs to use less energy
– may mean poorer user experience
• Examples
– change from color output to black and white
– speech recognition reduces vocabulary
– less resolution or detail in an image