Lecture 7b I/O
I/O devices Device (mechanical hardware) Device controller (electrical hardware) Device driver (software)
Devices and their controllers Components of a simple personal computer Monitor Bus
How to communicate with a device? Hardware supports I/O ports or memory mapped I/O for accessing device controller registers and buffers
Wide performance range for I/O
Performance challenges: I/O hardware How to prevent slow devices from slowing down memory How to identify I/O addresses without interfering with memory performance
Hardware view of Pentium Structure of a large Pentium system
Performance challenges: I/O software How to prevent CPU throughput from being limited by I/O device speed How to prevent I/O throughput from being limited by CPU speed How to achieve good utilization of CPU and I/O devices How to meet the real-time requirements of devices
Programmed I/O Polling/busy-waiting approach copy_from_user(buffer,p,count); for(i=0;i<count;i++){ while (*p_stat_reg != READY); *p_data_reg = p[i]; } return();
Interrupt driven I/O (b)
Interrupt-driven I/O Asynchronous approach give device data, do something else! resume when device interrupts copy_from_user(buffer,p,count); enable_interrupts(); while (*p_stat_reg != READY); *p_data_reg=p[0]; scheduler(); if (count==0){ unblock_user(); } else { *p_data_reg = p[i]; count--; i++; } ack_interrupt(); return_from_interrupt();
DMA Offload all work to a DMA controller avoids using the CPU to do the transfer reduces number of interrupts DMA controller is like a co-processor doing programmed I/O copy_from_user(buffer,p,count); set_up_DMA_controller(); scheduler(); ack_interrupt(); unblock_user(); return_from_interrupt();
DMA
Software engineering-related challenges How to remove the complexities of I/O handling from application programs standard I/O APIs (libraries and system calls) generic across different device types How to support a wide range of device types on a wide range of operating systems standard interfaces for device drivers standard/published interfaces for access to kernel facilities
I/O Software: Device Drivers Device drivers “connect” devices with the operating system Typically a nasty assembly-level job Must deal with hardware changes Must deal with O.S. changes Device drivers are typically given kernel privileges Can bring down O.S.!
I/O Software design issues 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
I/O software design issues 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 Shouldn’t depend upon the device Error handling Handle as close to the hardware as possible
Devices as files Before mounting, files on floppy are inaccessible After mounting floppy on b, files on floppy are part of file hierarchy
Spare Slides
Disks
Disk geometry Disk head, platters, surfaces
Disk geometry CAV & CLV
RAID
CD-ROMs
Plastic technology CDs Approximately 650 Mbytes of data Approximately 74 minutes of audio DVDs Many types of formats DVD-R, DVD-ROM, DVD-Video Single layer vs. multi-layer Single sided vs. double sided Authoring vs. non-authoring
Disk 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 Error checking is done by controllers
Disk scheduling algorithms First-come first serve Shortest seek time first Scan back and forth to ends of disk C-Scan only one direction Look back and forth to last request C-Look only one direction
Disk scheduling algorithms
Display hardware PCI graphics card (traditional) Map frame buffer into memory
Display hardware Intel-based systems
Display hardware Resolution Determines the amount of pixels displayable and the # of colors that can be used 1024*768*24-bit color ~2 MBytes 1600*1200*24-bit color ~6 Mbytes 1600*1200*(16 colors) ~1 Mbytes Usually double-buffered Data rate Determines refresh rate Monitor must be greater than what the video card is trying to display
X-terminals
Long past X-terminals were great because of limited pixel depth Good way to share expensive resources Future Great way to limit maintenance costs Great for basic applications X-terminals are getting killed by multimedia applications DVD 740*480*24-bit color 255 Mbps!!
Summary Mismash of I/O topics Readings: 5.1 – 5.1.4, 5.2, 5.4 – 5.4.3, Homework #4 – Due Wed. Dec. 1 Chapter 4: Problem # 23, 29 Chapter 5: Problem # 24