INPUT/OUTPUT - vidyakodgirwar.files.wordpress.com€¦ · input/output 5.1 principles of i/o...
Transcript of INPUT/OUTPUT - vidyakodgirwar.files.wordpress.com€¦ · input/output 5.1 principles of i/o...
5INPUT/OUTPUT
5.1 PRINCIPLES OF I/O HARDWARE
5.2 PRINCIPLES OF I/O SOFTWARE
5.3 I/O SOFTWARE LAYERS
5.4 DISKS
5.5 CLOCKS
5.6 CHARACTER-ORIENTED TERMINALS
5.7 GRAPHICAL USER INTERFACES
5.8 NETWORK TERMINALS
5.9 POWER MANAGEMENT
5.10 RESEARCH ON INPUT/OUTPUT
5.11 SUMMARY
2222222222222222222222222222222222222222222222Device Data rate2222222222222222222222222222222222222222222222
Keyboard 10 bytes/sec2222222222222222222222222222222222222222222222Mouse 100 bytes/sec222222222222222222222222222222222222222222222256K modem 7 KB/sec2222222222222222222222222222222222222222222222Telephone channel 8 KB/sec2222222222222222222222222222222222222222222222Dual ISDN lines 16 KB/sec2222222222222222222222222222222222222222222222Laser printer 100 KB/sec2222222222222222222222222222222222222222222222Scanner 400 KB/sec2222222222222222222222222222222222222222222222Classic Ethernet 1.25 MB/sec2222222222222222222222222222222222222222222222USB (Universal Serial Bus) 1.5 MB/sec2222222222222222222222222222222222222222222222Digital camcorder 4 MB/sec2222222222222222222222222222222222222222222222IDE disk 5 MB/sec222222222222222222222222222222222222222222222240x CD-ROM 6 MB/sec2222222222222222222222222222222222222222222222Fast Ethernet 12.5 MB/sec2222222222222222222222222222222222222222222222ISA bus 16.7 MB/sec2222222222222222222222222222222222222222222222EIDE (ATA-2) disk 16.7 MB/sec2222222222222222222222222222222222222222222222FireWire (IEEE 1394) 50 MB/sec2222222222222222222222222222222222222222222222XGA Monitor 60 MB/sec2222222222222222222222222222222222222222222222SONET OC-12 network 78 MB/sec2222222222222222222222222222222222222222222222SCSI Ultra 2 disk 80 MB/sec2222222222222222222222222222222222222222222222Gigabit Ethernet 125 MB/sec2222222222222222222222222222222222222222222222Ultrium tape 320 MB/sec2222222222222222222222222222222222222222222222PCI bus 528 MB/sec2222222222222222222222222222222222222222222222Sun Gigaplane XB backplane 20 GB/sec222222222222222222222222222222222222222222222211
1111111111111111111111111111111
111111111111111111111111111111111
111111111111111111111111111111111
Fig. 5-1. Some typical device, network, and bus data rates.
Two address One address space Two address spaces
Memory
I/O ports
0xFFFF…
0
(a) (b) (c)
Fig. 5-2. (a) Separate I/O and memory space. (b) Memory-mappedI/O. (c) Hybrid.
CPU Memory I/O
BusAll addresses (memory
and I/O) go here
CPU Memory I/O
CPU reads and writes of memorygo over this high-bandwidth bus
This memory port isto allow I/O devicesaccess to memory
(a) (b)
Fig. 5-3. (a) A single-bus architecture. (b) A dual-bus memoryarchitecture.
CPUDMA
controllerDisk
controllerMain
memoryBuffer
1. CPUprogramsthe DMAcontroller
Interrupt whendone
2. DMA requeststransfer to memory 3. Data transferred
Bus
4. Ack
Address
Count
Control
Drive
Fig. 5-4. Operation of a DMA transfer.
CPUInterruptcontroller3. CPU acks
interrupt
2. Controller issues interrupt
1. Device is finished
Disk
Keyboard
Printer
Clock
Bus
12
6
9 348
57
111210
Fig. 5-5. How an interrupt happens. The connections between thedevices and the interrupt controller actually use interrupt lines onthe bus rather than dedicated wires.
String tobe printedUser
space
Kernelspace
ABCDEFGH
Printedpage
(a)
ABCDEFGH
ABCDEFGH
Printedpage
(b)
ANext
(c)
ABNext
Fig. 5-6. Steps in printing a string.
copy3from3user(buffer, p, count); /* p is the kernel bufer */for (i = 0; i < count; i++) { /* loop on every character */
while (*printer3status3reg != READY) ;/* loop until ready */
*printer3data3register = p[i]; /* output one character */}return3to3user( );
Fig. 5-7. Writing a string to the printer using programmed I/O.
copy3from3user(buffer, p, count); if (count == 0) {enable3 interrupts( ); unblock3user( );while (*printer3status3reg != READY) ; } else {
*printer3data3register = p[0]; *printer3data3register = p[i];scheduler( ); count = count − 1;
i = i + 1;}acknowledge3 interrupt( );return3from3 interrupt( );
(a) (b)
Fig. 5-8. Writing a string to the printer using interrupt-driven I/O.(a) Code executed when the print system call is made. (b) Inter-rupt service procedure.
copy3from3user(buffer, p, count); acknowledge3 interrupt( );set3up3DMA3controller( ); unblock3user( );scheduler( ); return3from3 interrupt( );
(a) (b)
Fig. 5-9. Printing a string using DMA. (a) Code executed whenthe print system call is made. (b) Interrupt service procedure.
User-level I/O software
Device-independent operating system software
Device drivers
Interrupt handlers
Hardware
Fig. 5-10. Layers of the I/O software system.
Userspace
Kernelspace
User process
Userprogram
Rest of the operating system
Printerdriver
Camcorderdriver
CD-ROMdriver
Printer controllerHardware
Devices
Camcorder controller CD-ROM controller
Fig. 5-11. Logical positioning of device drivers. In reality allcommunication between drivers and device controllers goes overthe bus.
222222222222222222222222222222222222222222Uniform interfacing for device drivers222222222222222222222222222222222222222222Buffering222222222222222222222222222222222222222222Error reporting222222222222222222222222222222222222222222Allocating and releasing dedicated devices222222222222222222222222222222222222222222Providing a device-independent block size2222222222222222222222222222222222222222221111111
1111111
Fig. 5-12. Functions of the device-independent I/O software.
Operating system Operating system
Disk driver Printer driver Keyboard driver Disk driver Printer driver Keyboard driver
(a) (b)
Fig. 5-13. (a) Without a standard driver interface. (b) With a stan-dard driver interface.
User process
Userspace
Kernelspace
2 2
1 1 3
Modem Modem Modem Modem
(a) (b) (c) (d)
Fig. 5-14. (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.
2
1 5
4
3
User process
Network
Networkcontroller
Userspace
Kernelspace
Fig. 5-15. Networking may involve many copies of a packet.
I/Orequest
LayerI/Oreply I/O functions
Make I/O call; format I/O; spooling
Naming, protection, blocking, buffering, allocation
Set up device registers; check status
Wake up driver when I/O completed
Perform I/O operation
User processes
Device-independentsoftware
Device drivers
Interrupt handlers
Hardware
Fig. 5-16. Layers of the I/O system and the main functions of eachlayer.
2222222222222222222222222222222222222222222222222222222222222222222222222222222Parameter IBM 360-KB floppy disk WD 18300 hard disk2222222222222222222222222222222222222222222222222222222222222222222222222222222
Number of cylinders 40 106012222222222222222222222222222222222222222222222222222222222222222222222222222222Tracks per cylinder 2 122222222222222222222222222222222222222222222222222222222222222222222222222222222Sectors per track 9 281 (avg)2222222222222222222222222222222222222222222222222222222222222222222222222222222Sectors per disk 720 357420002222222222222222222222222222222222222222222222222222222222222222222222222222222Bytes per sector 512 5122222222222222222222222222222222222222222222222222222222222222222222222222222222Disk capacity 360 KB 18.3 GB2222222222222222222222222222222222222222222222222222222222222222222222222222222Seek time (adjacent cylinders) 6 msec 0.8 msec2222222222222222222222222222222222222222222222222222222222222222222222222222222Seek time (average case) 77 msec 6.9 msec2222222222222222222222222222222222222222222222222222222222222222222222222222222Rotation time 200 msec 8.33 msec2222222222222222222222222222222222222222222222222222222222222222222222222222222Motor stop/start time 250 msec 20 sec2222222222222222222222222222222222222222222222222222222222222222222222222222222Time to transfer 1 sector 22 msec 17 µsec222222222222222222222222222222222222222222222222222222222222222222222222222222211111111111111111
11111111111111111
11111111111111111
11111111111111111
Fig. 5-17. Disk parameters for the original IBM PC 360-KBfloppy disk and a Western Digital WD 18300 hard disk.
0 1
23
45
67891011
1213
1415
0 12
3
45
67
89
1011
1213
1415161718
19
2021
2223
2425
2627
2829
30 31 01
23
45
67
89
1011
121314
15
1617
1819
2021
2223
24
Fig. 5-18. (a) Physical geometry of a disk with two zones.(b) A possible virtual geometry for this disk.
P16-19 Strip 16 Strip 17 Strip 18
Strip 12 P12-15 Strip 13 Strip 14
(a)
(b)
(c)
(d)
(e)
(f)
RAID level 0
Strip 8
Strip 4
Strip 0
Strip 9
Strip 5
Strip 1
Strip 10
Strip 6
Strip 2
RAID level 2
Strip 11
Strip 7
Strip 3
Strip 8
Strip 4
Strip 0
Strip 9
Strip 5
Strip 1
Strip 10
Strip 6
Strip 2
Strip 11
Strip 7
Strip 3
Strip 8
Strip 4
Strip 0
Strip 9
Strip 5
Strip 1
Strip 10
Strip 6
Strip 2
Strip 11
Strip 7
Strip 3
Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6
RAIDlevel 1
Bit 7
Bit 1 Bit 2 Bit 3 Bit 4
Strip 8
Strip 4
Strip 0
Strip 9
Strip 5
Strip 1
Strip 10
Strip 6
Strip 2
Strip 11
Strip 7
Strip 3
Strip 8
Strip 4
Strip 0
Strip 9
Strip 5
Strip 1
P8-11
Strip 6
Strip 2
Strip 10
P4-7
Strip 3
Strip 19
Strip 15
RAID level 3
RAID level 4
RAID level 5
Parity
P8-11
P4-7
P0-3
Strip 11
Strip 7
P0-3
Fig. 5-19. RAID levels 0 through 5. Backup and parity drives areshown shaded.
Spiral groove
Pit
Land
2K block ofuser data
Fig. 5-20. Recording structure of a compact disc or CD-ROM.
Preamble
Bytes 16
Data
2048 288
ECCMode 1sector
(2352 bytes)
Frames of 588 bits,each containing24 data bytes
Symbols of14 bits each
42 Symbols make 1 frame
98 Frames make 1 sector
…
…
Fig. 5-21. Logical data layout on a CD-ROM.
Printed label
Protective lacquerReflective gold layer
layer
Substrate
Directionof motion Lens
Photodetector Prism
Infraredlaserdiode
Dark spot in thedye layer burnedby laser whenwriting1.2 mm
Dye
Polycarbonate
Fig. 5-22. Cross section of a CD-R disk and laser (not to scale).A silver CD-ROM has a similar structure, except without the dyelayer and with a pitted aluminum layer instead of a gold layer.
Polycarbonate substrate 1
Polycarbonate substrate 2
Semireflectivelayer
Semireflectivelayer
Aluminumreflector
Aluminumreflector
0.6 mmSingle-sided
disk
0.6 mmSingle-sided
disk
�������
Adhesive layer
Fig. 5-23. A double-sided, dual layer DVD disk.
Preamble Data ECC
Fig. 5-24. A disk sector.
0 1 23
45
67
89
10111213141516171819
2021
2223
2425
2627
2829 30 31
29 30 310
12
34
56
78
91011121314151617
1819
2021
2223
24
2526 27 28
26 27 28 29
3031
01
23
45
678910111213
1415
1617
1819
2021
2223 24 25
23 24 2526
2728
2930
310
12
34
56789
10
1112
1314
1516
1718
1920
21 22
20 2122
23
2425
2627
2829
3031
01
23456
7
89
1011
1213
1415
1617
18 19
17 1819
20
2122
2324
2526
2728
2930
310123
4
5
67
89
1011
1213
1415 16 Direction of disk
rotation
Fig. 5-25. An illustration of cylinder skew.
(a)
07
34
1
2
6
5
(b)
07
52
4
1
3
6
(c)
05
14
3
6
2
7
Fig. 5-26. (a) No interleaving. (b) Single interleaving. (c) Doubleinterleaving.
Initialposition
Pendingrequests
Sequence of seeks
Cylinder
X X X X X X X
0 5 10 15 20 25 30 35
Tim
e
Fig. 5-27. Shortest Seek First (SSF) disk scheduling algorithm.
Initialposition
Cylinder
X X X X X X X
0 5 10 15 20 25 30 35
Tim
e Sequence of seeks
Fig. 5-28. The elevator algorithm for scheduling disk requests.
Sparesectors Bad
sector
0 1 23
456
89
1011
1213
141516171819
2021
2223242526
2728
29
(a)
Replacementsector
0 1 23
456
89
1011
1213
141516171819
2021
2223242526
2728
29 7
(b)
0 1 23
456
78
910
1112
131415161718
1920
21222324
2526
272829
(c)
Fig. 5-29. (a) A disk track with a bad sector. (b) Substituting aspare for the bad sector. (c) Shifting all the sectors to bypass thebad one.
Old
1
Old
2Disk
1
Old
2Disk
New
1
Old
2Disk
New
1 2Disk
New
1
New
2Disk
Crash Crash Crash Crash Crash(a) (b) (c) (d) (e)
ECCerror
Fig. 5-30. Analysis of the influence of crashes on stable writes.
Crystal oscillator
Counter is decremented at each pulse
Holding register is used to load the counter
Fig. 5-31. A programmable clock.
(a) (b) (c)
Time of day in ticks
Time of dayin seconds
Counter in ticks
System boot timein seconds
Number of ticksin current second
64 bits 32 bits 32 bits
Fig. 5-32. Three ways to maintain the time of day.
Current time Next signal
Clockheader
3 4 6 2 1 X
4200 3
Fig. 5-33. Simulating multiple timers with a single clock.
CPU MemoryRS-232interface
UART
Computer
Transmit
Recieve
Bus
Fig. 5-34. An RS-232 terminal communicates with a computerover a communication line, one bit at a time.
(a) (b)
Terminaldata structure
Terminaldata structure
TerminalTerminalCentral
buffer pool
0 Bufferarea for
terminal 0
1 Bufferarea for
terminal 1
0
1
2
3
Fig. 5-35. (a) Central buffer pool. (b) Dedicated buffer for eachterminal.
2222222222222222222222222222222222222222222222222222222222Character POSIX name Comment2222222222222222222222222222222222222222222222222222222222CTRL-H ERASE Backspace one character2222222222222222222222222222222222222222222222222222222222CTRL-U KILL Erase entire line being typed2222222222222222222222222222222222222222222222222222222222CTRL-V LNEXT Interpret next character literally2222222222222222222222222222222222222222222222222222222222CTRL-S STOP Stop output2222222222222222222222222222222222222222222222222222222222CTRL-Q START Start output2222222222222222222222222222222222222222222222222222222222DEL INTR Interrupt process (SIGINT)2222222222222222222222222222222222222222222222222222222222CTRL-\ QUIT Force core dump (SIGQUIT)2222222222222222222222222222222222222222222222222222222222CTRL-D EOF End of file2222222222222222222222222222222222222222222222222222222222CTRL-M CR Carriage return (unchangeable)2222222222222222222222222222222222222222222222222222222222CTRL-J NL Linefeed (unchangeable)22222222222222222222222222222222222222222222222222222222221
11111111111111
111111111111111
111111111111111
111111111111111
Fig. 5-36. Characters that are handled specially in canonical mode.
22222222222222222222222222222222222222222222222222222222222222222222222222222Escape sequence Meaning22222222222222222222222222222222222222222222222222222222222222222222222222222ESC [ n A Move up n lines22222222222222222222222222222222222222222222222222222222222222222222222222222ESC [ n B Move down n lines22222222222222222222222222222222222222222222222222222222222222222222222222222ESC [ n C Move right n spaces22222222222222222222222222222222222222222222222222222222222222222222222222222ESC [ n D Move left n spaces22222222222222222222222222222222222222222222222222222222222222222222222222222ESC [ m ; n H Move cursor to (m,n)22222222222222222222222222222222222222222222222222222222222222222222222222222ESC [ s J Clear screen from cursor (0 to end, 1 from start, 2 all)22222222222222222222222222222222222222222222222222222222222222222222222222222ESC [ s K Clear line from cursor (0 to end, 1 from start, 2 all)22222222222222222222222222222222222222222222222222222222222222222222222222222ESC [ n L Insert n lines at cursor22222222222222222222222222222222222222222222222222222222222222222222222222222ESC [ n M Delete n lines at cursor22222222222222222222222222222222222222222222222222222222222222222222222222222ESC [ n P Delete n chars at cursor22222222222222222222222222222222222222222222222222222222222222222222222222222ESC [ n @ Insert n chars at cursor22222222222222222222222222222222222222222222222222222222222222222222222222222ESC [ n m Enable rendition n (0=normal, 4=bold, 5=blinking, 7=reverse)22222222222222222222222222222222222222222222222222222222222222222222222222222ESC M Scroll the screen backward if the cursor is on the top line2222222222222222222222222222222222222222222222222222222222222222222222222222211
111111111111111111
11111111111111111111
11111111111111111111
Fig. 5-37. The ANSI escape sequences accepted by the terminaldriver on output. ESC denotes the ASCII escape character (0x1B),and n, m, and s are optional numeric parameters.
CPU MemoryGraphicsadapter Video
controllerVideoRAM
Analogvideo signal
Parallel port
Bus
Fig. 5-38. With memory-mapped displays, the driver writesdirectly into the display’s video RAM.
… × 3 × 2 × 1 × 0
160 characters
(a)
Video RAM
0×B00A0
RAM address
0×B0000
80 characters
(a)
Screen
A B C D0 1 2 3
25 lines
… × D × C × B × A
Fig. 5-39. (a) A video RAM image for a simple monochromedisplay in character mode. (b) The corresponding screen. The ×sare attribute bytes.
Thumb
Title bar
File Edit View Tools Options Help
Client area
(200, 100)
(0, 0)
(0, 767)
Menu bar
Tool bar
Window
Scroll bar
(1023, 767)
(1023, 0)
12
6
9 348
57
111210
Fig. 5-40. A sample window located at (200, 100) on an XGAdisplay.
#include <windows.h>
int WINAPI WinMain(HINSTANCE h, HINSTANCE, hprev, char *szCmd, int iCmdShow){
WNDCLASS wndclass; /* class object for this window */MSG msg; /* incoming messages are stored here */HWND hwnd; /* handle (pointer) to the window object */
/* Initialize wndclass */wndclass.lpfnWndProc = WndProc; /* tells which procedure to call */wndclass.lpszClassName = "Program name"; /* Text for title bar */wndclass.hIcon = LoadIcon(NULL, IDI3APPLICATION);/* load program icon */wndclass.hCursor = LoadCursor(NULL, IDC3ARROW); /* load mouse cursor */
RegisterClass(&wndclass); /* tell Windows about wndclass */hwnd = CreateWindow ( ... ) /* allocate storage for the window */ShowWindow(hwnd, iCmdShow); /* display the window on the screen */UpdateWindow(hwnd); /* tell the window to paint itself */
while (GetMessage(&msg, NULL, 0, 0)) { /* get message from queue */TranslateMessage(&msg); /* translate the message */DispatchMessage(&msg); /* send msg to the appropriate procedure */
}return(msg.wParam);
}
long CALLBACK WndProc(HWND hwnd, UINT message, UINT wParam, long lParam){
/* Declarations go here. */
switch (message) {case WM3CREATE: ... ; return ... ; /* create window */case WM3PAINT: ... ; return ... ; /* repaint contents of window */case WM3DESTROY: ... ; return ... ; /* destroy window */
}return(DefWindowProc(hwnd, message, wParam, lParam));/* default */
}
Fig. 5-41. A skeleton of a Windows main program.
0
0
1
2
3
4
5
6
7
1 2 3 4 5 6 7 8
Fig. 5-42. An example rectangle drawn using Rectangle. Each boxrepresents one pixel.
0 2 4 6 802468
0 2 4 6 802468
Window 1
Window 2
0 2 4 6 802468
0 2 4 6 802468
Window 1
Window 2
(a) (b)
Fig. 5-43. Copying bitmaps using BitBlt. (a) Before. (b) After.
20 pt:
53 pt:
81 pt:
Fig. 5-44. Some examples of character outlines at different pointsizes.
Remote host
Windowmanager
Applicationprogram
Motif
Intrinsics
Xlib
X client
UNIX
Hardware
X server
UNIX
Hardware
X terminal
Window
Userspace
Kernelspace
X protocol
Network
Fig. 5-45. Clients and servers in the M.I.T. X Window System.
#include <X11/Xlib.h>#include <X11/Xutil.h>
main(int argc, char *argv[]){
Display disp; /* server identifier */Window win; /* window identifier */GC gc; /* graphic context identifier */XEvent event; /* storage for one event */int running = 1;
disp = XOpenDisplay("display3name"); /* connect to the X server */win = XCreateSimpleWindow(disp, ... ); /* allocate memory for new window */XSetStandardProperties(disp, ...); /* announces window to window mgr */gc = XCreateGC(disp, win, 0, 0); /* create graphic context */XSelectInput(disp, win, ButtonPressMask | KeyPressMask | ExposureMask);XMapRaised(disp, win); /* display window; send Expose event */
while (running) {XNextEvent(disp, &event); /* get next event */switch (event.type) {
case Expose: ...; break; /* repaint window */case ButtonPress: ...; break; /* process mouse click */case Keypress: ...; break; /* process keyboard input */
}}
XFreeGC(disp, gc); /* release graphic context */XDestroyWindow(disp, win); /* deallocate window’s memory space */XCloseDisplay(disp); /* tear down network connection */
}
Fig. 5-46. A skeleton of an X Window application program.
Computer center
Dedicatednetwork
connection
Switch
Disks
Thin clientServer(s)
Fig. 5-47. The architecture of the SLIM terminal system.
222222222222222222222222222222222222222222222222222222222222222222222Message Meaning222222222222222222222222222222222222222222222222222222222222222222222SET Update a rectangle with new pixels222222222222222222222222222222222222222222222222222222222222222222222FILL Fill a rectangle with one pixel value222222222222222222222222222222222222222222222222222222222222222222222BITMAP Expand a bitmap to fill a rectangle222222222222222222222222222222222222222222222222222222222222222222222COPY Copy a rectangle from one part of the frame buffer to another222222222222222222222222222222222222222222222222222222222222222222222CSCS Convert a rectangle from television color (YUV) to RGB2222222222222222222222222222222222222222222222222222222222222222222221
1111111
11111111
11111111
Fig. 5-48. Messages used in the SLIM protocol from the server tothe terminals.
2222222222222222222222222222222222222222222222222222Device Li et al. (1994) Lorch and Smith (1998)2222222222222222222222222222222222222222222222222222
Display 68% 39%2222222222222222222222222222222222222222222222222222CPU 12% 18%2222222222222222222222222222222222222222222222222222Hard disk 20% 12%2222222222222222222222222222222222222222222222222222Modem 6%2222222222222222222222222222222222222222222222222222Sound 2%2222222222222222222222222222222222222222222222222222Memory 0.5% 1%2222222222222222222222222222222222222222222222222222Other 22%22222222222222222222222222222222222222222222222222221
1111111111
11111111111
11111111111
11111111111
Fig. 5-49. Power consumption of various parts of a laptop com-puter.
Window 1
Window 2
Window 1
Window 2
Zone
(a) (b)
Fig. 5-50. The use of zones for backlighting the display. (a) Whenwindow 2 is selected it is not moved. (b) When window 1 isselected, it moves to reduce the number of zones illuminated.
1.00
0.75
0.50
0.25
00 T/2 T
Time
Pow
er
(a)
1.00
0.75
0.50
0.25
00 T/2 T
Time
Pow
er
(b)
Fig. 5-51. (a) Running at full clock speed. (b) Cutting voltage bytwo cuts clock speed by two and power consumption by four.