1 Input / Output. Today: I/O Systems How does I/O hardware influence the OS? What I/O services does the OS provide? How does the OS implement those services?

Slides:



Advertisements
Similar presentations
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Advertisements

Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 13: I/O Systems I/O Hardware Application I/O Interface.
04/14/2008CSCI 315 Operating Systems Design1 I/O Systems Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem.
Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Jan 2, 2005 Chapter 13: I/O Systems I/O Hardware.
I/O Hardware n Incredible variety of I/O devices n Common concepts: – Port – connection point to the computer – Bus (daisy chain or shared direct access)
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.
04/16/2010CSCI 315 Operating Systems Design1 I/O Systems Notice: The slides for this lecture have been largely based on those accompanying an earlier edition.
I/O Systems CS 3100 I/O Hardware1. I/O Hardware Incredible variety of I/O devices Common concepts ◦Port ◦Bus (daisy chain or shared direct access) ◦Controller.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
CHAPTER 9: Input / Output
1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers.
I/O Systems CSCI 444/544 Operating Systems Fall 2008.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Copyright ©: Nahrstedt, Angrave, Abdelzaher
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
Input/Output. Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower.
CHAPTER 13: I/O SYSTEMS Overview Overview I/O Hardware I/O Hardware I/O API I/O API I/O Subsystem I/O Subsystem Transforming I/O Requests to Hardware Operations.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
1 Computer System Overview Chapter 1. 2 n An Operating System makes the computing power available to users by controlling the hardware n Let us review.
CHAPTER 9: Input / Output
NETW 3005 I/O Systems. Reading For this lecture, you should have read Chapter 13 (Sections 1-4, 7). NETW3005 (Operating Systems) Lecture 10 - I/O Systems2.
Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Jan 2, 2005 Chapter 13: I/O Systems I/O Hardware.
MICROPROCESSOR INPUT/OUTPUT
Hardware Definitions –Port: Point of connection –Bus: Interface Daisy Chain (A=>B=>…=>X) Shared Direct Device Access –Controller: Device Electronics –Registers:
ITEC 502 컴퓨터 시스템 및 실습 Chapter 8-2: I/O Management (Review) Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 AE4B33OSS Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O.
I/O Systems I/O Hardware Application I/O Interface
1 Lecture 20: I/O n I/O hardware n I/O structure n communication with controllers n device interrupts n device drivers n streams.
CHAPTER 3 TOP LEVEL VIEW OF COMPUTER FUNCTION AND INTERCONNECTION
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
I/O management is a major component of operating system design and operation Important aspect of computer operation I/O devices vary greatly Various methods.
Chapter 13: I/O Systems. 13.2/34 Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests to Hardware.
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
Fall 2000M.B. Ibáñez Lecture 25 I/O Systems. Fall 2000M.B. Ibáñez Categories of I/O Devices Human readable –used to communicate with the user –video display.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem.
Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 13: I/O Systems I/O Hardware Application I/O Interface.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 4 Computer Systems Review.
Silberschatz, Galvin and Gagne  Operating System Concepts Six Step Process to Perform DMA Transfer.
XE33OSA Chapter 13: I/O Systems. 13.2XE33OSA Silberschatz, Galvin and Gagne ©2005 Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel.
CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Jan 2, 2005 Chapter 13: I/O Systems I/O Hardware.
Lecture 1: Review of Computer Organization
Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower than CPU.
Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 13: I/O Systems Overview I/O Hardware Application.
Review of Computer System Organization. Computer Startup For a computer to start running when it is first powered up, it needs to execute an initial program.
بسم الله الرحمن الرحيم MEMORY AND I/O.
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 12: I/O Systems I/O hardwared Application I/O Interface Kernel I/O.
CMSC 421 Section 0202 I/O Systems Chapter 13: I/O Systems.
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
Part IVI/O Systems Chapter 13: I/O Systems. I/O Hardware a typical PCI bus structure 2.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Chapter 13: I/O Systems.
Module 12: I/O Systems I/O hardware Application I/O Interface
Chapter 13: I/O Systems Modified by Dr. Neerja Mhaskar for CS 3SH3.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
CSCI 315 Operating Systems Design
I/O Systems I/O Hardware Application I/O Interface
Operating Systems Chapter 5: Input/Output Management
Operating System Concepts
13: I/O Systems I/O hardwared Application I/O Interface
CS703 - Advanced Operating Systems
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Chapter 13: I/O Systems.
Module 12: I/O Systems I/O hardwared Application I/O Interface
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

1 Input / Output

Today: I/O Systems How does I/O hardware influence the OS? What I/O services does the OS provide? How does the OS implement those services? How can the OS improve the performance of I/O? 2

Architecture of I/O Systems Key components System bus: allows the device to communicate with the CPU, typically shared by multiple devices. A device port typically consisting of 4 registers: Status indicates a device busy, data ready, or error condition Control: command to perform Data-in: data being sent from the device to the CPU Data-out: data being sent from the CPU to the device Controller: receives commands from the system bus, translates them into device actions, and reads/writes data onto the system bus. The device itself Traditional devices: disk drive, printer, keyboard, modem, mouse, display Non-traditional devices: joystick, robot actuators, flying surfaces of an airplane, fuel injection system of a car,... 3

PCI Bus Structure 4

Kernel I/O Subsystem 5

Device I/O Port location on PCs 6

I/O Services Provided by OS Naming of files and devices. (On Unix, devices appear as files in the /dev directory) Access control. Operations appropriate to the files and devices. Device allocation. Buffering, caching, and spooling to allow efficient communication with devices. I/O scheduling. Error handling and failure recovery associated with devices (command retries, for example). Device drivers to implement device-specific behaviors. 7

Communication using Polling CPU busy-waits until the status is idle. CPU sets the command register and data-out if it is an output operation. CPU sets status to command-ready => controller sets status to busy. Controller reads the command register and performs the command, placing a value in data-in if it is an input command. If the operation succeeds, the controller changes the status to idle. CPU observes the change to idle and reads the data if it was an input operation. Good choice if data must be handled promptly, like for a modem or keyboard. What happens if the device is slow compared to the CPU? 8

Communication using Interrupts Rather than using busy waiting, the device can interrupt the CPU when it completes an I/O operation. On an I/O interrupt: Determine which device caused the interrupt. If the last command was an input operation, retrieve the data from the device register. Start the next operation for that device. 9

Interrupts 10 An interrupt is a change in the flow that is external to the program. Typically the interrupt is related to an I/O event. A CPU has an input line (INT) that allows I/O devices to interrupt the CPU. A CPU has an output line (INTA) that acknowledges interrupts. I/O device can interrupt processor when: – data is available to transfer – I/O request is complete

Interrupts: Basic Flow I/O device triggers CPU interrupt request line. 2. CPU receives interrupt. 3. CPU suspends current process to execute code to handle the interrupt.

Processing Interrupts The device controller asserts an interrupt line.

Processing Interrupts Once the CPU is ready to handle the interrupt, it will acknowledge the interrupt on the bus.

Processing Interrupts Upon seeing the acknowledgment, the device controller will put a small integer on the system bus data lines. This integer, called the interrupt vector, corresponds to the type of interrupt.

Processing Interrupts CPU temporarily saves the interrupt vector from the bus. 5. CPU will save the current values of PC and other inaccessible system registers (such as the status word) on the stack.

Processing Interrupts CPU uses the interrupt vector as an index the interrupt vector table stored in memory. The interrupt vector table stores the starting addresses of interrupt service routines.

Processing Interrupts Jump to the interrupt service routine. Different interrupt vectors (corresponding to different interrupt types) will jump to different interrupt service routines.

Processing Interrupts Once the interrupt service routine is completed, it must execute a special "return from interrupt" instruction. This instruction restores the saved values of PC and system registers (saved in step 5) and resumes execution of the program where it left off.

Interrupt Service Routine 19 An interrupt service routine for I/O devices does the following: 1. Save all the registers on the stack. 2. Execute I/O device code. This will involve code from the device driver. 3. Restore the registers. 4. Return to original process (where it left off).

Interrupts - Issues 20 Handling multiple interrupts at once. Interrupt vector table is prioritized. Interrupt priority levels: lower levels are automatically disabled when servicing higher priority interrupts. I/O controllers may also resolve cases where multiple I/O devices want to interrupt the CPU. Need to defer interrupt handling during critical processing. – Temporarily enable and disable all interrupts. – Maskable interrupts can be turned off and on individually. – Some interrupts are not maskable (used for unrecoverable errors).

Handling Interrupts in the CPU 21 Interrupts can occur at any time without advance notice. Need to check for interrupts before starting every instruction. In a pipelined implementation, squash all instructions still in the pipeline. FetchExecute Decode Interrupt Handler int = N int = Y

Traps 22 A trap is similar to a interrupt but is caused by an abnormal execution of an instruction. A trap is also called an exception or a fault. Examples of situations that cause traps: Overflow and underflow conditions Divide by zero errors Invalid memory access Illegal instruction Non-existent I/O device

Traps and Interrupts 23 When a trap occurs, flow transfers to a trap handler specific to the situation that caused the trap. trap handler = interrupt service routine Systems use the same interrupt mechanism to handle traps and interrupts. Key difference between traps and interrupts: Traps are synchronous: occur at a well-defined point in the program. Interrupts are asynchronous: occur unexpectedly with respect to ongoing activity of the system.

Intel Pentium Event Vectors 24

Revisiting Interrupt-Driven I/O 25 Advantages: CPU can do useful work while waiting for I/O data. Can be modified to accommodate hardware changes. Can use interrupt mechanism to handle traps and unexpected events. Disadvantages: CPU still heavily involved in I/O operations. Complexity / overhead in suspending / resuming the program.

Direct Memory Access For devices that transfer large volumes of data at a time (like a disk block), it is expensive to have the CPU retrieve these one byte at a time. Solution: Direct memory access (DMA) Use a sophisticated DMA controller that can write directly to memory. Instead of data-in/data-out registers, it has an address register. The CPU tells the DMA the locations of the source and destination of the transfer. The DMA controller operates the bus and interrupts the CPU when the entire transfer is complete, instead of when each byte is ready. The DMA controller and the CPU compete for the memory bus, slowing down the CPU somewhat, but still providing better performance than if the CPU had to do the transfer itself. 26

Steps in DMA transfer 27

Application Programmer's View of I/O Devices The OS provides a high-level interface to devices, greatly simplifying the programmer's job. Standard interfaces are provided for related devices. Device dependencies are encapsulated in device drivers. New devices can be supported by providing a new device driver. Device characteristics: Transfer unit: character or block Access method: sequential or random access Timing: synchronous or asynchronous. Most devices are asynchronous, while I/O system calls are synchronous => The OS implements blocking I/O Sharable or dedicated Speed Operations: Input, output, or both Examples: keyboard (sequential, character), disk (block, random or sequential) 28

Examples of I/O Device types 29

Block and Character devices Block devices include disk drives Commands include read, write, seek Raw I/O or file-system access Memory-mapped file access possible Character devices include keyboards, mice, serial ports Commands include get, put Libraries layered on top allow line editing 30

I/O Buffering I/O devices typically contain a small on-board memory where they can store data temporarily before transferring to/from the CPU. A disk buffer stores a block when it is read from the disk. It is transferred over the bus by the DMA controller into a buffer in physical memory. The DMA controller interrupts the CPU when the transfer is done. 31

Why buffer on the OS side? To cope with speed mismatches between device and CPU. Example: Compute the contents of a display in a buffer (slow) and then zap the buffer to the screen (fast) To cope with devices that have different data transfer sizes. Example: ftp brings the file over the network one packet at a time. Stores to disk happen one block at a time. To minimize the time a user process is blocked on a write. Writes => copy data to a kernel buffer and return control to the user program. The write from the kernel buffer to the disk is done later. 32

Caching Improve disk performance by reducing the number of disk accesses. Idea: keep recently used disk blocks in main memory after the I/O call that brought them into memory completes. Example: Read (diskAddress) If (block in memory) return value from memory Else ReadSector(diskAddress) Example: Write (diskAddress) If (block in memory) update value in memory Else Allocate space in memory, read block from disk, and update value in memory What should happen when we write to a cache? write-through policy (write to all levels of memory containing the block, including to disk). High reliability. write-back policy (write only to the fastest memory containing the block, write to slower memories and disk sometime later). Faster. 33

Putting the Pieces Together - a Typical Read Call 1. User process requests a read from a device. 2. OS checks if data is in a buffer. If not, a) OS tells the device driver to perform input. b) Device driver tells the DMA controller what to do and blocks itself. c) DMA controller transfers the data to the kernel buffer when it has all been retrieved from the device. d) DMA controller interrupts the CPU when the transfer is complete. 3. OS transfers the data to the user process and places the process in the ready queue. 4. When the process gets the CPU, it begins execution following the system call. 34

I/O request Lifecycle 35

Summary I/O is expensive for several reasons: Slow devices and slow communication links Contention from multiple processes. I/O is typically supported via system calls and interrupt handling, which are slow. Approaches to improving performance: Reduce data copying by caching in memory Reduce interrupt frequency by using large data transfers Offload computation from the main CPU by using DMA controllers. Increase the number of devices to reduce contention for a single device and thereby improve CPU utilization. Increase physical memory to reduce amount of time paging and thereby improve CPU utilization. 36

37 Thank You!