1 / 27

Input/Output I cs423

Input/Output I cs423. Klara Nahrstedt/Sam King. Administrative. MP3 is out Page Replacement – FIFO and Second Chance Start early Deadline November 5, 2007 (Monday, 8am) Re-grading of HW1 and Midterm is still going on for online-Internet students

kayleen
Télécharger la présentation

Input/Output I cs423

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Input/Output I cs423 Klara Nahrstedt/Sam King

  2. Administrative • MP3 is out • Page Replacement – FIFO and Second Chance • Start early • Deadline November 5, 2007 (Monday, 8am) • Re-grading of HW1 and Midterm is still going on for online-Internet students • On-campus students should pick up their midterms from Kenton’s office • Online-Internet students should have received scanned HW1 and Midterm on Friday

  3. Overview • Basic I/O hardware • ports, buses, devices and controllers • I/O Software • Interrupt Handlers, Device Driver, Device-Independent Software, User-Space I/O Software • Real I/O devices • Disks, Character-Oriented Terminals, Graphical User Interfaces, Network Terminals,

  4. Devices • Devices • Storage devices (disk, tapes) • Transmission devices (network card, modem) • Human interface devices (screen, keyboard, mouse) • Specialized device (joystick)

  5. Device-Computer/Device-Device Communication • Physically: via signals over a cable or through air • Logically: via a connection point - port (e.G., Serial port) • Multiple devices are connected via a bus • A common set of wires and a rigidly defined protocol that specifies a set of messages that can be sent on the wires

  6. Device I/O Controller • I/O units typically consist of • mechanical component (device itself) • electronic component (device controller/adapter, e.g., circuit board). • Example : Disk controller • implements the disk side of the protocol that does: bad error mapping, prefetching, buffering, caching • Converts the serial bit stream, coming off the drive into a block of bytes, • Performs error correction • Assembles block of bytes in a buffer • Verifies checksum • Copies error-free block to main memory. • Controller components • registers for data and control • Communication protocol between CPU and controllers via I/O instructions and registers

  7. I/O Ports • 4 registers - status, control, data-in, data-out • Status - states whether the current command is completed, byte is available, device has an error, etc • Control - host determines to start a command or change the mode of a device • Data-in - host reads to get input • Data-out - host writes to send output • Size of registers - 1 to 4 bytes

  8. Interrupt-Driven I/O (Host-controller interface) • CPU hardware has the interrupt report line that the CPU senses after executing every instruction • device raises an interrupt • CPU catches the interrupt and saves the state (e.g., Instruction pointer) • CPU dispatches the interrupt handler • interrupt handler determines cause, services the device and clears the interrupt • Why interrupts?

  9. Support for Interrupts • Need the ability to defer interrupt handling during critical processing • CPUs have two interrupt request lines • non-maskable interrupt (reserved for unrecoverable memory errors) • maskable interrupt (can be turned off by cpus before the execution of critical instructions • Need efficient way to dispatch the proper device • Interrupt comes with an address (offset in interrupt vector) that selects a specific interrupt handling • Need multilevel interrupts - interrupt priority level • Need interrupt handler • At boot time, OS probes the hardware buses to determine what devices are present and installs corresponding interrupt handlers into the interrupt vector

  10. Direct Memory Access (DMA) • Programmed I/O (PIO) • use CPU to watch status bits and feed data into a controller register 1 byte at a time - EXPENSIVE for large transfers • Direct memory access (DMA) • use a special purpose processor, called a DMA controller

  11. Direct Memory Access (DMA) DMA controller feeds the characters to disk one at the time, without CPU being bothered. DMA is actually the programmed IO, only with DMA controller doing the work. What are the issues with DMA?

  12. DMA Issues • Handshaking between DMA controller and the device controller • Cycle stealing • DMA controller takes away CPU cycles when it uses CPU memory bus, hence blocks the CPU from accessing the memory • In general DMA controller improves the total system performance

  13. Memory-Mapped I/O (1) • (a) Separate I/O and memory space • (b) Memory-mapped I/O • ( c) Hybrid

  14. Memory-Mapped I/O (2) (a) A single-bus architecture (b) A dual-bus memory architecture

  15. Programming I/O Hardware • Principles of I/O Hardware • Programmers look at the hardware as the interface to the software – • the commands the hardware accepts, • the functions it carries out, and • the errors that it reports back • We consider programming of I/O devices, not building them in this class • However, I/O devices are closely connected with their internal operations hence we need to understand at least some of the basic principles

  16. Programmed I/O • Three ways to perform I/O • Interrupt-driven IO • IO using DMA • programmed IO. • Every IO operation is programmed and controlled. • Example: printing a file from user program to the printer means that data is first copied to the kernel, then the OS enters a tight loop outputting the characters one at a time. • Essential aspect of programmed IO is that the CPU continuously polls the device to see if it is ready to accept another character. It uses polling (or busy waiting) behavior. • Programmed IO is simple but required CPU full time until all the IO is done.

  17. Host-Controller Interface: Polling • Consider a producer-consumer relation between controller and host • Controller indicates through busy bit (status bit) if it is busy to work or not • Host signals its wishes via command-ready bit (command register) • Polling behavior

  18. Handshaking Protocol for Host-to-Device Writing • Host reads busy bit (poll) until bit is clear • Host sets write bit in command register and writes byte into the data-out register • Host sets the command-ready bit in command register • When controller notices command-ready bit, it sets busy bit and starts to work • Controller reads the command register and sees the write command. It reads data-out and performs I/O • Controller clears the command-ready bit, error bit and busy bit

  19. Tradeoffs • Interrupt-driven IO: • Pro: save CPU time for busy polling • Con: triggering interrupt takes time, too. • Programmed I/O • Pro: require no interrupt or DMA support • Con: waste CPU time • I/O using DMA: • Pro: relieve CPU from I/O operation • Con: DMA is slower than CPU

  20. Device Classification • Character-stream or block devices • Sequential or random access devices • Synchronous or asynchronous devices • Sharable or dedicated devices • Speed of operation • WO, RO, RW devices

  21. Block Devices • Block device - transfers blocks of data (e.G., Disk device) • Commands: read, write, seek (if random access device) • Memory-mapped files access can be layered on top of block-device drivers

  22. Character Devices • Character device - transfers byte by byte (e.G., Keyboard) • Commands: get, put one character • Libraries can built on top of this device which provide line-at-a time access with buffering and editing services, etc • Can block device be implemented using character device?

  23. Network Devices • Network socket interface • Commands; create socket, connect local socket to remote address, select information from a socket • Other interfaces: half-duplex pipes, full-duplex fifos, message queues, sockets (UNIX)

  24. I/O Software: Principles • device independence • possible to write programs that can access any IO device without having to specify the device in advance. • read file as input on a floppy, hard disk, or CD-ROM, without modifying the program for each device • uniform naming • the name of a file or a device should simply be a string or an integer and not depend on the device in any way • Example: In Unix all files and devices are addressed the same way by a path name. • Synchronous (blocking) vs asynchronous (interrupt-driven) transfers • Example: most devices are asynchronous. User programs are easier to write if the IO operations are synchronous. Hence, it is up to OS to make asynchronous operations look like synchronous to the user programs.

  25. Principles (cont.) • Buffering • data might need to be buffered because they might not be stored immediately • Example: Network packets come in off the network, and need to be buffered for protocol processing, audio buffering between audio speakers and network. • shared vs dedicated devices • allowing for sharing, considering two users having open files on the same device, or allowing dedicated devices and deal with deadlock problems. • Example: Disk, audio devices.

  26. I/O Software Layers of the I/O system and the main functions of each layer

  27. I/O Software Layer: Principle • Interrupts are facts of life, but should be hidden away, so that as little of the OS as possible knows about them. • The best way to hide interrupts is to have the driver starting an IO operation block until IO has completed and the interrupt occurs. • When interrupt happens, the interrupt handler handles the interrupt. • Once the handling of interrupt is done, the interrupt handler unblocks the device driver that started it. • This model works if drivers are structures as kernel processes with their own states, stacks and program counters.

More Related