Avishai Wool lecture Introduction to Systems Programming Lecture 8 Input-Output
Avishai Wool lecture Devices, Controllers, and I/O Architectures
Avishai Wool lecture I/O Device Types Block Devices –block size of bytes –block can be read/written individually –typical: disks / floppy / CD Character Devices –delivers / accepts a sequential stream of characters –non-addressable –typical: keyboard, mouse, printer, network Other: Monitor, Clock
Avishai Wool lecture Typical Data Rates
Avishai Wool lecture 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
Avishai Wool lecture Communicating with Controllers Controllers have registers to deliver data, accept data, etc. Option 1: special I/O commands, I/O ports in r0, 4 “4” is not memory address 4, it is I/O port 4 Option 2: I/O registers mapped to memory addresses
Avishai Wool lecture Memory-Mapped Registers Controller connected to the bus Has a physical “memory address” like B When this address appears on the bus, the controller responds (read/write to its I/O register) RAM configured to ignore controller’s address
Avishai Wool lecture Possible I/O Register Mappings Separate I/O and memory space (IBM 360) Memory-mapped I/O (PDP-11) Hybrid (Pentium, 640K-1M are for I/O)
Avishai Wool lecture Advantages of Memory Mapped I/O No special instructions, can be written in C. Protection by not putting I/O memory in user virtual address space. All machine instructions can access I/O: LOOP: test *b // check if port_4 is 0 beq READY branch LOOP READY:...
Avishai Wool lecture Disadvantages of Memory Mapped I/O Memory and I/O controllers have to be on the same bus: –modern architectures have separate memory bus! –Pentium has 3 buses: memory, PCI, ISA
Avishai Wool lecture Bus Architectures (a) A single-bus architecture (b) A dual-bus memory architecture
Avishai Wool lecture Memory Mapped with Separate Bus I/O Controllers do not see memory bus. Option 1: all addresses to memory bus. No response I/O bus Option 2: Snooping device between buses –speed difference is a problem Option 3 (Pentium): filter addresses in PCI bridge
Avishai Wool lecture Structure of a large Pentium system
Avishai Wool lecture Principles of I/O Software
Avishai Wool lecture Goals of I/O Software 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
Avishai Wool lecture 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
Avishai Wool lecture How is I/O Programmed Programmed I/O Interrupt-driven I/O DMA (Direct Memory Access)
Avishai Wool lecture Programmed I/O Steps in printing a string
Avishai Wool lecture Polling Busy-waiting until device can accept another character Example assumes memory- mapped registers
Avishai Wool lecture Properties of Programmed I/O Simple to program Ties up CPU, especially if device is slow
Avishai Wool lecture Interrupts Revisited bus
Avishai Wool lecture Interrupt-Driven I/O Code executed when print system call is made Interrupt service procedure
Avishai Wool lecture Properties of Interrupt-Driven I/O Interrupt every character or word. Interrupt handling takes time. Makes sense for slow devices (keyboard, mouse) For fast device: use dedicated DMA controller –usually for disk and network.
Avishai Wool lecture Direct Memory Access (DMA) DMA controller has access to bus. Registers: –memory address to write/read from –byte count –I/O port or mapped-memory address to use –direction (read from / write to device) –transfer unit (byte or word)
Avishai Wool lecture Operation of a DMA transfer
Avishai Wool lecture I/O Using DMA code executed when the print system call is made interrupt service procedure
Avishai Wool lecture DMA with Virtual Memory Most DMA controllers use physical addresses What if memory of buffer is paged out during DMA transfer? Force the page to not page out (“pinning”)
Avishai Wool lecture Burst or Cycle-stealing DMA controller grabs bus for one word at a time, it competes with CPU bus access. This is called “cycle-stealing”. In “burst” mode the DMA controller acquires the bus (exclusively), issues several transfers, and releases. –More efficient –May block CPU and other devices
Avishai Wool lecture Concepts for review TLB Local/Global page replacement Demand paging Page-fault-frequency monitor I/O device controller in/out commands Memory-mapped registers PCI Bridge Programmed I/O (Polling) Interrupt-driven I/O I/O using DMA Page pinning DMA cycle-stealing DMA burst mode