Summary

This document is a presentation on Input/Output (I/O) systems. It covers various aspects of I/O systems, including their components, hardware interfacing, communication methods, and software layers. The presentation includes detailed explanations and diagrams.

Full Transcript

(Part 1) I/O Systems Based on: - Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639 - Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-1...

(Part 1) I/O Systems Based on: - Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639 - Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8 I/O systems The two main jobs of a computer are I/O and processing. Hence, I/O is an essential part of an operating system. The largest, most complex subsystem in OS Most lines of code Highest rate of code changes Where OS engineers most likely to work Difficult to test thoroughly Make-or-break issue for any system Big impact on performance and perception Bigger impact on acceptability in market I/O devices Widely vary in their types and characteristics, hence their interfacing within the OS. Block devices Character devices I/O-device technology exhibits two conflicting trends. Increasing standardization of software and hardware interfaces. Increasingly broad variety of I/O devices. Hardware Ports Buses Device controllers Software Device drivers present a uniform device-access interface to the I/O subsystem, Modern I/O Systems Slide from Kubiatowichz I/O Hardware ⚫ General Categories ⚫ Storage devices (disks, tapes), ⚫ Transmission devices (network cards, modems), ⚫ Human-interface devices (screen, keyboard, mouse), ⚫ Specialized devices I/O Devices: Hardware interfacing Interfacing medium Wired Wireless Interfacing Components Port: one device can be connected (e.g. serial port) Bus: More than one device Device controller How does CPU communicate with the control registers and the device data buffers? Controller has registers which OS can write and read Write- gives command to device Read- learn device status…… Devices have data buffer which OS can read/write How does CPU communicate with registers and buffers? (a) Separate I/O ports and memory space. (b) Memory-mapped I/O. (c) Memory mapped data buffers and separate ports (Hybrid) I/O ports I/O Ports are memory addresses used by the processor for direct Device controller communication with a device that has sent an interrupt signal to the status processor. The exchange of commands Device driver command or data between the processor and OS data-in the device takes place through the I/O port address of the device, which is a data-out hexadecimal number. No two devices can share the same I/O port. I/O ports An I/O port typically consists of four registers, Status register contains bits that can be read by Device the host. controller These bits indicate states such as whether the current command has completed, whether a byte status is available to be read from the data-in register, Device driver and whether there has been a device error. command Control register can be written by the host OS to start a command or data-in to change the mode of a device. data-out Data-in register is read by the host to get input. Data-out register is written by the host to send output. I/O ports Advantages: The whole system is smaller and less complicated. This method works faster due to lesser delays. Disadvantages: More instructions are required to complete the same task (compared to mapped memory) Less powerful and flexible Memory-Mapped I/O The processor treats the I/O devices like any other memory location. The I/O devices are efficiently mapped into the system memory along with the RAM and ROM memory. A user can use the same instruction commands for data transfer to/from an I/O as they use for memory. (a) A single-bus architecture. (b) A dual-bus memory architecture. Memory-Mapped I/O o Advantages: o Don’t need special instructions to read/write control registers=> can write a device driver in C o Don’t need special protection to keep users from doing I/O directly. Just don’t put I/O memory in any user space o Separate control signals are not required since there is no switching between two different address spaces. o Disadvantages o I/O devices and memory have to respond to memory references o Works with single bus because both memory and I/O look at address on bus and decide who it is for o harder with multiple buses o But the new trend: multiple buses, so we need solutions o One solution is for CPU to try memory first. If it does not get a response, then it tries I/O device Methods of transferring data between CPU and device Programmed I/O (PIO) Interrupt driven I/O Direct Memory Access (DMA) PIO Each input is read after first testing whether the device is ready with the input Each output written after first testing whether the device is ready to accept the byte(s) at its output register or output buffer is empty Input read by the processor in programmed I/O mode The program waits for the ready status by repeatedly testing the status bit(s) and till all targeted bytes are read from the input device Output write in Programmed I/O mode The program waits for the ready status by repeatedly testing the status bit(s) and till all the targeted bytes are written to the device Programmed I/O (1) Steps in printing a string. Programmed I/O (2) Writing a string to the printer using programmed I/O. + and – of PIO +: A program and processor dedicated to wait and repeatedly tests the status and for IO data transfer till the IO operation completes - : A program has to wait and repeatedly tests the status; Waiting period for an asynchronous event can be too large Many I/O devices generate asynchronous events— events that occur at times that the processor cannot predict or control, but which the processor must respond to reasonably quickly to provide acceptable performance Exp: The processor cannot predict when the user will press a key with the keyboard but must react to the key-press in well under a second or the response time will be noticeable to the user The programmed I/O mode therefore not appropriate due to prolonged wait states Methods of transferring data between CPU and device programmed I/O (PIO) Interrupt driven IO Direct Memory Access (DMA) Programmed-driven I/O means the program is polling or checking some hardware item e.g. mouse within a loop. For Interrupt driven I/O, the same mouse will trigger a signal to the program to process the mouse event. Interrupts Revisited How an interrupt happens. The connections between the devices and the interrupt controller actually use interrupt lines on the bus rather than dedicated wires. I/O interfacing: Interrupts CPU hardware has a wire called the interrupt-request line that the CPU senses after executing every instruction. Upon interrupt, the CPU saves a small amount of state, such as the current value of the instruction pointer, and jumps to the interrupt-handler routine at a fixed address in memory. interrupt handler determines the cause of the interrupt, performs the necessary processing, and executes a return from interrupt instruction to return the CPU to the execution state prior to the interrupt. Direct Memory Access For a device that does large transfers, such as a disk drive, it seems wasteful to use an expensive general-purpose processor to watch status bits and to feed data into a controller register 1 byte at a time—a process termed Programmed I/O (PIO) Avoid burdening the main CPU with PIO by offloading some of this work to a special-purpose processor called a direct-memory- access (DMA) controller. Direct Memory Access To initiate a DMA transfer, the host writes a DMA command block into memory. a pointer to the source of a transfer, a pointer to the destination of the transfer, and a count of the number of bytes to be transferred. The CPU writes the address of this command block to the DMA controller, then goes on with other work. The DMA controller proceeds to operate the memory bus directly, placing addresses on the bus to perform transfers without the help of the main CPU. A simple DMA controller is a standard component in PCs, and bus-mastering I/O boards for the PC usually contain their own high- speed DMA hardware Operation of DMA Operation of DMA Why buffer data in controllers? Can do check-sum Bus may be busy-need to store data someplace Is DMA really worth it? Not if CPU is much faster then DMA controller and can do the job faster don’t have too much data to transfer I/O using DMA Printing a string using DMA. (a) Code executed when the print system call is made. (b) Interrupt service procedure. (Part 2) Input / Output Based on: - Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639 - Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8 I/O Software Layers Layers of the I/O software system. Interrupt Handlers The idea: driver starting the I/O blocks until interrupt happens when I/O finishes Handler processes interrupt Wakes up driver when processing is finished Drivers are kernel processes Device Drivers Device Drivers Driver contains code specific to the device Supplied by manufacturer Installed in the kernel User space might be better place Why? Bad driver can mess up kernel Checks input parameters for validity Check device status. Might have to start it. Puts commands in device controller’s registers Driver blocks itself until interrupt arrives Does return status information Device-Independent I/O Software Functions done in the device independent software: Why the OS needs a standard interface Without a standard driver interface. With a standard driver interface. Driver functions differ for different drivers Kernel functions which each driver needs are different for different drivers Too much work to have new interface for each new device type Std Interface:Driver functions To achieve b): OS defines functions for each class of devices which it MUST supply, e.g. read, write, turn on, turn off…….. Driver has a table of pointers to functions OS just needs table address to call the functions OS maps symbolic device names onto the right driver Another aspect of having a uniform interface is how I/O devices are named Interface:Names and protection OS maps symbolic device names onto the right driver Unix: /dev/disk0 maps to an i-node which contains the major and minor device numbers for disk0 Major device number locates driver, minor device number passes parameters (e.g. disk) Protection: How does the system prevent users from accessing devices that they are not entitled to access? In Unix and Windows devices appear as named objects => can use file protection system → the usual protection rules for files also apply to I/O devices Buffering (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. Buffering Exp: a process that wants to read data from a modem a) unbuffered: process does a read system call and block waiting for one character. Each arriving character causes an interrupt → process has to be started up for every incoming character (not efficient) b) Buffering in user space: The interrupt service procedure puts incoming characters in this buffer until it fills up. Then it wakes up the user process. more efficient but what happens if the buffer is paged out when a character arrives? Buffering c) Buffering in the kernel: what happens when a character arrives while copying the buffer? d) Double buffering: Characters goes to buffer 2 when buffer 1 is full More Functions of Independent Software Error reporting-programming errors (the user asks for the wrong thing), hardware problems (bad disk) are reported if they can’t be solved by the driver Allocates and releases devices which can only be used by one user at a time (CD-ROM players) User Space I/O Software Library routines are involved with I/O - printf, scanf for example. These routines makes system calls Spooling systems-keep track of device requests made by users. Think printing. User generates file, puts it in a spooling directory. Daemon process monitors the directory, printing the user file File transfers also use a spooling directory Summary of I/O system Clock Clock Hardware A programmable clock. Clock Software Typical duties of a clock driver 1. Maintaining the time of day. 2. Preventing processes from running longer than they are allowed to. 3. Accounting for CPU usage. 4. Handling alarm system call made by user processes. 5. Providing watchdog timers for parts of the system itself. 6. Doing profiling, monitoring, statistics gathering.

Use Quizgecko on...
Browser
Browser