Upload
tran-van-hien
View
231
Download
0
Embed Size (px)
Citation preview
8/2/2019 09 Input Output
1/70
CH1.1
OperatingSystem
Course
Chapter 9: Input/Output
Ho Dac Phuong, Msc
Computer Networking & Telecommunication Department
College of Technology
Vietnam National University, Hanoi
http://www.coltech.vnu.edu.vn/courses/cour
se/view.php?id=69
8/2/2019 09 Input Output
2/70
CH1.2
OperatingSystem
Course Input/Output
Introduction
5.1 Principles of I/O hardware5.2 Principles of I/O software
5.3 I/O software layers
5.4 Disks
5.5 Clocks5.6 Character-oriented terminals
5.7 Graphical user interfaces
5.8 Network terminals
5.9 Power management
8/2/2019 09 Input Output
3/70
CH1.3
OperatingSystem
Course
Principles of I/O Hardware
Some typical device, network, and data base rates
8/2/2019 09 Input Output
4/70
CH1.4
OperatingSystem
Course
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
make available to main memory
8/2/2019 09 Input Output
5/70
CH1.5
OperatingSystem
Course
Memory-Mapped I/O (1)
Separate I/O and memory space Memory-mapped I/O
Hybrid
8/2/2019 09 Input Output
6/70
CH1.6
OperatingSystem
Course
Memory-Mapped I/O (2)
(a) A single-bus architecture
(b) A dual-bus memory architecture
8/2/2019 09 Input Output
7/70CH1.7
OperatingSystem
Course
Direct Memory Access (DMA)
Operation of a DMA transfer
8/2/2019 09 Input Output
8/70CH1.8
OperatingSystem
Course
Interrupts Revisited
How interrupts happens. Connections between devices and interruptcontroller actually use interrupt lines on the bus rather than dedicatedwires
8/2/2019 09 Input Output
9/70CH1.9
OperatingSystem
Course
Principles of I/O SoftwareGoals of I/O Software (1)
Device independence programs can access any I/O device
without specifying device in advance
(floppy, hard drive, or CD-ROM)
Uniform naming
name of a file or device a string or an integer
not depending on which machine
Error handling handle as close to the hardware as possible
8/2/2019 09 Input Output
10/70CH1.10
OperatingSystem
Course
Goals of I/O Software (2)
Synchronous vs. asynchronous transfers blocked transfers vs. interrupt-driven
Buffering
data coming off a device cannot be stored in
final destination Sharable vs. dedicated devices
disks are sharable
tape drives would not be
8/2/2019 09 Input Output
11/70CH1.11
OperatingSystem
Course
Programmed I/O (1)
Steps in printing a string
8/2/2019 09 Input Output
12/70CH1.12
OperatingSystem
Course
Programmed I/O (2)
Writing a string to the printer using programmed I/O
8/2/2019 09 Input Output
13/70CH1.13
OperatingSystem
Course
Interrupt-Driven I/O
Writing a string to the printer using interrupt-driven I/O
Code executed when print system call is made
Interrupt service procedure
8/2/2019 09 Input Output
14/70CH1.14
OperatingSystem
Course
I/O Using DMA
Printing a string using DMA
code executed when the print system call ismade
interrupt service procedure
8/2/2019 09 Input Output
15/70CH1.15
OperatingSystem
Course
I/O Software Layers
Layers of the I/O Software System
8/2/2019 09 Input Output
16/70CH1.16
OperatingSystem
Course
Interrupt Handlers (1)
Interrupt handlers are best hidden have driver starting an I/O operation block until
interrupt notifies of completion
Interrupt procedure does its task then unblocks driver that started it
Steps must be performed in software afterinterrupt completed
1. Save regs not already saved by interrupt hardware
2. Set up context for interrupt service procedure
8/2/2019 09 Input Output
17/70CH1.17
OperatingSystem
Course
Interrupt Handlers (2)
3. Set up stack for interrupt service procedure4. Ack interrupt controller, reenable
interrupts5. Copy registers from where saved6. Run service procedure7. Set up MMU context for process to run
next8. Load new process' registers9. Start running the new process
8/2/2019 09 Input Output
18/70CH1.18
OperatingSystem
Course
Device Drivers
Logical position of device drivers is shown here
Communications between drivers and device controllers goes over
the bus
8/2/2019 09 Input Output
19/70CH1.19
OperatingSystem
Course
Device-Independent I/O Software (1)
Functions of the device-independent I/O software
Uniform interfacing for device drivers
Buffering
Error reporting
Allocating and releasing dedicate devices
Providing a device-independent block size
8/2/2019 09 Input Output
20/70CH1.20
OperatingSystem
Course
Device-Independent I/O Software (2)
(a) Without a standard driver interface
(b) With a standard driver interface
8/2/2019 09 Input Output
21/70CH1.21
OperatingSystem
Course
Device-Independent I/O Software (3)s
(a) Unbuffered input(b) Buffering in user space(c) Buffering in the kernel followed by copying to user
space(d) Double buffering in the kernel
8/2/2019 09 Input Output
22/70CH1.22
OperatingSystem
Course
Device-Independent I/O Software (4)
Networking may involve many copies
8/2/2019 09 Input Output
23/70CH1.23
OperatingSystem
Course
User-Space I/O Software
Layers of the I/O system and the mainfunctions of each layer
8/2/2019 09 Input Output
24/70
CH1.24
OperatingSystem
Course
DisksDisk Hardware (1)
Disk parameters for the original IBM PC floppy disk and aWestern Digital WD 18300 hard disk
8/2/2019 09 Input Output
25/70
CH1.25
OperatingSystem
Course
Disk Hardware (2)
Physical geometry of a disk with two zones
A possible virtual geometry for this disk
8/2/2019 09 Input Output
26/70
CH1.26
OperatingSystem
Course
Disk Hardware (3)
Raid levels 0 through 2
Backup and parity drives are shaded
8/2/2019 09 Input Output
27/70
CH1.27
OperatingSystem
Course
Hamming code
Consider a Hamming code to detect and correct
for single-bit errors assuming each codewordcontains a seven-bit data field, e.g. an ASCIIcharacter. for example. Such a coding schemerequires four check bits since, with this scheme,
the check bits occupy all bit positions that arepowers of 2. Such a code is thus known as an (11,7) block code with a rate of 7/11 and aredundancy of . For example, the bit positions of
the value 1001101 are: Bit Position 11 10 9 8 7 6 5 4 3 2 1
Bit value 1 0 0 x 1 1 0 x 1 x x
8/2/2019 09 Input Output
28/70
CH1.28
OperatingSystem
Course
Hamming distance
Let x and y be two binary sequences of the same length.
The Hamming distance between these two codes is thenumber of symbols that disagree. Suppose the code x istransmitted over the channel. Due to errors, y is received.The decoder will assign to y the code x that minimises theHamming distance between x and y. For example, consider
the codewords: a = 10000
b = 01100
c = 10011
If the transmitter sends 10000 but there is a single bit errorand the receiver gets 10001, it can be seen that the "nearest"codeword is in fact 10000 and so the correct codeword isfound.
8/2/2019 09 Input Output
29/70
CH1.29
OperatingSystem
Course
Hamming distance
It can be shown that to detect n bit errors, a
coding scheme requires the use of codewordswith a Hamming distance of at least n + 1. It canalso be shown that to correct n bit errors requiresa coding scheme with at least a Hamming
distnace of2n + 1 between the codewords. By designing a good code, we try to ensure that
the Hamming distance between possiblecodewords x is larger than the Hamming distance
arising from errors
8/2/2019 09 Input Output
30/70
CH1.30
OperatingSystem
Course
Hamming distance
11 = 1011
7 = 0111
6 = 0110
3 = 0011
1001
The transmitted codeword is thus:
Bit Position 11 10 9 8 7 6 5 4 3 2 1
Bit value 1 0 0 1 1 1 0 0 1 0 1
8/2/2019 09 Input Output
31/70
CH1.31
OperatingSystem
Course
Hamming distance
Similarly, at the receiver, the four-bit binary
numbers corresponding to those bit positionshaving a binary 1, including the check bits, areagain added together and, if no errors haveoccurred, the modulo 2 sum should be zero:
11= 1101 8 = 1100
7 = 0111
6 = 0110
3 = 0011
1 = 0001
0000
8/2/2019 09 Input Output
32/70
CH1.32
OperatingSystem
Course
Hamming distance
Now consider a single-bit error; say bit 11 is corrupted
from 1 to 0. The new modulo 2 sum would now be: 8 = 1100
7 = 0111
6 = 0110
3 = 0011 1 = 0001
1011
Firstly, the sum is non-zero, which indicates an error, andsecondly the modulo 2 sum, equivalent to decimal 11,
indicates that bit 11 is the erroneous bit. The latter wouldtherefore be inverted to obtain the corrected codeword andhence data bits.
8/2/2019 09 Input Output
33/70
CH1.33
OperatingSystem
Course
Disk Hardware (4)
Raid levels 3 through 5
Backup and parity drives are shaded
8/2/2019 09 Input Output
34/70
CH1.34
OperatingSystem
Course
Disk Hardware (5)
Recording structure of a CD or CD-ROM
8/2/2019 09 Input Output
35/70
CH1.35
OperatingSystem
Course
Disk Hardware (6)
Logical data layout on a CD-ROM
8/2/2019 09 Input Output
36/70
CH1.36
OperatingSystem
Course
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
8/2/2019 09 Input Output
37/70
CH1.37
OperatingSystem
Course
Disk Hardware (8)
A double sided, dual layer DVD disk
8/2/2019 09 Input Output
38/70
CH1.38
OperatingSystem
Course
Disk Formatting (1)
A disk sector
8/2/2019 09 Input Output
39/70
CH1.39
OperatingSystem
Course
Disk Formatting (2)
An illustration of cylinder skew
8/2/2019 09 Input Output
40/70
CH1.40
OperatingSystem
Course
Disk Formatting (3)
No interleaving
Single interleaving
Double interleaving
8/2/2019 09 Input Output
41/70
CH1.41
OperatingSystem
Course
Disk Arm Scheduling Algorithms (1)
Time required to read or write a diskblock determined by 3 factors
1. Seek time
2. Rotational delay
3. Actual transfer time
Seek time dominates
Error checking is done by controllers
8/2/2019 09 Input Output
42/70
CH1.42
OperatingSystem
Course
Disk Arm Scheduling Algorithms (2)
Shortest Seek First (SSF) disk scheduling algorithm
Initialposition
Pendingrequests
8/2/2019 09 Input Output
43/70
CH1.43
OperatingSystem
Course
Disk Arm Scheduling Algorithms (3)
The elevator algorithm for scheduling disk requests
dli
8/2/2019 09 Input Output
44/70
CH1.44
OperatingSystem
Course
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
S bl S
8/2/2019 09 Input Output
45/70
CH1.45
OperatingSystem
Course
Stable Storage
Analysis of the influence of crashes on stable writes
Clocks
8/2/2019 09 Input Output
46/70
CH1.46
OperatingSystem
Course
ClocksClock Hardware
A programmable clock
Cl k S f (1)
8/2/2019 09 Input Output
47/70
CH1.47
OperatingSystem
Course
Clock Software (1)
Three ways to maintain the time of day
Cl k S f (2)
8/2/2019 09 Input Output
48/70
CH1.48
OperatingSystem
Course
Clock Software (2)
Simulating multiple timers with a single clock
S f Ti
8/2/2019 09 Input Output
49/70
CH1.49
OperatingSystem
Course
Soft Timers
A second clock available for timer interrupts specified by applications
no problems if interrupt frequency is low
Soft timers avoid interrupts
kernel checks for soft timer expirationbefore it exits to user mode
how well this works depends on rate ofkernel entries
Character Oriented Terminals
8/2/2019 09 Input Output
50/70
CH1.50
OperatingSystem
Course
Character Oriented TerminalsRS-232 Terminal Hardware
An RS-232 terminal communicates with computer 1 bit at a time Called a serial linebits 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
I t S ft (1)
8/2/2019 09 Input Output
51/70
CH1.51
OperatingSystem
Course
Central buffer pool
Dedicated buffer for each terminal
Input Software (1)
I t S ft (2)
8/2/2019 09 Input Output
52/70
CH1.52
OperatingSystem
Course
Input Software (2)
Characters handled specially in canonical mode
O t t S ft
8/2/2019 09 Input Output
53/70
CH1.53
OperatingSystem
Course
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
Di l H d (1)
8/2/2019 09 Input Output
54/70
CH1.54
OperatingSystem
Course
Display Hardware (1)
Memory-mapped displays
driver writes directly into display's video RAM
Parallel port
Di l H d (2)
8/2/2019 09 Input Output
55/70
CH1.55
OperatingSystem
Course
Display Hardware (2)
A video RAM image
simple monochrome display
character mode
Corresponding screen
the xs are attribute bytes
Inp t Soft are
8/2/2019 09 Input Output
56/70
CH1.56
OperatingSystem
Course
Input Software
Keyboard driver delivers a number driver converts to characters
uses a ASCII table
Exceptions, adaptations needed for otherlanguages
many OS provide for loadable keymaps
or code pages
O t t S ft f Wi d (1)
8/2/2019 09 Input Output
57/70
CH1.57
OperatingSystem
Course
Output Software for Windows (1)
Sample window located at (200,100) on XGA display
O t t S ft f Wi d (2)
8/2/2019 09 Input Output
58/70
CH1.58
OperatingSystem
Course
Output Software for Windows (2)
Skeleton of a Windows main program (part 1)
Output Software for Windows (3)
8/2/2019 09 Input Output
59/70
CH1.59
OperatingSystem
Course
Output Software for Windows (3)
Skeleton of a Windows main program (part 2)
Output Software for Windows (4)
8/2/2019 09 Input Output
60/70
CH1.60
OperatingSystem
Course
Output Software for Windows (4)
An example rectangle drawn usingRectangle
Output Software for Windows (5)
8/2/2019 09 Input Output
61/70
CH1.61
OperatingSystem
Course
Output Software for Windows (5)
Copying bitmaps usingBitBlt.
before
after
Output Software for Windows (6)
8/2/2019 09 Input Output
62/70
CH1.62
OperatingSystem
Course
Output Software for Windows (6)
Examples of character outlines at different point sizes
Network Terminals
8/2/2019 09 Input Output
63/70
CH1.63
OperatingSystem
Course
Network TerminalsX Windows (1)
Clients and servers in the M.I.T. X Window System
X Windows (2)
8/2/2019 09 Input Output
64/70
CH1.64
OperatingSystem
Course
X Windows (2)
Skeleton of an X Windows application program
The SLIM Network Terminal (1)
8/2/2019 09 Input Output
65/70
CH1.65
Operating
System
Course
The SLIM Network Terminal (1)
The architecture of the SLIM terminal system
The SLIM Network Terminal (2)
8/2/2019 09 Input Output
66/70
CH1.66
Operating
System
Course
The SLIM Network Terminal (2)
Messages used in the SLIM protocol from the server to the terminals
Power Management (1)
8/2/2019 09 Input Output
67/70
CH1.67
Operating
System
Course
Power Management (1)
Power consumption of various parts of a laptop computer
Power management (2)
8/2/2019 09 Input Output
68/70
CH1.68
Operating
System
Course
Power management (2)
The use of zones for backlighting the display
Power Management (3)
8/2/2019 09 Input Output
69/70
CH1.69
Operating
System
Course
Power Management (3)
Running at full clock speed
Cutting voltage by two cuts clock speed by two,
cuts power by four
Power Management (4)
8/2/2019 09 Input Output
70/70
Operating
System
Course
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